Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel(R) Gigabit Ethernet Linux driver |
Alexander Duyck | 86d5d38 | 2009-02-06 23:23:12 +0000 | [diff] [blame] | 4 | Copyright(c) 2007-2009 Intel Corporation. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/vmalloc.h> |
| 32 | #include <linux/pagemap.h> |
| 33 | #include <linux/netdevice.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 34 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 36 | #include <net/checksum.h> |
| 37 | #include <net/ip6_checksum.h> |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 38 | #include <linux/net_tstamp.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 39 | #include <linux/mii.h> |
| 40 | #include <linux/ethtool.h> |
| 41 | #include <linux/if_vlan.h> |
| 42 | #include <linux/pci.h> |
Alexander Duyck | c54106b | 2008-10-16 21:26:57 -0700 | [diff] [blame] | 43 | #include <linux/pci-aspm.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 44 | #include <linux/delay.h> |
| 45 | #include <linux/interrupt.h> |
| 46 | #include <linux/if_ether.h> |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 47 | #include <linux/aer.h> |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 48 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 49 | #include <linux/dca.h> |
| 50 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 51 | #include "igb.h" |
| 52 | |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 53 | #define DRV_VERSION "2.1.0-k2" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 54 | char igb_driver_name[] = "igb"; |
| 55 | char igb_driver_version[] = DRV_VERSION; |
| 56 | static const char igb_driver_string[] = |
| 57 | "Intel(R) Gigabit Ethernet Network Driver"; |
Alexander Duyck | 86d5d38 | 2009-02-06 23:23:12 +0000 | [diff] [blame] | 58 | static const char igb_copyright[] = "Copyright (c) 2007-2009 Intel Corporation."; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 59 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 60 | static const struct e1000_info *igb_info_tbl[] = { |
| 61 | [board_82575] = &e1000_82575_info, |
| 62 | }; |
| 63 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 64 | static DEFINE_PCI_DEVICE_TABLE(igb_pci_tbl) = { |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 65 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 }, |
| 66 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 }, |
| 67 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 }, |
| 68 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 }, |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 69 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 }, |
| 70 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 }, |
| 71 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 }, |
| 72 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 }, |
| 73 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 }, |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 74 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 }, |
Alexander Duyck | 9eb2341 | 2009-03-13 20:42:15 +0000 | [diff] [blame] | 75 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 }, |
Alexander Duyck | 747d49b | 2009-10-05 06:33:27 +0000 | [diff] [blame] | 76 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 }, |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 77 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 }, |
| 78 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 }, |
Alexander Duyck | 4703bf7 | 2009-07-23 18:09:48 +0000 | [diff] [blame] | 79 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 }, |
Carolyn Wyborny | b894fa2 | 2010-03-19 06:07:48 +0000 | [diff] [blame] | 80 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 }, |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 81 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 }, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 82 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 }, |
| 83 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 }, |
| 84 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 }, |
| 85 | /* required last entry */ |
| 86 | {0, } |
| 87 | }; |
| 88 | |
| 89 | MODULE_DEVICE_TABLE(pci, igb_pci_tbl); |
| 90 | |
| 91 | void igb_reset(struct igb_adapter *); |
| 92 | static int igb_setup_all_tx_resources(struct igb_adapter *); |
| 93 | static int igb_setup_all_rx_resources(struct igb_adapter *); |
| 94 | static void igb_free_all_tx_resources(struct igb_adapter *); |
| 95 | static void igb_free_all_rx_resources(struct igb_adapter *); |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 96 | static void igb_setup_mrqc(struct igb_adapter *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 97 | void igb_update_stats(struct igb_adapter *); |
| 98 | static int igb_probe(struct pci_dev *, const struct pci_device_id *); |
| 99 | static void __devexit igb_remove(struct pci_dev *pdev); |
| 100 | static int igb_sw_init(struct igb_adapter *); |
| 101 | static int igb_open(struct net_device *); |
| 102 | static int igb_close(struct net_device *); |
| 103 | static void igb_configure_tx(struct igb_adapter *); |
| 104 | static void igb_configure_rx(struct igb_adapter *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 105 | static void igb_clean_all_tx_rings(struct igb_adapter *); |
| 106 | static void igb_clean_all_rx_rings(struct igb_adapter *); |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 107 | static void igb_clean_tx_ring(struct igb_ring *); |
| 108 | static void igb_clean_rx_ring(struct igb_ring *); |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 109 | static void igb_set_rx_mode(struct net_device *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 110 | static void igb_update_phy_info(unsigned long); |
| 111 | static void igb_watchdog(unsigned long); |
| 112 | static void igb_watchdog_task(struct work_struct *); |
Alexander Duyck | b1a436c | 2009-10-27 15:54:43 +0000 | [diff] [blame] | 113 | static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 114 | static struct net_device_stats *igb_get_stats(struct net_device *); |
| 115 | static int igb_change_mtu(struct net_device *, int); |
| 116 | static int igb_set_mac(struct net_device *, void *); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 117 | static void igb_set_uta(struct igb_adapter *adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 118 | static irqreturn_t igb_intr(int irq, void *); |
| 119 | static irqreturn_t igb_intr_msi(int irq, void *); |
| 120 | static irqreturn_t igb_msix_other(int irq, void *); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 121 | static irqreturn_t igb_msix_ring(int irq, void *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 122 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 123 | static void igb_update_dca(struct igb_q_vector *); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 124 | static void igb_setup_dca(struct igb_adapter *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 125 | #endif /* CONFIG_IGB_DCA */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 126 | static bool igb_clean_tx_irq(struct igb_q_vector *); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 127 | static int igb_poll(struct napi_struct *, int); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 128 | static bool igb_clean_rx_irq_adv(struct igb_q_vector *, int *, int); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 129 | static int igb_ioctl(struct net_device *, struct ifreq *, int cmd); |
| 130 | static void igb_tx_timeout(struct net_device *); |
| 131 | static void igb_reset_task(struct work_struct *); |
| 132 | static void igb_vlan_rx_register(struct net_device *, struct vlan_group *); |
| 133 | static void igb_vlan_rx_add_vid(struct net_device *, u16); |
| 134 | static void igb_vlan_rx_kill_vid(struct net_device *, u16); |
| 135 | static void igb_restore_vlan(struct igb_adapter *); |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 136 | static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 137 | static void igb_ping_all_vfs(struct igb_adapter *); |
| 138 | static void igb_msg_task(struct igb_adapter *); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 139 | static void igb_vmm_control(struct igb_adapter *); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 140 | static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 141 | static void igb_restore_vf_multicasts(struct igb_adapter *adapter); |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 142 | static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac); |
| 143 | static int igb_ndo_set_vf_vlan(struct net_device *netdev, |
| 144 | int vf, u16 vlan, u8 qos); |
| 145 | static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate); |
| 146 | static int igb_ndo_get_vf_config(struct net_device *netdev, int vf, |
| 147 | struct ifla_vf_info *ivi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 148 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 149 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 150 | static int igb_suspend(struct pci_dev *, pm_message_t); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 151 | static int igb_resume(struct pci_dev *); |
| 152 | #endif |
| 153 | static void igb_shutdown(struct pci_dev *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 154 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 155 | static int igb_notify_dca(struct notifier_block *, unsigned long, void *); |
| 156 | static struct notifier_block dca_notifier = { |
| 157 | .notifier_call = igb_notify_dca, |
| 158 | .next = NULL, |
| 159 | .priority = 0 |
| 160 | }; |
| 161 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 162 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 163 | /* for netdump / net console */ |
| 164 | static void igb_netpoll(struct net_device *); |
| 165 | #endif |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 166 | #ifdef CONFIG_PCI_IOV |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 167 | static unsigned int max_vfs = 0; |
| 168 | module_param(max_vfs, uint, 0); |
| 169 | MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate " |
| 170 | "per physical function"); |
| 171 | #endif /* CONFIG_PCI_IOV */ |
| 172 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 173 | static pci_ers_result_t igb_io_error_detected(struct pci_dev *, |
| 174 | pci_channel_state_t); |
| 175 | static pci_ers_result_t igb_io_slot_reset(struct pci_dev *); |
| 176 | static void igb_io_resume(struct pci_dev *); |
| 177 | |
| 178 | static struct pci_error_handlers igb_err_handler = { |
| 179 | .error_detected = igb_io_error_detected, |
| 180 | .slot_reset = igb_io_slot_reset, |
| 181 | .resume = igb_io_resume, |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | static struct pci_driver igb_driver = { |
| 186 | .name = igb_driver_name, |
| 187 | .id_table = igb_pci_tbl, |
| 188 | .probe = igb_probe, |
| 189 | .remove = __devexit_p(igb_remove), |
| 190 | #ifdef CONFIG_PM |
| 191 | /* Power Managment Hooks */ |
| 192 | .suspend = igb_suspend, |
| 193 | .resume = igb_resume, |
| 194 | #endif |
| 195 | .shutdown = igb_shutdown, |
| 196 | .err_handler = &igb_err_handler |
| 197 | }; |
| 198 | |
| 199 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 200 | MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver"); |
| 201 | MODULE_LICENSE("GPL"); |
| 202 | MODULE_VERSION(DRV_VERSION); |
| 203 | |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 204 | struct igb_reg_info { |
| 205 | u32 ofs; |
| 206 | char *name; |
| 207 | }; |
| 208 | |
| 209 | static const struct igb_reg_info igb_reg_info_tbl[] = { |
| 210 | |
| 211 | /* General Registers */ |
| 212 | {E1000_CTRL, "CTRL"}, |
| 213 | {E1000_STATUS, "STATUS"}, |
| 214 | {E1000_CTRL_EXT, "CTRL_EXT"}, |
| 215 | |
| 216 | /* Interrupt Registers */ |
| 217 | {E1000_ICR, "ICR"}, |
| 218 | |
| 219 | /* RX Registers */ |
| 220 | {E1000_RCTL, "RCTL"}, |
| 221 | {E1000_RDLEN(0), "RDLEN"}, |
| 222 | {E1000_RDH(0), "RDH"}, |
| 223 | {E1000_RDT(0), "RDT"}, |
| 224 | {E1000_RXDCTL(0), "RXDCTL"}, |
| 225 | {E1000_RDBAL(0), "RDBAL"}, |
| 226 | {E1000_RDBAH(0), "RDBAH"}, |
| 227 | |
| 228 | /* TX Registers */ |
| 229 | {E1000_TCTL, "TCTL"}, |
| 230 | {E1000_TDBAL(0), "TDBAL"}, |
| 231 | {E1000_TDBAH(0), "TDBAH"}, |
| 232 | {E1000_TDLEN(0), "TDLEN"}, |
| 233 | {E1000_TDH(0), "TDH"}, |
| 234 | {E1000_TDT(0), "TDT"}, |
| 235 | {E1000_TXDCTL(0), "TXDCTL"}, |
| 236 | {E1000_TDFH, "TDFH"}, |
| 237 | {E1000_TDFT, "TDFT"}, |
| 238 | {E1000_TDFHS, "TDFHS"}, |
| 239 | {E1000_TDFPC, "TDFPC"}, |
| 240 | |
| 241 | /* List Terminator */ |
| 242 | {} |
| 243 | }; |
| 244 | |
| 245 | /* |
| 246 | * igb_regdump - register printout routine |
| 247 | */ |
| 248 | static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo) |
| 249 | { |
| 250 | int n = 0; |
| 251 | char rname[16]; |
| 252 | u32 regs[8]; |
| 253 | |
| 254 | switch (reginfo->ofs) { |
| 255 | case E1000_RDLEN(0): |
| 256 | for (n = 0; n < 4; n++) |
| 257 | regs[n] = rd32(E1000_RDLEN(n)); |
| 258 | break; |
| 259 | case E1000_RDH(0): |
| 260 | for (n = 0; n < 4; n++) |
| 261 | regs[n] = rd32(E1000_RDH(n)); |
| 262 | break; |
| 263 | case E1000_RDT(0): |
| 264 | for (n = 0; n < 4; n++) |
| 265 | regs[n] = rd32(E1000_RDT(n)); |
| 266 | break; |
| 267 | case E1000_RXDCTL(0): |
| 268 | for (n = 0; n < 4; n++) |
| 269 | regs[n] = rd32(E1000_RXDCTL(n)); |
| 270 | break; |
| 271 | case E1000_RDBAL(0): |
| 272 | for (n = 0; n < 4; n++) |
| 273 | regs[n] = rd32(E1000_RDBAL(n)); |
| 274 | break; |
| 275 | case E1000_RDBAH(0): |
| 276 | for (n = 0; n < 4; n++) |
| 277 | regs[n] = rd32(E1000_RDBAH(n)); |
| 278 | break; |
| 279 | case E1000_TDBAL(0): |
| 280 | for (n = 0; n < 4; n++) |
| 281 | regs[n] = rd32(E1000_RDBAL(n)); |
| 282 | break; |
| 283 | case E1000_TDBAH(0): |
| 284 | for (n = 0; n < 4; n++) |
| 285 | regs[n] = rd32(E1000_TDBAH(n)); |
| 286 | break; |
| 287 | case E1000_TDLEN(0): |
| 288 | for (n = 0; n < 4; n++) |
| 289 | regs[n] = rd32(E1000_TDLEN(n)); |
| 290 | break; |
| 291 | case E1000_TDH(0): |
| 292 | for (n = 0; n < 4; n++) |
| 293 | regs[n] = rd32(E1000_TDH(n)); |
| 294 | break; |
| 295 | case E1000_TDT(0): |
| 296 | for (n = 0; n < 4; n++) |
| 297 | regs[n] = rd32(E1000_TDT(n)); |
| 298 | break; |
| 299 | case E1000_TXDCTL(0): |
| 300 | for (n = 0; n < 4; n++) |
| 301 | regs[n] = rd32(E1000_TXDCTL(n)); |
| 302 | break; |
| 303 | default: |
| 304 | printk(KERN_INFO "%-15s %08x\n", |
| 305 | reginfo->name, rd32(reginfo->ofs)); |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]"); |
| 310 | printk(KERN_INFO "%-15s ", rname); |
| 311 | for (n = 0; n < 4; n++) |
| 312 | printk(KERN_CONT "%08x ", regs[n]); |
| 313 | printk(KERN_CONT "\n"); |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * igb_dump - Print registers, tx-rings and rx-rings |
| 318 | */ |
| 319 | static void igb_dump(struct igb_adapter *adapter) |
| 320 | { |
| 321 | struct net_device *netdev = adapter->netdev; |
| 322 | struct e1000_hw *hw = &adapter->hw; |
| 323 | struct igb_reg_info *reginfo; |
| 324 | int n = 0; |
| 325 | struct igb_ring *tx_ring; |
| 326 | union e1000_adv_tx_desc *tx_desc; |
| 327 | struct my_u0 { u64 a; u64 b; } *u0; |
| 328 | struct igb_buffer *buffer_info; |
| 329 | struct igb_ring *rx_ring; |
| 330 | union e1000_adv_rx_desc *rx_desc; |
| 331 | u32 staterr; |
| 332 | int i = 0; |
| 333 | |
| 334 | if (!netif_msg_hw(adapter)) |
| 335 | return; |
| 336 | |
| 337 | /* Print netdevice Info */ |
| 338 | if (netdev) { |
| 339 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
| 340 | printk(KERN_INFO "Device Name state " |
| 341 | "trans_start last_rx\n"); |
| 342 | printk(KERN_INFO "%-15s %016lX %016lX %016lX\n", |
| 343 | netdev->name, |
| 344 | netdev->state, |
| 345 | netdev->trans_start, |
| 346 | netdev->last_rx); |
| 347 | } |
| 348 | |
| 349 | /* Print Registers */ |
| 350 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
| 351 | printk(KERN_INFO " Register Name Value\n"); |
| 352 | for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl; |
| 353 | reginfo->name; reginfo++) { |
| 354 | igb_regdump(hw, reginfo); |
| 355 | } |
| 356 | |
| 357 | /* Print TX Ring Summary */ |
| 358 | if (!netdev || !netif_running(netdev)) |
| 359 | goto exit; |
| 360 | |
| 361 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
| 362 | printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]" |
| 363 | " leng ntw timestamp\n"); |
| 364 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 365 | tx_ring = adapter->tx_ring[n]; |
| 366 | buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean]; |
| 367 | printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n", |
| 368 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 369 | (u64)buffer_info->dma, |
| 370 | buffer_info->length, |
| 371 | buffer_info->next_to_watch, |
| 372 | (u64)buffer_info->time_stamp); |
| 373 | } |
| 374 | |
| 375 | /* Print TX Rings */ |
| 376 | if (!netif_msg_tx_done(adapter)) |
| 377 | goto rx_ring_summary; |
| 378 | |
| 379 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 380 | |
| 381 | /* Transmit Descriptor Formats |
| 382 | * |
| 383 | * Advanced Transmit Descriptor |
| 384 | * +--------------------------------------------------------------+ |
| 385 | * 0 | Buffer Address [63:0] | |
| 386 | * +--------------------------------------------------------------+ |
| 387 | * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN | |
| 388 | * +--------------------------------------------------------------+ |
| 389 | * 63 46 45 40 39 38 36 35 32 31 24 15 0 |
| 390 | */ |
| 391 | |
| 392 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 393 | tx_ring = adapter->tx_ring[n]; |
| 394 | printk(KERN_INFO "------------------------------------\n"); |
| 395 | printk(KERN_INFO "TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 396 | printk(KERN_INFO "------------------------------------\n"); |
| 397 | printk(KERN_INFO "T [desc] [address 63:0 ] " |
| 398 | "[PlPOCIStDDM Ln] [bi->dma ] " |
| 399 | "leng ntw timestamp bi->skb\n"); |
| 400 | |
| 401 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
| 402 | tx_desc = E1000_TX_DESC_ADV(*tx_ring, i); |
| 403 | buffer_info = &tx_ring->buffer_info[i]; |
| 404 | u0 = (struct my_u0 *)tx_desc; |
| 405 | printk(KERN_INFO "T [0x%03X] %016llX %016llX %016llX" |
| 406 | " %04X %3X %016llX %p", i, |
| 407 | le64_to_cpu(u0->a), |
| 408 | le64_to_cpu(u0->b), |
| 409 | (u64)buffer_info->dma, |
| 410 | buffer_info->length, |
| 411 | buffer_info->next_to_watch, |
| 412 | (u64)buffer_info->time_stamp, |
| 413 | buffer_info->skb); |
| 414 | if (i == tx_ring->next_to_use && |
| 415 | i == tx_ring->next_to_clean) |
| 416 | printk(KERN_CONT " NTC/U\n"); |
| 417 | else if (i == tx_ring->next_to_use) |
| 418 | printk(KERN_CONT " NTU\n"); |
| 419 | else if (i == tx_ring->next_to_clean) |
| 420 | printk(KERN_CONT " NTC\n"); |
| 421 | else |
| 422 | printk(KERN_CONT "\n"); |
| 423 | |
| 424 | if (netif_msg_pktdata(adapter) && buffer_info->dma != 0) |
| 425 | print_hex_dump(KERN_INFO, "", |
| 426 | DUMP_PREFIX_ADDRESS, |
| 427 | 16, 1, phys_to_virt(buffer_info->dma), |
| 428 | buffer_info->length, true); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | /* Print RX Rings Summary */ |
| 433 | rx_ring_summary: |
| 434 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
| 435 | printk(KERN_INFO "Queue [NTU] [NTC]\n"); |
| 436 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 437 | rx_ring = adapter->rx_ring[n]; |
| 438 | printk(KERN_INFO " %5d %5X %5X\n", n, |
| 439 | rx_ring->next_to_use, rx_ring->next_to_clean); |
| 440 | } |
| 441 | |
| 442 | /* Print RX Rings */ |
| 443 | if (!netif_msg_rx_status(adapter)) |
| 444 | goto exit; |
| 445 | |
| 446 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 447 | |
| 448 | /* Advanced Receive Descriptor (Read) Format |
| 449 | * 63 1 0 |
| 450 | * +-----------------------------------------------------+ |
| 451 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 452 | * +----------------------------------------------+------+ |
| 453 | * 8 | Header Buffer Address [63:1] | DD | |
| 454 | * +-----------------------------------------------------+ |
| 455 | * |
| 456 | * |
| 457 | * Advanced Receive Descriptor (Write-Back) Format |
| 458 | * |
| 459 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 460 | * +------------------------------------------------------+ |
| 461 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | |
| 462 | * | Checksum Ident | | | | Type | Type | |
| 463 | * +------------------------------------------------------+ |
| 464 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 465 | * +------------------------------------------------------+ |
| 466 | * 63 48 47 32 31 20 19 0 |
| 467 | */ |
| 468 | |
| 469 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 470 | rx_ring = adapter->rx_ring[n]; |
| 471 | printk(KERN_INFO "------------------------------------\n"); |
| 472 | printk(KERN_INFO "RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 473 | printk(KERN_INFO "------------------------------------\n"); |
| 474 | printk(KERN_INFO "R [desc] [ PktBuf A0] " |
| 475 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " |
| 476 | "<-- Adv Rx Read format\n"); |
| 477 | printk(KERN_INFO "RWB[desc] [PcsmIpSHl PtRs] " |
| 478 | "[vl er S cks ln] ---------------- [bi->skb] " |
| 479 | "<-- Adv Rx Write-Back format\n"); |
| 480 | |
| 481 | for (i = 0; i < rx_ring->count; i++) { |
| 482 | buffer_info = &rx_ring->buffer_info[i]; |
| 483 | rx_desc = E1000_RX_DESC_ADV(*rx_ring, i); |
| 484 | u0 = (struct my_u0 *)rx_desc; |
| 485 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 486 | if (staterr & E1000_RXD_STAT_DD) { |
| 487 | /* Descriptor Done */ |
| 488 | printk(KERN_INFO "RWB[0x%03X] %016llX " |
| 489 | "%016llX ---------------- %p", i, |
| 490 | le64_to_cpu(u0->a), |
| 491 | le64_to_cpu(u0->b), |
| 492 | buffer_info->skb); |
| 493 | } else { |
| 494 | printk(KERN_INFO "R [0x%03X] %016llX " |
| 495 | "%016llX %016llX %p", i, |
| 496 | le64_to_cpu(u0->a), |
| 497 | le64_to_cpu(u0->b), |
| 498 | (u64)buffer_info->dma, |
| 499 | buffer_info->skb); |
| 500 | |
| 501 | if (netif_msg_pktdata(adapter)) { |
| 502 | print_hex_dump(KERN_INFO, "", |
| 503 | DUMP_PREFIX_ADDRESS, |
| 504 | 16, 1, |
| 505 | phys_to_virt(buffer_info->dma), |
| 506 | rx_ring->rx_buffer_len, true); |
| 507 | if (rx_ring->rx_buffer_len |
| 508 | < IGB_RXBUFFER_1024) |
| 509 | print_hex_dump(KERN_INFO, "", |
| 510 | DUMP_PREFIX_ADDRESS, |
| 511 | 16, 1, |
| 512 | phys_to_virt( |
| 513 | buffer_info->page_dma + |
| 514 | buffer_info->page_offset), |
| 515 | PAGE_SIZE/2, true); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | if (i == rx_ring->next_to_use) |
| 520 | printk(KERN_CONT " NTU\n"); |
| 521 | else if (i == rx_ring->next_to_clean) |
| 522 | printk(KERN_CONT " NTC\n"); |
| 523 | else |
| 524 | printk(KERN_CONT "\n"); |
| 525 | |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | exit: |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 534 | /** |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 535 | * igb_read_clock - read raw cycle counter (to be used by time counter) |
| 536 | */ |
| 537 | static cycle_t igb_read_clock(const struct cyclecounter *tc) |
| 538 | { |
| 539 | struct igb_adapter *adapter = |
| 540 | container_of(tc, struct igb_adapter, cycles); |
| 541 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 542 | u64 stamp = 0; |
| 543 | int shift = 0; |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 544 | |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 545 | /* |
| 546 | * The timestamp latches on lowest register read. For the 82580 |
| 547 | * the lowest register is SYSTIMR instead of SYSTIML. However we never |
| 548 | * adjusted TIMINCA so SYSTIMR will just read as all 0s so ignore it. |
| 549 | */ |
| 550 | if (hw->mac.type == e1000_82580) { |
| 551 | stamp = rd32(E1000_SYSTIMR) >> 8; |
| 552 | shift = IGB_82580_TSYNC_SHIFT; |
| 553 | } |
| 554 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 555 | stamp |= (u64)rd32(E1000_SYSTIML) << shift; |
| 556 | stamp |= (u64)rd32(E1000_SYSTIMH) << (shift + 32); |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 557 | return stamp; |
| 558 | } |
| 559 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 560 | /** |
Alexander Duyck | c041076 | 2010-03-25 13:10:08 +0000 | [diff] [blame] | 561 | * igb_get_hw_dev - return device |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 562 | * used by hardware layer to print debugging information |
| 563 | **/ |
Alexander Duyck | c041076 | 2010-03-25 13:10:08 +0000 | [diff] [blame] | 564 | struct net_device *igb_get_hw_dev(struct e1000_hw *hw) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 565 | { |
| 566 | struct igb_adapter *adapter = hw->back; |
Alexander Duyck | c041076 | 2010-03-25 13:10:08 +0000 | [diff] [blame] | 567 | return adapter->netdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 568 | } |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 569 | |
| 570 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 571 | * igb_init_module - Driver Registration Routine |
| 572 | * |
| 573 | * igb_init_module is the first routine called when the driver is |
| 574 | * loaded. All it does is register with the PCI subsystem. |
| 575 | **/ |
| 576 | static int __init igb_init_module(void) |
| 577 | { |
| 578 | int ret; |
| 579 | printk(KERN_INFO "%s - version %s\n", |
| 580 | igb_driver_string, igb_driver_version); |
| 581 | |
| 582 | printk(KERN_INFO "%s\n", igb_copyright); |
| 583 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 584 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 585 | dca_register_notify(&dca_notifier); |
| 586 | #endif |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 587 | ret = pci_register_driver(&igb_driver); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | module_init(igb_init_module); |
| 592 | |
| 593 | /** |
| 594 | * igb_exit_module - Driver Exit Cleanup Routine |
| 595 | * |
| 596 | * igb_exit_module is called just before the driver is removed |
| 597 | * from memory. |
| 598 | **/ |
| 599 | static void __exit igb_exit_module(void) |
| 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_unregister_notify(&dca_notifier); |
| 603 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 604 | pci_unregister_driver(&igb_driver); |
| 605 | } |
| 606 | |
| 607 | module_exit(igb_exit_module); |
| 608 | |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 609 | #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1)) |
| 610 | /** |
| 611 | * igb_cache_ring_register - Descriptor ring to register mapping |
| 612 | * @adapter: board private structure to initialize |
| 613 | * |
| 614 | * Once we know the feature-set enabled for the device, we'll cache |
| 615 | * the register offset the descriptor ring is assigned to. |
| 616 | **/ |
| 617 | static void igb_cache_ring_register(struct igb_adapter *adapter) |
| 618 | { |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 619 | int i = 0, j = 0; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 620 | u32 rbase_offset = adapter->vfs_allocated_count; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 621 | |
| 622 | switch (adapter->hw.mac.type) { |
| 623 | case e1000_82576: |
| 624 | /* The queues are allocated for virtualization such that VF 0 |
| 625 | * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc. |
| 626 | * In order to avoid collision we start at the first free queue |
| 627 | * and continue consuming queues in the same sequence |
| 628 | */ |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 629 | if (adapter->vfs_allocated_count) { |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 630 | for (; i < adapter->rss_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 631 | adapter->rx_ring[i]->reg_idx = rbase_offset + |
| 632 | Q_IDX_82576(i); |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 633 | for (; j < adapter->rss_queues; j++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 634 | adapter->tx_ring[j]->reg_idx = rbase_offset + |
| 635 | Q_IDX_82576(j); |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 636 | } |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 637 | case e1000_82575: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 638 | case e1000_82580: |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 639 | case e1000_i350: |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 640 | default: |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 641 | for (; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 642 | adapter->rx_ring[i]->reg_idx = rbase_offset + i; |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 643 | for (; j < adapter->num_tx_queues; j++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 644 | adapter->tx_ring[j]->reg_idx = rbase_offset + j; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 645 | break; |
| 646 | } |
| 647 | } |
| 648 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 649 | static void igb_free_queues(struct igb_adapter *adapter) |
| 650 | { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 651 | int i; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 652 | |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 653 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 654 | kfree(adapter->tx_ring[i]); |
| 655 | adapter->tx_ring[i] = NULL; |
| 656 | } |
| 657 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 658 | kfree(adapter->rx_ring[i]); |
| 659 | adapter->rx_ring[i] = NULL; |
| 660 | } |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 661 | adapter->num_rx_queues = 0; |
| 662 | adapter->num_tx_queues = 0; |
| 663 | } |
| 664 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 665 | /** |
| 666 | * igb_alloc_queues - Allocate memory for all rings |
| 667 | * @adapter: board private structure to initialize |
| 668 | * |
| 669 | * We allocate one ring per queue at run-time since we don't know the |
| 670 | * number of queues at compile-time. |
| 671 | **/ |
| 672 | static int igb_alloc_queues(struct igb_adapter *adapter) |
| 673 | { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 674 | struct igb_ring *ring; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 675 | int i; |
| 676 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 677 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 678 | ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL); |
| 679 | if (!ring) |
| 680 | goto err; |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 681 | ring->count = adapter->tx_ring_count; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 682 | ring->queue_index = i; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 683 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 684 | ring->netdev = adapter->netdev; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 685 | /* For 82575, context index must be unique per ring. */ |
| 686 | if (adapter->hw.mac.type == e1000_82575) |
| 687 | ring->flags = IGB_RING_FLAG_TX_CTX_IDX; |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 688 | adapter->tx_ring[i] = ring; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 689 | } |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 690 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 691 | for (i = 0; i < adapter->num_rx_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->rx_ring_count; |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -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 | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 699 | ring->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 700 | ring->flags = IGB_RING_FLAG_RX_CSUM; /* enable rx checksum */ |
| 701 | /* set flag indicating ring supports SCTP checksum offload */ |
| 702 | if (adapter->hw.mac.type >= e1000_82576) |
| 703 | ring->flags |= IGB_RING_FLAG_RX_SCTP_CSUM; |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 704 | adapter->rx_ring[i] = ring; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 705 | } |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 706 | |
| 707 | igb_cache_ring_register(adapter); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 708 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 709 | return 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 710 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 711 | err: |
| 712 | igb_free_queues(adapter); |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 713 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 714 | return -ENOMEM; |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 717 | #define IGB_N0_QUEUE -1 |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 718 | 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] | 719 | { |
| 720 | u32 msixbm = 0; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 721 | struct igb_adapter *adapter = q_vector->adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 722 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 723 | u32 ivar, index; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 724 | int rx_queue = IGB_N0_QUEUE; |
| 725 | int tx_queue = IGB_N0_QUEUE; |
| 726 | |
| 727 | if (q_vector->rx_ring) |
| 728 | rx_queue = q_vector->rx_ring->reg_idx; |
| 729 | if (q_vector->tx_ring) |
| 730 | tx_queue = q_vector->tx_ring->reg_idx; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 731 | |
| 732 | switch (hw->mac.type) { |
| 733 | case e1000_82575: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 734 | /* The 82575 assigns vectors using a bitmask, which matches the |
| 735 | bitmask for the EICR/EIMS/EIMC registers. To assign one |
| 736 | or more queues to a vector, we write the appropriate bits |
| 737 | into the MSIXBM register for that vector. */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 738 | if (rx_queue > IGB_N0_QUEUE) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 739 | msixbm = E1000_EICR_RX_QUEUE0 << rx_queue; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 740 | if (tx_queue > IGB_N0_QUEUE) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 741 | msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue; |
Alexander Duyck | feeb272 | 2010-02-03 21:59:51 +0000 | [diff] [blame] | 742 | if (!adapter->msix_entries && msix_vector == 0) |
| 743 | msixbm |= E1000_EIMS_OTHER; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 744 | array_wr32(E1000_MSIXBM(0), msix_vector, msixbm); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 745 | q_vector->eims_value = msixbm; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 746 | break; |
| 747 | case e1000_82576: |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 748 | /* 82576 uses a table-based method for assigning vectors. |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 749 | Each queue has a single entry in the table to which we write |
| 750 | a vector number along with a "valid" bit. Sadly, the layout |
| 751 | of the table is somewhat counterintuitive. */ |
| 752 | if (rx_queue > IGB_N0_QUEUE) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 753 | index = (rx_queue & 0x7); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 754 | ivar = array_rd32(E1000_IVAR0, index); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 755 | if (rx_queue < 8) { |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 756 | /* vector goes into low byte of register */ |
| 757 | ivar = ivar & 0xFFFFFF00; |
| 758 | ivar |= msix_vector | E1000_IVAR_VALID; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 759 | } else { |
| 760 | /* vector goes into third byte of register */ |
| 761 | ivar = ivar & 0xFF00FFFF; |
| 762 | ivar |= (msix_vector | E1000_IVAR_VALID) << 16; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 763 | } |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 764 | array_wr32(E1000_IVAR0, index, ivar); |
| 765 | } |
| 766 | if (tx_queue > IGB_N0_QUEUE) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 767 | index = (tx_queue & 0x7); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 768 | ivar = array_rd32(E1000_IVAR0, index); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 769 | if (tx_queue < 8) { |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 770 | /* vector goes into second byte of register */ |
| 771 | ivar = ivar & 0xFFFF00FF; |
| 772 | ivar |= (msix_vector | E1000_IVAR_VALID) << 8; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 773 | } else { |
| 774 | /* vector goes into high byte of register */ |
| 775 | ivar = ivar & 0x00FFFFFF; |
| 776 | ivar |= (msix_vector | E1000_IVAR_VALID) << 24; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 777 | } |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 778 | array_wr32(E1000_IVAR0, index, ivar); |
| 779 | } |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 780 | q_vector->eims_value = 1 << msix_vector; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 781 | break; |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 782 | case e1000_82580: |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 783 | case e1000_i350: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 784 | /* 82580 uses the same table-based approach as 82576 but has fewer |
| 785 | entries as a result we carry over for queues greater than 4. */ |
| 786 | if (rx_queue > IGB_N0_QUEUE) { |
| 787 | index = (rx_queue >> 1); |
| 788 | ivar = array_rd32(E1000_IVAR0, index); |
| 789 | if (rx_queue & 0x1) { |
| 790 | /* vector goes into third byte of register */ |
| 791 | ivar = ivar & 0xFF00FFFF; |
| 792 | ivar |= (msix_vector | E1000_IVAR_VALID) << 16; |
| 793 | } else { |
| 794 | /* vector goes into low byte of register */ |
| 795 | ivar = ivar & 0xFFFFFF00; |
| 796 | ivar |= msix_vector | E1000_IVAR_VALID; |
| 797 | } |
| 798 | array_wr32(E1000_IVAR0, index, ivar); |
| 799 | } |
| 800 | if (tx_queue > IGB_N0_QUEUE) { |
| 801 | index = (tx_queue >> 1); |
| 802 | ivar = array_rd32(E1000_IVAR0, index); |
| 803 | if (tx_queue & 0x1) { |
| 804 | /* vector goes into high byte of register */ |
| 805 | ivar = ivar & 0x00FFFFFF; |
| 806 | ivar |= (msix_vector | E1000_IVAR_VALID) << 24; |
| 807 | } else { |
| 808 | /* vector goes into second byte of register */ |
| 809 | ivar = ivar & 0xFFFF00FF; |
| 810 | ivar |= (msix_vector | E1000_IVAR_VALID) << 8; |
| 811 | } |
| 812 | array_wr32(E1000_IVAR0, index, ivar); |
| 813 | } |
| 814 | q_vector->eims_value = 1 << msix_vector; |
| 815 | break; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 816 | default: |
| 817 | BUG(); |
| 818 | break; |
| 819 | } |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 820 | |
| 821 | /* add q_vector eims value to global eims_enable_mask */ |
| 822 | adapter->eims_enable_mask |= q_vector->eims_value; |
| 823 | |
| 824 | /* configure q_vector to set itr on first interrupt */ |
| 825 | q_vector->set_itr = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | /** |
| 829 | * igb_configure_msix - Configure MSI-X hardware |
| 830 | * |
| 831 | * igb_configure_msix sets up the hardware to properly |
| 832 | * generate MSI-X interrupts. |
| 833 | **/ |
| 834 | static void igb_configure_msix(struct igb_adapter *adapter) |
| 835 | { |
| 836 | u32 tmp; |
| 837 | int i, vector = 0; |
| 838 | struct e1000_hw *hw = &adapter->hw; |
| 839 | |
| 840 | adapter->eims_enable_mask = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 841 | |
| 842 | /* set vector for other causes, i.e. link changes */ |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 843 | switch (hw->mac.type) { |
| 844 | case e1000_82575: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 845 | tmp = rd32(E1000_CTRL_EXT); |
| 846 | /* enable MSI-X PBA support*/ |
| 847 | tmp |= E1000_CTRL_EXT_PBA_CLR; |
| 848 | |
| 849 | /* Auto-Mask interrupts upon ICR read. */ |
| 850 | tmp |= E1000_CTRL_EXT_EIAME; |
| 851 | tmp |= E1000_CTRL_EXT_IRCA; |
| 852 | |
| 853 | wr32(E1000_CTRL_EXT, tmp); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 854 | |
| 855 | /* enable msix_other interrupt */ |
| 856 | array_wr32(E1000_MSIXBM(0), vector++, |
| 857 | E1000_EIMS_OTHER); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 858 | adapter->eims_other = E1000_EIMS_OTHER; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 859 | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 860 | break; |
| 861 | |
| 862 | case e1000_82576: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 863 | case e1000_82580: |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 864 | case e1000_i350: |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 865 | /* Turn on MSI-X capability first, or our settings |
| 866 | * won't stick. And it will take days to debug. */ |
| 867 | wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE | |
| 868 | E1000_GPIE_PBA | E1000_GPIE_EIAME | |
| 869 | E1000_GPIE_NSICR); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 870 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 871 | /* enable msix_other interrupt */ |
| 872 | adapter->eims_other = 1 << vector; |
| 873 | tmp = (vector++ | E1000_IVAR_VALID) << 8; |
| 874 | |
| 875 | wr32(E1000_IVAR_MISC, tmp); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 876 | break; |
| 877 | default: |
| 878 | /* do nothing, since nothing else supports MSI-X */ |
| 879 | break; |
| 880 | } /* switch (hw->mac.type) */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 881 | |
| 882 | adapter->eims_enable_mask |= adapter->eims_other; |
| 883 | |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 884 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 885 | igb_assign_vector(adapter->q_vector[i], vector++); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 886 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 887 | wrfl(); |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * igb_request_msix - Initialize MSI-X interrupts |
| 892 | * |
| 893 | * igb_request_msix allocates MSI-X vectors and requests interrupts from the |
| 894 | * kernel. |
| 895 | **/ |
| 896 | static int igb_request_msix(struct igb_adapter *adapter) |
| 897 | { |
| 898 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 899 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 900 | int i, err = 0, vector = 0; |
| 901 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 902 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 903 | igb_msix_other, 0, netdev->name, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 904 | if (err) |
| 905 | goto out; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 906 | vector++; |
| 907 | |
| 908 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 909 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 910 | |
| 911 | q_vector->itr_register = hw->hw_addr + E1000_EITR(vector); |
| 912 | |
| 913 | if (q_vector->rx_ring && q_vector->tx_ring) |
| 914 | sprintf(q_vector->name, "%s-TxRx-%u", netdev->name, |
| 915 | q_vector->rx_ring->queue_index); |
| 916 | else if (q_vector->tx_ring) |
| 917 | sprintf(q_vector->name, "%s-tx-%u", netdev->name, |
| 918 | q_vector->tx_ring->queue_index); |
| 919 | else if (q_vector->rx_ring) |
| 920 | sprintf(q_vector->name, "%s-rx-%u", netdev->name, |
| 921 | q_vector->rx_ring->queue_index); |
| 922 | else |
| 923 | sprintf(q_vector->name, "%s-unused", netdev->name); |
| 924 | |
| 925 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 926 | igb_msix_ring, 0, q_vector->name, |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 927 | q_vector); |
| 928 | if (err) |
| 929 | goto out; |
| 930 | vector++; |
| 931 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 932 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 933 | igb_configure_msix(adapter); |
| 934 | return 0; |
| 935 | out: |
| 936 | return err; |
| 937 | } |
| 938 | |
| 939 | static void igb_reset_interrupt_capability(struct igb_adapter *adapter) |
| 940 | { |
| 941 | if (adapter->msix_entries) { |
| 942 | pci_disable_msix(adapter->pdev); |
| 943 | kfree(adapter->msix_entries); |
| 944 | adapter->msix_entries = NULL; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 945 | } else if (adapter->flags & IGB_FLAG_HAS_MSI) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 946 | pci_disable_msi(adapter->pdev); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 947 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 948 | } |
| 949 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 950 | /** |
| 951 | * igb_free_q_vectors - Free memory allocated for interrupt vectors |
| 952 | * @adapter: board private structure to initialize |
| 953 | * |
| 954 | * This function frees the memory allocated to the q_vectors. In addition if |
| 955 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 956 | * to freeing the q_vector. |
| 957 | **/ |
| 958 | static void igb_free_q_vectors(struct igb_adapter *adapter) |
| 959 | { |
| 960 | int v_idx; |
| 961 | |
| 962 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
| 963 | struct igb_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 964 | adapter->q_vector[v_idx] = NULL; |
Nick Nunley | fe0592b | 2010-02-17 01:05:35 +0000 | [diff] [blame] | 965 | if (!q_vector) |
| 966 | continue; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 967 | netif_napi_del(&q_vector->napi); |
| 968 | kfree(q_vector); |
| 969 | } |
| 970 | adapter->num_q_vectors = 0; |
| 971 | } |
| 972 | |
| 973 | /** |
| 974 | * igb_clear_interrupt_scheme - reset the device to a state of no interrupts |
| 975 | * |
| 976 | * This function resets the device so that it has 0 rx queues, tx queues, and |
| 977 | * MSI-X interrupts allocated. |
| 978 | */ |
| 979 | static void igb_clear_interrupt_scheme(struct igb_adapter *adapter) |
| 980 | { |
| 981 | igb_free_queues(adapter); |
| 982 | igb_free_q_vectors(adapter); |
| 983 | igb_reset_interrupt_capability(adapter); |
| 984 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 985 | |
| 986 | /** |
| 987 | * igb_set_interrupt_capability - set MSI or MSI-X if supported |
| 988 | * |
| 989 | * Attempt to configure interrupts using the best available |
| 990 | * capabilities of the hardware and kernel. |
| 991 | **/ |
| 992 | static void igb_set_interrupt_capability(struct igb_adapter *adapter) |
| 993 | { |
| 994 | int err; |
| 995 | int numvecs, i; |
| 996 | |
Alexander Duyck | 83b7180 | 2009-02-06 23:15:45 +0000 | [diff] [blame] | 997 | /* Number of supported queues. */ |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 998 | adapter->num_rx_queues = adapter->rss_queues; |
| 999 | adapter->num_tx_queues = adapter->rss_queues; |
Alexander Duyck | 83b7180 | 2009-02-06 23:15:45 +0000 | [diff] [blame] | 1000 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1001 | /* start with one vector for every rx queue */ |
| 1002 | numvecs = adapter->num_rx_queues; |
| 1003 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1004 | /* if tx handler is separate add 1 for every tx queue */ |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 1005 | if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) |
| 1006 | numvecs += adapter->num_tx_queues; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1007 | |
| 1008 | /* store the number of vectors reserved for queues */ |
| 1009 | adapter->num_q_vectors = numvecs; |
| 1010 | |
| 1011 | /* add 1 vector for link status interrupts */ |
| 1012 | numvecs++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1013 | adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry), |
| 1014 | GFP_KERNEL); |
| 1015 | if (!adapter->msix_entries) |
| 1016 | goto msi_only; |
| 1017 | |
| 1018 | for (i = 0; i < numvecs; i++) |
| 1019 | adapter->msix_entries[i].entry = i; |
| 1020 | |
| 1021 | err = pci_enable_msix(adapter->pdev, |
| 1022 | adapter->msix_entries, |
| 1023 | numvecs); |
| 1024 | if (err == 0) |
Alexander Duyck | 34a20e8 | 2008-08-26 04:25:13 -0700 | [diff] [blame] | 1025 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1026 | |
| 1027 | igb_reset_interrupt_capability(adapter); |
| 1028 | |
| 1029 | /* If we can't do MSI-X, try MSI */ |
| 1030 | msi_only: |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 1031 | #ifdef CONFIG_PCI_IOV |
| 1032 | /* disable SR-IOV for non MSI-X configurations */ |
| 1033 | if (adapter->vf_data) { |
| 1034 | struct e1000_hw *hw = &adapter->hw; |
| 1035 | /* disable iov and allow time for transactions to clear */ |
| 1036 | pci_disable_sriov(adapter->pdev); |
| 1037 | msleep(500); |
| 1038 | |
| 1039 | kfree(adapter->vf_data); |
| 1040 | adapter->vf_data = NULL; |
| 1041 | wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ); |
| 1042 | msleep(100); |
| 1043 | dev_info(&adapter->pdev->dev, "IOV Disabled\n"); |
| 1044 | } |
| 1045 | #endif |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1046 | adapter->vfs_allocated_count = 0; |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 1047 | adapter->rss_queues = 1; |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1048 | adapter->flags |= IGB_FLAG_QUEUE_PAIRS; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1049 | adapter->num_rx_queues = 1; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 1050 | adapter->num_tx_queues = 1; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1051 | adapter->num_q_vectors = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1052 | if (!pci_enable_msi(adapter->pdev)) |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1053 | adapter->flags |= IGB_FLAG_HAS_MSI; |
Alexander Duyck | 34a20e8 | 2008-08-26 04:25:13 -0700 | [diff] [blame] | 1054 | out: |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 1055 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 1056 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1057 | return; |
| 1058 | } |
| 1059 | |
| 1060 | /** |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1061 | * igb_alloc_q_vectors - Allocate memory for interrupt vectors |
| 1062 | * @adapter: board private structure to initialize |
| 1063 | * |
| 1064 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 1065 | * return -ENOMEM. |
| 1066 | **/ |
| 1067 | static int igb_alloc_q_vectors(struct igb_adapter *adapter) |
| 1068 | { |
| 1069 | struct igb_q_vector *q_vector; |
| 1070 | struct e1000_hw *hw = &adapter->hw; |
| 1071 | int v_idx; |
| 1072 | |
| 1073 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
| 1074 | q_vector = kzalloc(sizeof(struct igb_q_vector), GFP_KERNEL); |
| 1075 | if (!q_vector) |
| 1076 | goto err_out; |
| 1077 | q_vector->adapter = adapter; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1078 | q_vector->itr_register = hw->hw_addr + E1000_EITR(0); |
| 1079 | q_vector->itr_val = IGB_START_ITR; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1080 | netif_napi_add(adapter->netdev, &q_vector->napi, igb_poll, 64); |
| 1081 | adapter->q_vector[v_idx] = q_vector; |
| 1082 | } |
| 1083 | return 0; |
| 1084 | |
| 1085 | err_out: |
Nick Nunley | fe0592b | 2010-02-17 01:05:35 +0000 | [diff] [blame] | 1086 | igb_free_q_vectors(adapter); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1087 | return -ENOMEM; |
| 1088 | } |
| 1089 | |
| 1090 | static void igb_map_rx_ring_to_vector(struct igb_adapter *adapter, |
| 1091 | int ring_idx, int v_idx) |
| 1092 | { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1093 | struct igb_q_vector *q_vector = adapter->q_vector[v_idx]; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1094 | |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1095 | q_vector->rx_ring = adapter->rx_ring[ring_idx]; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1096 | q_vector->rx_ring->q_vector = q_vector; |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1097 | q_vector->itr_val = adapter->rx_itr_setting; |
| 1098 | if (q_vector->itr_val && q_vector->itr_val <= 3) |
| 1099 | q_vector->itr_val = IGB_START_ITR; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | static void igb_map_tx_ring_to_vector(struct igb_adapter *adapter, |
| 1103 | int ring_idx, int v_idx) |
| 1104 | { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1105 | struct igb_q_vector *q_vector = adapter->q_vector[v_idx]; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1106 | |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1107 | q_vector->tx_ring = adapter->tx_ring[ring_idx]; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1108 | q_vector->tx_ring->q_vector = q_vector; |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1109 | q_vector->itr_val = adapter->tx_itr_setting; |
| 1110 | if (q_vector->itr_val && q_vector->itr_val <= 3) |
| 1111 | q_vector->itr_val = IGB_START_ITR; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * igb_map_ring_to_vector - maps allocated queues to vectors |
| 1116 | * |
| 1117 | * This function maps the recently allocated queues to vectors. |
| 1118 | **/ |
| 1119 | static int igb_map_ring_to_vector(struct igb_adapter *adapter) |
| 1120 | { |
| 1121 | int i; |
| 1122 | int v_idx = 0; |
| 1123 | |
| 1124 | if ((adapter->num_q_vectors < adapter->num_rx_queues) || |
| 1125 | (adapter->num_q_vectors < adapter->num_tx_queues)) |
| 1126 | return -ENOMEM; |
| 1127 | |
| 1128 | if (adapter->num_q_vectors >= |
| 1129 | (adapter->num_rx_queues + adapter->num_tx_queues)) { |
| 1130 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1131 | igb_map_rx_ring_to_vector(adapter, i, v_idx++); |
| 1132 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 1133 | igb_map_tx_ring_to_vector(adapter, i, v_idx++); |
| 1134 | } else { |
| 1135 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1136 | if (i < adapter->num_tx_queues) |
| 1137 | igb_map_tx_ring_to_vector(adapter, i, v_idx); |
| 1138 | igb_map_rx_ring_to_vector(adapter, i, v_idx++); |
| 1139 | } |
| 1140 | for (; i < adapter->num_tx_queues; i++) |
| 1141 | igb_map_tx_ring_to_vector(adapter, i, v_idx++); |
| 1142 | } |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
| 1146 | /** |
| 1147 | * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors |
| 1148 | * |
| 1149 | * This function initializes the interrupts and allocates all of the queues. |
| 1150 | **/ |
| 1151 | static int igb_init_interrupt_scheme(struct igb_adapter *adapter) |
| 1152 | { |
| 1153 | struct pci_dev *pdev = adapter->pdev; |
| 1154 | int err; |
| 1155 | |
| 1156 | igb_set_interrupt_capability(adapter); |
| 1157 | |
| 1158 | err = igb_alloc_q_vectors(adapter); |
| 1159 | if (err) { |
| 1160 | dev_err(&pdev->dev, "Unable to allocate memory for vectors\n"); |
| 1161 | goto err_alloc_q_vectors; |
| 1162 | } |
| 1163 | |
| 1164 | err = igb_alloc_queues(adapter); |
| 1165 | if (err) { |
| 1166 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 1167 | goto err_alloc_queues; |
| 1168 | } |
| 1169 | |
| 1170 | err = igb_map_ring_to_vector(adapter); |
| 1171 | if (err) { |
| 1172 | dev_err(&pdev->dev, "Invalid q_vector to ring mapping\n"); |
| 1173 | goto err_map_queues; |
| 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | return 0; |
| 1178 | err_map_queues: |
| 1179 | igb_free_queues(adapter); |
| 1180 | err_alloc_queues: |
| 1181 | igb_free_q_vectors(adapter); |
| 1182 | err_alloc_q_vectors: |
| 1183 | igb_reset_interrupt_capability(adapter); |
| 1184 | return err; |
| 1185 | } |
| 1186 | |
| 1187 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1188 | * igb_request_irq - initialize interrupts |
| 1189 | * |
| 1190 | * Attempts to configure interrupts using the best available |
| 1191 | * capabilities of the hardware and kernel. |
| 1192 | **/ |
| 1193 | static int igb_request_irq(struct igb_adapter *adapter) |
| 1194 | { |
| 1195 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1196 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1197 | int err = 0; |
| 1198 | |
| 1199 | if (adapter->msix_entries) { |
| 1200 | err = igb_request_msix(adapter); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1201 | if (!err) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1202 | goto request_done; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1203 | /* fall back to MSI */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1204 | igb_clear_interrupt_scheme(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1205 | if (!pci_enable_msi(adapter->pdev)) |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1206 | adapter->flags |= IGB_FLAG_HAS_MSI; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1207 | igb_free_all_tx_resources(adapter); |
| 1208 | igb_free_all_rx_resources(adapter); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1209 | adapter->num_tx_queues = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1210 | adapter->num_rx_queues = 1; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1211 | adapter->num_q_vectors = 1; |
| 1212 | err = igb_alloc_q_vectors(adapter); |
| 1213 | if (err) { |
| 1214 | dev_err(&pdev->dev, |
| 1215 | "Unable to allocate memory for vectors\n"); |
| 1216 | goto request_done; |
| 1217 | } |
| 1218 | err = igb_alloc_queues(adapter); |
| 1219 | if (err) { |
| 1220 | dev_err(&pdev->dev, |
| 1221 | "Unable to allocate memory for queues\n"); |
| 1222 | igb_free_q_vectors(adapter); |
| 1223 | goto request_done; |
| 1224 | } |
| 1225 | igb_setup_all_tx_resources(adapter); |
| 1226 | igb_setup_all_rx_resources(adapter); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1227 | } else { |
Alexander Duyck | feeb272 | 2010-02-03 21:59:51 +0000 | [diff] [blame] | 1228 | igb_assign_vector(adapter->q_vector[0], 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1229 | } |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1230 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1231 | if (adapter->flags & IGB_FLAG_HAS_MSI) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1232 | err = request_irq(adapter->pdev->irq, igb_intr_msi, 0, |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1233 | netdev->name, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1234 | if (!err) |
| 1235 | goto request_done; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1236 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1237 | /* fall back to legacy interrupts */ |
| 1238 | igb_reset_interrupt_capability(adapter); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1239 | adapter->flags &= ~IGB_FLAG_HAS_MSI; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1242 | err = request_irq(adapter->pdev->irq, igb_intr, IRQF_SHARED, |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1243 | netdev->name, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1244 | |
Andy Gospodarek | 6cb5e57 | 2008-02-15 14:05:25 -0800 | [diff] [blame] | 1245 | if (err) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1246 | dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n", |
| 1247 | err); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1248 | |
| 1249 | request_done: |
| 1250 | return err; |
| 1251 | } |
| 1252 | |
| 1253 | static void igb_free_irq(struct igb_adapter *adapter) |
| 1254 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1255 | if (adapter->msix_entries) { |
| 1256 | int vector = 0, i; |
| 1257 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1258 | free_irq(adapter->msix_entries[vector++].vector, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1259 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1260 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 1261 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 1262 | free_irq(adapter->msix_entries[vector++].vector, |
| 1263 | q_vector); |
| 1264 | } |
| 1265 | } else { |
| 1266 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1267 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | /** |
| 1271 | * igb_irq_disable - Mask off interrupt generation on the NIC |
| 1272 | * @adapter: board private structure |
| 1273 | **/ |
| 1274 | static void igb_irq_disable(struct igb_adapter *adapter) |
| 1275 | { |
| 1276 | struct e1000_hw *hw = &adapter->hw; |
| 1277 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1278 | /* |
| 1279 | * we need to be careful when disabling interrupts. The VFs are also |
| 1280 | * mapped into these registers and so clearing the bits can cause |
| 1281 | * issues on the VF drivers so we only need to clear what we set |
| 1282 | */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1283 | if (adapter->msix_entries) { |
Alexander Duyck | 2dfd121 | 2009-09-03 14:49:15 +0000 | [diff] [blame] | 1284 | u32 regval = rd32(E1000_EIAM); |
| 1285 | wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask); |
| 1286 | wr32(E1000_EIMC, adapter->eims_enable_mask); |
| 1287 | regval = rd32(E1000_EIAC); |
| 1288 | wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1289 | } |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1290 | |
| 1291 | wr32(E1000_IAM, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1292 | wr32(E1000_IMC, ~0); |
| 1293 | wrfl(); |
| 1294 | synchronize_irq(adapter->pdev->irq); |
| 1295 | } |
| 1296 | |
| 1297 | /** |
| 1298 | * igb_irq_enable - Enable default interrupt generation settings |
| 1299 | * @adapter: board private structure |
| 1300 | **/ |
| 1301 | static void igb_irq_enable(struct igb_adapter *adapter) |
| 1302 | { |
| 1303 | struct e1000_hw *hw = &adapter->hw; |
| 1304 | |
| 1305 | if (adapter->msix_entries) { |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1306 | u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC; |
Alexander Duyck | 2dfd121 | 2009-09-03 14:49:15 +0000 | [diff] [blame] | 1307 | u32 regval = rd32(E1000_EIAC); |
| 1308 | wr32(E1000_EIAC, regval | adapter->eims_enable_mask); |
| 1309 | regval = rd32(E1000_EIAM); |
| 1310 | wr32(E1000_EIAM, regval | adapter->eims_enable_mask); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1311 | wr32(E1000_EIMS, adapter->eims_enable_mask); |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1312 | if (adapter->vfs_allocated_count) { |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1313 | wr32(E1000_MBVFIMR, 0xFF); |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1314 | ims |= E1000_IMS_VMMB; |
| 1315 | } |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1316 | if (adapter->hw.mac.type == e1000_82580) |
| 1317 | ims |= E1000_IMS_DRSTA; |
| 1318 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1319 | wr32(E1000_IMS, ims); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1320 | } else { |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1321 | wr32(E1000_IMS, IMS_ENABLE_MASK | |
| 1322 | E1000_IMS_DRSTA); |
| 1323 | wr32(E1000_IAM, IMS_ENABLE_MASK | |
| 1324 | E1000_IMS_DRSTA); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1325 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | static void igb_update_mng_vlan(struct igb_adapter *adapter) |
| 1329 | { |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 1330 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1331 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 1332 | u16 old_vid = adapter->mng_vlan_id; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1333 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 1334 | if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 1335 | /* add VID to filter table */ |
| 1336 | igb_vfta_set(hw, vid, true); |
| 1337 | adapter->mng_vlan_id = vid; |
| 1338 | } else { |
| 1339 | adapter->mng_vlan_id = IGB_MNG_VLAN_NONE; |
| 1340 | } |
| 1341 | |
| 1342 | if ((old_vid != (u16)IGB_MNG_VLAN_NONE) && |
| 1343 | (vid != old_vid) && |
| 1344 | !vlan_group_get_device(adapter->vlgrp, old_vid)) { |
| 1345 | /* remove VID from filter table */ |
| 1346 | igb_vfta_set(hw, old_vid, false); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * igb_release_hw_control - release control of the h/w to f/w |
| 1352 | * @adapter: address of board private structure |
| 1353 | * |
| 1354 | * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit. |
| 1355 | * For ASF and Pass Through versions of f/w this means that the |
| 1356 | * driver is no longer loaded. |
| 1357 | * |
| 1358 | **/ |
| 1359 | static void igb_release_hw_control(struct igb_adapter *adapter) |
| 1360 | { |
| 1361 | struct e1000_hw *hw = &adapter->hw; |
| 1362 | u32 ctrl_ext; |
| 1363 | |
| 1364 | /* Let firmware take over control of h/w */ |
| 1365 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 1366 | wr32(E1000_CTRL_EXT, |
| 1367 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
| 1368 | } |
| 1369 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1370 | /** |
| 1371 | * igb_get_hw_control - get control of the h/w from f/w |
| 1372 | * @adapter: address of board private structure |
| 1373 | * |
| 1374 | * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit. |
| 1375 | * For ASF and Pass Through versions of f/w this means that |
| 1376 | * the driver is loaded. |
| 1377 | * |
| 1378 | **/ |
| 1379 | static void igb_get_hw_control(struct igb_adapter *adapter) |
| 1380 | { |
| 1381 | struct e1000_hw *hw = &adapter->hw; |
| 1382 | u32 ctrl_ext; |
| 1383 | |
| 1384 | /* Let firmware know the driver has taken over */ |
| 1385 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 1386 | wr32(E1000_CTRL_EXT, |
| 1387 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
| 1388 | } |
| 1389 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1390 | /** |
| 1391 | * igb_configure - configure the hardware for RX and TX |
| 1392 | * @adapter: private board structure |
| 1393 | **/ |
| 1394 | static void igb_configure(struct igb_adapter *adapter) |
| 1395 | { |
| 1396 | struct net_device *netdev = adapter->netdev; |
| 1397 | int i; |
| 1398 | |
| 1399 | igb_get_hw_control(adapter); |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 1400 | igb_set_rx_mode(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1401 | |
| 1402 | igb_restore_vlan(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1403 | |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 1404 | igb_setup_tctl(adapter); |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 1405 | igb_setup_mrqc(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1406 | igb_setup_rctl(adapter); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 1407 | |
| 1408 | igb_configure_tx(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1409 | igb_configure_rx(adapter); |
Alexander Duyck | 662d720 | 2008-06-27 11:00:29 -0700 | [diff] [blame] | 1410 | |
| 1411 | igb_rx_fifo_flush_82575(&adapter->hw); |
| 1412 | |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 1413 | /* call igb_desc_unused which always leaves |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1414 | * at least 1 descriptor unused to make sure |
| 1415 | * next_to_use != next_to_clean */ |
| 1416 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1417 | struct igb_ring *ring = adapter->rx_ring[i]; |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 1418 | igb_alloc_rx_buffers_adv(ring, igb_desc_unused(ring)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1419 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1420 | } |
| 1421 | |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 1422 | /** |
| 1423 | * igb_power_up_link - Power up the phy/serdes link |
| 1424 | * @adapter: address of board private structure |
| 1425 | **/ |
| 1426 | void igb_power_up_link(struct igb_adapter *adapter) |
| 1427 | { |
| 1428 | if (adapter->hw.phy.media_type == e1000_media_type_copper) |
| 1429 | igb_power_up_phy_copper(&adapter->hw); |
| 1430 | else |
| 1431 | igb_power_up_serdes_link_82575(&adapter->hw); |
| 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * igb_power_down_link - Power down the phy/serdes link |
| 1436 | * @adapter: address of board private structure |
| 1437 | */ |
| 1438 | static void igb_power_down_link(struct igb_adapter *adapter) |
| 1439 | { |
| 1440 | if (adapter->hw.phy.media_type == e1000_media_type_copper) |
| 1441 | igb_power_down_phy_copper_82575(&adapter->hw); |
| 1442 | else |
| 1443 | igb_shutdown_serdes_link_82575(&adapter->hw); |
| 1444 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1445 | |
| 1446 | /** |
| 1447 | * igb_up - Open the interface and prepare it to handle traffic |
| 1448 | * @adapter: board private structure |
| 1449 | **/ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1450 | int igb_up(struct igb_adapter *adapter) |
| 1451 | { |
| 1452 | struct e1000_hw *hw = &adapter->hw; |
| 1453 | int i; |
| 1454 | |
| 1455 | /* hardware has been reset, we need to reload some things */ |
| 1456 | igb_configure(adapter); |
| 1457 | |
| 1458 | clear_bit(__IGB_DOWN, &adapter->state); |
| 1459 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1460 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 1461 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 1462 | napi_enable(&q_vector->napi); |
| 1463 | } |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1464 | if (adapter->msix_entries) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1465 | igb_configure_msix(adapter); |
Alexander Duyck | feeb272 | 2010-02-03 21:59:51 +0000 | [diff] [blame] | 1466 | else |
| 1467 | igb_assign_vector(adapter->q_vector[0], 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1468 | |
| 1469 | /* Clear any pending interrupts. */ |
| 1470 | rd32(E1000_ICR); |
| 1471 | igb_irq_enable(adapter); |
| 1472 | |
Alexander Duyck | d496030 | 2009-10-27 15:53:45 +0000 | [diff] [blame] | 1473 | /* notify VFs that reset has been completed */ |
| 1474 | if (adapter->vfs_allocated_count) { |
| 1475 | u32 reg_data = rd32(E1000_CTRL_EXT); |
| 1476 | reg_data |= E1000_CTRL_EXT_PFRSTD; |
| 1477 | wr32(E1000_CTRL_EXT, reg_data); |
| 1478 | } |
| 1479 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 1480 | netif_tx_start_all_queues(adapter->netdev); |
| 1481 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1482 | /* start the watchdog. */ |
| 1483 | hw->mac.get_link_status = 1; |
| 1484 | schedule_work(&adapter->watchdog_task); |
| 1485 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1486 | return 0; |
| 1487 | } |
| 1488 | |
| 1489 | void igb_down(struct igb_adapter *adapter) |
| 1490 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1491 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1492 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1493 | u32 tctl, rctl; |
| 1494 | int i; |
| 1495 | |
| 1496 | /* signal that we're down so the interrupt handler does not |
| 1497 | * reschedule our watchdog timer */ |
| 1498 | set_bit(__IGB_DOWN, &adapter->state); |
| 1499 | |
| 1500 | /* disable receives in the hardware */ |
| 1501 | rctl = rd32(E1000_RCTL); |
| 1502 | wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN); |
| 1503 | /* flush and sleep below */ |
| 1504 | |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 1505 | netif_tx_stop_all_queues(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1506 | |
| 1507 | /* disable transmits in the hardware */ |
| 1508 | tctl = rd32(E1000_TCTL); |
| 1509 | tctl &= ~E1000_TCTL_EN; |
| 1510 | wr32(E1000_TCTL, tctl); |
| 1511 | /* flush both disables and wait for them to finish */ |
| 1512 | wrfl(); |
| 1513 | msleep(10); |
| 1514 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1515 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 1516 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 1517 | napi_disable(&q_vector->napi); |
| 1518 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1519 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1520 | igb_irq_disable(adapter); |
| 1521 | |
| 1522 | del_timer_sync(&adapter->watchdog_timer); |
| 1523 | del_timer_sync(&adapter->phy_info_timer); |
| 1524 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1525 | netif_carrier_off(netdev); |
Alexander Duyck | 04fe635 | 2009-02-06 23:22:32 +0000 | [diff] [blame] | 1526 | |
| 1527 | /* record the stats before reset*/ |
| 1528 | igb_update_stats(adapter); |
| 1529 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1530 | adapter->link_speed = 0; |
| 1531 | adapter->link_duplex = 0; |
| 1532 | |
Jeff Kirsher | 3023682 | 2008-06-24 17:01:15 -0700 | [diff] [blame] | 1533 | if (!pci_channel_offline(adapter->pdev)) |
| 1534 | igb_reset(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1535 | igb_clean_all_tx_rings(adapter); |
| 1536 | igb_clean_all_rx_rings(adapter); |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 1537 | #ifdef CONFIG_IGB_DCA |
| 1538 | |
| 1539 | /* since we reset the hardware DCA settings were cleared */ |
| 1540 | igb_setup_dca(adapter); |
| 1541 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | void igb_reinit_locked(struct igb_adapter *adapter) |
| 1545 | { |
| 1546 | WARN_ON(in_interrupt()); |
| 1547 | while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) |
| 1548 | msleep(1); |
| 1549 | igb_down(adapter); |
| 1550 | igb_up(adapter); |
| 1551 | clear_bit(__IGB_RESETTING, &adapter->state); |
| 1552 | } |
| 1553 | |
| 1554 | void igb_reset(struct igb_adapter *adapter) |
| 1555 | { |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 1556 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1557 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1558 | struct e1000_mac_info *mac = &hw->mac; |
| 1559 | struct e1000_fc_info *fc = &hw->fc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1560 | u32 pba = 0, tx_space, min_tx_space, min_rx_space; |
| 1561 | u16 hwm; |
| 1562 | |
| 1563 | /* Repartition Pba for greater than 9k mtu |
| 1564 | * To take effect CTRL.RST is required. |
| 1565 | */ |
Alexander Duyck | fa4dfae | 2009-02-06 23:21:31 +0000 | [diff] [blame] | 1566 | switch (mac->type) { |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 1567 | case e1000_i350: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1568 | case e1000_82580: |
| 1569 | pba = rd32(E1000_RXPBS); |
| 1570 | pba = igb_rxpbs_adjust_82580(pba); |
| 1571 | break; |
Alexander Duyck | fa4dfae | 2009-02-06 23:21:31 +0000 | [diff] [blame] | 1572 | case e1000_82576: |
Alexander Duyck | d249be5 | 2009-10-27 23:46:38 +0000 | [diff] [blame] | 1573 | pba = rd32(E1000_RXPBS); |
| 1574 | pba &= E1000_RXPBS_SIZE_MASK_82576; |
Alexander Duyck | fa4dfae | 2009-02-06 23:21:31 +0000 | [diff] [blame] | 1575 | break; |
| 1576 | case e1000_82575: |
| 1577 | default: |
| 1578 | pba = E1000_PBA_34K; |
| 1579 | break; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1580 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1581 | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1582 | if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 1583 | (mac->type < e1000_82576)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1584 | /* adjust PBA for jumbo frames */ |
| 1585 | wr32(E1000_PBA, pba); |
| 1586 | |
| 1587 | /* To maintain wire speed transmits, the Tx FIFO should be |
| 1588 | * large enough to accommodate two full transmit packets, |
| 1589 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 1590 | * the Rx FIFO should be large enough to accommodate at least |
| 1591 | * one full receive packet and is similarly rounded up and |
| 1592 | * expressed in KB. */ |
| 1593 | pba = rd32(E1000_PBA); |
| 1594 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
| 1595 | tx_space = pba >> 16; |
| 1596 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
| 1597 | pba &= 0xffff; |
| 1598 | /* the tx fifo also stores 16 bytes of information about the tx |
| 1599 | * but don't include ethernet FCS because hardware appends it */ |
| 1600 | min_tx_space = (adapter->max_frame_size + |
Alexander Duyck | 85e8d00 | 2009-02-16 00:00:20 -0800 | [diff] [blame] | 1601 | sizeof(union e1000_adv_tx_desc) - |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1602 | ETH_FCS_LEN) * 2; |
| 1603 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 1604 | min_tx_space >>= 10; |
| 1605 | /* software strips receive CRC, so leave room for it */ |
| 1606 | min_rx_space = adapter->max_frame_size; |
| 1607 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 1608 | min_rx_space >>= 10; |
| 1609 | |
| 1610 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 1611 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 1612 | * allocation, take space away from current Rx allocation */ |
| 1613 | if (tx_space < min_tx_space && |
| 1614 | ((min_tx_space - tx_space) < pba)) { |
| 1615 | pba = pba - (min_tx_space - tx_space); |
| 1616 | |
| 1617 | /* if short on rx space, rx wins and must trump tx |
| 1618 | * adjustment */ |
| 1619 | if (pba < min_rx_space) |
| 1620 | pba = min_rx_space; |
| 1621 | } |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1622 | wr32(E1000_PBA, pba); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1623 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1624 | |
| 1625 | /* flow control settings */ |
| 1626 | /* The high water mark must be low enough to fit one full frame |
| 1627 | * (or the size used for early receive) above it in the Rx FIFO. |
| 1628 | * Set it to the lower of: |
| 1629 | * - 90% of the Rx FIFO size, or |
| 1630 | * - the full Rx FIFO size minus one full frame */ |
| 1631 | hwm = min(((pba << 10) * 9 / 10), |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1632 | ((pba << 10) - 2 * adapter->max_frame_size)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1633 | |
Alexander Duyck | d405ea3 | 2009-12-23 13:21:27 +0000 | [diff] [blame] | 1634 | fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */ |
| 1635 | fc->low_water = fc->high_water - 16; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1636 | fc->pause_time = 0xFFFF; |
| 1637 | fc->send_xon = 1; |
Alexander Duyck | 0cce119 | 2009-07-23 18:10:24 +0000 | [diff] [blame] | 1638 | fc->current_mode = fc->requested_mode; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1639 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1640 | /* disable receive for all VFs and wait one second */ |
| 1641 | if (adapter->vfs_allocated_count) { |
| 1642 | int i; |
| 1643 | for (i = 0 ; i < adapter->vfs_allocated_count; i++) |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 1644 | adapter->vf_data[i].flags = 0; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1645 | |
| 1646 | /* 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] | 1647 | igb_ping_all_vfs(adapter); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1648 | |
| 1649 | /* disable transmits and receives */ |
| 1650 | wr32(E1000_VFRE, 0); |
| 1651 | wr32(E1000_VFTE, 0); |
| 1652 | } |
| 1653 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1654 | /* Allow time for pending master requests to run */ |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1655 | hw->mac.ops.reset_hw(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1656 | wr32(E1000_WUC, 0); |
| 1657 | |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1658 | if (hw->mac.ops.init_hw(hw)) |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 1659 | dev_err(&pdev->dev, "Hardware Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1660 | |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1661 | if (hw->mac.type == e1000_82580) { |
| 1662 | u32 reg = rd32(E1000_PCIEMISC); |
| 1663 | wr32(E1000_PCIEMISC, |
| 1664 | reg & ~E1000_PCIEMISC_LX_DECISION); |
| 1665 | } |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 1666 | if (!netif_running(adapter->netdev)) |
| 1667 | igb_power_down_link(adapter); |
| 1668 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1669 | igb_update_mng_vlan(adapter); |
| 1670 | |
| 1671 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 1672 | wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE); |
| 1673 | |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1674 | igb_get_phy_info(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1675 | } |
| 1676 | |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1677 | static const struct net_device_ops igb_netdev_ops = { |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 1678 | .ndo_open = igb_open, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1679 | .ndo_stop = igb_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 1680 | .ndo_start_xmit = igb_xmit_frame_adv, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1681 | .ndo_get_stats = igb_get_stats, |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 1682 | .ndo_set_rx_mode = igb_set_rx_mode, |
| 1683 | .ndo_set_multicast_list = igb_set_rx_mode, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1684 | .ndo_set_mac_address = igb_set_mac, |
| 1685 | .ndo_change_mtu = igb_change_mtu, |
| 1686 | .ndo_do_ioctl = igb_ioctl, |
| 1687 | .ndo_tx_timeout = igb_tx_timeout, |
| 1688 | .ndo_validate_addr = eth_validate_addr, |
| 1689 | .ndo_vlan_rx_register = igb_vlan_rx_register, |
| 1690 | .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid, |
| 1691 | .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid, |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 1692 | .ndo_set_vf_mac = igb_ndo_set_vf_mac, |
| 1693 | .ndo_set_vf_vlan = igb_ndo_set_vf_vlan, |
| 1694 | .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw, |
| 1695 | .ndo_get_vf_config = igb_ndo_get_vf_config, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1696 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1697 | .ndo_poll_controller = igb_netpoll, |
| 1698 | #endif |
| 1699 | }; |
| 1700 | |
Taku Izumi | 42bfd33a | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 1701 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1702 | * igb_probe - Device Initialization Routine |
| 1703 | * @pdev: PCI device information struct |
| 1704 | * @ent: entry in igb_pci_tbl |
| 1705 | * |
| 1706 | * Returns 0 on success, negative on failure |
| 1707 | * |
| 1708 | * igb_probe initializes an adapter identified by a pci_dev structure. |
| 1709 | * The OS initialization, configuring of the adapter private structure, |
| 1710 | * and a hardware reset occur. |
| 1711 | **/ |
| 1712 | static int __devinit igb_probe(struct pci_dev *pdev, |
| 1713 | const struct pci_device_id *ent) |
| 1714 | { |
| 1715 | struct net_device *netdev; |
| 1716 | struct igb_adapter *adapter; |
| 1717 | struct e1000_hw *hw; |
Alexander Duyck | 4337e99 | 2009-10-27 23:48:31 +0000 | [diff] [blame] | 1718 | u16 eeprom_data = 0; |
| 1719 | static int global_quad_port_a; /* global quad port a indication */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1720 | const struct e1000_info *ei = igb_info_tbl[ent->driver_data]; |
| 1721 | unsigned long mmio_start, mmio_len; |
David S. Miller | 2d6a5e9 | 2009-03-17 15:01:30 -0700 | [diff] [blame] | 1722 | int err, pci_using_dac; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1723 | u16 eeprom_apme_mask = IGB_EEPROM_APME; |
| 1724 | u32 part_num; |
| 1725 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 1726 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1727 | if (err) |
| 1728 | return err; |
| 1729 | |
| 1730 | pci_using_dac = 0; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 1731 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1732 | if (!err) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 1733 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1734 | if (!err) |
| 1735 | pci_using_dac = 1; |
| 1736 | } else { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 1737 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1738 | if (err) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 1739 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1740 | if (err) { |
| 1741 | dev_err(&pdev->dev, "No usable DMA " |
| 1742 | "configuration, aborting\n"); |
| 1743 | goto err_dma; |
| 1744 | } |
| 1745 | } |
| 1746 | } |
| 1747 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 1748 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 1749 | IORESOURCE_MEM), |
| 1750 | igb_driver_name); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1751 | if (err) |
| 1752 | goto err_pci_reg; |
| 1753 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 1754 | pci_enable_pcie_error_reporting(pdev); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 1755 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1756 | pci_set_master(pdev); |
Auke Kok | c682fc2 | 2008-04-23 11:09:34 -0700 | [diff] [blame] | 1757 | pci_save_state(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1758 | |
| 1759 | err = -ENOMEM; |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 1760 | netdev = alloc_etherdev_mq(sizeof(struct igb_adapter), |
| 1761 | IGB_ABS_MAX_TX_QUEUES); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1762 | if (!netdev) |
| 1763 | goto err_alloc_etherdev; |
| 1764 | |
| 1765 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1766 | |
| 1767 | pci_set_drvdata(pdev, netdev); |
| 1768 | adapter = netdev_priv(netdev); |
| 1769 | adapter->netdev = netdev; |
| 1770 | adapter->pdev = pdev; |
| 1771 | hw = &adapter->hw; |
| 1772 | hw->back = adapter; |
| 1773 | adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 1774 | |
| 1775 | mmio_start = pci_resource_start(pdev, 0); |
| 1776 | mmio_len = pci_resource_len(pdev, 0); |
| 1777 | |
| 1778 | err = -EIO; |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 1779 | hw->hw_addr = ioremap(mmio_start, mmio_len); |
| 1780 | if (!hw->hw_addr) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1781 | goto err_ioremap; |
| 1782 | |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1783 | netdev->netdev_ops = &igb_netdev_ops; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1784 | igb_set_ethtool_ops(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1785 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1786 | |
| 1787 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 1788 | |
| 1789 | netdev->mem_start = mmio_start; |
| 1790 | netdev->mem_end = mmio_start + mmio_len; |
| 1791 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1792 | /* PCI config space info */ |
| 1793 | hw->vendor_id = pdev->vendor; |
| 1794 | hw->device_id = pdev->device; |
| 1795 | hw->revision_id = pdev->revision; |
| 1796 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1797 | hw->subsystem_device_id = pdev->subsystem_device; |
| 1798 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1799 | /* Copy the default MAC, PHY and NVM function pointers */ |
| 1800 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 1801 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 1802 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 1803 | /* Initialize skew-specific constants */ |
| 1804 | err = ei->get_invariants(hw); |
| 1805 | if (err) |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 1806 | goto err_sw_init; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1807 | |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 1808 | /* setup the private structure */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1809 | err = igb_sw_init(adapter); |
| 1810 | if (err) |
| 1811 | goto err_sw_init; |
| 1812 | |
| 1813 | igb_get_bus_info_pcie(hw); |
| 1814 | |
| 1815 | hw->phy.autoneg_wait_to_complete = false; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1816 | |
| 1817 | /* Copper options */ |
| 1818 | if (hw->phy.media_type == e1000_media_type_copper) { |
| 1819 | hw->phy.mdix = AUTO_ALL_MODES; |
| 1820 | hw->phy.disable_polarity_correction = false; |
| 1821 | hw->phy.ms_type = e1000_ms_hw_default; |
| 1822 | } |
| 1823 | |
| 1824 | if (igb_check_reset_block(hw)) |
| 1825 | dev_info(&pdev->dev, |
| 1826 | "PHY reset is blocked due to SOL/IDER session.\n"); |
| 1827 | |
| 1828 | netdev->features = NETIF_F_SG | |
Alexander Duyck | 7d8eb29 | 2009-02-06 23:18:27 +0000 | [diff] [blame] | 1829 | NETIF_F_IP_CSUM | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1830 | NETIF_F_HW_VLAN_TX | |
| 1831 | NETIF_F_HW_VLAN_RX | |
| 1832 | NETIF_F_HW_VLAN_FILTER; |
| 1833 | |
Alexander Duyck | 7d8eb29 | 2009-02-06 23:18:27 +0000 | [diff] [blame] | 1834 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1835 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1836 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 5c0999b | 2009-01-19 15:20:57 -0800 | [diff] [blame] | 1837 | netdev->features |= NETIF_F_GRO; |
Alexander Duyck | d335252 | 2008-07-08 15:12:13 -0700 | [diff] [blame] | 1838 | |
Jeff Kirsher | 48f29ff | 2008-06-05 04:06:27 -0700 | [diff] [blame] | 1839 | netdev->vlan_features |= NETIF_F_TSO; |
| 1840 | netdev->vlan_features |= NETIF_F_TSO6; |
Alexander Duyck | 7d8eb29 | 2009-02-06 23:18:27 +0000 | [diff] [blame] | 1841 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 1842 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | 48f29ff | 2008-06-05 04:06:27 -0700 | [diff] [blame] | 1843 | netdev->vlan_features |= NETIF_F_SG; |
| 1844 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1845 | if (pci_using_dac) |
| 1846 | netdev->features |= NETIF_F_HIGHDMA; |
| 1847 | |
Alexander Duyck | 5b043fb | 2009-10-27 23:52:31 +0000 | [diff] [blame] | 1848 | if (hw->mac.type >= e1000_82576) |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 1849 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 1850 | |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1851 | adapter->en_mng_pt = igb_enable_mng_pass_thru(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1852 | |
| 1853 | /* before reading the NVM, reset the controller to put the device in a |
| 1854 | * known good starting state */ |
| 1855 | hw->mac.ops.reset_hw(hw); |
| 1856 | |
| 1857 | /* make sure the NVM is good */ |
| 1858 | if (igb_validate_nvm_checksum(hw) < 0) { |
| 1859 | dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); |
| 1860 | err = -EIO; |
| 1861 | goto err_eeprom; |
| 1862 | } |
| 1863 | |
| 1864 | /* copy the MAC address out of the NVM */ |
| 1865 | if (hw->mac.ops.read_mac_addr(hw)) |
| 1866 | dev_err(&pdev->dev, "NVM Read Error\n"); |
| 1867 | |
| 1868 | memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len); |
| 1869 | memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len); |
| 1870 | |
| 1871 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
| 1872 | dev_err(&pdev->dev, "Invalid MAC Address\n"); |
| 1873 | err = -EIO; |
| 1874 | goto err_eeprom; |
| 1875 | } |
| 1876 | |
Alexander Duyck | 0e34048 | 2009-03-20 00:17:08 +0000 | [diff] [blame] | 1877 | setup_timer(&adapter->watchdog_timer, &igb_watchdog, |
| 1878 | (unsigned long) adapter); |
| 1879 | setup_timer(&adapter->phy_info_timer, &igb_update_phy_info, |
| 1880 | (unsigned long) adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1881 | |
| 1882 | INIT_WORK(&adapter->reset_task, igb_reset_task); |
| 1883 | INIT_WORK(&adapter->watchdog_task, igb_watchdog_task); |
| 1884 | |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 1885 | /* Initialize link properties that are user-changeable */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1886 | adapter->fc_autoneg = true; |
| 1887 | hw->mac.autoneg = true; |
| 1888 | hw->phy.autoneg_advertised = 0x2f; |
| 1889 | |
Alexander Duyck | 0cce119 | 2009-07-23 18:10:24 +0000 | [diff] [blame] | 1890 | hw->fc.requested_mode = e1000_fc_default; |
| 1891 | hw->fc.current_mode = e1000_fc_default; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1892 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1893 | igb_validate_mdi_setting(hw); |
| 1894 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1895 | /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM, |
| 1896 | * enable the ACPI Magic Packet filter |
| 1897 | */ |
| 1898 | |
Alexander Duyck | a2cf8b6 | 2009-03-13 20:41:17 +0000 | [diff] [blame] | 1899 | if (hw->bus.func == 0) |
Alexander Duyck | 312c75a | 2009-02-06 23:17:47 +0000 | [diff] [blame] | 1900 | hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1901 | else if (hw->mac.type == e1000_82580) |
| 1902 | hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A + |
| 1903 | NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1, |
| 1904 | &eeprom_data); |
Alexander Duyck | a2cf8b6 | 2009-03-13 20:41:17 +0000 | [diff] [blame] | 1905 | else if (hw->bus.func == 1) |
| 1906 | 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] | 1907 | |
| 1908 | if (eeprom_data & eeprom_apme_mask) |
| 1909 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1910 | |
| 1911 | /* now that we have the eeprom settings, apply the special cases where |
| 1912 | * the eeprom may be wrong or the board simply won't support wake on |
| 1913 | * lan on a particular port */ |
| 1914 | switch (pdev->device) { |
| 1915 | case E1000_DEV_ID_82575GB_QUAD_COPPER: |
| 1916 | adapter->eeprom_wol = 0; |
| 1917 | break; |
| 1918 | case E1000_DEV_ID_82575EB_FIBER_SERDES: |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1919 | case E1000_DEV_ID_82576_FIBER: |
| 1920 | case E1000_DEV_ID_82576_SERDES: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1921 | /* Wake events only supported on port A for dual fiber |
| 1922 | * regardless of eeprom setting */ |
| 1923 | if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1) |
| 1924 | adapter->eeprom_wol = 0; |
| 1925 | break; |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 1926 | case E1000_DEV_ID_82576_QUAD_COPPER: |
Stefan Assmann | d5aa225 | 2010-04-09 09:51:34 +0000 | [diff] [blame] | 1927 | case E1000_DEV_ID_82576_QUAD_COPPER_ET2: |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 1928 | /* if quad port adapter, disable WoL on all but port A */ |
| 1929 | if (global_quad_port_a != 0) |
| 1930 | adapter->eeprom_wol = 0; |
| 1931 | else |
| 1932 | adapter->flags |= IGB_FLAG_QUAD_PORT_A; |
| 1933 | /* Reset for multiple quad port adapters */ |
| 1934 | if (++global_quad_port_a == 4) |
| 1935 | global_quad_port_a = 0; |
| 1936 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | /* initialize the wol settings based on the eeprom settings */ |
| 1940 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | e1b86d8 | 2008-11-07 20:30:37 +0000 | [diff] [blame] | 1941 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1942 | |
| 1943 | /* reset the hardware with the new settings */ |
| 1944 | igb_reset(adapter); |
| 1945 | |
| 1946 | /* let the f/w know that the h/w is now under the control of the |
| 1947 | * driver. */ |
| 1948 | igb_get_hw_control(adapter); |
| 1949 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1950 | strcpy(netdev->name, "eth%d"); |
| 1951 | err = register_netdev(netdev); |
| 1952 | if (err) |
| 1953 | goto err_register; |
| 1954 | |
Jesse Brandeburg | b168dfc | 2009-04-17 20:44:32 +0000 | [diff] [blame] | 1955 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 1956 | netif_carrier_off(netdev); |
| 1957 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 1958 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 1959 | if (dca_add_requester(&pdev->dev) == 0) { |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1960 | adapter->flags |= IGB_FLAG_DCA_ENABLED; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 1961 | dev_info(&pdev->dev, "DCA enabled\n"); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 1962 | igb_setup_dca(adapter); |
| 1963 | } |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 1964 | |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 1965 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1966 | dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n"); |
| 1967 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 1968 | dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n", |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1969 | netdev->name, |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 1970 | ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
Alexander Duyck | ff846f5 | 2010-04-27 01:02:40 +0000 | [diff] [blame] | 1971 | (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" : |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 1972 | "unknown"), |
Alexander Duyck | 59c3de8 | 2009-03-31 20:38:00 +0000 | [diff] [blame] | 1973 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 1974 | (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" : |
| 1975 | (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" : |
| 1976 | "unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 1977 | netdev->dev_addr); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1978 | |
| 1979 | igb_read_part_num(hw, &part_num); |
| 1980 | dev_info(&pdev->dev, "%s: PBA No: %06x-%03x\n", netdev->name, |
| 1981 | (part_num >> 8), (part_num & 0xff)); |
| 1982 | |
| 1983 | dev_info(&pdev->dev, |
| 1984 | "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n", |
| 1985 | adapter->msix_entries ? "MSI-X" : |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1986 | (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy", |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1987 | adapter->num_rx_queues, adapter->num_tx_queues); |
| 1988 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1989 | return 0; |
| 1990 | |
| 1991 | err_register: |
| 1992 | igb_release_hw_control(adapter); |
| 1993 | err_eeprom: |
| 1994 | if (!igb_check_reset_block(hw)) |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 1995 | igb_reset_phy(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1996 | |
| 1997 | if (hw->flash_address) |
| 1998 | iounmap(hw->flash_address); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1999 | err_sw_init: |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 2000 | igb_clear_interrupt_scheme(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2001 | iounmap(hw->hw_addr); |
| 2002 | err_ioremap: |
| 2003 | free_netdev(netdev); |
| 2004 | err_alloc_etherdev: |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2005 | pci_release_selected_regions(pdev, |
| 2006 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2007 | err_pci_reg: |
| 2008 | err_dma: |
| 2009 | pci_disable_device(pdev); |
| 2010 | return err; |
| 2011 | } |
| 2012 | |
| 2013 | /** |
| 2014 | * igb_remove - Device Removal Routine |
| 2015 | * @pdev: PCI device information struct |
| 2016 | * |
| 2017 | * igb_remove is called by the PCI subsystem to alert the driver |
| 2018 | * that it should release a PCI device. The could be caused by a |
| 2019 | * Hot-Plug event, or because the driver is going to be removed from |
| 2020 | * memory. |
| 2021 | **/ |
| 2022 | static void __devexit igb_remove(struct pci_dev *pdev) |
| 2023 | { |
| 2024 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2025 | struct igb_adapter *adapter = netdev_priv(netdev); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2026 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2027 | |
| 2028 | /* flush_scheduled work may reschedule our watchdog task, so |
| 2029 | * explicitly disable watchdog tasks from being rescheduled */ |
| 2030 | set_bit(__IGB_DOWN, &adapter->state); |
| 2031 | del_timer_sync(&adapter->watchdog_timer); |
| 2032 | del_timer_sync(&adapter->phy_info_timer); |
| 2033 | |
| 2034 | flush_scheduled_work(); |
| 2035 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 2036 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 2037 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) { |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2038 | dev_info(&pdev->dev, "DCA disabled\n"); |
| 2039 | dca_remove_requester(&pdev->dev); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 2040 | adapter->flags &= ~IGB_FLAG_DCA_ENABLED; |
Alexander Duyck | cbd347a | 2009-02-15 23:59:44 -0800 | [diff] [blame] | 2041 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2042 | } |
| 2043 | #endif |
| 2044 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2045 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 2046 | * would have already happened in close and is redundant. */ |
| 2047 | igb_release_hw_control(adapter); |
| 2048 | |
| 2049 | unregister_netdev(netdev); |
| 2050 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 2051 | igb_clear_interrupt_scheme(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2052 | |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 2053 | #ifdef CONFIG_PCI_IOV |
| 2054 | /* reclaim resources allocated to VFs */ |
| 2055 | if (adapter->vf_data) { |
| 2056 | /* disable iov and allow time for transactions to clear */ |
| 2057 | pci_disable_sriov(pdev); |
| 2058 | msleep(500); |
| 2059 | |
| 2060 | kfree(adapter->vf_data); |
| 2061 | adapter->vf_data = NULL; |
| 2062 | wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ); |
| 2063 | msleep(100); |
| 2064 | dev_info(&pdev->dev, "IOV Disabled\n"); |
| 2065 | } |
| 2066 | #endif |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2067 | |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 2068 | iounmap(hw->hw_addr); |
| 2069 | if (hw->flash_address) |
| 2070 | iounmap(hw->flash_address); |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2071 | pci_release_selected_regions(pdev, |
| 2072 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2073 | |
| 2074 | free_netdev(netdev); |
| 2075 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 2076 | pci_disable_pcie_error_reporting(pdev); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 2077 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2078 | pci_disable_device(pdev); |
| 2079 | } |
| 2080 | |
| 2081 | /** |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2082 | * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space |
| 2083 | * @adapter: board private structure to initialize |
| 2084 | * |
| 2085 | * This function initializes the vf specific data storage and then attempts to |
| 2086 | * allocate the VFs. The reason for ordering it this way is because it is much |
| 2087 | * mor expensive time wise to disable SR-IOV than it is to allocate and free |
| 2088 | * the memory for the VFs. |
| 2089 | **/ |
| 2090 | static void __devinit igb_probe_vfs(struct igb_adapter * adapter) |
| 2091 | { |
| 2092 | #ifdef CONFIG_PCI_IOV |
| 2093 | struct pci_dev *pdev = adapter->pdev; |
| 2094 | |
| 2095 | if (adapter->vfs_allocated_count > 7) |
| 2096 | adapter->vfs_allocated_count = 7; |
| 2097 | |
| 2098 | if (adapter->vfs_allocated_count) { |
| 2099 | adapter->vf_data = kcalloc(adapter->vfs_allocated_count, |
| 2100 | sizeof(struct vf_data_storage), |
| 2101 | GFP_KERNEL); |
| 2102 | /* if allocation failed then we do not support SR-IOV */ |
| 2103 | if (!adapter->vf_data) { |
| 2104 | adapter->vfs_allocated_count = 0; |
| 2105 | dev_err(&pdev->dev, "Unable to allocate memory for VF " |
| 2106 | "Data Storage\n"); |
| 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | if (pci_enable_sriov(pdev, adapter->vfs_allocated_count)) { |
| 2111 | kfree(adapter->vf_data); |
| 2112 | adapter->vf_data = NULL; |
| 2113 | #endif /* CONFIG_PCI_IOV */ |
| 2114 | adapter->vfs_allocated_count = 0; |
| 2115 | #ifdef CONFIG_PCI_IOV |
| 2116 | } else { |
| 2117 | unsigned char mac_addr[ETH_ALEN]; |
| 2118 | int i; |
| 2119 | dev_info(&pdev->dev, "%d vfs allocated\n", |
| 2120 | adapter->vfs_allocated_count); |
| 2121 | for (i = 0; i < adapter->vfs_allocated_count; i++) { |
| 2122 | random_ether_addr(mac_addr); |
| 2123 | igb_set_vf_mac(adapter, i, mac_addr); |
| 2124 | } |
| 2125 | } |
| 2126 | #endif /* CONFIG_PCI_IOV */ |
| 2127 | } |
| 2128 | |
Alexander Duyck | 115f459 | 2009-11-12 18:37:00 +0000 | [diff] [blame] | 2129 | |
| 2130 | /** |
| 2131 | * igb_init_hw_timer - Initialize hardware timer used with IEEE 1588 timestamp |
| 2132 | * @adapter: board private structure to initialize |
| 2133 | * |
| 2134 | * igb_init_hw_timer initializes the function pointer and values for the hw |
| 2135 | * timer found in hardware. |
| 2136 | **/ |
| 2137 | static void igb_init_hw_timer(struct igb_adapter *adapter) |
| 2138 | { |
| 2139 | struct e1000_hw *hw = &adapter->hw; |
| 2140 | |
| 2141 | switch (hw->mac.type) { |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 2142 | case e1000_i350: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 2143 | case e1000_82580: |
| 2144 | memset(&adapter->cycles, 0, sizeof(adapter->cycles)); |
| 2145 | adapter->cycles.read = igb_read_clock; |
| 2146 | adapter->cycles.mask = CLOCKSOURCE_MASK(64); |
| 2147 | adapter->cycles.mult = 1; |
| 2148 | /* |
| 2149 | * The 82580 timesync updates the system timer every 8ns by 8ns |
| 2150 | * and the value cannot be shifted. Instead we need to shift |
| 2151 | * the registers to generate a 64bit timer value. As a result |
| 2152 | * SYSTIMR/L/H, TXSTMPL/H, RXSTMPL/H all have to be shifted by |
| 2153 | * 24 in order to generate a larger value for synchronization. |
| 2154 | */ |
| 2155 | adapter->cycles.shift = IGB_82580_TSYNC_SHIFT; |
| 2156 | /* disable system timer temporarily by setting bit 31 */ |
| 2157 | wr32(E1000_TSAUXC, 0x80000000); |
| 2158 | wrfl(); |
| 2159 | |
| 2160 | /* Set registers so that rollover occurs soon to test this. */ |
| 2161 | wr32(E1000_SYSTIMR, 0x00000000); |
| 2162 | wr32(E1000_SYSTIML, 0x80000000); |
| 2163 | wr32(E1000_SYSTIMH, 0x000000FF); |
| 2164 | wrfl(); |
| 2165 | |
| 2166 | /* enable system timer by clearing bit 31 */ |
| 2167 | wr32(E1000_TSAUXC, 0x0); |
| 2168 | wrfl(); |
| 2169 | |
| 2170 | timecounter_init(&adapter->clock, |
| 2171 | &adapter->cycles, |
| 2172 | ktime_to_ns(ktime_get_real())); |
| 2173 | /* |
| 2174 | * Synchronize our NIC clock against system wall clock. NIC |
| 2175 | * time stamp reading requires ~3us per sample, each sample |
| 2176 | * was pretty stable even under load => only require 10 |
| 2177 | * samples for each offset comparison. |
| 2178 | */ |
| 2179 | memset(&adapter->compare, 0, sizeof(adapter->compare)); |
| 2180 | adapter->compare.source = &adapter->clock; |
| 2181 | adapter->compare.target = ktime_get_real; |
| 2182 | adapter->compare.num_samples = 10; |
| 2183 | timecompare_update(&adapter->compare, 0); |
| 2184 | break; |
Alexander Duyck | 115f459 | 2009-11-12 18:37:00 +0000 | [diff] [blame] | 2185 | case e1000_82576: |
| 2186 | /* |
| 2187 | * Initialize hardware timer: we keep it running just in case |
| 2188 | * that some program needs it later on. |
| 2189 | */ |
| 2190 | memset(&adapter->cycles, 0, sizeof(adapter->cycles)); |
| 2191 | adapter->cycles.read = igb_read_clock; |
| 2192 | adapter->cycles.mask = CLOCKSOURCE_MASK(64); |
| 2193 | adapter->cycles.mult = 1; |
| 2194 | /** |
| 2195 | * Scale the NIC clock cycle by a large factor so that |
| 2196 | * relatively small clock corrections can be added or |
| 2197 | * substracted at each clock tick. The drawbacks of a large |
| 2198 | * factor are a) that the clock register overflows more quickly |
| 2199 | * (not such a big deal) and b) that the increment per tick has |
| 2200 | * to fit into 24 bits. As a result we need to use a shift of |
| 2201 | * 19 so we can fit a value of 16 into the TIMINCA register. |
| 2202 | */ |
| 2203 | adapter->cycles.shift = IGB_82576_TSYNC_SHIFT; |
| 2204 | wr32(E1000_TIMINCA, |
| 2205 | (1 << E1000_TIMINCA_16NS_SHIFT) | |
| 2206 | (16 << IGB_82576_TSYNC_SHIFT)); |
| 2207 | |
| 2208 | /* Set registers so that rollover occurs soon to test this. */ |
| 2209 | wr32(E1000_SYSTIML, 0x00000000); |
| 2210 | wr32(E1000_SYSTIMH, 0xFF800000); |
| 2211 | wrfl(); |
| 2212 | |
| 2213 | timecounter_init(&adapter->clock, |
| 2214 | &adapter->cycles, |
| 2215 | ktime_to_ns(ktime_get_real())); |
| 2216 | /* |
| 2217 | * Synchronize our NIC clock against system wall clock. NIC |
| 2218 | * time stamp reading requires ~3us per sample, each sample |
| 2219 | * was pretty stable even under load => only require 10 |
| 2220 | * samples for each offset comparison. |
| 2221 | */ |
| 2222 | memset(&adapter->compare, 0, sizeof(adapter->compare)); |
| 2223 | adapter->compare.source = &adapter->clock; |
| 2224 | adapter->compare.target = ktime_get_real; |
| 2225 | adapter->compare.num_samples = 10; |
| 2226 | timecompare_update(&adapter->compare, 0); |
| 2227 | break; |
| 2228 | case e1000_82575: |
| 2229 | /* 82575 does not support timesync */ |
| 2230 | default: |
| 2231 | break; |
| 2232 | } |
| 2233 | |
| 2234 | } |
| 2235 | |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2236 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2237 | * igb_sw_init - Initialize general software structures (struct igb_adapter) |
| 2238 | * @adapter: board private structure to initialize |
| 2239 | * |
| 2240 | * igb_sw_init initializes the Adapter private data structure. |
| 2241 | * Fields are initialized based on PCI device information and |
| 2242 | * OS network device settings (MTU size). |
| 2243 | **/ |
| 2244 | static int __devinit igb_sw_init(struct igb_adapter *adapter) |
| 2245 | { |
| 2246 | struct e1000_hw *hw = &adapter->hw; |
| 2247 | struct net_device *netdev = adapter->netdev; |
| 2248 | struct pci_dev *pdev = adapter->pdev; |
| 2249 | |
| 2250 | pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word); |
| 2251 | |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 2252 | adapter->tx_ring_count = IGB_DEFAULT_TXD; |
| 2253 | adapter->rx_ring_count = IGB_DEFAULT_RXD; |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 2254 | adapter->rx_itr_setting = IGB_DEFAULT_ITR; |
| 2255 | adapter->tx_itr_setting = IGB_DEFAULT_ITR; |
| 2256 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2257 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 2258 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
| 2259 | |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2260 | #ifdef CONFIG_PCI_IOV |
| 2261 | if (hw->mac.type == e1000_82576) |
| 2262 | adapter->vfs_allocated_count = max_vfs; |
| 2263 | |
| 2264 | #endif /* CONFIG_PCI_IOV */ |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2265 | adapter->rss_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus()); |
| 2266 | |
| 2267 | /* |
| 2268 | * if rss_queues > 4 or vfs are going to be allocated with rss_queues |
| 2269 | * then we should combine the queues into a queue pair in order to |
| 2270 | * conserve interrupts due to limited supply |
| 2271 | */ |
| 2272 | if ((adapter->rss_queues > 4) || |
| 2273 | ((adapter->rss_queues > 1) && (adapter->vfs_allocated_count > 6))) |
| 2274 | adapter->flags |= IGB_FLAG_QUEUE_PAIRS; |
| 2275 | |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2276 | /* This call may decrease the number of queues */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 2277 | if (igb_init_interrupt_scheme(adapter)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2278 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 2279 | return -ENOMEM; |
| 2280 | } |
| 2281 | |
Alexander Duyck | 115f459 | 2009-11-12 18:37:00 +0000 | [diff] [blame] | 2282 | igb_init_hw_timer(adapter); |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2283 | igb_probe_vfs(adapter); |
| 2284 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2285 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
| 2286 | igb_irq_disable(adapter); |
| 2287 | |
| 2288 | set_bit(__IGB_DOWN, &adapter->state); |
| 2289 | return 0; |
| 2290 | } |
| 2291 | |
| 2292 | /** |
| 2293 | * igb_open - Called when a network interface is made active |
| 2294 | * @netdev: network interface device structure |
| 2295 | * |
| 2296 | * Returns 0 on success, negative value on failure |
| 2297 | * |
| 2298 | * The open entry point is called when a network interface is made |
| 2299 | * active by the system (IFF_UP). At this point all resources needed |
| 2300 | * for transmit and receive operations are allocated, the interrupt |
| 2301 | * handler is registered with the OS, the watchdog timer is started, |
| 2302 | * and the stack is notified that the interface is ready. |
| 2303 | **/ |
| 2304 | static int igb_open(struct net_device *netdev) |
| 2305 | { |
| 2306 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 2307 | struct e1000_hw *hw = &adapter->hw; |
| 2308 | int err; |
| 2309 | int i; |
| 2310 | |
| 2311 | /* disallow open during test */ |
| 2312 | if (test_bit(__IGB_TESTING, &adapter->state)) |
| 2313 | return -EBUSY; |
| 2314 | |
Jesse Brandeburg | b168dfc | 2009-04-17 20:44:32 +0000 | [diff] [blame] | 2315 | netif_carrier_off(netdev); |
| 2316 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2317 | /* allocate transmit descriptors */ |
| 2318 | err = igb_setup_all_tx_resources(adapter); |
| 2319 | if (err) |
| 2320 | goto err_setup_tx; |
| 2321 | |
| 2322 | /* allocate receive descriptors */ |
| 2323 | err = igb_setup_all_rx_resources(adapter); |
| 2324 | if (err) |
| 2325 | goto err_setup_rx; |
| 2326 | |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2327 | igb_power_up_link(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2328 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2329 | /* before we allocate an interrupt, we must be ready to handle it. |
| 2330 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 2331 | * as soon as we call pci_request_irq, so we have to setup our |
| 2332 | * clean_rx handler before we do so. */ |
| 2333 | igb_configure(adapter); |
| 2334 | |
| 2335 | err = igb_request_irq(adapter); |
| 2336 | if (err) |
| 2337 | goto err_req_irq; |
| 2338 | |
| 2339 | /* From here on the code is the same as igb_up() */ |
| 2340 | clear_bit(__IGB_DOWN, &adapter->state); |
| 2341 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 2342 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 2343 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 2344 | napi_enable(&q_vector->napi); |
| 2345 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2346 | |
| 2347 | /* Clear any pending interrupts. */ |
| 2348 | rd32(E1000_ICR); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 2349 | |
| 2350 | igb_irq_enable(adapter); |
| 2351 | |
Alexander Duyck | d496030 | 2009-10-27 15:53:45 +0000 | [diff] [blame] | 2352 | /* notify VFs that reset has been completed */ |
| 2353 | if (adapter->vfs_allocated_count) { |
| 2354 | u32 reg_data = rd32(E1000_CTRL_EXT); |
| 2355 | reg_data |= E1000_CTRL_EXT_PFRSTD; |
| 2356 | wr32(E1000_CTRL_EXT, reg_data); |
| 2357 | } |
| 2358 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 2359 | netif_tx_start_all_queues(netdev); |
| 2360 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 2361 | /* start the watchdog. */ |
| 2362 | hw->mac.get_link_status = 1; |
| 2363 | schedule_work(&adapter->watchdog_task); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2364 | |
| 2365 | return 0; |
| 2366 | |
| 2367 | err_req_irq: |
| 2368 | igb_release_hw_control(adapter); |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2369 | igb_power_down_link(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2370 | igb_free_all_rx_resources(adapter); |
| 2371 | err_setup_rx: |
| 2372 | igb_free_all_tx_resources(adapter); |
| 2373 | err_setup_tx: |
| 2374 | igb_reset(adapter); |
| 2375 | |
| 2376 | return err; |
| 2377 | } |
| 2378 | |
| 2379 | /** |
| 2380 | * igb_close - Disables a network interface |
| 2381 | * @netdev: network interface device structure |
| 2382 | * |
| 2383 | * Returns 0, this is not allowed to fail |
| 2384 | * |
| 2385 | * The close entry point is called when an interface is de-activated |
| 2386 | * by the OS. The hardware is still under the driver's control, but |
| 2387 | * needs to be disabled. A global MAC reset is issued to stop the |
| 2388 | * hardware, and all transmit and receive resources are freed. |
| 2389 | **/ |
| 2390 | static int igb_close(struct net_device *netdev) |
| 2391 | { |
| 2392 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 2393 | |
| 2394 | WARN_ON(test_bit(__IGB_RESETTING, &adapter->state)); |
| 2395 | igb_down(adapter); |
| 2396 | |
| 2397 | igb_free_irq(adapter); |
| 2398 | |
| 2399 | igb_free_all_tx_resources(adapter); |
| 2400 | igb_free_all_rx_resources(adapter); |
| 2401 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2402 | return 0; |
| 2403 | } |
| 2404 | |
| 2405 | /** |
| 2406 | * igb_setup_tx_resources - allocate Tx resources (Descriptors) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2407 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
| 2408 | * |
| 2409 | * Return 0 on success, negative on failure |
| 2410 | **/ |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 2411 | int igb_setup_tx_resources(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2412 | { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2413 | struct device *dev = tx_ring->dev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2414 | int size; |
| 2415 | |
| 2416 | size = sizeof(struct igb_buffer) * tx_ring->count; |
| 2417 | tx_ring->buffer_info = vmalloc(size); |
| 2418 | if (!tx_ring->buffer_info) |
| 2419 | goto err; |
| 2420 | memset(tx_ring->buffer_info, 0, size); |
| 2421 | |
| 2422 | /* round up to nearest 4K */ |
Alexander Duyck | 85e8d00 | 2009-02-16 00:00:20 -0800 | [diff] [blame] | 2423 | tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2424 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2425 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2426 | tx_ring->desc = dma_alloc_coherent(dev, |
| 2427 | tx_ring->size, |
| 2428 | &tx_ring->dma, |
| 2429 | GFP_KERNEL); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2430 | |
| 2431 | if (!tx_ring->desc) |
| 2432 | goto err; |
| 2433 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2434 | tx_ring->next_to_use = 0; |
| 2435 | tx_ring->next_to_clean = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2436 | return 0; |
| 2437 | |
| 2438 | err: |
| 2439 | vfree(tx_ring->buffer_info); |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2440 | dev_err(dev, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2441 | "Unable to allocate memory for the transmit descriptor ring\n"); |
| 2442 | return -ENOMEM; |
| 2443 | } |
| 2444 | |
| 2445 | /** |
| 2446 | * igb_setup_all_tx_resources - wrapper to allocate Tx resources |
| 2447 | * (Descriptors) for all queues |
| 2448 | * @adapter: board private structure |
| 2449 | * |
| 2450 | * Return 0 on success, negative on failure |
| 2451 | **/ |
| 2452 | static int igb_setup_all_tx_resources(struct igb_adapter *adapter) |
| 2453 | { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2454 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2455 | int i, err = 0; |
| 2456 | |
| 2457 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2458 | err = igb_setup_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2459 | if (err) { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2460 | dev_err(&pdev->dev, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2461 | "Allocation for Tx Queue %u failed\n", i); |
| 2462 | for (i--; i >= 0; i--) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2463 | igb_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2464 | break; |
| 2465 | } |
| 2466 | } |
| 2467 | |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2468 | for (i = 0; i < IGB_ABS_MAX_TX_QUEUES; i++) { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2469 | int r_idx = i % adapter->num_tx_queues; |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2470 | adapter->multi_tx_table[i] = adapter->tx_ring[r_idx]; |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 2471 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2472 | return err; |
| 2473 | } |
| 2474 | |
| 2475 | /** |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2476 | * igb_setup_tctl - configure the transmit control registers |
| 2477 | * @adapter: Board private structure |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2478 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 2479 | void igb_setup_tctl(struct igb_adapter *adapter) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2480 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2481 | struct e1000_hw *hw = &adapter->hw; |
| 2482 | u32 tctl; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2483 | |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2484 | /* disable queue 0 which is enabled by default on 82575 and 82576 */ |
| 2485 | wr32(E1000_TXDCTL(0), 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2486 | |
| 2487 | /* Program the Transmit Control Register */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2488 | tctl = rd32(E1000_TCTL); |
| 2489 | tctl &= ~E1000_TCTL_CT; |
| 2490 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 2491 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 2492 | |
| 2493 | igb_config_collision_dist(hw); |
| 2494 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2495 | /* Enable transmits */ |
| 2496 | tctl |= E1000_TCTL_EN; |
| 2497 | |
| 2498 | wr32(E1000_TCTL, tctl); |
| 2499 | } |
| 2500 | |
| 2501 | /** |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2502 | * igb_configure_tx_ring - Configure transmit ring after Reset |
| 2503 | * @adapter: board private structure |
| 2504 | * @ring: tx ring to configure |
| 2505 | * |
| 2506 | * Configure a transmit ring after a reset. |
| 2507 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 2508 | void igb_configure_tx_ring(struct igb_adapter *adapter, |
| 2509 | struct igb_ring *ring) |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2510 | { |
| 2511 | struct e1000_hw *hw = &adapter->hw; |
| 2512 | u32 txdctl; |
| 2513 | u64 tdba = ring->dma; |
| 2514 | int reg_idx = ring->reg_idx; |
| 2515 | |
| 2516 | /* disable the queue */ |
| 2517 | txdctl = rd32(E1000_TXDCTL(reg_idx)); |
| 2518 | wr32(E1000_TXDCTL(reg_idx), |
| 2519 | txdctl & ~E1000_TXDCTL_QUEUE_ENABLE); |
| 2520 | wrfl(); |
| 2521 | mdelay(10); |
| 2522 | |
| 2523 | wr32(E1000_TDLEN(reg_idx), |
| 2524 | ring->count * sizeof(union e1000_adv_tx_desc)); |
| 2525 | wr32(E1000_TDBAL(reg_idx), |
| 2526 | tdba & 0x00000000ffffffffULL); |
| 2527 | wr32(E1000_TDBAH(reg_idx), tdba >> 32); |
| 2528 | |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 2529 | ring->head = hw->hw_addr + E1000_TDH(reg_idx); |
| 2530 | ring->tail = hw->hw_addr + E1000_TDT(reg_idx); |
| 2531 | writel(0, ring->head); |
| 2532 | writel(0, ring->tail); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2533 | |
| 2534 | txdctl |= IGB_TX_PTHRESH; |
| 2535 | txdctl |= IGB_TX_HTHRESH << 8; |
| 2536 | txdctl |= IGB_TX_WTHRESH << 16; |
| 2537 | |
| 2538 | txdctl |= E1000_TXDCTL_QUEUE_ENABLE; |
| 2539 | wr32(E1000_TXDCTL(reg_idx), txdctl); |
| 2540 | } |
| 2541 | |
| 2542 | /** |
| 2543 | * igb_configure_tx - Configure transmit Unit after Reset |
| 2544 | * @adapter: board private structure |
| 2545 | * |
| 2546 | * Configure the Tx unit of the MAC after a reset. |
| 2547 | **/ |
| 2548 | static void igb_configure_tx(struct igb_adapter *adapter) |
| 2549 | { |
| 2550 | int i; |
| 2551 | |
| 2552 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2553 | igb_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2557 | * igb_setup_rx_resources - allocate Rx resources (Descriptors) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2558 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 2559 | * |
| 2560 | * Returns 0 on success, negative on failure |
| 2561 | **/ |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 2562 | int igb_setup_rx_resources(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2563 | { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2564 | struct device *dev = rx_ring->dev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2565 | int size, desc_len; |
| 2566 | |
| 2567 | size = sizeof(struct igb_buffer) * rx_ring->count; |
| 2568 | rx_ring->buffer_info = vmalloc(size); |
| 2569 | if (!rx_ring->buffer_info) |
| 2570 | goto err; |
| 2571 | memset(rx_ring->buffer_info, 0, size); |
| 2572 | |
| 2573 | desc_len = sizeof(union e1000_adv_rx_desc); |
| 2574 | |
| 2575 | /* Round up to nearest 4K */ |
| 2576 | rx_ring->size = rx_ring->count * desc_len; |
| 2577 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2578 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2579 | rx_ring->desc = dma_alloc_coherent(dev, |
| 2580 | rx_ring->size, |
| 2581 | &rx_ring->dma, |
| 2582 | GFP_KERNEL); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2583 | |
| 2584 | if (!rx_ring->desc) |
| 2585 | goto err; |
| 2586 | |
| 2587 | rx_ring->next_to_clean = 0; |
| 2588 | rx_ring->next_to_use = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2589 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2590 | return 0; |
| 2591 | |
| 2592 | err: |
| 2593 | vfree(rx_ring->buffer_info); |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2594 | rx_ring->buffer_info = NULL; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2595 | dev_err(dev, "Unable to allocate memory for the receive descriptor" |
| 2596 | " ring\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2597 | return -ENOMEM; |
| 2598 | } |
| 2599 | |
| 2600 | /** |
| 2601 | * igb_setup_all_rx_resources - wrapper to allocate Rx resources |
| 2602 | * (Descriptors) for all queues |
| 2603 | * @adapter: board private structure |
| 2604 | * |
| 2605 | * Return 0 on success, negative on failure |
| 2606 | **/ |
| 2607 | static int igb_setup_all_rx_resources(struct igb_adapter *adapter) |
| 2608 | { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2609 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2610 | int i, err = 0; |
| 2611 | |
| 2612 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2613 | err = igb_setup_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2614 | if (err) { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2615 | dev_err(&pdev->dev, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2616 | "Allocation for Rx Queue %u failed\n", i); |
| 2617 | for (i--; i >= 0; i--) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2618 | igb_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2619 | break; |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | return err; |
| 2624 | } |
| 2625 | |
| 2626 | /** |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2627 | * igb_setup_mrqc - configure the multiple receive queue control registers |
| 2628 | * @adapter: Board private structure |
| 2629 | **/ |
| 2630 | static void igb_setup_mrqc(struct igb_adapter *adapter) |
| 2631 | { |
| 2632 | struct e1000_hw *hw = &adapter->hw; |
| 2633 | u32 mrqc, rxcsum; |
| 2634 | u32 j, num_rx_queues, shift = 0, shift2 = 0; |
| 2635 | union e1000_reta { |
| 2636 | u32 dword; |
| 2637 | u8 bytes[4]; |
| 2638 | } reta; |
| 2639 | static const u8 rsshash[40] = { |
| 2640 | 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 0x41, 0x67, |
| 2641 | 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, 0xd0, 0xca, 0x2b, 0xcb, |
| 2642 | 0xae, 0x7b, 0x30, 0xb4, 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, |
| 2643 | 0xf2, 0x0c, 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa }; |
| 2644 | |
| 2645 | /* Fill out hash function seeds */ |
| 2646 | for (j = 0; j < 10; j++) { |
| 2647 | u32 rsskey = rsshash[(j * 4)]; |
| 2648 | rsskey |= rsshash[(j * 4) + 1] << 8; |
| 2649 | rsskey |= rsshash[(j * 4) + 2] << 16; |
| 2650 | rsskey |= rsshash[(j * 4) + 3] << 24; |
| 2651 | array_wr32(E1000_RSSRK(0), j, rsskey); |
| 2652 | } |
| 2653 | |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2654 | num_rx_queues = adapter->rss_queues; |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2655 | |
| 2656 | if (adapter->vfs_allocated_count) { |
| 2657 | /* 82575 and 82576 supports 2 RSS queues for VMDq */ |
| 2658 | switch (hw->mac.type) { |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 2659 | case e1000_i350: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 2660 | case e1000_82580: |
| 2661 | num_rx_queues = 1; |
| 2662 | shift = 0; |
| 2663 | break; |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2664 | case e1000_82576: |
| 2665 | shift = 3; |
| 2666 | num_rx_queues = 2; |
| 2667 | break; |
| 2668 | case e1000_82575: |
| 2669 | shift = 2; |
| 2670 | shift2 = 6; |
| 2671 | default: |
| 2672 | break; |
| 2673 | } |
| 2674 | } else { |
| 2675 | if (hw->mac.type == e1000_82575) |
| 2676 | shift = 6; |
| 2677 | } |
| 2678 | |
| 2679 | for (j = 0; j < (32 * 4); j++) { |
| 2680 | reta.bytes[j & 3] = (j % num_rx_queues) << shift; |
| 2681 | if (shift2) |
| 2682 | reta.bytes[j & 3] |= num_rx_queues << shift2; |
| 2683 | if ((j & 3) == 3) |
| 2684 | wr32(E1000_RETA(j >> 2), reta.dword); |
| 2685 | } |
| 2686 | |
| 2687 | /* |
| 2688 | * Disable raw packet checksumming so that RSS hash is placed in |
| 2689 | * descriptor on writeback. No need to enable TCP/UDP/IP checksum |
| 2690 | * offloads as they are enabled by default |
| 2691 | */ |
| 2692 | rxcsum = rd32(E1000_RXCSUM); |
| 2693 | rxcsum |= E1000_RXCSUM_PCSD; |
| 2694 | |
| 2695 | if (adapter->hw.mac.type >= e1000_82576) |
| 2696 | /* Enable Receive Checksum Offload for SCTP */ |
| 2697 | rxcsum |= E1000_RXCSUM_CRCOFL; |
| 2698 | |
| 2699 | /* Don't need to set TUOFL or IPOFL, they default to 1 */ |
| 2700 | wr32(E1000_RXCSUM, rxcsum); |
| 2701 | |
| 2702 | /* If VMDq is enabled then we set the appropriate mode for that, else |
| 2703 | * we default to RSS so that an RSS hash is calculated per packet even |
| 2704 | * if we are only using one queue */ |
| 2705 | if (adapter->vfs_allocated_count) { |
| 2706 | if (hw->mac.type > e1000_82575) { |
| 2707 | /* Set the default pool for the PF's first queue */ |
| 2708 | u32 vtctl = rd32(E1000_VT_CTL); |
| 2709 | vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK | |
| 2710 | E1000_VT_CTL_DISABLE_DEF_POOL); |
| 2711 | vtctl |= adapter->vfs_allocated_count << |
| 2712 | E1000_VT_CTL_DEFAULT_POOL_SHIFT; |
| 2713 | wr32(E1000_VT_CTL, vtctl); |
| 2714 | } |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2715 | if (adapter->rss_queues > 1) |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2716 | mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q; |
| 2717 | else |
| 2718 | mrqc = E1000_MRQC_ENABLE_VMDQ; |
| 2719 | } else { |
| 2720 | mrqc = E1000_MRQC_ENABLE_RSS_4Q; |
| 2721 | } |
| 2722 | igb_vmm_control(adapter); |
| 2723 | |
| 2724 | mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 | |
| 2725 | E1000_MRQC_RSS_FIELD_IPV4_TCP); |
| 2726 | mrqc |= (E1000_MRQC_RSS_FIELD_IPV6 | |
| 2727 | E1000_MRQC_RSS_FIELD_IPV6_TCP); |
| 2728 | mrqc |= (E1000_MRQC_RSS_FIELD_IPV4_UDP | |
| 2729 | E1000_MRQC_RSS_FIELD_IPV6_UDP); |
| 2730 | mrqc |= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX | |
| 2731 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); |
| 2732 | |
| 2733 | wr32(E1000_MRQC, mrqc); |
| 2734 | } |
| 2735 | |
| 2736 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2737 | * igb_setup_rctl - configure the receive control registers |
| 2738 | * @adapter: Board private structure |
| 2739 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 2740 | void igb_setup_rctl(struct igb_adapter *adapter) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2741 | { |
| 2742 | struct e1000_hw *hw = &adapter->hw; |
| 2743 | u32 rctl; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2744 | |
| 2745 | rctl = rd32(E1000_RCTL); |
| 2746 | |
| 2747 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
Alexander Duyck | 69d728b | 2008-11-25 01:04:03 -0800 | [diff] [blame] | 2748 | rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2749 | |
Alexander Duyck | 69d728b | 2008-11-25 01:04:03 -0800 | [diff] [blame] | 2750 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF | |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 2751 | (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2752 | |
Auke Kok | 87cb7e8 | 2008-07-08 15:08:29 -0700 | [diff] [blame] | 2753 | /* |
| 2754 | * enable stripping of CRC. It's unlikely this will break BMC |
| 2755 | * redirection as it did with e1000. Newer features require |
| 2756 | * that the HW strips the CRC. |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 2757 | */ |
Auke Kok | 87cb7e8 | 2008-07-08 15:08:29 -0700 | [diff] [blame] | 2758 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2759 | |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2760 | /* disable store bad packets and clear size bits. */ |
Alexander Duyck | ec54d7d | 2009-01-31 00:52:57 -0800 | [diff] [blame] | 2761 | rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2762 | |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 2763 | /* enable LPE to prevent packets larger than max_frame_size */ |
| 2764 | rctl |= E1000_RCTL_LPE; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2765 | |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 2766 | /* disable queue 0 to prevent tail write w/o re-config */ |
| 2767 | wr32(E1000_RXDCTL(0), 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2768 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2769 | /* Attention!!! For SR-IOV PF driver operations you must enable |
| 2770 | * queue drop for all VF and PF queues to prevent head of line blocking |
| 2771 | * if an un-trusted VF does not provide descriptors to hardware. |
| 2772 | */ |
| 2773 | if (adapter->vfs_allocated_count) { |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2774 | /* set all queue drop enable bits */ |
| 2775 | wr32(E1000_QDE, ALL_QUEUES); |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2776 | } |
| 2777 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2778 | wr32(E1000_RCTL, rctl); |
| 2779 | } |
| 2780 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2781 | static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size, |
| 2782 | int vfn) |
| 2783 | { |
| 2784 | struct e1000_hw *hw = &adapter->hw; |
| 2785 | u32 vmolr; |
| 2786 | |
| 2787 | /* if it isn't the PF check to see if VFs are enabled and |
| 2788 | * increase the size to support vlan tags */ |
| 2789 | if (vfn < adapter->vfs_allocated_count && |
| 2790 | adapter->vf_data[vfn].vlans_enabled) |
| 2791 | size += VLAN_TAG_SIZE; |
| 2792 | |
| 2793 | vmolr = rd32(E1000_VMOLR(vfn)); |
| 2794 | vmolr &= ~E1000_VMOLR_RLPML_MASK; |
| 2795 | vmolr |= size | E1000_VMOLR_LPE; |
| 2796 | wr32(E1000_VMOLR(vfn), vmolr); |
| 2797 | |
| 2798 | return 0; |
| 2799 | } |
| 2800 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2801 | /** |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2802 | * igb_rlpml_set - set maximum receive packet size |
| 2803 | * @adapter: board private structure |
| 2804 | * |
| 2805 | * Configure maximum receivable packet size. |
| 2806 | **/ |
| 2807 | static void igb_rlpml_set(struct igb_adapter *adapter) |
| 2808 | { |
| 2809 | u32 max_frame_size = adapter->max_frame_size; |
| 2810 | struct e1000_hw *hw = &adapter->hw; |
| 2811 | u16 pf_id = adapter->vfs_allocated_count; |
| 2812 | |
| 2813 | if (adapter->vlgrp) |
| 2814 | max_frame_size += VLAN_TAG_SIZE; |
| 2815 | |
| 2816 | /* if vfs are enabled we set RLPML to the largest possible request |
| 2817 | * size and set the VMOLR RLPML to the size we need */ |
| 2818 | if (pf_id) { |
| 2819 | igb_set_vf_rlpml(adapter, max_frame_size, pf_id); |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2820 | max_frame_size = MAX_JUMBO_FRAME_SIZE; |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | wr32(E1000_RLPML, max_frame_size); |
| 2824 | } |
| 2825 | |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 2826 | static inline void igb_set_vmolr(struct igb_adapter *adapter, |
| 2827 | int vfn, bool aupe) |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2828 | { |
| 2829 | struct e1000_hw *hw = &adapter->hw; |
| 2830 | u32 vmolr; |
| 2831 | |
| 2832 | /* |
| 2833 | * This register exists only on 82576 and newer so if we are older then |
| 2834 | * we should exit and do nothing |
| 2835 | */ |
| 2836 | if (hw->mac.type < e1000_82576) |
| 2837 | return; |
| 2838 | |
| 2839 | vmolr = rd32(E1000_VMOLR(vfn)); |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 2840 | vmolr |= E1000_VMOLR_STRVLAN; /* Strip vlan tags */ |
| 2841 | if (aupe) |
| 2842 | vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */ |
| 2843 | else |
| 2844 | vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */ |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2845 | |
| 2846 | /* clear all bits that might not be set */ |
| 2847 | vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE); |
| 2848 | |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2849 | if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count) |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2850 | vmolr |= E1000_VMOLR_RSSE; /* enable RSS */ |
| 2851 | /* |
| 2852 | * for VMDq only allow the VFs and pool 0 to accept broadcast and |
| 2853 | * multicast packets |
| 2854 | */ |
| 2855 | if (vfn <= adapter->vfs_allocated_count) |
| 2856 | vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */ |
| 2857 | |
| 2858 | wr32(E1000_VMOLR(vfn), vmolr); |
| 2859 | } |
| 2860 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2861 | /** |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2862 | * igb_configure_rx_ring - Configure a receive ring after Reset |
| 2863 | * @adapter: board private structure |
| 2864 | * @ring: receive ring to be configured |
| 2865 | * |
| 2866 | * Configure the Rx unit of the MAC after a reset. |
| 2867 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 2868 | void igb_configure_rx_ring(struct igb_adapter *adapter, |
| 2869 | struct igb_ring *ring) |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2870 | { |
| 2871 | struct e1000_hw *hw = &adapter->hw; |
| 2872 | u64 rdba = ring->dma; |
| 2873 | int reg_idx = ring->reg_idx; |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 2874 | u32 srrctl, rxdctl; |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2875 | |
| 2876 | /* disable the queue */ |
| 2877 | rxdctl = rd32(E1000_RXDCTL(reg_idx)); |
| 2878 | wr32(E1000_RXDCTL(reg_idx), |
| 2879 | rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE); |
| 2880 | |
| 2881 | /* Set DMA base address registers */ |
| 2882 | wr32(E1000_RDBAL(reg_idx), |
| 2883 | rdba & 0x00000000ffffffffULL); |
| 2884 | wr32(E1000_RDBAH(reg_idx), rdba >> 32); |
| 2885 | wr32(E1000_RDLEN(reg_idx), |
| 2886 | ring->count * sizeof(union e1000_adv_rx_desc)); |
| 2887 | |
| 2888 | /* initialize head and tail */ |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 2889 | ring->head = hw->hw_addr + E1000_RDH(reg_idx); |
| 2890 | ring->tail = hw->hw_addr + E1000_RDT(reg_idx); |
| 2891 | writel(0, ring->head); |
| 2892 | writel(0, ring->tail); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2893 | |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 2894 | /* set descriptor configuration */ |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 2895 | if (ring->rx_buffer_len < IGB_RXBUFFER_1024) { |
| 2896 | srrctl = ALIGN(ring->rx_buffer_len, 64) << |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 2897 | E1000_SRRCTL_BSIZEHDRSIZE_SHIFT; |
| 2898 | #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384 |
| 2899 | srrctl |= IGB_RXBUFFER_16384 >> |
| 2900 | E1000_SRRCTL_BSIZEPKT_SHIFT; |
| 2901 | #else |
| 2902 | srrctl |= (PAGE_SIZE / 2) >> |
| 2903 | E1000_SRRCTL_BSIZEPKT_SHIFT; |
| 2904 | #endif |
| 2905 | srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
| 2906 | } else { |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 2907 | srrctl = ALIGN(ring->rx_buffer_len, 1024) >> |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 2908 | E1000_SRRCTL_BSIZEPKT_SHIFT; |
| 2909 | srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF; |
| 2910 | } |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 2911 | if (hw->mac.type == e1000_82580) |
| 2912 | srrctl |= E1000_SRRCTL_TIMESTAMP; |
Nick Nunley | e6bdb6f | 2010-02-17 01:03:38 +0000 | [diff] [blame] | 2913 | /* Only set Drop Enable if we are supporting multiple queues */ |
| 2914 | if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1) |
| 2915 | srrctl |= E1000_SRRCTL_DROP_EN; |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 2916 | |
| 2917 | wr32(E1000_SRRCTL(reg_idx), srrctl); |
| 2918 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2919 | /* set filtering for VMDQ pools */ |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 2920 | igb_set_vmolr(adapter, reg_idx & 0x7, true); |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2921 | |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2922 | /* enable receive descriptor fetching */ |
| 2923 | rxdctl = rd32(E1000_RXDCTL(reg_idx)); |
| 2924 | rxdctl |= E1000_RXDCTL_QUEUE_ENABLE; |
| 2925 | rxdctl &= 0xFFF00000; |
| 2926 | rxdctl |= IGB_RX_PTHRESH; |
| 2927 | rxdctl |= IGB_RX_HTHRESH << 8; |
| 2928 | rxdctl |= IGB_RX_WTHRESH << 16; |
| 2929 | wr32(E1000_RXDCTL(reg_idx), rxdctl); |
| 2930 | } |
| 2931 | |
| 2932 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2933 | * igb_configure_rx - Configure receive Unit after Reset |
| 2934 | * @adapter: board private structure |
| 2935 | * |
| 2936 | * Configure the Rx unit of the MAC after a reset. |
| 2937 | **/ |
| 2938 | static void igb_configure_rx(struct igb_adapter *adapter) |
| 2939 | { |
Hannes Eder | 9107584 | 2009-02-18 19:36:04 -0800 | [diff] [blame] | 2940 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2941 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 2942 | /* set UTA to appropriate mode */ |
| 2943 | igb_set_uta(adapter); |
| 2944 | |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 2945 | /* set the correct pool for the PF default MAC address in entry 0 */ |
| 2946 | igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0, |
| 2947 | adapter->vfs_allocated_count); |
| 2948 | |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2949 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2950 | * the Base and Length of the Rx Descriptor Ring */ |
| 2951 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2952 | igb_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | /** |
| 2956 | * igb_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2957 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2958 | * |
| 2959 | * Free all transmit software resources |
| 2960 | **/ |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 2961 | void igb_free_tx_resources(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2962 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2963 | igb_clean_tx_ring(tx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2964 | |
| 2965 | vfree(tx_ring->buffer_info); |
| 2966 | tx_ring->buffer_info = NULL; |
| 2967 | |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2968 | /* if not set, then don't free */ |
| 2969 | if (!tx_ring->desc) |
| 2970 | return; |
| 2971 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2972 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 2973 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2974 | |
| 2975 | tx_ring->desc = NULL; |
| 2976 | } |
| 2977 | |
| 2978 | /** |
| 2979 | * igb_free_all_tx_resources - Free Tx Resources for All Queues |
| 2980 | * @adapter: board private structure |
| 2981 | * |
| 2982 | * Free all transmit software resources |
| 2983 | **/ |
| 2984 | static void igb_free_all_tx_resources(struct igb_adapter *adapter) |
| 2985 | { |
| 2986 | int i; |
| 2987 | |
| 2988 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2989 | igb_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2990 | } |
| 2991 | |
Alexander Duyck | b1a436c | 2009-10-27 15:54:43 +0000 | [diff] [blame] | 2992 | void igb_unmap_and_free_tx_resource(struct igb_ring *tx_ring, |
| 2993 | struct igb_buffer *buffer_info) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2994 | { |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 2995 | if (buffer_info->dma) { |
| 2996 | if (buffer_info->mapped_as_page) |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2997 | dma_unmap_page(tx_ring->dev, |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 2998 | buffer_info->dma, |
| 2999 | buffer_info->length, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3000 | DMA_TO_DEVICE); |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3001 | else |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3002 | dma_unmap_single(tx_ring->dev, |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3003 | buffer_info->dma, |
| 3004 | buffer_info->length, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3005 | DMA_TO_DEVICE); |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3006 | buffer_info->dma = 0; |
| 3007 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3008 | if (buffer_info->skb) { |
| 3009 | dev_kfree_skb_any(buffer_info->skb); |
| 3010 | buffer_info->skb = NULL; |
| 3011 | } |
| 3012 | buffer_info->time_stamp = 0; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3013 | buffer_info->length = 0; |
| 3014 | buffer_info->next_to_watch = 0; |
| 3015 | buffer_info->mapped_as_page = false; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | /** |
| 3019 | * igb_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3020 | * @tx_ring: ring to be cleaned |
| 3021 | **/ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 3022 | static void igb_clean_tx_ring(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3023 | { |
| 3024 | struct igb_buffer *buffer_info; |
| 3025 | unsigned long size; |
| 3026 | unsigned int i; |
| 3027 | |
| 3028 | if (!tx_ring->buffer_info) |
| 3029 | return; |
| 3030 | /* Free all the Tx ring sk_buffs */ |
| 3031 | |
| 3032 | for (i = 0; i < tx_ring->count; i++) { |
| 3033 | buffer_info = &tx_ring->buffer_info[i]; |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 3034 | igb_unmap_and_free_tx_resource(tx_ring, buffer_info); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | size = sizeof(struct igb_buffer) * tx_ring->count; |
| 3038 | memset(tx_ring->buffer_info, 0, size); |
| 3039 | |
| 3040 | /* Zero out the descriptor ring */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3041 | memset(tx_ring->desc, 0, tx_ring->size); |
| 3042 | |
| 3043 | tx_ring->next_to_use = 0; |
| 3044 | tx_ring->next_to_clean = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | /** |
| 3048 | * igb_clean_all_tx_rings - Free Tx Buffers for all queues |
| 3049 | * @adapter: board private structure |
| 3050 | **/ |
| 3051 | static void igb_clean_all_tx_rings(struct igb_adapter *adapter) |
| 3052 | { |
| 3053 | int i; |
| 3054 | |
| 3055 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3056 | igb_clean_tx_ring(adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | /** |
| 3060 | * igb_free_rx_resources - Free Rx Resources |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3061 | * @rx_ring: ring to clean the resources from |
| 3062 | * |
| 3063 | * Free all receive software resources |
| 3064 | **/ |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 3065 | void igb_free_rx_resources(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3066 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 3067 | igb_clean_rx_ring(rx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3068 | |
| 3069 | vfree(rx_ring->buffer_info); |
| 3070 | rx_ring->buffer_info = NULL; |
| 3071 | |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 3072 | /* if not set, then don't free */ |
| 3073 | if (!rx_ring->desc) |
| 3074 | return; |
| 3075 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3076 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 3077 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3078 | |
| 3079 | rx_ring->desc = NULL; |
| 3080 | } |
| 3081 | |
| 3082 | /** |
| 3083 | * igb_free_all_rx_resources - Free Rx Resources for All Queues |
| 3084 | * @adapter: board private structure |
| 3085 | * |
| 3086 | * Free all receive software resources |
| 3087 | **/ |
| 3088 | static void igb_free_all_rx_resources(struct igb_adapter *adapter) |
| 3089 | { |
| 3090 | int i; |
| 3091 | |
| 3092 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3093 | igb_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | /** |
| 3097 | * igb_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3098 | * @rx_ring: ring to free buffers from |
| 3099 | **/ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 3100 | static void igb_clean_rx_ring(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3101 | { |
| 3102 | struct igb_buffer *buffer_info; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3103 | unsigned long size; |
| 3104 | unsigned int i; |
| 3105 | |
| 3106 | if (!rx_ring->buffer_info) |
| 3107 | return; |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 3108 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3109 | /* Free all the Rx ring sk_buffs */ |
| 3110 | for (i = 0; i < rx_ring->count; i++) { |
| 3111 | buffer_info = &rx_ring->buffer_info[i]; |
| 3112 | if (buffer_info->dma) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3113 | dma_unmap_single(rx_ring->dev, |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 3114 | buffer_info->dma, |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 3115 | rx_ring->rx_buffer_len, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3116 | DMA_FROM_DEVICE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3117 | buffer_info->dma = 0; |
| 3118 | } |
| 3119 | |
| 3120 | if (buffer_info->skb) { |
| 3121 | dev_kfree_skb(buffer_info->skb); |
| 3122 | buffer_info->skb = NULL; |
| 3123 | } |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 3124 | if (buffer_info->page_dma) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3125 | dma_unmap_page(rx_ring->dev, |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 3126 | buffer_info->page_dma, |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 3127 | PAGE_SIZE / 2, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3128 | DMA_FROM_DEVICE); |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 3129 | buffer_info->page_dma = 0; |
| 3130 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3131 | if (buffer_info->page) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3132 | put_page(buffer_info->page); |
| 3133 | buffer_info->page = NULL; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 3134 | buffer_info->page_offset = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3135 | } |
| 3136 | } |
| 3137 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3138 | size = sizeof(struct igb_buffer) * rx_ring->count; |
| 3139 | memset(rx_ring->buffer_info, 0, size); |
| 3140 | |
| 3141 | /* Zero out the descriptor ring */ |
| 3142 | memset(rx_ring->desc, 0, rx_ring->size); |
| 3143 | |
| 3144 | rx_ring->next_to_clean = 0; |
| 3145 | rx_ring->next_to_use = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * igb_clean_all_rx_rings - Free Rx Buffers for all queues |
| 3150 | * @adapter: board private structure |
| 3151 | **/ |
| 3152 | static void igb_clean_all_rx_rings(struct igb_adapter *adapter) |
| 3153 | { |
| 3154 | int i; |
| 3155 | |
| 3156 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3157 | igb_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | /** |
| 3161 | * igb_set_mac - Change the Ethernet Address of the NIC |
| 3162 | * @netdev: network interface device structure |
| 3163 | * @p: pointer to an address structure |
| 3164 | * |
| 3165 | * Returns 0 on success, negative on failure |
| 3166 | **/ |
| 3167 | static int igb_set_mac(struct net_device *netdev, void *p) |
| 3168 | { |
| 3169 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 3170 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3171 | struct sockaddr *addr = p; |
| 3172 | |
| 3173 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3174 | return -EADDRNOTAVAIL; |
| 3175 | |
| 3176 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 3177 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3178 | |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 3179 | /* set the correct pool for the new PF MAC address in entry 0 */ |
| 3180 | igb_rar_set_qsel(adapter, hw->mac.addr, 0, |
| 3181 | adapter->vfs_allocated_count); |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 3182 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3183 | return 0; |
| 3184 | } |
| 3185 | |
| 3186 | /** |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3187 | * igb_write_mc_addr_list - write multicast addresses to MTA |
| 3188 | * @netdev: network interface device structure |
| 3189 | * |
| 3190 | * Writes multicast address list to the MTA hash table. |
| 3191 | * Returns: -ENOMEM on failure |
| 3192 | * 0 on no addresses written |
| 3193 | * X on writing X addresses to MTA |
| 3194 | **/ |
| 3195 | static int igb_write_mc_addr_list(struct net_device *netdev) |
| 3196 | { |
| 3197 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3198 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3199 | struct netdev_hw_addr *ha; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3200 | u8 *mta_list; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3201 | int i; |
| 3202 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3203 | if (netdev_mc_empty(netdev)) { |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3204 | /* nothing to program, so clear mc list */ |
| 3205 | igb_update_mc_addr_list(hw, NULL, 0); |
| 3206 | igb_restore_vf_multicasts(adapter); |
| 3207 | return 0; |
| 3208 | } |
| 3209 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3210 | mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3211 | if (!mta_list) |
| 3212 | return -ENOMEM; |
| 3213 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3214 | /* The shared function expects a packed array of only addresses. */ |
Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 3215 | i = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3216 | netdev_for_each_mc_addr(ha, netdev) |
| 3217 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3218 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3219 | igb_update_mc_addr_list(hw, mta_list, i); |
| 3220 | kfree(mta_list); |
| 3221 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3222 | return netdev_mc_count(netdev); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | /** |
| 3226 | * igb_write_uc_addr_list - write unicast addresses to RAR table |
| 3227 | * @netdev: network interface device structure |
| 3228 | * |
| 3229 | * Writes unicast address list to the RAR table. |
| 3230 | * Returns: -ENOMEM on failure/insufficient address space |
| 3231 | * 0 on no addresses written |
| 3232 | * X on writing X addresses to the RAR table |
| 3233 | **/ |
| 3234 | static int igb_write_uc_addr_list(struct net_device *netdev) |
| 3235 | { |
| 3236 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3237 | struct e1000_hw *hw = &adapter->hw; |
| 3238 | unsigned int vfn = adapter->vfs_allocated_count; |
| 3239 | unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1); |
| 3240 | int count = 0; |
| 3241 | |
| 3242 | /* return ENOMEM indicating insufficient memory for addresses */ |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 3243 | if (netdev_uc_count(netdev) > rar_entries) |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3244 | return -ENOMEM; |
| 3245 | |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 3246 | if (!netdev_uc_empty(netdev) && rar_entries) { |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3247 | struct netdev_hw_addr *ha; |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 3248 | |
| 3249 | netdev_for_each_uc_addr(ha, netdev) { |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3250 | if (!rar_entries) |
| 3251 | break; |
| 3252 | igb_rar_set_qsel(adapter, ha->addr, |
| 3253 | rar_entries--, |
| 3254 | vfn); |
| 3255 | count++; |
| 3256 | } |
| 3257 | } |
| 3258 | /* write the addresses in reverse order to avoid write combining */ |
| 3259 | for (; rar_entries > 0 ; rar_entries--) { |
| 3260 | wr32(E1000_RAH(rar_entries), 0); |
| 3261 | wr32(E1000_RAL(rar_entries), 0); |
| 3262 | } |
| 3263 | wrfl(); |
| 3264 | |
| 3265 | return count; |
| 3266 | } |
| 3267 | |
| 3268 | /** |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 3269 | * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3270 | * @netdev: network interface device structure |
| 3271 | * |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 3272 | * The set_rx_mode entry point is called whenever the unicast or multicast |
| 3273 | * address lists or the network interface flags are updated. This routine is |
| 3274 | * responsible for configuring the hardware for proper unicast, multicast, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3275 | * promiscuous mode, and all-multi behavior. |
| 3276 | **/ |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 3277 | static void igb_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3278 | { |
| 3279 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3280 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3281 | unsigned int vfn = adapter->vfs_allocated_count; |
| 3282 | u32 rctl, vmolr = 0; |
| 3283 | int count; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3284 | |
| 3285 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3286 | rctl = rd32(E1000_RCTL); |
| 3287 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3288 | /* clear the effected bits */ |
| 3289 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE); |
| 3290 | |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3291 | if (netdev->flags & IFF_PROMISC) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3292 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3293 | vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3294 | } else { |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3295 | if (netdev->flags & IFF_ALLMULTI) { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3296 | rctl |= E1000_RCTL_MPE; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3297 | vmolr |= E1000_VMOLR_MPME; |
| 3298 | } else { |
| 3299 | /* |
| 3300 | * Write addresses to the MTA, if the attempt fails |
| 3301 | * then we should just turn on promiscous mode so |
| 3302 | * that we can at least receive multicast traffic |
| 3303 | */ |
| 3304 | count = igb_write_mc_addr_list(netdev); |
| 3305 | if (count < 0) { |
| 3306 | rctl |= E1000_RCTL_MPE; |
| 3307 | vmolr |= E1000_VMOLR_MPME; |
| 3308 | } else if (count) { |
| 3309 | vmolr |= E1000_VMOLR_ROMPE; |
| 3310 | } |
| 3311 | } |
| 3312 | /* |
| 3313 | * Write addresses to available RAR registers, if there is not |
| 3314 | * sufficient space to store all the addresses then enable |
| 3315 | * unicast promiscous mode |
| 3316 | */ |
| 3317 | count = igb_write_uc_addr_list(netdev); |
| 3318 | if (count < 0) { |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 3319 | rctl |= E1000_RCTL_UPE; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3320 | vmolr |= E1000_VMOLR_ROPE; |
| 3321 | } |
Patrick McHardy | 78ed11a | 2008-07-16 20:16:14 -0700 | [diff] [blame] | 3322 | rctl |= E1000_RCTL_VFE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3323 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3324 | wr32(E1000_RCTL, rctl); |
| 3325 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3326 | /* |
| 3327 | * In order to support SR-IOV and eventually VMDq it is necessary to set |
| 3328 | * the VMOLR to enable the appropriate modes. Without this workaround |
| 3329 | * we will have issues with VLAN tag stripping not being done for frames |
| 3330 | * that are only arriving because we are the default pool |
| 3331 | */ |
| 3332 | if (hw->mac.type < e1000_82576) |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame] | 3333 | return; |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame] | 3334 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3335 | vmolr |= rd32(E1000_VMOLR(vfn)) & |
| 3336 | ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE); |
| 3337 | wr32(E1000_VMOLR(vfn), vmolr); |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame] | 3338 | igb_restore_vf_multicasts(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 3342 | * the phy */ |
| 3343 | static void igb_update_phy_info(unsigned long data) |
| 3344 | { |
| 3345 | struct igb_adapter *adapter = (struct igb_adapter *) data; |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 3346 | igb_get_phy_info(&adapter->hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | /** |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3350 | * igb_has_link - check shared code for link and determine up/down |
| 3351 | * @adapter: pointer to driver private info |
| 3352 | **/ |
Nick Nunley | 3145535 | 2010-02-17 01:01:21 +0000 | [diff] [blame] | 3353 | bool igb_has_link(struct igb_adapter *adapter) |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3354 | { |
| 3355 | struct e1000_hw *hw = &adapter->hw; |
| 3356 | bool link_active = false; |
| 3357 | s32 ret_val = 0; |
| 3358 | |
| 3359 | /* get_link_status is set on LSC (link status) interrupt or |
| 3360 | * rx sequence error interrupt. get_link_status will stay |
| 3361 | * false until the e1000_check_for_link establishes link |
| 3362 | * for copper adapters ONLY |
| 3363 | */ |
| 3364 | switch (hw->phy.media_type) { |
| 3365 | case e1000_media_type_copper: |
| 3366 | if (hw->mac.get_link_status) { |
| 3367 | ret_val = hw->mac.ops.check_for_link(hw); |
| 3368 | link_active = !hw->mac.get_link_status; |
| 3369 | } else { |
| 3370 | link_active = true; |
| 3371 | } |
| 3372 | break; |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3373 | case e1000_media_type_internal_serdes: |
| 3374 | ret_val = hw->mac.ops.check_for_link(hw); |
| 3375 | link_active = hw->mac.serdes_has_link; |
| 3376 | break; |
| 3377 | default: |
| 3378 | case e1000_media_type_unknown: |
| 3379 | break; |
| 3380 | } |
| 3381 | |
| 3382 | return link_active; |
| 3383 | } |
| 3384 | |
| 3385 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3386 | * igb_watchdog - Timer Call-back |
| 3387 | * @data: pointer to adapter cast into an unsigned long |
| 3388 | **/ |
| 3389 | static void igb_watchdog(unsigned long data) |
| 3390 | { |
| 3391 | struct igb_adapter *adapter = (struct igb_adapter *)data; |
| 3392 | /* Do the rest outside of interrupt context */ |
| 3393 | schedule_work(&adapter->watchdog_task); |
| 3394 | } |
| 3395 | |
| 3396 | static void igb_watchdog_task(struct work_struct *work) |
| 3397 | { |
| 3398 | struct igb_adapter *adapter = container_of(work, |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 3399 | struct igb_adapter, |
| 3400 | watchdog_task); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3401 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3402 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3403 | u32 link; |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 3404 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3405 | |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3406 | link = igb_has_link(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3407 | if (link) { |
| 3408 | if (!netif_carrier_ok(netdev)) { |
| 3409 | u32 ctrl; |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 3410 | hw->mac.ops.get_speed_and_duplex(hw, |
| 3411 | &adapter->link_speed, |
| 3412 | &adapter->link_duplex); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3413 | |
| 3414 | ctrl = rd32(E1000_CTRL); |
Alexander Duyck | 527d47c | 2008-11-27 00:21:39 -0800 | [diff] [blame] | 3415 | /* Links status message must follow this format */ |
| 3416 | printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, " |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3417 | "Flow Control: %s\n", |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 3418 | netdev->name, |
| 3419 | adapter->link_speed, |
| 3420 | adapter->link_duplex == FULL_DUPLEX ? |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3421 | "Full Duplex" : "Half Duplex", |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 3422 | ((ctrl & E1000_CTRL_TFCE) && |
| 3423 | (ctrl & E1000_CTRL_RFCE)) ? "RX/TX" : |
| 3424 | ((ctrl & E1000_CTRL_RFCE) ? "RX" : |
| 3425 | ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None"))); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3426 | |
Emil Tantilov | d07f3e3 | 2010-03-23 18:34:57 +0000 | [diff] [blame] | 3427 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3428 | adapter->tx_timeout_factor = 1; |
| 3429 | switch (adapter->link_speed) { |
| 3430 | case SPEED_10: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3431 | adapter->tx_timeout_factor = 14; |
| 3432 | break; |
| 3433 | case SPEED_100: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3434 | /* maybe add some timeout factor ? */ |
| 3435 | break; |
| 3436 | } |
| 3437 | |
| 3438 | netif_carrier_on(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3439 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 3440 | igb_ping_all_vfs(adapter); |
| 3441 | |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 3442 | /* link state has changed, schedule phy info update */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3443 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 3444 | mod_timer(&adapter->phy_info_timer, |
| 3445 | round_jiffies(jiffies + 2 * HZ)); |
| 3446 | } |
| 3447 | } else { |
| 3448 | if (netif_carrier_ok(netdev)) { |
| 3449 | adapter->link_speed = 0; |
| 3450 | adapter->link_duplex = 0; |
Alexander Duyck | 527d47c | 2008-11-27 00:21:39 -0800 | [diff] [blame] | 3451 | /* Links status message must follow this format */ |
| 3452 | printk(KERN_INFO "igb: %s NIC Link is Down\n", |
| 3453 | netdev->name); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3454 | netif_carrier_off(netdev); |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 3455 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 3456 | igb_ping_all_vfs(adapter); |
| 3457 | |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 3458 | /* link state has changed, schedule phy info update */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3459 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 3460 | mod_timer(&adapter->phy_info_timer, |
| 3461 | round_jiffies(jiffies + 2 * HZ)); |
| 3462 | } |
| 3463 | } |
| 3464 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3465 | igb_update_stats(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3466 | |
Alexander Duyck | dbabb06 | 2009-11-12 18:38:16 +0000 | [diff] [blame] | 3467 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3468 | struct igb_ring *tx_ring = adapter->tx_ring[i]; |
Alexander Duyck | dbabb06 | 2009-11-12 18:38:16 +0000 | [diff] [blame] | 3469 | if (!netif_carrier_ok(netdev)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3470 | /* We've lost link, so the controller stops DMA, |
| 3471 | * but we've got queued Tx work that's never going |
| 3472 | * to get done, so reset controller to flush Tx. |
| 3473 | * (Do the reset outside of interrupt context). */ |
Alexander Duyck | dbabb06 | 2009-11-12 18:38:16 +0000 | [diff] [blame] | 3474 | if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) { |
| 3475 | adapter->tx_timeout_count++; |
| 3476 | schedule_work(&adapter->reset_task); |
| 3477 | /* return immediately since reset is imminent */ |
| 3478 | return; |
| 3479 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3480 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3481 | |
Alexander Duyck | dbabb06 | 2009-11-12 18:38:16 +0000 | [diff] [blame] | 3482 | /* Force detection of hung controller every watchdog period */ |
| 3483 | tx_ring->detect_tx_hung = true; |
| 3484 | } |
Alexander Duyck | f7ba205 | 2009-10-27 23:48:51 +0000 | [diff] [blame] | 3485 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3486 | /* Cause software interrupt to ensure rx ring is cleaned */ |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 3487 | if (adapter->msix_entries) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3488 | u32 eics = 0; |
| 3489 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 3490 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 3491 | eics |= q_vector->eims_value; |
| 3492 | } |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 3493 | wr32(E1000_EICS, eics); |
| 3494 | } else { |
| 3495 | wr32(E1000_ICS, E1000_ICS_RXDMT0); |
| 3496 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3497 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3498 | /* Reset the timer */ |
| 3499 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 3500 | mod_timer(&adapter->watchdog_timer, |
| 3501 | round_jiffies(jiffies + 2 * HZ)); |
| 3502 | } |
| 3503 | |
| 3504 | enum latency_range { |
| 3505 | lowest_latency = 0, |
| 3506 | low_latency = 1, |
| 3507 | bulk_latency = 2, |
| 3508 | latency_invalid = 255 |
| 3509 | }; |
| 3510 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3511 | /** |
| 3512 | * igb_update_ring_itr - update the dynamic ITR value based on packet size |
| 3513 | * |
| 3514 | * Stores a new ITR value based on strictly on packet size. This |
| 3515 | * algorithm is less sophisticated than that used in igb_update_itr, |
| 3516 | * due to the difficulty of synchronizing statistics across multiple |
| 3517 | * receive rings. The divisors and thresholds used by this fuction |
| 3518 | * were determined based on theoretical maximum wire speed and testing |
| 3519 | * data, in order to minimize response time while increasing bulk |
| 3520 | * throughput. |
| 3521 | * This functionality is controlled by the InterruptThrottleRate module |
| 3522 | * parameter (see igb_param.c) |
| 3523 | * NOTE: This function is called only when operating in a multiqueue |
| 3524 | * receive environment. |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3525 | * @q_vector: pointer to q_vector |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3526 | **/ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3527 | static void igb_update_ring_itr(struct igb_q_vector *q_vector) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3528 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3529 | int new_val = q_vector->itr_val; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3530 | int avg_wire_size = 0; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3531 | struct igb_adapter *adapter = q_vector->adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3532 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3533 | /* For non-gigabit speeds, just fix the interrupt rate at 4000 |
| 3534 | * ints/sec - ITR timer value of 120 ticks. |
| 3535 | */ |
| 3536 | if (adapter->link_speed != SPEED_1000) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3537 | new_val = 976; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3538 | goto set_itr_val; |
| 3539 | } |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3540 | |
| 3541 | if (q_vector->rx_ring && q_vector->rx_ring->total_packets) { |
| 3542 | struct igb_ring *ring = q_vector->rx_ring; |
| 3543 | avg_wire_size = ring->total_bytes / ring->total_packets; |
| 3544 | } |
| 3545 | |
| 3546 | if (q_vector->tx_ring && q_vector->tx_ring->total_packets) { |
| 3547 | struct igb_ring *ring = q_vector->tx_ring; |
| 3548 | avg_wire_size = max_t(u32, avg_wire_size, |
| 3549 | (ring->total_bytes / |
| 3550 | ring->total_packets)); |
| 3551 | } |
| 3552 | |
| 3553 | /* if avg_wire_size isn't set no work was done */ |
| 3554 | if (!avg_wire_size) |
| 3555 | goto clear_counts; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3556 | |
| 3557 | /* Add 24 bytes to size to account for CRC, preamble, and gap */ |
| 3558 | avg_wire_size += 24; |
| 3559 | |
| 3560 | /* Don't starve jumbo frames */ |
| 3561 | avg_wire_size = min(avg_wire_size, 3000); |
| 3562 | |
| 3563 | /* Give a little boost to mid-size frames */ |
| 3564 | if ((avg_wire_size > 300) && (avg_wire_size < 1200)) |
| 3565 | new_val = avg_wire_size / 3; |
| 3566 | else |
| 3567 | new_val = avg_wire_size / 2; |
| 3568 | |
Nick Nunley | abe1c36 | 2010-02-17 01:03:19 +0000 | [diff] [blame] | 3569 | /* when in itr mode 3 do not exceed 20K ints/sec */ |
| 3570 | if (adapter->rx_itr_setting == 3 && new_val < 196) |
| 3571 | new_val = 196; |
| 3572 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3573 | set_itr_val: |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3574 | if (new_val != q_vector->itr_val) { |
| 3575 | q_vector->itr_val = new_val; |
| 3576 | q_vector->set_itr = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3577 | } |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3578 | clear_counts: |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3579 | if (q_vector->rx_ring) { |
| 3580 | q_vector->rx_ring->total_bytes = 0; |
| 3581 | q_vector->rx_ring->total_packets = 0; |
| 3582 | } |
| 3583 | if (q_vector->tx_ring) { |
| 3584 | q_vector->tx_ring->total_bytes = 0; |
| 3585 | q_vector->tx_ring->total_packets = 0; |
| 3586 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * igb_update_itr - update the dynamic ITR value based on statistics |
| 3591 | * Stores a new ITR value based on packets and byte |
| 3592 | * counts during the last interrupt. The advantage of per interrupt |
| 3593 | * computation is faster updates and more accurate ITR for the current |
| 3594 | * traffic pattern. Constants in this function were computed |
| 3595 | * based on theoretical maximum wire speed and thresholds were set based |
| 3596 | * on testing data as well as attempting to minimize response time |
| 3597 | * while increasing bulk throughput. |
| 3598 | * this functionality is controlled by the InterruptThrottleRate module |
| 3599 | * parameter (see igb_param.c) |
| 3600 | * NOTE: These calculations are only valid when operating in a single- |
| 3601 | * queue environment. |
| 3602 | * @adapter: pointer to adapter |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3603 | * @itr_setting: current q_vector->itr_val |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3604 | * @packets: the number of packets during this measurement interval |
| 3605 | * @bytes: the number of bytes during this measurement interval |
| 3606 | **/ |
| 3607 | static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting, |
| 3608 | int packets, int bytes) |
| 3609 | { |
| 3610 | unsigned int retval = itr_setting; |
| 3611 | |
| 3612 | if (packets == 0) |
| 3613 | goto update_itr_done; |
| 3614 | |
| 3615 | switch (itr_setting) { |
| 3616 | case lowest_latency: |
| 3617 | /* handle TSO and jumbo frames */ |
| 3618 | if (bytes/packets > 8000) |
| 3619 | retval = bulk_latency; |
| 3620 | else if ((packets < 5) && (bytes > 512)) |
| 3621 | retval = low_latency; |
| 3622 | break; |
| 3623 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 3624 | if (bytes > 10000) { |
| 3625 | /* this if handles the TSO accounting */ |
| 3626 | if (bytes/packets > 8000) { |
| 3627 | retval = bulk_latency; |
| 3628 | } else if ((packets < 10) || ((bytes/packets) > 1200)) { |
| 3629 | retval = bulk_latency; |
| 3630 | } else if ((packets > 35)) { |
| 3631 | retval = lowest_latency; |
| 3632 | } |
| 3633 | } else if (bytes/packets > 2000) { |
| 3634 | retval = bulk_latency; |
| 3635 | } else if (packets <= 2 && bytes < 512) { |
| 3636 | retval = lowest_latency; |
| 3637 | } |
| 3638 | break; |
| 3639 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 3640 | if (bytes > 25000) { |
| 3641 | if (packets > 35) |
| 3642 | retval = low_latency; |
Alexander Duyck | 1e5c3d2 | 2009-02-12 18:17:21 +0000 | [diff] [blame] | 3643 | } else if (bytes < 1500) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3644 | retval = low_latency; |
| 3645 | } |
| 3646 | break; |
| 3647 | } |
| 3648 | |
| 3649 | update_itr_done: |
| 3650 | return retval; |
| 3651 | } |
| 3652 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3653 | static void igb_set_itr(struct igb_adapter *adapter) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3654 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3655 | struct igb_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3656 | u16 current_itr; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3657 | u32 new_itr = q_vector->itr_val; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3658 | |
| 3659 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 3660 | if (adapter->link_speed != SPEED_1000) { |
| 3661 | current_itr = 0; |
| 3662 | new_itr = 4000; |
| 3663 | goto set_itr_now; |
| 3664 | } |
| 3665 | |
| 3666 | adapter->rx_itr = igb_update_itr(adapter, |
| 3667 | adapter->rx_itr, |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3668 | q_vector->rx_ring->total_packets, |
| 3669 | q_vector->rx_ring->total_bytes); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3670 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3671 | adapter->tx_itr = igb_update_itr(adapter, |
| 3672 | adapter->tx_itr, |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3673 | q_vector->tx_ring->total_packets, |
| 3674 | q_vector->tx_ring->total_bytes); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3675 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3676 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3677 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 3678 | if (adapter->rx_itr_setting == 3 && current_itr == lowest_latency) |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3679 | current_itr = low_latency; |
| 3680 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3681 | switch (current_itr) { |
| 3682 | /* counts and packets in update_itr are dependent on these numbers */ |
| 3683 | case lowest_latency: |
Alexander Duyck | 78b1f607 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 3684 | new_itr = 56; /* aka 70,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3685 | break; |
| 3686 | case low_latency: |
Alexander Duyck | 78b1f607 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 3687 | new_itr = 196; /* aka 20,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3688 | break; |
| 3689 | case bulk_latency: |
Alexander Duyck | 78b1f607 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 3690 | new_itr = 980; /* aka 4,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3691 | break; |
| 3692 | default: |
| 3693 | break; |
| 3694 | } |
| 3695 | |
| 3696 | set_itr_now: |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3697 | q_vector->rx_ring->total_bytes = 0; |
| 3698 | q_vector->rx_ring->total_packets = 0; |
| 3699 | q_vector->tx_ring->total_bytes = 0; |
| 3700 | q_vector->tx_ring->total_packets = 0; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3701 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3702 | if (new_itr != q_vector->itr_val) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3703 | /* this attempts to bias the interrupt rate towards Bulk |
| 3704 | * by adding intermediate steps when interrupt rate is |
| 3705 | * increasing */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3706 | new_itr = new_itr > q_vector->itr_val ? |
| 3707 | max((new_itr * q_vector->itr_val) / |
| 3708 | (new_itr + (q_vector->itr_val >> 2)), |
| 3709 | new_itr) : |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3710 | new_itr; |
| 3711 | /* Don't write the value here; it resets the adapter's |
| 3712 | * internal timer, and causes us to delay far longer than |
| 3713 | * we should between interrupts. Instead, we write the ITR |
| 3714 | * value at the beginning of the next interrupt so the timing |
| 3715 | * ends up being correct. |
| 3716 | */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3717 | q_vector->itr_val = new_itr; |
| 3718 | q_vector->set_itr = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | return; |
| 3722 | } |
| 3723 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3724 | #define IGB_TX_FLAGS_CSUM 0x00000001 |
| 3725 | #define IGB_TX_FLAGS_VLAN 0x00000002 |
| 3726 | #define IGB_TX_FLAGS_TSO 0x00000004 |
| 3727 | #define IGB_TX_FLAGS_IPV4 0x00000008 |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 3728 | #define IGB_TX_FLAGS_TSTAMP 0x00000010 |
| 3729 | #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 3730 | #define IGB_TX_FLAGS_VLAN_SHIFT 16 |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3731 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 3732 | static inline int igb_tso_adv(struct igb_ring *tx_ring, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3733 | struct sk_buff *skb, u32 tx_flags, u8 *hdr_len) |
| 3734 | { |
| 3735 | struct e1000_adv_tx_context_desc *context_desc; |
| 3736 | unsigned int i; |
| 3737 | int err; |
| 3738 | struct igb_buffer *buffer_info; |
| 3739 | u32 info = 0, tu_cmd = 0; |
Nick Nunley | 91d4ee3 | 2010-02-17 01:04:56 +0000 | [diff] [blame] | 3740 | u32 mss_l4len_idx; |
| 3741 | u8 l4len; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3742 | |
| 3743 | if (skb_header_cloned(skb)) { |
| 3744 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 3745 | if (err) |
| 3746 | return err; |
| 3747 | } |
| 3748 | |
| 3749 | l4len = tcp_hdrlen(skb); |
| 3750 | *hdr_len += l4len; |
| 3751 | |
| 3752 | if (skb->protocol == htons(ETH_P_IP)) { |
| 3753 | struct iphdr *iph = ip_hdr(skb); |
| 3754 | iph->tot_len = 0; |
| 3755 | iph->check = 0; |
| 3756 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 3757 | iph->daddr, 0, |
| 3758 | IPPROTO_TCP, |
| 3759 | 0); |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 3760 | } else if (skb_is_gso_v6(skb)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3761 | ipv6_hdr(skb)->payload_len = 0; |
| 3762 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 3763 | &ipv6_hdr(skb)->daddr, |
| 3764 | 0, IPPROTO_TCP, 0); |
| 3765 | } |
| 3766 | |
| 3767 | i = tx_ring->next_to_use; |
| 3768 | |
| 3769 | buffer_info = &tx_ring->buffer_info[i]; |
| 3770 | context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i); |
| 3771 | /* VLAN MACLEN IPLEN */ |
| 3772 | if (tx_flags & IGB_TX_FLAGS_VLAN) |
| 3773 | info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK); |
| 3774 | info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT); |
| 3775 | *hdr_len += skb_network_offset(skb); |
| 3776 | info |= skb_network_header_len(skb); |
| 3777 | *hdr_len += skb_network_header_len(skb); |
| 3778 | context_desc->vlan_macip_lens = cpu_to_le32(info); |
| 3779 | |
| 3780 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 3781 | tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT); |
| 3782 | |
| 3783 | if (skb->protocol == htons(ETH_P_IP)) |
| 3784 | tu_cmd |= E1000_ADVTXD_TUCMD_IPV4; |
| 3785 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; |
| 3786 | |
| 3787 | context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd); |
| 3788 | |
| 3789 | /* MSS L4LEN IDX */ |
| 3790 | mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT); |
| 3791 | mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT); |
| 3792 | |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 3793 | /* For 82575, context index must be unique per ring. */ |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 3794 | if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX) |
| 3795 | mss_l4len_idx |= tx_ring->reg_idx << 4; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3796 | |
| 3797 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 3798 | context_desc->seqnum_seed = 0; |
| 3799 | |
| 3800 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3801 | buffer_info->next_to_watch = i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3802 | buffer_info->dma = 0; |
| 3803 | i++; |
| 3804 | if (i == tx_ring->count) |
| 3805 | i = 0; |
| 3806 | |
| 3807 | tx_ring->next_to_use = i; |
| 3808 | |
| 3809 | return true; |
| 3810 | } |
| 3811 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 3812 | static inline bool igb_tx_csum_adv(struct igb_ring *tx_ring, |
| 3813 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3814 | { |
| 3815 | struct e1000_adv_tx_context_desc *context_desc; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3816 | struct device *dev = tx_ring->dev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3817 | struct igb_buffer *buffer_info; |
| 3818 | u32 info = 0, tu_cmd = 0; |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 3819 | unsigned int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3820 | |
| 3821 | if ((skb->ip_summed == CHECKSUM_PARTIAL) || |
| 3822 | (tx_flags & IGB_TX_FLAGS_VLAN)) { |
| 3823 | i = tx_ring->next_to_use; |
| 3824 | buffer_info = &tx_ring->buffer_info[i]; |
| 3825 | context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i); |
| 3826 | |
| 3827 | if (tx_flags & IGB_TX_FLAGS_VLAN) |
| 3828 | info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK); |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 3829 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3830 | info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT); |
| 3831 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 3832 | info |= skb_network_header_len(skb); |
| 3833 | |
| 3834 | context_desc->vlan_macip_lens = cpu_to_le32(info); |
| 3835 | |
| 3836 | tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT); |
| 3837 | |
| 3838 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Arthur Jones | fa4a7ef | 2009-03-21 16:55:07 -0700 | [diff] [blame] | 3839 | __be16 protocol; |
| 3840 | |
| 3841 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) { |
| 3842 | const struct vlan_ethhdr *vhdr = |
| 3843 | (const struct vlan_ethhdr*)skb->data; |
| 3844 | |
| 3845 | protocol = vhdr->h_vlan_encapsulated_proto; |
| 3846 | } else { |
| 3847 | protocol = skb->protocol; |
| 3848 | } |
| 3849 | |
| 3850 | switch (protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 3851 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3852 | tu_cmd |= E1000_ADVTXD_TUCMD_IPV4; |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3853 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 3854 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 3855 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 3856 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP; |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3857 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 3858 | case cpu_to_be16(ETH_P_IPV6): |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3859 | /* XXX what about other V6 headers?? */ |
| 3860 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 3861 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 3862 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 3863 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP; |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3864 | break; |
| 3865 | default: |
| 3866 | if (unlikely(net_ratelimit())) |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3867 | dev_warn(dev, |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3868 | "partial checksum but proto=%x!\n", |
| 3869 | skb->protocol); |
| 3870 | break; |
| 3871 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd); |
| 3875 | context_desc->seqnum_seed = 0; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 3876 | if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX) |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3877 | context_desc->mss_l4len_idx = |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 3878 | cpu_to_le32(tx_ring->reg_idx << 4); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3879 | |
| 3880 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3881 | buffer_info->next_to_watch = i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3882 | buffer_info->dma = 0; |
| 3883 | |
| 3884 | i++; |
| 3885 | if (i == tx_ring->count) |
| 3886 | i = 0; |
| 3887 | tx_ring->next_to_use = i; |
| 3888 | |
| 3889 | return true; |
| 3890 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3891 | return false; |
| 3892 | } |
| 3893 | |
| 3894 | #define IGB_MAX_TXD_PWR 16 |
| 3895 | #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR) |
| 3896 | |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 3897 | static inline int igb_tx_map_adv(struct igb_ring *tx_ring, struct sk_buff *skb, |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3898 | unsigned int first) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3899 | { |
| 3900 | struct igb_buffer *buffer_info; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3901 | struct device *dev = tx_ring->dev; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 3902 | unsigned int hlen = skb_headlen(skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3903 | unsigned int count = 0, i; |
| 3904 | unsigned int f; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 3905 | u16 gso_segs = skb_shinfo(skb)->gso_segs ?: 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3906 | |
| 3907 | i = tx_ring->next_to_use; |
| 3908 | |
| 3909 | buffer_info = &tx_ring->buffer_info[i]; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 3910 | BUG_ON(hlen >= IGB_MAX_DATA_PER_TXD); |
| 3911 | buffer_info->length = hlen; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3912 | /* set time_stamp *before* dma to help avoid a possible race */ |
| 3913 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3914 | buffer_info->next_to_watch = i; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 3915 | buffer_info->dma = dma_map_single(dev, skb->data, hlen, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3916 | DMA_TO_DEVICE); |
| 3917 | if (dma_mapping_error(dev, buffer_info->dma)) |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3918 | goto dma_error; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3919 | |
| 3920 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 3921 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[f]; |
| 3922 | unsigned int len = frag->size; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3923 | |
Alexander Duyck | 8581145 | 2010-01-23 01:35:00 -0800 | [diff] [blame] | 3924 | count++; |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3925 | i++; |
| 3926 | if (i == tx_ring->count) |
| 3927 | i = 0; |
| 3928 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3929 | buffer_info = &tx_ring->buffer_info[i]; |
| 3930 | BUG_ON(len >= IGB_MAX_DATA_PER_TXD); |
| 3931 | buffer_info->length = len; |
| 3932 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3933 | buffer_info->next_to_watch = i; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3934 | buffer_info->mapped_as_page = true; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3935 | buffer_info->dma = dma_map_page(dev, |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3936 | frag->page, |
| 3937 | frag->page_offset, |
| 3938 | len, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3939 | DMA_TO_DEVICE); |
| 3940 | if (dma_mapping_error(dev, buffer_info->dma)) |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3941 | goto dma_error; |
| 3942 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3943 | } |
| 3944 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3945 | tx_ring->buffer_info[i].skb = skb; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 3946 | tx_ring->buffer_info[i].shtx = skb_shinfo(skb)->tx_flags; |
| 3947 | /* multiply data chunks by size of headers */ |
| 3948 | tx_ring->buffer_info[i].bytecount = ((gso_segs - 1) * hlen) + skb->len; |
| 3949 | tx_ring->buffer_info[i].gso_segs = gso_segs; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3950 | tx_ring->buffer_info[first].next_to_watch = i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3951 | |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 3952 | return ++count; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3953 | |
| 3954 | dma_error: |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3955 | dev_err(dev, "TX DMA map failed\n"); |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3956 | |
| 3957 | /* clear timestamp and dma mappings for failed buffer_info mapping */ |
| 3958 | buffer_info->dma = 0; |
| 3959 | buffer_info->time_stamp = 0; |
| 3960 | buffer_info->length = 0; |
| 3961 | buffer_info->next_to_watch = 0; |
| 3962 | buffer_info->mapped_as_page = false; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3963 | |
| 3964 | /* clear timestamp and dma mappings for remaining portion of packet */ |
Nick Nunley | a77ff70 | 2010-02-17 01:06:16 +0000 | [diff] [blame] | 3965 | while (count--) { |
| 3966 | if (i == 0) |
| 3967 | i = tx_ring->count; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3968 | i--; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3969 | buffer_info = &tx_ring->buffer_info[i]; |
| 3970 | igb_unmap_and_free_tx_resource(tx_ring, buffer_info); |
| 3971 | } |
| 3972 | |
| 3973 | return 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3974 | } |
| 3975 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 3976 | static inline void igb_tx_queue_adv(struct igb_ring *tx_ring, |
Nick Nunley | 91d4ee3 | 2010-02-17 01:04:56 +0000 | [diff] [blame] | 3977 | u32 tx_flags, int count, u32 paylen, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3978 | u8 hdr_len) |
| 3979 | { |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 3980 | union e1000_adv_tx_desc *tx_desc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3981 | struct igb_buffer *buffer_info; |
| 3982 | u32 olinfo_status = 0, cmd_type_len; |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 3983 | unsigned int i = tx_ring->next_to_use; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3984 | |
| 3985 | cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS | |
| 3986 | E1000_ADVTXD_DCMD_DEXT); |
| 3987 | |
| 3988 | if (tx_flags & IGB_TX_FLAGS_VLAN) |
| 3989 | cmd_type_len |= E1000_ADVTXD_DCMD_VLE; |
| 3990 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 3991 | if (tx_flags & IGB_TX_FLAGS_TSTAMP) |
| 3992 | cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP; |
| 3993 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3994 | if (tx_flags & IGB_TX_FLAGS_TSO) { |
| 3995 | cmd_type_len |= E1000_ADVTXD_DCMD_TSE; |
| 3996 | |
| 3997 | /* insert tcp checksum */ |
| 3998 | olinfo_status |= E1000_TXD_POPTS_TXSM << 8; |
| 3999 | |
| 4000 | /* insert ip checksum */ |
| 4001 | if (tx_flags & IGB_TX_FLAGS_IPV4) |
| 4002 | olinfo_status |= E1000_TXD_POPTS_IXSM << 8; |
| 4003 | |
| 4004 | } else if (tx_flags & IGB_TX_FLAGS_CSUM) { |
| 4005 | olinfo_status |= E1000_TXD_POPTS_TXSM << 8; |
| 4006 | } |
| 4007 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4008 | if ((tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX) && |
| 4009 | (tx_flags & (IGB_TX_FLAGS_CSUM | |
| 4010 | IGB_TX_FLAGS_TSO | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4011 | IGB_TX_FLAGS_VLAN))) |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4012 | olinfo_status |= tx_ring->reg_idx << 4; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4013 | |
| 4014 | olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT); |
| 4015 | |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4016 | do { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4017 | buffer_info = &tx_ring->buffer_info[i]; |
| 4018 | tx_desc = E1000_TX_DESC_ADV(*tx_ring, i); |
| 4019 | tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4020 | tx_desc->read.cmd_type_len = |
| 4021 | cpu_to_le32(cmd_type_len | buffer_info->length); |
| 4022 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4023 | count--; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4024 | i++; |
| 4025 | if (i == tx_ring->count) |
| 4026 | i = 0; |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4027 | } while (count > 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4028 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4029 | tx_desc->read.cmd_type_len |= cpu_to_le32(IGB_ADVTXD_DCMD); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4030 | /* Force memory writes to complete before letting h/w |
| 4031 | * know there are new descriptors to fetch. (Only |
| 4032 | * applicable for weak-ordered memory model archs, |
| 4033 | * such as IA-64). */ |
| 4034 | wmb(); |
| 4035 | |
| 4036 | tx_ring->next_to_use = i; |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 4037 | writel(i, tx_ring->tail); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4038 | /* we need this if more than one processor can write to our tail |
| 4039 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 4040 | mmiowb(); |
| 4041 | } |
| 4042 | |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4043 | 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] | 4044 | { |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4045 | struct net_device *netdev = tx_ring->netdev; |
| 4046 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4047 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4048 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4049 | /* Herbert's original patch had: |
| 4050 | * smp_mb__after_netif_stop_queue(); |
| 4051 | * but since that doesn't exist yet, just open code it. */ |
| 4052 | smp_mb(); |
| 4053 | |
| 4054 | /* We need to check again in a case another CPU has just |
| 4055 | * made room available. */ |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 4056 | if (igb_desc_unused(tx_ring) < size) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4057 | return -EBUSY; |
| 4058 | |
| 4059 | /* A reprieve! */ |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4060 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Alexander Duyck | 04a5fcaa | 2009-10-27 15:52:27 +0000 | [diff] [blame] | 4061 | tx_ring->tx_stats.restart_queue++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4062 | return 0; |
| 4063 | } |
| 4064 | |
Nick Nunley | 717ba08 | 2010-02-17 01:04:18 +0000 | [diff] [blame] | 4065 | 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] | 4066 | { |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 4067 | if (igb_desc_unused(tx_ring) >= size) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4068 | return 0; |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4069 | return __igb_maybe_stop_tx(tx_ring, size); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4070 | } |
| 4071 | |
Alexander Duyck | b1a436c | 2009-10-27 15:54:43 +0000 | [diff] [blame] | 4072 | netdev_tx_t igb_xmit_frame_ring_adv(struct sk_buff *skb, |
| 4073 | struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4074 | { |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4075 | struct igb_adapter *adapter = netdev_priv(tx_ring->netdev); |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4076 | int tso = 0, count; |
Nick Nunley | 91d4ee3 | 2010-02-17 01:04:56 +0000 | [diff] [blame] | 4077 | u32 tx_flags = 0; |
| 4078 | u16 first; |
| 4079 | u8 hdr_len = 0; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 4080 | union skb_shared_tx *shtx = skb_tx(skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4081 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4082 | /* need: 1 descriptor per page, |
| 4083 | * + 2 desc gap to keep tail from touching head, |
| 4084 | * + 1 desc for skb->data, |
| 4085 | * + 1 desc for context descriptor, |
| 4086 | * otherwise try next time */ |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4087 | 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] | 4088 | /* this is a hard error */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4089 | return NETDEV_TX_BUSY; |
| 4090 | } |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4091 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4092 | if (unlikely(shtx->hardware)) { |
| 4093 | shtx->in_progress = 1; |
| 4094 | tx_flags |= IGB_TX_FLAGS_TSTAMP; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4095 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4096 | |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4097 | if (vlan_tx_tag_present(skb) && adapter->vlgrp) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4098 | tx_flags |= IGB_TX_FLAGS_VLAN; |
| 4099 | tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT); |
| 4100 | } |
| 4101 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4102 | if (skb->protocol == htons(ETH_P_IP)) |
| 4103 | tx_flags |= IGB_TX_FLAGS_IPV4; |
| 4104 | |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4105 | first = tx_ring->next_to_use; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4106 | if (skb_is_gso(skb)) { |
| 4107 | tso = igb_tso_adv(tx_ring, skb, tx_flags, &hdr_len); |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4108 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4109 | if (tso < 0) { |
| 4110 | dev_kfree_skb_any(skb); |
| 4111 | return NETDEV_TX_OK; |
| 4112 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4113 | } |
| 4114 | |
| 4115 | if (tso) |
| 4116 | tx_flags |= IGB_TX_FLAGS_TSO; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4117 | else if (igb_tx_csum_adv(tx_ring, skb, tx_flags) && |
Alexander Duyck | bc1cbd3 | 2009-02-13 14:45:17 +0000 | [diff] [blame] | 4118 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 4119 | tx_flags |= IGB_TX_FLAGS_CSUM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4120 | |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4121 | /* |
Alexander Duyck | cdfd01fc | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4122 | * count reflects descriptors mapped, if 0 or less then mapping error |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4123 | * has occured and we need to rewind the descriptor queue |
| 4124 | */ |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 4125 | count = igb_tx_map_adv(tx_ring, skb, first); |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4126 | if (!count) { |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4127 | dev_kfree_skb_any(skb); |
| 4128 | tx_ring->buffer_info[first].time_stamp = 0; |
| 4129 | tx_ring->next_to_use = first; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4130 | return NETDEV_TX_OK; |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4131 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4132 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4133 | igb_tx_queue_adv(tx_ring, tx_flags, count, skb->len, hdr_len); |
| 4134 | |
| 4135 | /* Make sure there is space in the ring for the next send. */ |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4136 | igb_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 4); |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4137 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4138 | return NETDEV_TX_OK; |
| 4139 | } |
| 4140 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 4141 | static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb, |
| 4142 | struct net_device *netdev) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4143 | { |
| 4144 | struct igb_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4145 | struct igb_ring *tx_ring; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4146 | int r_idx = 0; |
Alexander Duyck | b1a436c | 2009-10-27 15:54:43 +0000 | [diff] [blame] | 4147 | |
| 4148 | if (test_bit(__IGB_DOWN, &adapter->state)) { |
| 4149 | dev_kfree_skb_any(skb); |
| 4150 | return NETDEV_TX_OK; |
| 4151 | } |
| 4152 | |
| 4153 | if (skb->len <= 0) { |
| 4154 | dev_kfree_skb_any(skb); |
| 4155 | return NETDEV_TX_OK; |
| 4156 | } |
| 4157 | |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 4158 | r_idx = skb->queue_mapping & (IGB_ABS_MAX_TX_QUEUES - 1); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4159 | tx_ring = adapter->multi_tx_table[r_idx]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4160 | |
| 4161 | /* This goes back to the question of how to logically map a tx queue |
| 4162 | * to a flow. Right now, performance is impacted slightly negatively |
| 4163 | * if using multiple tx queues. If the stack breaks away from a |
| 4164 | * single qdisc implementation, we can look at this again. */ |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4165 | return igb_xmit_frame_ring_adv(skb, tx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | /** |
| 4169 | * igb_tx_timeout - Respond to a Tx Hang |
| 4170 | * @netdev: network interface device structure |
| 4171 | **/ |
| 4172 | static void igb_tx_timeout(struct net_device *netdev) |
| 4173 | { |
| 4174 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 4175 | struct e1000_hw *hw = &adapter->hw; |
| 4176 | |
| 4177 | /* Do the reset outside of interrupt context */ |
| 4178 | adapter->tx_timeout_count++; |
Alexander Duyck | f7ba205 | 2009-10-27 23:48:51 +0000 | [diff] [blame] | 4179 | |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 4180 | if (hw->mac.type == e1000_82580) |
| 4181 | hw->dev_spec._82575.global_device_reset = true; |
| 4182 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4183 | schedule_work(&adapter->reset_task); |
Alexander Duyck | 265de40 | 2009-02-06 23:22:52 +0000 | [diff] [blame] | 4184 | wr32(E1000_EICS, |
| 4185 | (adapter->eims_enable_mask & ~adapter->eims_other)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | static void igb_reset_task(struct work_struct *work) |
| 4189 | { |
| 4190 | struct igb_adapter *adapter; |
| 4191 | adapter = container_of(work, struct igb_adapter, reset_task); |
| 4192 | |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 4193 | igb_dump(adapter); |
| 4194 | netdev_err(adapter->netdev, "Reset adapter\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4195 | igb_reinit_locked(adapter); |
| 4196 | } |
| 4197 | |
| 4198 | /** |
| 4199 | * igb_get_stats - Get System Network Statistics |
| 4200 | * @netdev: network interface device structure |
| 4201 | * |
| 4202 | * Returns the address of the device statistics structure. |
| 4203 | * The statistics are actually updated from the timer callback. |
| 4204 | **/ |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4205 | static struct net_device_stats *igb_get_stats(struct net_device *netdev) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4206 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4207 | /* only return the current stats */ |
Ajit Khaparde | 8d24e93 | 2009-10-07 02:42:56 +0000 | [diff] [blame] | 4208 | return &netdev->stats; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | /** |
| 4212 | * igb_change_mtu - Change the Maximum Transfer Unit |
| 4213 | * @netdev: network interface device structure |
| 4214 | * @new_mtu: new value for maximum frame size |
| 4215 | * |
| 4216 | * Returns 0 on success, negative on failure |
| 4217 | **/ |
| 4218 | static int igb_change_mtu(struct net_device *netdev, int new_mtu) |
| 4219 | { |
| 4220 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4221 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4222 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 4223 | u32 rx_buffer_len, i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4224 | |
Alexander Duyck | c809d22 | 2009-10-27 23:52:13 +0000 | [diff] [blame] | 4225 | if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4226 | dev_err(&pdev->dev, "Invalid MTU setting\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4227 | return -EINVAL; |
| 4228 | } |
| 4229 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4230 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4231 | dev_err(&pdev->dev, "MTU > 9216 not supported.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4232 | return -EINVAL; |
| 4233 | } |
| 4234 | |
| 4235 | while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) |
| 4236 | msleep(1); |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4237 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4238 | /* igb_down has a dependency on max_frame_size */ |
| 4239 | adapter->max_frame_size = max_frame; |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 4240 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4241 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
| 4242 | * means we reserve 2 more, this pushes us to allocate from the next |
| 4243 | * larger slab size. |
| 4244 | * i.e. RXBUFFER_2048 --> size-4096 slab |
| 4245 | */ |
| 4246 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 4247 | if (adapter->hw.mac.type == e1000_82580) |
| 4248 | max_frame += IGB_TS_HDR_LEN; |
| 4249 | |
Alexander Duyck | 7d95b71 | 2009-10-27 15:50:08 +0000 | [diff] [blame] | 4250 | if (max_frame <= IGB_RXBUFFER_1024) |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 4251 | rx_buffer_len = IGB_RXBUFFER_1024; |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 4252 | else if (max_frame <= MAXIMUM_ETHERNET_VLAN_SIZE) |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 4253 | rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 4254 | else |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 4255 | rx_buffer_len = IGB_RXBUFFER_128; |
| 4256 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 4257 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN + IGB_TS_HDR_LEN) || |
| 4258 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE + IGB_TS_HDR_LEN)) |
| 4259 | rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE + IGB_TS_HDR_LEN; |
| 4260 | |
| 4261 | if ((adapter->hw.mac.type == e1000_82580) && |
| 4262 | (rx_buffer_len == IGB_RXBUFFER_128)) |
| 4263 | rx_buffer_len += IGB_RXBUFFER_64; |
| 4264 | |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 4265 | if (netif_running(netdev)) |
| 4266 | igb_down(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4267 | |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4268 | dev_info(&pdev->dev, "changing MTU from %d to %d\n", |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4269 | netdev->mtu, new_mtu); |
| 4270 | netdev->mtu = new_mtu; |
| 4271 | |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 4272 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 4273 | adapter->rx_ring[i]->rx_buffer_len = rx_buffer_len; |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 4274 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4275 | if (netif_running(netdev)) |
| 4276 | igb_up(adapter); |
| 4277 | else |
| 4278 | igb_reset(adapter); |
| 4279 | |
| 4280 | clear_bit(__IGB_RESETTING, &adapter->state); |
| 4281 | |
| 4282 | return 0; |
| 4283 | } |
| 4284 | |
| 4285 | /** |
| 4286 | * igb_update_stats - Update the board statistics counters |
| 4287 | * @adapter: board private structure |
| 4288 | **/ |
| 4289 | |
| 4290 | void igb_update_stats(struct igb_adapter *adapter) |
| 4291 | { |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4292 | struct net_device_stats *net_stats = igb_get_stats(adapter->netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4293 | struct e1000_hw *hw = &adapter->hw; |
| 4294 | struct pci_dev *pdev = adapter->pdev; |
Mitch Williams | fa3d9a6 | 2010-03-23 18:34:38 +0000 | [diff] [blame] | 4295 | u32 reg, mpc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4296 | u16 phy_tmp; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4297 | int i; |
| 4298 | u64 bytes, packets; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4299 | |
| 4300 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 4301 | |
| 4302 | /* |
| 4303 | * Prevent stats update while adapter is being reset, or if the pci |
| 4304 | * connection is down. |
| 4305 | */ |
| 4306 | if (adapter->link_speed == 0) |
| 4307 | return; |
| 4308 | if (pci_channel_offline(pdev)) |
| 4309 | return; |
| 4310 | |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4311 | bytes = 0; |
| 4312 | packets = 0; |
| 4313 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4314 | u32 rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0x0FFF; |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 4315 | struct igb_ring *ring = adapter->rx_ring[i]; |
| 4316 | ring->rx_stats.drops += rqdpc_tmp; |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4317 | net_stats->rx_fifo_errors += rqdpc_tmp; |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 4318 | bytes += ring->rx_stats.bytes; |
| 4319 | packets += ring->rx_stats.packets; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4320 | } |
| 4321 | |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4322 | net_stats->rx_bytes = bytes; |
| 4323 | net_stats->rx_packets = packets; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4324 | |
| 4325 | bytes = 0; |
| 4326 | packets = 0; |
| 4327 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 4328 | struct igb_ring *ring = adapter->tx_ring[i]; |
| 4329 | bytes += ring->tx_stats.bytes; |
| 4330 | packets += ring->tx_stats.packets; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4331 | } |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4332 | net_stats->tx_bytes = bytes; |
| 4333 | net_stats->tx_packets = packets; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4334 | |
| 4335 | /* read stats registers */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4336 | adapter->stats.crcerrs += rd32(E1000_CRCERRS); |
| 4337 | adapter->stats.gprc += rd32(E1000_GPRC); |
| 4338 | adapter->stats.gorc += rd32(E1000_GORCL); |
| 4339 | rd32(E1000_GORCH); /* clear GORCL */ |
| 4340 | adapter->stats.bprc += rd32(E1000_BPRC); |
| 4341 | adapter->stats.mprc += rd32(E1000_MPRC); |
| 4342 | adapter->stats.roc += rd32(E1000_ROC); |
| 4343 | |
| 4344 | adapter->stats.prc64 += rd32(E1000_PRC64); |
| 4345 | adapter->stats.prc127 += rd32(E1000_PRC127); |
| 4346 | adapter->stats.prc255 += rd32(E1000_PRC255); |
| 4347 | adapter->stats.prc511 += rd32(E1000_PRC511); |
| 4348 | adapter->stats.prc1023 += rd32(E1000_PRC1023); |
| 4349 | adapter->stats.prc1522 += rd32(E1000_PRC1522); |
| 4350 | adapter->stats.symerrs += rd32(E1000_SYMERRS); |
| 4351 | adapter->stats.sec += rd32(E1000_SEC); |
| 4352 | |
Mitch Williams | fa3d9a6 | 2010-03-23 18:34:38 +0000 | [diff] [blame] | 4353 | mpc = rd32(E1000_MPC); |
| 4354 | adapter->stats.mpc += mpc; |
| 4355 | net_stats->rx_fifo_errors += mpc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4356 | adapter->stats.scc += rd32(E1000_SCC); |
| 4357 | adapter->stats.ecol += rd32(E1000_ECOL); |
| 4358 | adapter->stats.mcc += rd32(E1000_MCC); |
| 4359 | adapter->stats.latecol += rd32(E1000_LATECOL); |
| 4360 | adapter->stats.dc += rd32(E1000_DC); |
| 4361 | adapter->stats.rlec += rd32(E1000_RLEC); |
| 4362 | adapter->stats.xonrxc += rd32(E1000_XONRXC); |
| 4363 | adapter->stats.xontxc += rd32(E1000_XONTXC); |
| 4364 | adapter->stats.xoffrxc += rd32(E1000_XOFFRXC); |
| 4365 | adapter->stats.xofftxc += rd32(E1000_XOFFTXC); |
| 4366 | adapter->stats.fcruc += rd32(E1000_FCRUC); |
| 4367 | adapter->stats.gptc += rd32(E1000_GPTC); |
| 4368 | adapter->stats.gotc += rd32(E1000_GOTCL); |
| 4369 | rd32(E1000_GOTCH); /* clear GOTCL */ |
Mitch Williams | fa3d9a6 | 2010-03-23 18:34:38 +0000 | [diff] [blame] | 4370 | adapter->stats.rnbc += rd32(E1000_RNBC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4371 | adapter->stats.ruc += rd32(E1000_RUC); |
| 4372 | adapter->stats.rfc += rd32(E1000_RFC); |
| 4373 | adapter->stats.rjc += rd32(E1000_RJC); |
| 4374 | adapter->stats.tor += rd32(E1000_TORH); |
| 4375 | adapter->stats.tot += rd32(E1000_TOTH); |
| 4376 | adapter->stats.tpr += rd32(E1000_TPR); |
| 4377 | |
| 4378 | adapter->stats.ptc64 += rd32(E1000_PTC64); |
| 4379 | adapter->stats.ptc127 += rd32(E1000_PTC127); |
| 4380 | adapter->stats.ptc255 += rd32(E1000_PTC255); |
| 4381 | adapter->stats.ptc511 += rd32(E1000_PTC511); |
| 4382 | adapter->stats.ptc1023 += rd32(E1000_PTC1023); |
| 4383 | adapter->stats.ptc1522 += rd32(E1000_PTC1522); |
| 4384 | |
| 4385 | adapter->stats.mptc += rd32(E1000_MPTC); |
| 4386 | adapter->stats.bptc += rd32(E1000_BPTC); |
| 4387 | |
Nick Nunley | 2d0b0f6 | 2010-02-17 01:02:59 +0000 | [diff] [blame] | 4388 | adapter->stats.tpt += rd32(E1000_TPT); |
| 4389 | adapter->stats.colc += rd32(E1000_COLC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4390 | |
| 4391 | adapter->stats.algnerrc += rd32(E1000_ALGNERRC); |
Nick Nunley | 43915c7c | 2010-02-17 01:03:58 +0000 | [diff] [blame] | 4392 | /* read internal phy specific stats */ |
| 4393 | reg = rd32(E1000_CTRL_EXT); |
| 4394 | if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) { |
| 4395 | adapter->stats.rxerrc += rd32(E1000_RXERRC); |
| 4396 | adapter->stats.tncrs += rd32(E1000_TNCRS); |
| 4397 | } |
| 4398 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4399 | adapter->stats.tsctc += rd32(E1000_TSCTC); |
| 4400 | adapter->stats.tsctfc += rd32(E1000_TSCTFC); |
| 4401 | |
| 4402 | adapter->stats.iac += rd32(E1000_IAC); |
| 4403 | adapter->stats.icrxoc += rd32(E1000_ICRXOC); |
| 4404 | adapter->stats.icrxptc += rd32(E1000_ICRXPTC); |
| 4405 | adapter->stats.icrxatc += rd32(E1000_ICRXATC); |
| 4406 | adapter->stats.ictxptc += rd32(E1000_ICTXPTC); |
| 4407 | adapter->stats.ictxatc += rd32(E1000_ICTXATC); |
| 4408 | adapter->stats.ictxqec += rd32(E1000_ICTXQEC); |
| 4409 | adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC); |
| 4410 | adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC); |
| 4411 | |
| 4412 | /* Fill out the OS statistics structure */ |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4413 | net_stats->multicast = adapter->stats.mprc; |
| 4414 | net_stats->collisions = adapter->stats.colc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4415 | |
| 4416 | /* Rx Errors */ |
| 4417 | |
| 4418 | /* RLEC on some newer hardware can be incorrect so build |
Jesper Dangaard Brouer | 8c0ab70 | 2009-05-26 13:50:31 +0000 | [diff] [blame] | 4419 | * our own version based on RUC and ROC */ |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4420 | net_stats->rx_errors = adapter->stats.rxerrc + |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4421 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4422 | adapter->stats.ruc + adapter->stats.roc + |
| 4423 | adapter->stats.cexterr; |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4424 | net_stats->rx_length_errors = adapter->stats.ruc + |
| 4425 | adapter->stats.roc; |
| 4426 | net_stats->rx_crc_errors = adapter->stats.crcerrs; |
| 4427 | net_stats->rx_frame_errors = adapter->stats.algnerrc; |
| 4428 | net_stats->rx_missed_errors = adapter->stats.mpc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4429 | |
| 4430 | /* Tx Errors */ |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4431 | net_stats->tx_errors = adapter->stats.ecol + |
| 4432 | adapter->stats.latecol; |
| 4433 | net_stats->tx_aborted_errors = adapter->stats.ecol; |
| 4434 | net_stats->tx_window_errors = adapter->stats.latecol; |
| 4435 | net_stats->tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4436 | |
| 4437 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4438 | |
| 4439 | /* Phy Stats */ |
| 4440 | if (hw->phy.media_type == e1000_media_type_copper) { |
| 4441 | if ((adapter->link_speed == SPEED_1000) && |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4442 | (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4443 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 4444 | adapter->phy_stats.idle_errors += phy_tmp; |
| 4445 | } |
| 4446 | } |
| 4447 | |
| 4448 | /* Management Stats */ |
| 4449 | adapter->stats.mgptc += rd32(E1000_MGTPTC); |
| 4450 | adapter->stats.mgprc += rd32(E1000_MGTPRC); |
| 4451 | adapter->stats.mgpdc += rd32(E1000_MGTPDC); |
| 4452 | } |
| 4453 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4454 | static irqreturn_t igb_msix_other(int irq, void *data) |
| 4455 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4456 | struct igb_adapter *adapter = data; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4457 | struct e1000_hw *hw = &adapter->hw; |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 4458 | u32 icr = rd32(E1000_ICR); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 4459 | /* reading ICR causes bit 31 of EICR to be cleared */ |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 4460 | |
Alexander Duyck | 7f081d4 | 2010-01-07 17:41:00 +0000 | [diff] [blame] | 4461 | if (icr & E1000_ICR_DRSTA) |
| 4462 | schedule_work(&adapter->reset_task); |
| 4463 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4464 | if (icr & E1000_ICR_DOUTSYNC) { |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 4465 | /* HW is reporting DMA is out of sync */ |
| 4466 | adapter->stats.doosync++; |
| 4467 | } |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 4468 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4469 | /* Check for a mailbox event */ |
| 4470 | if (icr & E1000_ICR_VMMB) |
| 4471 | igb_msg_task(adapter); |
| 4472 | |
| 4473 | if (icr & E1000_ICR_LSC) { |
| 4474 | hw->mac.get_link_status = 1; |
| 4475 | /* guard against interrupt when we're going down */ |
| 4476 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 4477 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 4478 | } |
| 4479 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 4480 | if (adapter->vfs_allocated_count) |
| 4481 | wr32(E1000_IMS, E1000_IMS_LSC | |
| 4482 | E1000_IMS_VMMB | |
| 4483 | E1000_IMS_DOUTSYNC); |
| 4484 | else |
| 4485 | wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 4486 | wr32(E1000_EIMS, adapter->eims_other); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4487 | |
| 4488 | return IRQ_HANDLED; |
| 4489 | } |
| 4490 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4491 | static void igb_write_itr(struct igb_q_vector *q_vector) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4492 | { |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 4493 | struct igb_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4494 | u32 itr_val = q_vector->itr_val & 0x7FFC; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4495 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4496 | if (!q_vector->set_itr) |
| 4497 | return; |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4498 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4499 | if (!itr_val) |
| 4500 | itr_val = 0x4; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4501 | |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 4502 | if (adapter->hw.mac.type == e1000_82575) |
| 4503 | itr_val |= itr_val << 16; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4504 | else |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4505 | itr_val |= 0x8000000; |
| 4506 | |
| 4507 | writel(itr_val, q_vector->itr_register); |
| 4508 | q_vector->set_itr = 0; |
| 4509 | } |
| 4510 | |
| 4511 | static irqreturn_t igb_msix_ring(int irq, void *data) |
| 4512 | { |
| 4513 | struct igb_q_vector *q_vector = data; |
| 4514 | |
| 4515 | /* Write the ITR value calculated from the previous interrupt. */ |
| 4516 | igb_write_itr(q_vector); |
| 4517 | |
| 4518 | napi_schedule(&q_vector->napi); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4519 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4520 | return IRQ_HANDLED; |
| 4521 | } |
| 4522 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 4523 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4524 | static void igb_update_dca(struct igb_q_vector *q_vector) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4525 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4526 | struct igb_adapter *adapter = q_vector->adapter; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4527 | struct e1000_hw *hw = &adapter->hw; |
| 4528 | int cpu = get_cpu(); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4529 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4530 | if (q_vector->cpu == cpu) |
| 4531 | goto out_no_update; |
| 4532 | |
| 4533 | if (q_vector->tx_ring) { |
| 4534 | int q = q_vector->tx_ring->reg_idx; |
| 4535 | u32 dca_txctrl = rd32(E1000_DCA_TXCTRL(q)); |
| 4536 | if (hw->mac.type == e1000_82575) { |
| 4537 | dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK; |
| 4538 | dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 4539 | } else { |
| 4540 | dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576; |
| 4541 | dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 4542 | E1000_DCA_TXCTRL_CPUID_SHIFT; |
| 4543 | } |
| 4544 | dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN; |
| 4545 | wr32(E1000_DCA_TXCTRL(q), dca_txctrl); |
| 4546 | } |
| 4547 | if (q_vector->rx_ring) { |
| 4548 | int q = q_vector->rx_ring->reg_idx; |
| 4549 | u32 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q)); |
| 4550 | if (hw->mac.type == e1000_82575) { |
| 4551 | dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK; |
| 4552 | dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 4553 | } else { |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 4554 | dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576; |
Maciej Sosnowski | 92be791 | 2009-03-13 20:40:21 +0000 | [diff] [blame] | 4555 | dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) << |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 4556 | E1000_DCA_RXCTRL_CPUID_SHIFT; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 4557 | } |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4558 | dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN; |
| 4559 | dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN; |
| 4560 | dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN; |
| 4561 | wr32(E1000_DCA_RXCTRL(q), dca_rxctrl); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4562 | } |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4563 | q_vector->cpu = cpu; |
| 4564 | out_no_update: |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4565 | put_cpu(); |
| 4566 | } |
| 4567 | |
| 4568 | static void igb_setup_dca(struct igb_adapter *adapter) |
| 4569 | { |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 4570 | struct e1000_hw *hw = &adapter->hw; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4571 | int i; |
| 4572 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4573 | if (!(adapter->flags & IGB_FLAG_DCA_ENABLED)) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4574 | return; |
| 4575 | |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 4576 | /* Always use CB2 mode, difference is masked in the CB driver. */ |
| 4577 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2); |
| 4578 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4579 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 4580 | adapter->q_vector[i]->cpu = -1; |
| 4581 | igb_update_dca(adapter->q_vector[i]); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | static int __igb_notify_dca(struct device *dev, void *data) |
| 4586 | { |
| 4587 | struct net_device *netdev = dev_get_drvdata(dev); |
| 4588 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4589 | struct pci_dev *pdev = adapter->pdev; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4590 | struct e1000_hw *hw = &adapter->hw; |
| 4591 | unsigned long event = *(unsigned long *)data; |
| 4592 | |
| 4593 | switch (event) { |
| 4594 | case DCA_PROVIDER_ADD: |
| 4595 | /* if already enabled, don't do it again */ |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4596 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4597 | break; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4598 | if (dca_add_requester(dev) == 0) { |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 4599 | adapter->flags |= IGB_FLAG_DCA_ENABLED; |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4600 | dev_info(&pdev->dev, "DCA enabled\n"); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4601 | igb_setup_dca(adapter); |
| 4602 | break; |
| 4603 | } |
| 4604 | /* Fall Through since DCA is disabled. */ |
| 4605 | case DCA_PROVIDER_REMOVE: |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4606 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) { |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4607 | /* without this a class_device is left |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4608 | * hanging around in the sysfs model */ |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4609 | dca_remove_requester(dev); |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4610 | dev_info(&pdev->dev, "DCA disabled\n"); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4611 | adapter->flags &= ~IGB_FLAG_DCA_ENABLED; |
Alexander Duyck | cbd347a | 2009-02-15 23:59:44 -0800 | [diff] [blame] | 4612 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4613 | } |
| 4614 | break; |
| 4615 | } |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 4616 | |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4617 | return 0; |
| 4618 | } |
| 4619 | |
| 4620 | static int igb_notify_dca(struct notifier_block *nb, unsigned long event, |
| 4621 | void *p) |
| 4622 | { |
| 4623 | int ret_val; |
| 4624 | |
| 4625 | ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event, |
| 4626 | __igb_notify_dca); |
| 4627 | |
| 4628 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 4629 | } |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 4630 | #endif /* CONFIG_IGB_DCA */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4631 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4632 | static void igb_ping_all_vfs(struct igb_adapter *adapter) |
| 4633 | { |
| 4634 | struct e1000_hw *hw = &adapter->hw; |
| 4635 | u32 ping; |
| 4636 | int i; |
| 4637 | |
| 4638 | for (i = 0 ; i < adapter->vfs_allocated_count; i++) { |
| 4639 | ping = E1000_PF_CONTROL_MSG; |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4640 | if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4641 | ping |= E1000_VT_MSGTYPE_CTS; |
| 4642 | igb_write_mbx(hw, &ping, 1, i); |
| 4643 | } |
| 4644 | } |
| 4645 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4646 | static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf) |
| 4647 | { |
| 4648 | struct e1000_hw *hw = &adapter->hw; |
| 4649 | u32 vmolr = rd32(E1000_VMOLR(vf)); |
| 4650 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
| 4651 | |
| 4652 | vf_data->flags |= ~(IGB_VF_FLAG_UNI_PROMISC | |
| 4653 | IGB_VF_FLAG_MULTI_PROMISC); |
| 4654 | vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME); |
| 4655 | |
| 4656 | if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) { |
| 4657 | vmolr |= E1000_VMOLR_MPME; |
| 4658 | *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST; |
| 4659 | } else { |
| 4660 | /* |
| 4661 | * if we have hashes and we are clearing a multicast promisc |
| 4662 | * flag we need to write the hashes to the MTA as this step |
| 4663 | * was previously skipped |
| 4664 | */ |
| 4665 | if (vf_data->num_vf_mc_hashes > 30) { |
| 4666 | vmolr |= E1000_VMOLR_MPME; |
| 4667 | } else if (vf_data->num_vf_mc_hashes) { |
| 4668 | int j; |
| 4669 | vmolr |= E1000_VMOLR_ROMPE; |
| 4670 | for (j = 0; j < vf_data->num_vf_mc_hashes; j++) |
| 4671 | igb_mta_set(hw, vf_data->vf_mc_hashes[j]); |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | wr32(E1000_VMOLR(vf), vmolr); |
| 4676 | |
| 4677 | /* there are flags left unprocessed, likely not supported */ |
| 4678 | if (*msgbuf & E1000_VT_MSGINFO_MASK) |
| 4679 | return -EINVAL; |
| 4680 | |
| 4681 | return 0; |
| 4682 | |
| 4683 | } |
| 4684 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4685 | static int igb_set_vf_multicasts(struct igb_adapter *adapter, |
| 4686 | u32 *msgbuf, u32 vf) |
| 4687 | { |
| 4688 | int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT; |
| 4689 | u16 *hash_list = (u16 *)&msgbuf[1]; |
| 4690 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
| 4691 | int i; |
| 4692 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4693 | /* salt away the number of multicast addresses assigned |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4694 | * to this VF for later use to restore when the PF multi cast |
| 4695 | * list changes |
| 4696 | */ |
| 4697 | vf_data->num_vf_mc_hashes = n; |
| 4698 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4699 | /* only up to 30 hash values supported */ |
| 4700 | if (n > 30) |
| 4701 | n = 30; |
| 4702 | |
| 4703 | /* store the hashes for later use */ |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4704 | for (i = 0; i < n; i++) |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 4705 | vf_data->vf_mc_hashes[i] = hash_list[i]; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4706 | |
| 4707 | /* Flush and reset the mta with the new values */ |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 4708 | igb_set_rx_mode(adapter->netdev); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4709 | |
| 4710 | return 0; |
| 4711 | } |
| 4712 | |
| 4713 | static void igb_restore_vf_multicasts(struct igb_adapter *adapter) |
| 4714 | { |
| 4715 | struct e1000_hw *hw = &adapter->hw; |
| 4716 | struct vf_data_storage *vf_data; |
| 4717 | int i, j; |
| 4718 | |
| 4719 | for (i = 0; i < adapter->vfs_allocated_count; i++) { |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4720 | u32 vmolr = rd32(E1000_VMOLR(i)); |
| 4721 | vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME); |
| 4722 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4723 | vf_data = &adapter->vf_data[i]; |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4724 | |
| 4725 | if ((vf_data->num_vf_mc_hashes > 30) || |
| 4726 | (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) { |
| 4727 | vmolr |= E1000_VMOLR_MPME; |
| 4728 | } else if (vf_data->num_vf_mc_hashes) { |
| 4729 | vmolr |= E1000_VMOLR_ROMPE; |
| 4730 | for (j = 0; j < vf_data->num_vf_mc_hashes; j++) |
| 4731 | igb_mta_set(hw, vf_data->vf_mc_hashes[j]); |
| 4732 | } |
| 4733 | wr32(E1000_VMOLR(i), vmolr); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf) |
| 4738 | { |
| 4739 | struct e1000_hw *hw = &adapter->hw; |
| 4740 | u32 pool_mask, reg, vid; |
| 4741 | int i; |
| 4742 | |
| 4743 | pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf); |
| 4744 | |
| 4745 | /* Find the vlan filter for this id */ |
| 4746 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 4747 | reg = rd32(E1000_VLVF(i)); |
| 4748 | |
| 4749 | /* remove the vf from the pool */ |
| 4750 | reg &= ~pool_mask; |
| 4751 | |
| 4752 | /* if pool is empty then remove entry from vfta */ |
| 4753 | if (!(reg & E1000_VLVF_POOLSEL_MASK) && |
| 4754 | (reg & E1000_VLVF_VLANID_ENABLE)) { |
| 4755 | reg = 0; |
| 4756 | vid = reg & E1000_VLVF_VLANID_MASK; |
| 4757 | igb_vfta_set(hw, vid, false); |
| 4758 | } |
| 4759 | |
| 4760 | wr32(E1000_VLVF(i), reg); |
| 4761 | } |
Alexander Duyck | ae641bd | 2009-09-03 14:49:33 +0000 | [diff] [blame] | 4762 | |
| 4763 | adapter->vf_data[vf].vlans_enabled = 0; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4764 | } |
| 4765 | |
| 4766 | static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf) |
| 4767 | { |
| 4768 | struct e1000_hw *hw = &adapter->hw; |
| 4769 | u32 reg, i; |
| 4770 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 4771 | /* The vlvf table only exists on 82576 hardware and newer */ |
| 4772 | if (hw->mac.type < e1000_82576) |
| 4773 | return -1; |
| 4774 | |
| 4775 | /* we only need to do this if VMDq is enabled */ |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4776 | if (!adapter->vfs_allocated_count) |
| 4777 | return -1; |
| 4778 | |
| 4779 | /* Find the vlan filter for this id */ |
| 4780 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 4781 | reg = rd32(E1000_VLVF(i)); |
| 4782 | if ((reg & E1000_VLVF_VLANID_ENABLE) && |
| 4783 | vid == (reg & E1000_VLVF_VLANID_MASK)) |
| 4784 | break; |
| 4785 | } |
| 4786 | |
| 4787 | if (add) { |
| 4788 | if (i == E1000_VLVF_ARRAY_SIZE) { |
| 4789 | /* Did not find a matching VLAN ID entry that was |
| 4790 | * enabled. Search for a free filter entry, i.e. |
| 4791 | * one without the enable bit set |
| 4792 | */ |
| 4793 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 4794 | reg = rd32(E1000_VLVF(i)); |
| 4795 | if (!(reg & E1000_VLVF_VLANID_ENABLE)) |
| 4796 | break; |
| 4797 | } |
| 4798 | } |
| 4799 | if (i < E1000_VLVF_ARRAY_SIZE) { |
| 4800 | /* Found an enabled/available entry */ |
| 4801 | reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf); |
| 4802 | |
| 4803 | /* if !enabled we need to set this up in vfta */ |
| 4804 | if (!(reg & E1000_VLVF_VLANID_ENABLE)) { |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 4805 | /* add VID to filter table */ |
| 4806 | igb_vfta_set(hw, vid, true); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4807 | reg |= E1000_VLVF_VLANID_ENABLE; |
| 4808 | } |
Alexander Duyck | cad6d05 | 2009-03-13 20:41:37 +0000 | [diff] [blame] | 4809 | reg &= ~E1000_VLVF_VLANID_MASK; |
| 4810 | reg |= vid; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4811 | wr32(E1000_VLVF(i), reg); |
Alexander Duyck | ae641bd | 2009-09-03 14:49:33 +0000 | [diff] [blame] | 4812 | |
| 4813 | /* do not modify RLPML for PF devices */ |
| 4814 | if (vf >= adapter->vfs_allocated_count) |
| 4815 | return 0; |
| 4816 | |
| 4817 | if (!adapter->vf_data[vf].vlans_enabled) { |
| 4818 | u32 size; |
| 4819 | reg = rd32(E1000_VMOLR(vf)); |
| 4820 | size = reg & E1000_VMOLR_RLPML_MASK; |
| 4821 | size += 4; |
| 4822 | reg &= ~E1000_VMOLR_RLPML_MASK; |
| 4823 | reg |= size; |
| 4824 | wr32(E1000_VMOLR(vf), reg); |
| 4825 | } |
Alexander Duyck | ae641bd | 2009-09-03 14:49:33 +0000 | [diff] [blame] | 4826 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 4827 | adapter->vf_data[vf].vlans_enabled++; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4828 | return 0; |
| 4829 | } |
| 4830 | } else { |
| 4831 | if (i < E1000_VLVF_ARRAY_SIZE) { |
| 4832 | /* remove vf from the pool */ |
| 4833 | reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf)); |
| 4834 | /* if pool is empty then remove entry from vfta */ |
| 4835 | if (!(reg & E1000_VLVF_POOLSEL_MASK)) { |
| 4836 | reg = 0; |
| 4837 | igb_vfta_set(hw, vid, false); |
| 4838 | } |
| 4839 | wr32(E1000_VLVF(i), reg); |
Alexander Duyck | ae641bd | 2009-09-03 14:49:33 +0000 | [diff] [blame] | 4840 | |
| 4841 | /* do not modify RLPML for PF devices */ |
| 4842 | if (vf >= adapter->vfs_allocated_count) |
| 4843 | return 0; |
| 4844 | |
| 4845 | adapter->vf_data[vf].vlans_enabled--; |
| 4846 | if (!adapter->vf_data[vf].vlans_enabled) { |
| 4847 | u32 size; |
| 4848 | reg = rd32(E1000_VMOLR(vf)); |
| 4849 | size = reg & E1000_VMOLR_RLPML_MASK; |
| 4850 | size -= 4; |
| 4851 | reg &= ~E1000_VMOLR_RLPML_MASK; |
| 4852 | reg |= size; |
| 4853 | wr32(E1000_VMOLR(vf), reg); |
| 4854 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4855 | } |
| 4856 | } |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 4857 | return 0; |
| 4858 | } |
| 4859 | |
| 4860 | static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf) |
| 4861 | { |
| 4862 | struct e1000_hw *hw = &adapter->hw; |
| 4863 | |
| 4864 | if (vid) |
| 4865 | wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT)); |
| 4866 | else |
| 4867 | wr32(E1000_VMVIR(vf), 0); |
| 4868 | } |
| 4869 | |
| 4870 | static int igb_ndo_set_vf_vlan(struct net_device *netdev, |
| 4871 | int vf, u16 vlan, u8 qos) |
| 4872 | { |
| 4873 | int err = 0; |
| 4874 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 4875 | |
| 4876 | if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7)) |
| 4877 | return -EINVAL; |
| 4878 | if (vlan || qos) { |
| 4879 | err = igb_vlvf_set(adapter, vlan, !!vlan, vf); |
| 4880 | if (err) |
| 4881 | goto out; |
| 4882 | igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf); |
| 4883 | igb_set_vmolr(adapter, vf, !vlan); |
| 4884 | adapter->vf_data[vf].pf_vlan = vlan; |
| 4885 | adapter->vf_data[vf].pf_qos = qos; |
| 4886 | dev_info(&adapter->pdev->dev, |
| 4887 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); |
| 4888 | if (test_bit(__IGB_DOWN, &adapter->state)) { |
| 4889 | dev_warn(&adapter->pdev->dev, |
| 4890 | "The VF VLAN has been set," |
| 4891 | " but the PF device is not up.\n"); |
| 4892 | dev_warn(&adapter->pdev->dev, |
| 4893 | "Bring the PF device up before" |
| 4894 | " attempting to use the VF device.\n"); |
| 4895 | } |
| 4896 | } else { |
| 4897 | igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan, |
| 4898 | false, vf); |
| 4899 | igb_set_vmvir(adapter, vlan, vf); |
| 4900 | igb_set_vmolr(adapter, vf, true); |
| 4901 | adapter->vf_data[vf].pf_vlan = 0; |
| 4902 | adapter->vf_data[vf].pf_qos = 0; |
| 4903 | } |
| 4904 | out: |
| 4905 | return err; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf) |
| 4909 | { |
| 4910 | int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT; |
| 4911 | int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK); |
| 4912 | |
| 4913 | return igb_vlvf_set(adapter, vid, add, vf); |
| 4914 | } |
| 4915 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4916 | static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4917 | { |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 4918 | /* clear flags */ |
| 4919 | adapter->vf_data[vf].flags &= ~(IGB_VF_FLAG_PF_SET_MAC); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4920 | adapter->vf_data[vf].last_nack = jiffies; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4921 | |
| 4922 | /* reset offloads to defaults */ |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 4923 | igb_set_vmolr(adapter, vf, true); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4924 | |
| 4925 | /* reset vlans for device */ |
| 4926 | igb_clear_vf_vfta(adapter, vf); |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 4927 | if (adapter->vf_data[vf].pf_vlan) |
| 4928 | igb_ndo_set_vf_vlan(adapter->netdev, vf, |
| 4929 | adapter->vf_data[vf].pf_vlan, |
| 4930 | adapter->vf_data[vf].pf_qos); |
| 4931 | else |
| 4932 | igb_clear_vf_vfta(adapter, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4933 | |
| 4934 | /* reset multicast table array for vf */ |
| 4935 | adapter->vf_data[vf].num_vf_mc_hashes = 0; |
| 4936 | |
| 4937 | /* Flush and reset the mta with the new values */ |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 4938 | igb_set_rx_mode(adapter->netdev); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4939 | } |
| 4940 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4941 | static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf) |
| 4942 | { |
| 4943 | unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses; |
| 4944 | |
| 4945 | /* generate a new mac address as we were hotplug removed/added */ |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 4946 | if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC)) |
| 4947 | random_ether_addr(vf_mac); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4948 | |
| 4949 | /* process remaining reset events */ |
| 4950 | igb_vf_reset(adapter, vf); |
| 4951 | } |
| 4952 | |
| 4953 | static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4954 | { |
| 4955 | struct e1000_hw *hw = &adapter->hw; |
| 4956 | unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses; |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 4957 | int rar_entry = hw->mac.rar_entry_count - (vf + 1); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4958 | u32 reg, msgbuf[3]; |
| 4959 | u8 *addr = (u8 *)(&msgbuf[1]); |
| 4960 | |
| 4961 | /* process all the same items cleared in a function level reset */ |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4962 | igb_vf_reset(adapter, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4963 | |
| 4964 | /* set vf mac address */ |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 4965 | igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4966 | |
| 4967 | /* enable transmit and receive for vf */ |
| 4968 | reg = rd32(E1000_VFTE); |
| 4969 | wr32(E1000_VFTE, reg | (1 << vf)); |
| 4970 | reg = rd32(E1000_VFRE); |
| 4971 | wr32(E1000_VFRE, reg | (1 << vf)); |
| 4972 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4973 | adapter->vf_data[vf].flags = IGB_VF_FLAG_CTS; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4974 | |
| 4975 | /* reply to reset with ack and vf mac address */ |
| 4976 | msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK; |
| 4977 | memcpy(addr, vf_mac, 6); |
| 4978 | igb_write_mbx(hw, msgbuf, 3, vf); |
| 4979 | } |
| 4980 | |
| 4981 | static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf) |
| 4982 | { |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4983 | unsigned char *addr = (char *)&msg[1]; |
| 4984 | int err = -1; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4985 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4986 | if (is_valid_ether_addr(addr)) |
| 4987 | err = igb_set_vf_mac(adapter, vf, addr); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4988 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4989 | return err; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf) |
| 4993 | { |
| 4994 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4995 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4996 | u32 msg = E1000_VT_MSGTYPE_NACK; |
| 4997 | |
| 4998 | /* 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] | 4999 | if (!(vf_data->flags & IGB_VF_FLAG_CTS) && |
| 5000 | time_after(jiffies, vf_data->last_nack + (2 * HZ))) { |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5001 | igb_write_mbx(hw, &msg, 1, vf); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5002 | vf_data->last_nack = jiffies; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5003 | } |
| 5004 | } |
| 5005 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5006 | 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] | 5007 | { |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5008 | struct pci_dev *pdev = adapter->pdev; |
| 5009 | u32 msgbuf[E1000_VFMAILBOX_SIZE]; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5010 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5011 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5012 | s32 retval; |
| 5013 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5014 | retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5015 | |
Alexander Duyck | fef45f4 | 2009-12-11 22:57:34 -0800 | [diff] [blame] | 5016 | if (retval) { |
| 5017 | /* if receive failed revoke VF CTS stats and restart init */ |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5018 | dev_err(&pdev->dev, "Error receiving message from VF\n"); |
Alexander Duyck | fef45f4 | 2009-12-11 22:57:34 -0800 | [diff] [blame] | 5019 | vf_data->flags &= ~IGB_VF_FLAG_CTS; |
| 5020 | if (!time_after(jiffies, vf_data->last_nack + (2 * HZ))) |
| 5021 | return; |
| 5022 | goto out; |
| 5023 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5024 | |
| 5025 | /* this is a message we already processed, do nothing */ |
| 5026 | if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK)) |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5027 | return; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5028 | |
| 5029 | /* |
| 5030 | * until the vf completes a reset it should not be |
| 5031 | * allowed to start any configuration. |
| 5032 | */ |
| 5033 | |
| 5034 | if (msgbuf[0] == E1000_VF_RESET) { |
| 5035 | igb_vf_reset_msg(adapter, vf); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5036 | return; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5037 | } |
| 5038 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5039 | if (!(vf_data->flags & IGB_VF_FLAG_CTS)) { |
Alexander Duyck | fef45f4 | 2009-12-11 22:57:34 -0800 | [diff] [blame] | 5040 | if (!time_after(jiffies, vf_data->last_nack + (2 * HZ))) |
| 5041 | return; |
| 5042 | retval = -1; |
| 5043 | goto out; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | switch ((msgbuf[0] & 0xFFFF)) { |
| 5047 | case E1000_VF_SET_MAC_ADDR: |
| 5048 | retval = igb_set_vf_mac_addr(adapter, msgbuf, vf); |
| 5049 | break; |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 5050 | case E1000_VF_SET_PROMISC: |
| 5051 | retval = igb_set_vf_promisc(adapter, msgbuf, vf); |
| 5052 | break; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5053 | case E1000_VF_SET_MULTICAST: |
| 5054 | retval = igb_set_vf_multicasts(adapter, msgbuf, vf); |
| 5055 | break; |
| 5056 | case E1000_VF_SET_LPE: |
| 5057 | retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf); |
| 5058 | break; |
| 5059 | case E1000_VF_SET_VLAN: |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 5060 | if (adapter->vf_data[vf].pf_vlan) |
| 5061 | retval = -1; |
| 5062 | else |
| 5063 | retval = igb_set_vf_vlan(adapter, msgbuf, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5064 | break; |
| 5065 | default: |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 5066 | dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5067 | retval = -1; |
| 5068 | break; |
| 5069 | } |
| 5070 | |
Alexander Duyck | fef45f4 | 2009-12-11 22:57:34 -0800 | [diff] [blame] | 5071 | msgbuf[0] |= E1000_VT_MSGTYPE_CTS; |
| 5072 | out: |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5073 | /* notify the VF of the results of what it sent us */ |
| 5074 | if (retval) |
| 5075 | msgbuf[0] |= E1000_VT_MSGTYPE_NACK; |
| 5076 | else |
| 5077 | msgbuf[0] |= E1000_VT_MSGTYPE_ACK; |
| 5078 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5079 | igb_write_mbx(hw, msgbuf, 1, vf); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5080 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5081 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5082 | static void igb_msg_task(struct igb_adapter *adapter) |
| 5083 | { |
| 5084 | struct e1000_hw *hw = &adapter->hw; |
| 5085 | u32 vf; |
| 5086 | |
| 5087 | for (vf = 0; vf < adapter->vfs_allocated_count; vf++) { |
| 5088 | /* process any reset requests */ |
| 5089 | if (!igb_check_for_rst(hw, vf)) |
| 5090 | igb_vf_reset_event(adapter, vf); |
| 5091 | |
| 5092 | /* process any messages pending */ |
| 5093 | if (!igb_check_for_msg(hw, vf)) |
| 5094 | igb_rcv_msg_from_vf(adapter, vf); |
| 5095 | |
| 5096 | /* process any acks */ |
| 5097 | if (!igb_check_for_ack(hw, vf)) |
| 5098 | igb_rcv_ack_from_vf(adapter, vf); |
| 5099 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5100 | } |
| 5101 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5102 | /** |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 5103 | * igb_set_uta - Set unicast filter table address |
| 5104 | * @adapter: board private structure |
| 5105 | * |
| 5106 | * The unicast table address is a register array of 32-bit registers. |
| 5107 | * The table is meant to be used in a way similar to how the MTA is used |
| 5108 | * however due to certain limitations in the hardware it is necessary to |
| 5109 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscous |
| 5110 | * enable bit to allow vlan tag stripping when promiscous mode is enabled |
| 5111 | **/ |
| 5112 | static void igb_set_uta(struct igb_adapter *adapter) |
| 5113 | { |
| 5114 | struct e1000_hw *hw = &adapter->hw; |
| 5115 | int i; |
| 5116 | |
| 5117 | /* The UTA table only exists on 82576 hardware and newer */ |
| 5118 | if (hw->mac.type < e1000_82576) |
| 5119 | return; |
| 5120 | |
| 5121 | /* we only need to do this if VMDq is enabled */ |
| 5122 | if (!adapter->vfs_allocated_count) |
| 5123 | return; |
| 5124 | |
| 5125 | for (i = 0; i < hw->mac.uta_reg_count; i++) |
| 5126 | array_wr32(E1000_UTA, i, ~0); |
| 5127 | } |
| 5128 | |
| 5129 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5130 | * igb_intr_msi - Interrupt Handler |
| 5131 | * @irq: interrupt number |
| 5132 | * @data: pointer to a network interface device structure |
| 5133 | **/ |
| 5134 | static irqreturn_t igb_intr_msi(int irq, void *data) |
| 5135 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5136 | struct igb_adapter *adapter = data; |
| 5137 | struct igb_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5138 | struct e1000_hw *hw = &adapter->hw; |
| 5139 | /* read ICR disables interrupts using IAM */ |
| 5140 | u32 icr = rd32(E1000_ICR); |
| 5141 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5142 | igb_write_itr(q_vector); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5143 | |
Alexander Duyck | 7f081d4 | 2010-01-07 17:41:00 +0000 | [diff] [blame] | 5144 | if (icr & E1000_ICR_DRSTA) |
| 5145 | schedule_work(&adapter->reset_task); |
| 5146 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5147 | if (icr & E1000_ICR_DOUTSYNC) { |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 5148 | /* HW is reporting DMA is out of sync */ |
| 5149 | adapter->stats.doosync++; |
| 5150 | } |
| 5151 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5152 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 5153 | hw->mac.get_link_status = 1; |
| 5154 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 5155 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 5156 | } |
| 5157 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5158 | napi_schedule(&q_vector->napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5159 | |
| 5160 | return IRQ_HANDLED; |
| 5161 | } |
| 5162 | |
| 5163 | /** |
Alexander Duyck | 4a3c643 | 2009-02-06 23:20:49 +0000 | [diff] [blame] | 5164 | * igb_intr - Legacy Interrupt Handler |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5165 | * @irq: interrupt number |
| 5166 | * @data: pointer to a network interface device structure |
| 5167 | **/ |
| 5168 | static irqreturn_t igb_intr(int irq, void *data) |
| 5169 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5170 | struct igb_adapter *adapter = data; |
| 5171 | struct igb_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5172 | struct e1000_hw *hw = &adapter->hw; |
| 5173 | /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No |
| 5174 | * need for the IMC write */ |
| 5175 | u32 icr = rd32(E1000_ICR); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5176 | if (!icr) |
| 5177 | return IRQ_NONE; /* Not our interrupt */ |
| 5178 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5179 | igb_write_itr(q_vector); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5180 | |
| 5181 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 5182 | * not set, then the adapter didn't send an interrupt */ |
| 5183 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 5184 | return IRQ_NONE; |
| 5185 | |
Alexander Duyck | 7f081d4 | 2010-01-07 17:41:00 +0000 | [diff] [blame] | 5186 | if (icr & E1000_ICR_DRSTA) |
| 5187 | schedule_work(&adapter->reset_task); |
| 5188 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5189 | if (icr & E1000_ICR_DOUTSYNC) { |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 5190 | /* HW is reporting DMA is out of sync */ |
| 5191 | adapter->stats.doosync++; |
| 5192 | } |
| 5193 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5194 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 5195 | hw->mac.get_link_status = 1; |
| 5196 | /* guard against interrupt when we're going down */ |
| 5197 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 5198 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 5199 | } |
| 5200 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5201 | napi_schedule(&q_vector->napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5202 | |
| 5203 | return IRQ_HANDLED; |
| 5204 | } |
| 5205 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5206 | 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] | 5207 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5208 | struct igb_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5209 | struct e1000_hw *hw = &adapter->hw; |
| 5210 | |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 5211 | if ((q_vector->rx_ring && (adapter->rx_itr_setting & 3)) || |
| 5212 | (!q_vector->rx_ring && (adapter->tx_itr_setting & 3))) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5213 | if (!adapter->msix_entries) |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5214 | igb_set_itr(adapter); |
| 5215 | else |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5216 | igb_update_ring_itr(q_vector); |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5217 | } |
| 5218 | |
| 5219 | if (!test_bit(__IGB_DOWN, &adapter->state)) { |
| 5220 | if (adapter->msix_entries) |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5221 | wr32(E1000_EIMS, q_vector->eims_value); |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5222 | else |
| 5223 | igb_irq_enable(adapter); |
| 5224 | } |
| 5225 | } |
| 5226 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5227 | /** |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 5228 | * igb_poll - NAPI Rx polling callback |
| 5229 | * @napi: napi polling structure |
| 5230 | * @budget: count of how many packets we should handle |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5231 | **/ |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 5232 | static int igb_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5233 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5234 | struct igb_q_vector *q_vector = container_of(napi, |
| 5235 | struct igb_q_vector, |
| 5236 | napi); |
| 5237 | int tx_clean_complete = 1, work_done = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5238 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 5239 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5240 | if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED) |
| 5241 | igb_update_dca(q_vector); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 5242 | #endif |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5243 | if (q_vector->tx_ring) |
| 5244 | tx_clean_complete = igb_clean_tx_irq(q_vector); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5245 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5246 | if (q_vector->rx_ring) |
| 5247 | igb_clean_rx_irq_adv(q_vector, &work_done, budget); |
| 5248 | |
| 5249 | if (!tx_clean_complete) |
| 5250 | work_done = budget; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5251 | |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5252 | /* If not enough Rx work done, exit the polling mode */ |
Alexander Duyck | 5e6d5b1 | 2009-03-13 20:40:38 +0000 | [diff] [blame] | 5253 | if (work_done < budget) { |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5254 | napi_complete(napi); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5255 | igb_ring_irq_enable(q_vector); |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5256 | } |
| 5257 | |
| 5258 | return work_done; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5259 | } |
Al Viro | 6d8126f | 2008-03-16 22:23:24 +0000 | [diff] [blame] | 5260 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5261 | /** |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5262 | * igb_systim_to_hwtstamp - convert system time value to hw timestamp |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5263 | * @adapter: board private structure |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5264 | * @shhwtstamps: timestamp structure to update |
| 5265 | * @regval: unsigned 64bit system time value. |
| 5266 | * |
| 5267 | * We need to convert the system time value stored in the RX/TXSTMP registers |
| 5268 | * into a hwtstamp which can be used by the upper level timestamping functions |
| 5269 | */ |
| 5270 | static void igb_systim_to_hwtstamp(struct igb_adapter *adapter, |
| 5271 | struct skb_shared_hwtstamps *shhwtstamps, |
| 5272 | u64 regval) |
| 5273 | { |
| 5274 | u64 ns; |
| 5275 | |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 5276 | /* |
| 5277 | * The 82580 starts with 1ns at bit 0 in RX/TXSTMPL, shift this up to |
| 5278 | * 24 to match clock shift we setup earlier. |
| 5279 | */ |
| 5280 | if (adapter->hw.mac.type == e1000_82580) |
| 5281 | regval <<= IGB_82580_TSYNC_SHIFT; |
| 5282 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5283 | ns = timecounter_cyc2time(&adapter->clock, regval); |
| 5284 | timecompare_update(&adapter->compare, ns); |
| 5285 | memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); |
| 5286 | shhwtstamps->hwtstamp = ns_to_ktime(ns); |
| 5287 | shhwtstamps->syststamp = timecompare_transform(&adapter->compare, ns); |
| 5288 | } |
| 5289 | |
| 5290 | /** |
| 5291 | * igb_tx_hwtstamp - utility function which checks for TX time stamp |
| 5292 | * @q_vector: pointer to q_vector containing needed info |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 5293 | * @buffer: pointer to igb_buffer structure |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5294 | * |
| 5295 | * If we were asked to do hardware stamping and such a time stamp is |
| 5296 | * available, then it must have been for this skb here because we only |
| 5297 | * allow only one such packet into the queue. |
| 5298 | */ |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 5299 | static void igb_tx_hwtstamp(struct igb_q_vector *q_vector, struct igb_buffer *buffer_info) |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5300 | { |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5301 | struct igb_adapter *adapter = q_vector->adapter; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5302 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5303 | struct skb_shared_hwtstamps shhwtstamps; |
| 5304 | u64 regval; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5305 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5306 | /* if skb does not support hw timestamp or TX stamp not valid exit */ |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 5307 | if (likely(!buffer_info->shtx.hardware) || |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5308 | !(rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID)) |
| 5309 | return; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5310 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5311 | regval = rd32(E1000_TXSTMPL); |
| 5312 | regval |= (u64)rd32(E1000_TXSTMPH) << 32; |
| 5313 | |
| 5314 | igb_systim_to_hwtstamp(adapter, &shhwtstamps, regval); |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 5315 | skb_tstamp_tx(buffer_info->skb, &shhwtstamps); |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5319 | * igb_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5320 | * @q_vector: pointer to q_vector containing needed info |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5321 | * returns true if ring is completely cleaned |
| 5322 | **/ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5323 | static bool igb_clean_tx_irq(struct igb_q_vector *q_vector) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5324 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5325 | struct igb_adapter *adapter = q_vector->adapter; |
| 5326 | struct igb_ring *tx_ring = q_vector->tx_ring; |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 5327 | struct net_device *netdev = tx_ring->netdev; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5328 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5329 | struct igb_buffer *buffer_info; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5330 | union e1000_adv_tx_desc *tx_desc, *eop_desc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5331 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5332 | unsigned int i, eop, count = 0; |
| 5333 | bool cleaned = false; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5334 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5335 | i = tx_ring->next_to_clean; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5336 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 5337 | eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop); |
| 5338 | |
| 5339 | while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 5340 | (count < tx_ring->count)) { |
| 5341 | for (cleaned = false; !cleaned; count++) { |
| 5342 | tx_desc = E1000_TX_DESC_ADV(*tx_ring, i); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5343 | buffer_info = &tx_ring->buffer_info[i]; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5344 | cleaned = (i == eop); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5345 | |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 5346 | if (buffer_info->skb) { |
| 5347 | total_bytes += buffer_info->bytecount; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5348 | /* gso_segs is currently only valid for tcp */ |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame^] | 5349 | total_packets += buffer_info->gso_segs; |
| 5350 | igb_tx_hwtstamp(q_vector, buffer_info); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5351 | } |
| 5352 | |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 5353 | igb_unmap_and_free_tx_resource(tx_ring, buffer_info); |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5354 | tx_desc->wb.status = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5355 | |
| 5356 | i++; |
| 5357 | if (i == tx_ring->count) |
| 5358 | i = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5359 | } |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5360 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 5361 | eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop); |
| 5362 | } |
| 5363 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5364 | tx_ring->next_to_clean = i; |
| 5365 | |
Alexander Duyck | fc7d345 | 2008-08-26 04:25:08 -0700 | [diff] [blame] | 5366 | if (unlikely(count && |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5367 | netif_carrier_ok(netdev) && |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 5368 | igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5369 | /* Make sure that anybody stopping the queue after this |
| 5370 | * sees the new next_to_clean. |
| 5371 | */ |
| 5372 | smp_mb(); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 5373 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 5374 | !(test_bit(__IGB_DOWN, &adapter->state))) { |
| 5375 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Alexander Duyck | 04a5fcaa | 2009-10-27 15:52:27 +0000 | [diff] [blame] | 5376 | tx_ring->tx_stats.restart_queue++; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 5377 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | if (tx_ring->detect_tx_hung) { |
| 5381 | /* Detect a transmit hang in hardware, this serializes the |
| 5382 | * check with the clearing of time_stamp and movement of i */ |
| 5383 | tx_ring->detect_tx_hung = false; |
| 5384 | if (tx_ring->buffer_info[i].time_stamp && |
| 5385 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp + |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 5386 | (adapter->tx_timeout_factor * HZ)) && |
| 5387 | !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5388 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5389 | /* detected Tx unit hang */ |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5390 | dev_err(tx_ring->dev, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5391 | "Detected Tx Unit Hang\n" |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 5392 | " Tx Queue <%d>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5393 | " TDH <%x>\n" |
| 5394 | " TDT <%x>\n" |
| 5395 | " next_to_use <%x>\n" |
| 5396 | " next_to_clean <%x>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5397 | "buffer_info[next_to_clean]\n" |
| 5398 | " time_stamp <%lx>\n" |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5399 | " next_to_watch <%x>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5400 | " jiffies <%lx>\n" |
| 5401 | " desc.status <%x>\n", |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 5402 | tx_ring->queue_index, |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 5403 | readl(tx_ring->head), |
| 5404 | readl(tx_ring->tail), |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5405 | tx_ring->next_to_use, |
| 5406 | tx_ring->next_to_clean, |
Alexander Duyck | f7ba205 | 2009-10-27 23:48:51 +0000 | [diff] [blame] | 5407 | tx_ring->buffer_info[eop].time_stamp, |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5408 | eop, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5409 | jiffies, |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5410 | eop_desc->wb.status); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 5411 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5412 | } |
| 5413 | } |
| 5414 | tx_ring->total_bytes += total_bytes; |
| 5415 | tx_ring->total_packets += total_packets; |
Alexander Duyck | e21ed35 | 2008-07-08 15:07:24 -0700 | [diff] [blame] | 5416 | tx_ring->tx_stats.bytes += total_bytes; |
| 5417 | tx_ring->tx_stats.packets += total_packets; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5418 | return (count < tx_ring->count); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5419 | } |
| 5420 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5421 | /** |
| 5422 | * igb_receive_skb - helper function to handle rx indications |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5423 | * @q_vector: structure containing interrupt and ring information |
| 5424 | * @skb: packet to send up |
| 5425 | * @vlan_tag: vlan tag for packet |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5426 | **/ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5427 | static void igb_receive_skb(struct igb_q_vector *q_vector, |
| 5428 | struct sk_buff *skb, |
| 5429 | u16 vlan_tag) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5430 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5431 | struct igb_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d335252 | 2008-07-08 15:12:13 -0700 | [diff] [blame] | 5432 | |
Alexander Duyck | 31b24b9 | 2010-03-23 18:35:18 +0000 | [diff] [blame] | 5433 | if (vlan_tag && adapter->vlgrp) |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5434 | vlan_gro_receive(&q_vector->napi, adapter->vlgrp, |
| 5435 | vlan_tag, skb); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 5436 | else |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5437 | napi_gro_receive(&q_vector->napi, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5438 | } |
| 5439 | |
Alexander Duyck | 04a5fcaa | 2009-10-27 15:52:27 +0000 | [diff] [blame] | 5440 | static inline void igb_rx_checksum_adv(struct igb_ring *ring, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5441 | u32 status_err, struct sk_buff *skb) |
| 5442 | { |
| 5443 | skb->ip_summed = CHECKSUM_NONE; |
| 5444 | |
| 5445 | /* Ignore Checksum bit is set or checksum is disabled through ethtool */ |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 5446 | if (!(ring->flags & IGB_RING_FLAG_RX_CSUM) || |
| 5447 | (status_err & E1000_RXD_STAT_IXSM)) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5448 | return; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 5449 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5450 | /* TCP/UDP checksum error bit is set */ |
| 5451 | if (status_err & |
| 5452 | (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) { |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 5453 | /* |
| 5454 | * work around errata with sctp packets where the TCPE aka |
| 5455 | * L4E bit is set incorrectly on 64 byte (60 byte w/o crc) |
| 5456 | * packets, (aka let the stack check the crc32c) |
| 5457 | */ |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 5458 | if ((skb->len == 60) && |
| 5459 | (ring->flags & IGB_RING_FLAG_RX_SCTP_CSUM)) |
Alexander Duyck | 04a5fcaa | 2009-10-27 15:52:27 +0000 | [diff] [blame] | 5460 | ring->rx_stats.csum_err++; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 5461 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5462 | /* let the stack verify checksum errors */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5463 | return; |
| 5464 | } |
| 5465 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 5466 | if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)) |
| 5467 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5468 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5469 | dev_dbg(ring->dev, "cksum success: bits %08X\n", status_err); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5470 | } |
| 5471 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5472 | 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] | 5473 | struct sk_buff *skb) |
| 5474 | { |
| 5475 | struct igb_adapter *adapter = q_vector->adapter; |
| 5476 | struct e1000_hw *hw = &adapter->hw; |
| 5477 | u64 regval; |
| 5478 | |
| 5479 | /* |
| 5480 | * If this bit is set, then the RX registers contain the time stamp. No |
| 5481 | * other packet will be time stamped until we read these registers, so |
| 5482 | * read the registers to make them available again. Because only one |
| 5483 | * packet can be time stamped at a time, we know that the register |
| 5484 | * values must belong to this one here and therefore we don't need to |
| 5485 | * compare any of the additional attributes stored for it. |
| 5486 | * |
| 5487 | * If nothing went wrong, then it should have a skb_shared_tx that we |
| 5488 | * can turn into a skb_shared_hwtstamps. |
| 5489 | */ |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5490 | if (staterr & E1000_RXDADV_STAT_TSIP) { |
| 5491 | u32 *stamp = (u32 *)skb->data; |
| 5492 | regval = le32_to_cpu(*(stamp + 2)); |
| 5493 | regval |= (u64)le32_to_cpu(*(stamp + 3)) << 32; |
| 5494 | skb_pull(skb, IGB_TS_HDR_LEN); |
| 5495 | } else { |
| 5496 | if(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) |
| 5497 | return; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5498 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5499 | regval = rd32(E1000_RXSTMPL); |
| 5500 | regval |= (u64)rd32(E1000_RXSTMPH) << 32; |
| 5501 | } |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5502 | |
| 5503 | igb_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval); |
| 5504 | } |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 5505 | static inline u16 igb_get_hlen(struct igb_ring *rx_ring, |
Alexander Duyck | 2d94d8a | 2009-07-23 18:10:06 +0000 | [diff] [blame] | 5506 | union e1000_adv_rx_desc *rx_desc) |
| 5507 | { |
| 5508 | /* HW will not DMA in data larger than the given buffer, even if it |
| 5509 | * parses the (NFS, of course) header to be larger. In that case, it |
| 5510 | * fills the header buffer and spills the rest into the page. |
| 5511 | */ |
| 5512 | u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) & |
| 5513 | E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT; |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 5514 | if (hlen > rx_ring->rx_buffer_len) |
| 5515 | hlen = rx_ring->rx_buffer_len; |
Alexander Duyck | 2d94d8a | 2009-07-23 18:10:06 +0000 | [diff] [blame] | 5516 | return hlen; |
| 5517 | } |
| 5518 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5519 | static bool igb_clean_rx_irq_adv(struct igb_q_vector *q_vector, |
| 5520 | int *work_done, int budget) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5521 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5522 | struct igb_ring *rx_ring = q_vector->rx_ring; |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 5523 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5524 | struct device *dev = rx_ring->dev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5525 | union e1000_adv_rx_desc *rx_desc , *next_rxd; |
| 5526 | struct igb_buffer *buffer_info , *next_buffer; |
| 5527 | struct sk_buff *skb; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5528 | bool cleaned = false; |
| 5529 | int cleaned_count = 0; |
Alexander Duyck | d1eff35 | 2009-11-12 18:38:35 +0000 | [diff] [blame] | 5530 | int current_node = numa_node_id(); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5531 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 5532 | unsigned int i; |
Alexander Duyck | 2d94d8a | 2009-07-23 18:10:06 +0000 | [diff] [blame] | 5533 | u32 staterr; |
| 5534 | u16 length; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5535 | u16 vlan_tag; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5536 | |
| 5537 | i = rx_ring->next_to_clean; |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5538 | buffer_info = &rx_ring->buffer_info[i]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5539 | rx_desc = E1000_RX_DESC_ADV(*rx_ring, i); |
| 5540 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 5541 | |
| 5542 | while (staterr & E1000_RXD_STAT_DD) { |
| 5543 | if (*work_done >= budget) |
| 5544 | break; |
| 5545 | (*work_done)++; |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5546 | |
| 5547 | skb = buffer_info->skb; |
| 5548 | prefetch(skb->data - NET_IP_ALIGN); |
| 5549 | buffer_info->skb = NULL; |
| 5550 | |
| 5551 | i++; |
| 5552 | if (i == rx_ring->count) |
| 5553 | i = 0; |
Alexander Duyck | 42d0781 | 2009-10-27 23:51:16 +0000 | [diff] [blame] | 5554 | |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5555 | next_rxd = E1000_RX_DESC_ADV(*rx_ring, i); |
| 5556 | prefetch(next_rxd); |
| 5557 | next_buffer = &rx_ring->buffer_info[i]; |
| 5558 | |
| 5559 | length = le16_to_cpu(rx_desc->wb.upper.length); |
| 5560 | cleaned = true; |
| 5561 | cleaned_count++; |
| 5562 | |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 5563 | if (buffer_info->dma) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5564 | dma_unmap_single(dev, buffer_info->dma, |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 5565 | rx_ring->rx_buffer_len, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5566 | DMA_FROM_DEVICE); |
Jesse Brandeburg | 91615f7 | 2009-06-30 12:45:15 +0000 | [diff] [blame] | 5567 | buffer_info->dma = 0; |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 5568 | if (rx_ring->rx_buffer_len >= IGB_RXBUFFER_1024) { |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 5569 | skb_put(skb, length); |
| 5570 | goto send_up; |
| 5571 | } |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 5572 | skb_put(skb, igb_get_hlen(rx_ring, rx_desc)); |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | if (length) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5576 | dma_unmap_page(dev, buffer_info->page_dma, |
| 5577 | PAGE_SIZE / 2, DMA_FROM_DEVICE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5578 | buffer_info->page_dma = 0; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5579 | |
Koki Sanagi | aa91340 | 2010-04-27 01:01:19 +0000 | [diff] [blame] | 5580 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5581 | buffer_info->page, |
| 5582 | buffer_info->page_offset, |
| 5583 | length); |
| 5584 | |
Alexander Duyck | d1eff35 | 2009-11-12 18:38:35 +0000 | [diff] [blame] | 5585 | if ((page_count(buffer_info->page) != 1) || |
| 5586 | (page_to_nid(buffer_info->page) != current_node)) |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5587 | buffer_info->page = NULL; |
| 5588 | else |
| 5589 | get_page(buffer_info->page); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5590 | |
| 5591 | skb->len += length; |
| 5592 | skb->data_len += length; |
| 5593 | skb->truesize += length; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5594 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5595 | |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5596 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Alexander Duyck | b2d5653 | 2008-11-20 00:47:34 -0800 | [diff] [blame] | 5597 | buffer_info->skb = next_buffer->skb; |
| 5598 | buffer_info->dma = next_buffer->dma; |
| 5599 | next_buffer->skb = skb; |
| 5600 | next_buffer->dma = 0; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5601 | goto next_desc; |
| 5602 | } |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5603 | send_up: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5604 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
| 5605 | dev_kfree_skb_irq(skb); |
| 5606 | goto next_desc; |
| 5607 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5608 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5609 | if (staterr & (E1000_RXDADV_STAT_TSIP | E1000_RXDADV_STAT_TS)) |
| 5610 | igb_rx_hwtstamp(q_vector, staterr, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5611 | total_bytes += skb->len; |
| 5612 | total_packets++; |
| 5613 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 5614 | igb_rx_checksum_adv(rx_ring, staterr, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5615 | |
| 5616 | skb->protocol = eth_type_trans(skb, netdev); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5617 | skb_record_rx_queue(skb, rx_ring->queue_index); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5618 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5619 | vlan_tag = ((staterr & E1000_RXD_STAT_VP) ? |
| 5620 | le16_to_cpu(rx_desc->wb.upper.vlan) : 0); |
| 5621 | |
| 5622 | igb_receive_skb(q_vector, skb, vlan_tag); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5623 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5624 | next_desc: |
| 5625 | rx_desc->wb.upper.status_error = 0; |
| 5626 | |
| 5627 | /* return some buffers to hardware, one at a time is too slow */ |
| 5628 | if (cleaned_count >= IGB_RX_BUFFER_WRITE) { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 5629 | igb_alloc_rx_buffers_adv(rx_ring, cleaned_count); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5630 | cleaned_count = 0; |
| 5631 | } |
| 5632 | |
| 5633 | /* use prefetched values */ |
| 5634 | rx_desc = next_rxd; |
| 5635 | buffer_info = next_buffer; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5636 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 5637 | } |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5638 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5639 | rx_ring->next_to_clean = i; |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 5640 | cleaned_count = igb_desc_unused(rx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5641 | |
| 5642 | if (cleaned_count) |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 5643 | igb_alloc_rx_buffers_adv(rx_ring, cleaned_count); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5644 | |
| 5645 | rx_ring->total_packets += total_packets; |
| 5646 | rx_ring->total_bytes += total_bytes; |
| 5647 | rx_ring->rx_stats.packets += total_packets; |
| 5648 | rx_ring->rx_stats.bytes += total_bytes; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5649 | return cleaned; |
| 5650 | } |
| 5651 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5652 | /** |
| 5653 | * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split |
| 5654 | * @adapter: address of board private structure |
| 5655 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 5656 | void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring, int cleaned_count) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5657 | { |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 5658 | struct net_device *netdev = rx_ring->netdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5659 | union e1000_adv_rx_desc *rx_desc; |
| 5660 | struct igb_buffer *buffer_info; |
| 5661 | struct sk_buff *skb; |
| 5662 | unsigned int i; |
Alexander Duyck | db76176 | 2009-02-06 23:15:25 +0000 | [diff] [blame] | 5663 | int bufsz; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5664 | |
| 5665 | i = rx_ring->next_to_use; |
| 5666 | buffer_info = &rx_ring->buffer_info[i]; |
| 5667 | |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 5668 | bufsz = rx_ring->rx_buffer_len; |
Alexander Duyck | db76176 | 2009-02-06 23:15:25 +0000 | [diff] [blame] | 5669 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5670 | while (cleaned_count--) { |
| 5671 | rx_desc = E1000_RX_DESC_ADV(*rx_ring, i); |
| 5672 | |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 5673 | if ((bufsz < IGB_RXBUFFER_1024) && !buffer_info->page_dma) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5674 | if (!buffer_info->page) { |
Alexander Duyck | 42d0781 | 2009-10-27 23:51:16 +0000 | [diff] [blame] | 5675 | buffer_info->page = netdev_alloc_page(netdev); |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5676 | if (!buffer_info->page) { |
Alexander Duyck | 04a5fcaa | 2009-10-27 15:52:27 +0000 | [diff] [blame] | 5677 | rx_ring->rx_stats.alloc_failed++; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5678 | goto no_buffers; |
| 5679 | } |
| 5680 | buffer_info->page_offset = 0; |
| 5681 | } else { |
| 5682 | buffer_info->page_offset ^= PAGE_SIZE / 2; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5683 | } |
| 5684 | buffer_info->page_dma = |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5685 | dma_map_page(rx_ring->dev, buffer_info->page, |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5686 | buffer_info->page_offset, |
| 5687 | PAGE_SIZE / 2, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5688 | DMA_FROM_DEVICE); |
| 5689 | if (dma_mapping_error(rx_ring->dev, |
| 5690 | buffer_info->page_dma)) { |
Alexander Duyck | 42d0781 | 2009-10-27 23:51:16 +0000 | [diff] [blame] | 5691 | buffer_info->page_dma = 0; |
| 5692 | rx_ring->rx_stats.alloc_failed++; |
| 5693 | goto no_buffers; |
| 5694 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5695 | } |
| 5696 | |
Alexander Duyck | 42d0781 | 2009-10-27 23:51:16 +0000 | [diff] [blame] | 5697 | skb = buffer_info->skb; |
| 5698 | if (!skb) { |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 5699 | skb = netdev_alloc_skb_ip_align(netdev, bufsz); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5700 | if (!skb) { |
Alexander Duyck | 04a5fcaa | 2009-10-27 15:52:27 +0000 | [diff] [blame] | 5701 | rx_ring->rx_stats.alloc_failed++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5702 | goto no_buffers; |
| 5703 | } |
| 5704 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5705 | buffer_info->skb = skb; |
Alexander Duyck | 42d0781 | 2009-10-27 23:51:16 +0000 | [diff] [blame] | 5706 | } |
| 5707 | if (!buffer_info->dma) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5708 | buffer_info->dma = dma_map_single(rx_ring->dev, |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 5709 | skb->data, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5710 | bufsz, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5711 | DMA_FROM_DEVICE); |
| 5712 | if (dma_mapping_error(rx_ring->dev, |
| 5713 | buffer_info->dma)) { |
Alexander Duyck | 42d0781 | 2009-10-27 23:51:16 +0000 | [diff] [blame] | 5714 | buffer_info->dma = 0; |
| 5715 | rx_ring->rx_stats.alloc_failed++; |
| 5716 | goto no_buffers; |
| 5717 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5718 | } |
| 5719 | /* Refresh the desc even if buffer_addrs didn't change because |
| 5720 | * each write-back erases this info. */ |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 5721 | if (bufsz < IGB_RXBUFFER_1024) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5722 | rx_desc->read.pkt_addr = |
| 5723 | cpu_to_le64(buffer_info->page_dma); |
| 5724 | rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma); |
| 5725 | } else { |
Alexander Duyck | 42d0781 | 2009-10-27 23:51:16 +0000 | [diff] [blame] | 5726 | rx_desc->read.pkt_addr = cpu_to_le64(buffer_info->dma); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5727 | rx_desc->read.hdr_addr = 0; |
| 5728 | } |
| 5729 | |
| 5730 | i++; |
| 5731 | if (i == rx_ring->count) |
| 5732 | i = 0; |
| 5733 | buffer_info = &rx_ring->buffer_info[i]; |
| 5734 | } |
| 5735 | |
| 5736 | no_buffers: |
| 5737 | if (rx_ring->next_to_use != i) { |
| 5738 | rx_ring->next_to_use = i; |
| 5739 | if (i == 0) |
| 5740 | i = (rx_ring->count - 1); |
| 5741 | else |
| 5742 | i--; |
| 5743 | |
| 5744 | /* Force memory writes to complete before letting h/w |
| 5745 | * know there are new descriptors to fetch. (Only |
| 5746 | * applicable for weak-ordered memory model archs, |
| 5747 | * such as IA-64). */ |
| 5748 | wmb(); |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 5749 | writel(i, rx_ring->tail); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | /** |
| 5754 | * igb_mii_ioctl - |
| 5755 | * @netdev: |
| 5756 | * @ifreq: |
| 5757 | * @cmd: |
| 5758 | **/ |
| 5759 | static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5760 | { |
| 5761 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5762 | struct mii_ioctl_data *data = if_mii(ifr); |
| 5763 | |
| 5764 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
| 5765 | return -EOPNOTSUPP; |
| 5766 | |
| 5767 | switch (cmd) { |
| 5768 | case SIOCGMIIPHY: |
| 5769 | data->phy_id = adapter->hw.phy.addr; |
| 5770 | break; |
| 5771 | case SIOCGMIIREG: |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 5772 | if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
| 5773 | &data->val_out)) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5774 | return -EIO; |
| 5775 | break; |
| 5776 | case SIOCSMIIREG: |
| 5777 | default: |
| 5778 | return -EOPNOTSUPP; |
| 5779 | } |
| 5780 | return 0; |
| 5781 | } |
| 5782 | |
| 5783 | /** |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5784 | * igb_hwtstamp_ioctl - control hardware time stamping |
| 5785 | * @netdev: |
| 5786 | * @ifreq: |
| 5787 | * @cmd: |
| 5788 | * |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5789 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 5790 | * disable it when requested, although it shouldn't case any overhead |
| 5791 | * when no packet needs it. At most one packet in the queue may be |
| 5792 | * marked for time stamping, otherwise it would be impossible to tell |
| 5793 | * for sure to which packet the hardware time stamp belongs. |
| 5794 | * |
| 5795 | * Incoming time stamping has to be configured via the hardware |
| 5796 | * filters. Not all combinations are supported, in particular event |
| 5797 | * type has to be specified. Matching the kind of event packet is |
| 5798 | * not supported, with the exception of "all V2 events regardless of |
| 5799 | * level 2 or 4". |
| 5800 | * |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5801 | **/ |
| 5802 | static int igb_hwtstamp_ioctl(struct net_device *netdev, |
| 5803 | struct ifreq *ifr, int cmd) |
| 5804 | { |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5805 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5806 | struct e1000_hw *hw = &adapter->hw; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5807 | struct hwtstamp_config config; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5808 | u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; |
| 5809 | u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5810 | u32 tsync_rx_cfg = 0; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5811 | bool is_l4 = false; |
| 5812 | bool is_l2 = false; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5813 | u32 regval; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5814 | |
| 5815 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 5816 | return -EFAULT; |
| 5817 | |
| 5818 | /* reserved for future extensions */ |
| 5819 | if (config.flags) |
| 5820 | return -EINVAL; |
| 5821 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5822 | switch (config.tx_type) { |
| 5823 | case HWTSTAMP_TX_OFF: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5824 | tsync_tx_ctl = 0; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5825 | case HWTSTAMP_TX_ON: |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5826 | break; |
| 5827 | default: |
| 5828 | return -ERANGE; |
| 5829 | } |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5830 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5831 | switch (config.rx_filter) { |
| 5832 | case HWTSTAMP_FILTER_NONE: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5833 | tsync_rx_ctl = 0; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5834 | break; |
| 5835 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 5836 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 5837 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 5838 | case HWTSTAMP_FILTER_ALL: |
| 5839 | /* |
| 5840 | * register TSYNCRXCFG must be set, therefore it is not |
| 5841 | * possible to time stamp both Sync and Delay_Req messages |
| 5842 | * => fall back to time stamping all packets |
| 5843 | */ |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5844 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5845 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 5846 | break; |
| 5847 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5848 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5849 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5850 | is_l4 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5851 | break; |
| 5852 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5853 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5854 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5855 | is_l4 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5856 | break; |
| 5857 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 5858 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5859 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5860 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5861 | is_l2 = true; |
| 5862 | is_l4 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5863 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 5864 | break; |
| 5865 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 5866 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5867 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5868 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5869 | is_l2 = true; |
| 5870 | is_l4 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5871 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 5872 | break; |
| 5873 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 5874 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 5875 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5876 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5877 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5878 | is_l2 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5879 | break; |
| 5880 | default: |
| 5881 | return -ERANGE; |
| 5882 | } |
| 5883 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5884 | if (hw->mac.type == e1000_82575) { |
| 5885 | if (tsync_rx_ctl | tsync_tx_ctl) |
| 5886 | return -EINVAL; |
| 5887 | return 0; |
| 5888 | } |
| 5889 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5890 | /* |
| 5891 | * Per-packet timestamping only works if all packets are |
| 5892 | * timestamped, so enable timestamping in all packets as |
| 5893 | * long as one rx filter was configured. |
| 5894 | */ |
| 5895 | if ((hw->mac.type == e1000_82580) && tsync_rx_ctl) { |
| 5896 | tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; |
| 5897 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
| 5898 | } |
| 5899 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5900 | /* enable/disable TX */ |
| 5901 | regval = rd32(E1000_TSYNCTXCTL); |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5902 | regval &= ~E1000_TSYNCTXCTL_ENABLED; |
| 5903 | regval |= tsync_tx_ctl; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5904 | wr32(E1000_TSYNCTXCTL, regval); |
| 5905 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5906 | /* enable/disable RX */ |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5907 | regval = rd32(E1000_TSYNCRXCTL); |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5908 | regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); |
| 5909 | regval |= tsync_rx_ctl; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5910 | wr32(E1000_TSYNCRXCTL, regval); |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5911 | |
| 5912 | /* define which PTP packets are time stamped */ |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5913 | wr32(E1000_TSYNCRXCFG, tsync_rx_cfg); |
| 5914 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5915 | /* define ethertype filter for timestamped packets */ |
| 5916 | if (is_l2) |
| 5917 | wr32(E1000_ETQF(3), |
| 5918 | (E1000_ETQF_FILTER_ENABLE | /* enable filter */ |
| 5919 | E1000_ETQF_1588 | /* enable timestamping */ |
| 5920 | ETH_P_1588)); /* 1588 eth protocol type */ |
| 5921 | else |
| 5922 | wr32(E1000_ETQF(3), 0); |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5923 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5924 | #define PTP_PORT 319 |
| 5925 | /* L4 Queue Filter[3]: filter by destination port and protocol */ |
| 5926 | if (is_l4) { |
| 5927 | u32 ftqf = (IPPROTO_UDP /* UDP */ |
| 5928 | | E1000_FTQF_VF_BP /* VF not compared */ |
| 5929 | | E1000_FTQF_1588_TIME_STAMP /* Enable Timestamping */ |
| 5930 | | E1000_FTQF_MASK); /* mask all inputs */ |
| 5931 | ftqf &= ~E1000_FTQF_MASK_PROTO_BP; /* enable protocol check */ |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5932 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5933 | wr32(E1000_IMIR(3), htons(PTP_PORT)); |
| 5934 | wr32(E1000_IMIREXT(3), |
| 5935 | (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP)); |
| 5936 | if (hw->mac.type == e1000_82576) { |
| 5937 | /* enable source port check */ |
| 5938 | wr32(E1000_SPQF(3), htons(PTP_PORT)); |
| 5939 | ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP; |
| 5940 | } |
| 5941 | wr32(E1000_FTQF(3), ftqf); |
| 5942 | } else { |
| 5943 | wr32(E1000_FTQF(3), E1000_FTQF_MASK); |
| 5944 | } |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5945 | wrfl(); |
| 5946 | |
| 5947 | adapter->hwtstamp_config = config; |
| 5948 | |
| 5949 | /* clear TX/RX time stamp registers, just to be sure */ |
| 5950 | regval = rd32(E1000_TXSTMPH); |
| 5951 | regval = rd32(E1000_RXSTMPH); |
| 5952 | |
| 5953 | return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? |
| 5954 | -EFAULT : 0; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5958 | * igb_ioctl - |
| 5959 | * @netdev: |
| 5960 | * @ifreq: |
| 5961 | * @cmd: |
| 5962 | **/ |
| 5963 | static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5964 | { |
| 5965 | switch (cmd) { |
| 5966 | case SIOCGMIIPHY: |
| 5967 | case SIOCGMIIREG: |
| 5968 | case SIOCSMIIREG: |
| 5969 | return igb_mii_ioctl(netdev, ifr, cmd); |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5970 | case SIOCSHWTSTAMP: |
| 5971 | return igb_hwtstamp_ioctl(netdev, ifr, cmd); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5972 | default: |
| 5973 | return -EOPNOTSUPP; |
| 5974 | } |
| 5975 | } |
| 5976 | |
Alexander Duyck | 009bc06 | 2009-07-23 18:08:35 +0000 | [diff] [blame] | 5977 | s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) |
| 5978 | { |
| 5979 | struct igb_adapter *adapter = hw->back; |
| 5980 | u16 cap_offset; |
| 5981 | |
| 5982 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 5983 | if (!cap_offset) |
| 5984 | return -E1000_ERR_CONFIG; |
| 5985 | |
| 5986 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 5987 | |
| 5988 | return 0; |
| 5989 | } |
| 5990 | |
| 5991 | s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) |
| 5992 | { |
| 5993 | struct igb_adapter *adapter = hw->back; |
| 5994 | u16 cap_offset; |
| 5995 | |
| 5996 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 5997 | if (!cap_offset) |
| 5998 | return -E1000_ERR_CONFIG; |
| 5999 | |
| 6000 | pci_write_config_word(adapter->pdev, cap_offset + reg, *value); |
| 6001 | |
| 6002 | return 0; |
| 6003 | } |
| 6004 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6005 | static void igb_vlan_rx_register(struct net_device *netdev, |
| 6006 | struct vlan_group *grp) |
| 6007 | { |
| 6008 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6009 | struct e1000_hw *hw = &adapter->hw; |
| 6010 | u32 ctrl, rctl; |
| 6011 | |
| 6012 | igb_irq_disable(adapter); |
| 6013 | adapter->vlgrp = grp; |
| 6014 | |
| 6015 | if (grp) { |
| 6016 | /* enable VLAN tag insert/strip */ |
| 6017 | ctrl = rd32(E1000_CTRL); |
| 6018 | ctrl |= E1000_CTRL_VME; |
| 6019 | wr32(E1000_CTRL, ctrl); |
| 6020 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6021 | /* Disable CFI check */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6022 | rctl = rd32(E1000_RCTL); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6023 | rctl &= ~E1000_RCTL_CFIEN; |
| 6024 | wr32(E1000_RCTL, rctl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6025 | } else { |
| 6026 | /* disable VLAN tag insert/strip */ |
| 6027 | ctrl = rd32(E1000_CTRL); |
| 6028 | ctrl &= ~E1000_CTRL_VME; |
| 6029 | wr32(E1000_CTRL, ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6030 | } |
| 6031 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 6032 | igb_rlpml_set(adapter); |
| 6033 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6034 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 6035 | igb_irq_enable(adapter); |
| 6036 | } |
| 6037 | |
| 6038 | static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 6039 | { |
| 6040 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6041 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6042 | int pf_id = adapter->vfs_allocated_count; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6043 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6044 | /* attempt to add filter to vlvf array */ |
| 6045 | igb_vlvf_set(adapter, vid, true, pf_id); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6046 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6047 | /* add the filter since PF can receive vlans w/o entry in vlvf */ |
| 6048 | igb_vfta_set(hw, vid, true); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 6052 | { |
| 6053 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6054 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6055 | int pf_id = adapter->vfs_allocated_count; |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6056 | s32 err; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6057 | |
| 6058 | igb_irq_disable(adapter); |
| 6059 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
| 6060 | |
| 6061 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 6062 | igb_irq_enable(adapter); |
| 6063 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6064 | /* remove vlan from VLVF table array */ |
| 6065 | err = igb_vlvf_set(adapter, vid, false, pf_id); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6066 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6067 | /* if vid was not present in VLVF just remove it from table */ |
| 6068 | if (err) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6069 | igb_vfta_set(hw, vid, false); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | static void igb_restore_vlan(struct igb_adapter *adapter) |
| 6073 | { |
| 6074 | igb_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 6075 | |
| 6076 | if (adapter->vlgrp) { |
| 6077 | u16 vid; |
| 6078 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 6079 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 6080 | continue; |
| 6081 | igb_vlan_rx_add_vid(adapter->netdev, vid); |
| 6082 | } |
| 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx) |
| 6087 | { |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 6088 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6089 | struct e1000_mac_info *mac = &adapter->hw.mac; |
| 6090 | |
| 6091 | mac->autoneg = 0; |
| 6092 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6093 | switch (spddplx) { |
| 6094 | case SPEED_10 + DUPLEX_HALF: |
| 6095 | mac->forced_speed_duplex = ADVERTISE_10_HALF; |
| 6096 | break; |
| 6097 | case SPEED_10 + DUPLEX_FULL: |
| 6098 | mac->forced_speed_duplex = ADVERTISE_10_FULL; |
| 6099 | break; |
| 6100 | case SPEED_100 + DUPLEX_HALF: |
| 6101 | mac->forced_speed_duplex = ADVERTISE_100_HALF; |
| 6102 | break; |
| 6103 | case SPEED_100 + DUPLEX_FULL: |
| 6104 | mac->forced_speed_duplex = ADVERTISE_100_FULL; |
| 6105 | break; |
| 6106 | case SPEED_1000 + DUPLEX_FULL: |
| 6107 | mac->autoneg = 1; |
| 6108 | adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL; |
| 6109 | break; |
| 6110 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 6111 | default: |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 6112 | dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6113 | return -EINVAL; |
| 6114 | } |
| 6115 | return 0; |
| 6116 | } |
| 6117 | |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 6118 | static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6119 | { |
| 6120 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6121 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6122 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 6123 | u32 ctrl, rctl, status; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6124 | u32 wufc = adapter->wol; |
| 6125 | #ifdef CONFIG_PM |
| 6126 | int retval = 0; |
| 6127 | #endif |
| 6128 | |
| 6129 | netif_device_detach(netdev); |
| 6130 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 6131 | if (netif_running(netdev)) |
| 6132 | igb_close(netdev); |
| 6133 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6134 | igb_clear_interrupt_scheme(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6135 | |
| 6136 | #ifdef CONFIG_PM |
| 6137 | retval = pci_save_state(pdev); |
| 6138 | if (retval) |
| 6139 | return retval; |
| 6140 | #endif |
| 6141 | |
| 6142 | status = rd32(E1000_STATUS); |
| 6143 | if (status & E1000_STATUS_LU) |
| 6144 | wufc &= ~E1000_WUFC_LNKC; |
| 6145 | |
| 6146 | if (wufc) { |
| 6147 | igb_setup_rctl(adapter); |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 6148 | igb_set_rx_mode(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6149 | |
| 6150 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6151 | if (wufc & E1000_WUFC_MC) { |
| 6152 | rctl = rd32(E1000_RCTL); |
| 6153 | rctl |= E1000_RCTL_MPE; |
| 6154 | wr32(E1000_RCTL, rctl); |
| 6155 | } |
| 6156 | |
| 6157 | ctrl = rd32(E1000_CTRL); |
| 6158 | /* advertise wake from D3Cold */ |
| 6159 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 6160 | /* phy power management enable */ |
| 6161 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 6162 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 6163 | wr32(E1000_CTRL, ctrl); |
| 6164 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6165 | /* Allow time for pending master requests to run */ |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 6166 | igb_disable_pcie_master(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6167 | |
| 6168 | wr32(E1000_WUC, E1000_WUC_PME_EN); |
| 6169 | wr32(E1000_WUFC, wufc); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6170 | } else { |
| 6171 | wr32(E1000_WUC, 0); |
| 6172 | wr32(E1000_WUFC, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6173 | } |
| 6174 | |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 6175 | *enable_wake = wufc || adapter->en_mng_pt; |
| 6176 | if (!*enable_wake) |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 6177 | igb_power_down_link(adapter); |
| 6178 | else |
| 6179 | igb_power_up_link(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6180 | |
| 6181 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 6182 | * would have already happened in close and is redundant. */ |
| 6183 | igb_release_hw_control(adapter); |
| 6184 | |
| 6185 | pci_disable_device(pdev); |
| 6186 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6187 | return 0; |
| 6188 | } |
| 6189 | |
| 6190 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 6191 | static int igb_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6192 | { |
| 6193 | int retval; |
| 6194 | bool wake; |
| 6195 | |
| 6196 | retval = __igb_shutdown(pdev, &wake); |
| 6197 | if (retval) |
| 6198 | return retval; |
| 6199 | |
| 6200 | if (wake) { |
| 6201 | pci_prepare_to_sleep(pdev); |
| 6202 | } else { |
| 6203 | pci_wake_from_d3(pdev, false); |
| 6204 | pci_set_power_state(pdev, PCI_D3hot); |
| 6205 | } |
| 6206 | |
| 6207 | return 0; |
| 6208 | } |
| 6209 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6210 | static int igb_resume(struct pci_dev *pdev) |
| 6211 | { |
| 6212 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6213 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6214 | struct e1000_hw *hw = &adapter->hw; |
| 6215 | u32 err; |
| 6216 | |
| 6217 | pci_set_power_state(pdev, PCI_D0); |
| 6218 | pci_restore_state(pdev); |
Nick Nunley | b94f2d7 | 2010-02-17 01:02:19 +0000 | [diff] [blame] | 6219 | pci_save_state(pdev); |
Taku Izumi | 42bfd33a | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 6220 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 6221 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6222 | if (err) { |
| 6223 | dev_err(&pdev->dev, |
| 6224 | "igb: Cannot enable PCI device from suspend\n"); |
| 6225 | return err; |
| 6226 | } |
| 6227 | pci_set_master(pdev); |
| 6228 | |
| 6229 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 6230 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 6231 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6232 | if (igb_init_interrupt_scheme(adapter)) { |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 6233 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 6234 | return -ENOMEM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6235 | } |
| 6236 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6237 | igb_reset(adapter); |
Alexander Duyck | a8564f0 | 2009-02-06 23:21:10 +0000 | [diff] [blame] | 6238 | |
| 6239 | /* let the f/w know that the h/w is now under the control of the |
| 6240 | * driver. */ |
| 6241 | igb_get_hw_control(adapter); |
| 6242 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6243 | wr32(E1000_WUS, ~0); |
| 6244 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 6245 | if (netif_running(netdev)) { |
| 6246 | err = igb_open(netdev); |
| 6247 | if (err) |
| 6248 | return err; |
| 6249 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6250 | |
| 6251 | netif_device_attach(netdev); |
| 6252 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6253 | return 0; |
| 6254 | } |
| 6255 | #endif |
| 6256 | |
| 6257 | static void igb_shutdown(struct pci_dev *pdev) |
| 6258 | { |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 6259 | bool wake; |
| 6260 | |
| 6261 | __igb_shutdown(pdev, &wake); |
| 6262 | |
| 6263 | if (system_state == SYSTEM_POWER_OFF) { |
| 6264 | pci_wake_from_d3(pdev, wake); |
| 6265 | pci_set_power_state(pdev, PCI_D3hot); |
| 6266 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6270 | /* |
| 6271 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 6272 | * without having to re-enable interrupts. It's not called while |
| 6273 | * the interrupt routine is executing. |
| 6274 | */ |
| 6275 | static void igb_netpoll(struct net_device *netdev) |
| 6276 | { |
| 6277 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6278 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6279 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6280 | |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6281 | if (!adapter->msix_entries) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6282 | struct igb_q_vector *q_vector = adapter->q_vector[0]; |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6283 | igb_irq_disable(adapter); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6284 | napi_schedule(&q_vector->napi); |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6285 | return; |
| 6286 | } |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 6287 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6288 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 6289 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 6290 | wr32(E1000_EIMC, q_vector->eims_value); |
| 6291 | napi_schedule(&q_vector->napi); |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6292 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6293 | } |
| 6294 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 6295 | |
| 6296 | /** |
| 6297 | * igb_io_error_detected - called when PCI error is detected |
| 6298 | * @pdev: Pointer to PCI device |
| 6299 | * @state: The current pci connection state |
| 6300 | * |
| 6301 | * This function is called after a PCI bus error affecting |
| 6302 | * this device has been detected. |
| 6303 | */ |
| 6304 | static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev, |
| 6305 | pci_channel_state_t state) |
| 6306 | { |
| 6307 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6308 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6309 | |
| 6310 | netif_device_detach(netdev); |
| 6311 | |
Alexander Duyck | 59ed6ee | 2009-06-30 12:46:34 +0000 | [diff] [blame] | 6312 | if (state == pci_channel_io_perm_failure) |
| 6313 | return PCI_ERS_RESULT_DISCONNECT; |
| 6314 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6315 | if (netif_running(netdev)) |
| 6316 | igb_down(adapter); |
| 6317 | pci_disable_device(pdev); |
| 6318 | |
| 6319 | /* Request a slot slot reset. */ |
| 6320 | return PCI_ERS_RESULT_NEED_RESET; |
| 6321 | } |
| 6322 | |
| 6323 | /** |
| 6324 | * igb_io_slot_reset - called after the pci bus has been reset. |
| 6325 | * @pdev: Pointer to PCI device |
| 6326 | * |
| 6327 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 6328 | * resembles the first-half of the igb_resume routine. |
| 6329 | */ |
| 6330 | static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev) |
| 6331 | { |
| 6332 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6333 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6334 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 6335 | pci_ers_result_t result; |
Taku Izumi | 42bfd33a | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 6336 | int err; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6337 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 6338 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6339 | dev_err(&pdev->dev, |
| 6340 | "Cannot re-enable PCI device after reset.\n"); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 6341 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6342 | } else { |
| 6343 | pci_set_master(pdev); |
| 6344 | pci_restore_state(pdev); |
Nick Nunley | b94f2d7 | 2010-02-17 01:02:19 +0000 | [diff] [blame] | 6345 | pci_save_state(pdev); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 6346 | |
| 6347 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 6348 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 6349 | |
| 6350 | igb_reset(adapter); |
| 6351 | wr32(E1000_WUS, ~0); |
| 6352 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6353 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6354 | |
Jeff Kirsher | ea943d4 | 2008-12-11 20:34:19 -0800 | [diff] [blame] | 6355 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 6356 | if (err) { |
| 6357 | dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status " |
| 6358 | "failed 0x%0x\n", err); |
| 6359 | /* non-fatal, continue */ |
| 6360 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6361 | |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 6362 | return result; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | /** |
| 6366 | * igb_io_resume - called when traffic can start flowing again. |
| 6367 | * @pdev: Pointer to PCI device |
| 6368 | * |
| 6369 | * This callback is called when the error recovery driver tells us that |
| 6370 | * its OK to resume normal operation. Implementation resembles the |
| 6371 | * second-half of the igb_resume routine. |
| 6372 | */ |
| 6373 | static void igb_io_resume(struct pci_dev *pdev) |
| 6374 | { |
| 6375 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6376 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6377 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6378 | if (netif_running(netdev)) { |
| 6379 | if (igb_up(adapter)) { |
| 6380 | dev_err(&pdev->dev, "igb_up failed after reset\n"); |
| 6381 | return; |
| 6382 | } |
| 6383 | } |
| 6384 | |
| 6385 | netif_device_attach(netdev); |
| 6386 | |
| 6387 | /* let the f/w know that the h/w is now under the control of the |
| 6388 | * driver. */ |
| 6389 | igb_get_hw_control(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6390 | } |
| 6391 | |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 6392 | static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index, |
| 6393 | u8 qsel) |
| 6394 | { |
| 6395 | u32 rar_low, rar_high; |
| 6396 | struct e1000_hw *hw = &adapter->hw; |
| 6397 | |
| 6398 | /* HW expects these in little endian so we reverse the byte order |
| 6399 | * from network order (big endian) to little endian |
| 6400 | */ |
| 6401 | rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) | |
| 6402 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); |
| 6403 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); |
| 6404 | |
| 6405 | /* Indicate to hardware the Address is Valid. */ |
| 6406 | rar_high |= E1000_RAH_AV; |
| 6407 | |
| 6408 | if (hw->mac.type == e1000_82575) |
| 6409 | rar_high |= E1000_RAH_POOL_1 * qsel; |
| 6410 | else |
| 6411 | rar_high |= E1000_RAH_POOL_1 << qsel; |
| 6412 | |
| 6413 | wr32(E1000_RAL(index), rar_low); |
| 6414 | wrfl(); |
| 6415 | wr32(E1000_RAH(index), rar_high); |
| 6416 | wrfl(); |
| 6417 | } |
| 6418 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6419 | static int igb_set_vf_mac(struct igb_adapter *adapter, |
| 6420 | int vf, unsigned char *mac_addr) |
| 6421 | { |
| 6422 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 6423 | /* VF MAC addresses start at end of receive addresses and moves |
| 6424 | * torwards the first, as a result a collision should not be possible */ |
| 6425 | int rar_entry = hw->mac.rar_entry_count - (vf + 1); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6426 | |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 6427 | memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6428 | |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 6429 | igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6430 | |
| 6431 | return 0; |
| 6432 | } |
| 6433 | |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 6434 | static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 6435 | { |
| 6436 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6437 | if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count)) |
| 6438 | return -EINVAL; |
| 6439 | adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC; |
| 6440 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); |
| 6441 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" |
| 6442 | " change effective."); |
| 6443 | if (test_bit(__IGB_DOWN, &adapter->state)) { |
| 6444 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," |
| 6445 | " but the PF device is not up.\n"); |
| 6446 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" |
| 6447 | " attempting to use the VF device.\n"); |
| 6448 | } |
| 6449 | return igb_set_vf_mac(adapter, vf, mac); |
| 6450 | } |
| 6451 | |
| 6452 | static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate) |
| 6453 | { |
| 6454 | return -EOPNOTSUPP; |
| 6455 | } |
| 6456 | |
| 6457 | static int igb_ndo_get_vf_config(struct net_device *netdev, |
| 6458 | int vf, struct ifla_vf_info *ivi) |
| 6459 | { |
| 6460 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6461 | if (vf >= adapter->vfs_allocated_count) |
| 6462 | return -EINVAL; |
| 6463 | ivi->vf = vf; |
| 6464 | memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN); |
| 6465 | ivi->tx_rate = 0; |
| 6466 | ivi->vlan = adapter->vf_data[vf].pf_vlan; |
| 6467 | ivi->qos = adapter->vf_data[vf].pf_qos; |
| 6468 | return 0; |
| 6469 | } |
| 6470 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6471 | static void igb_vmm_control(struct igb_adapter *adapter) |
| 6472 | { |
| 6473 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 10d8e90 | 2009-10-27 15:54:04 +0000 | [diff] [blame] | 6474 | u32 reg; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6475 | |
Alexander Duyck | 52a1dd4 | 2010-03-22 14:07:46 +0000 | [diff] [blame] | 6476 | switch (hw->mac.type) { |
| 6477 | case e1000_82575: |
| 6478 | default: |
| 6479 | /* replication is not supported for 82575 */ |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6480 | return; |
Alexander Duyck | 52a1dd4 | 2010-03-22 14:07:46 +0000 | [diff] [blame] | 6481 | case e1000_82576: |
| 6482 | /* notify HW that the MAC is adding vlan tags */ |
| 6483 | reg = rd32(E1000_DTXCTL); |
| 6484 | reg |= E1000_DTXCTL_VLAN_ADDED; |
| 6485 | wr32(E1000_DTXCTL, reg); |
| 6486 | case e1000_82580: |
| 6487 | /* enable replication vlan tag stripping */ |
| 6488 | reg = rd32(E1000_RPLOLR); |
| 6489 | reg |= E1000_RPLOLR_STRVLAN; |
| 6490 | wr32(E1000_RPLOLR, reg); |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 6491 | case e1000_i350: |
| 6492 | /* none of the above registers are supported by i350 */ |
Alexander Duyck | 52a1dd4 | 2010-03-22 14:07:46 +0000 | [diff] [blame] | 6493 | break; |
| 6494 | } |
Alexander Duyck | 10d8e90 | 2009-10-27 15:54:04 +0000 | [diff] [blame] | 6495 | |
Alexander Duyck | d496030 | 2009-10-27 15:53:45 +0000 | [diff] [blame] | 6496 | if (adapter->vfs_allocated_count) { |
| 6497 | igb_vmdq_set_loopback_pf(hw, true); |
| 6498 | igb_vmdq_set_replication_pf(hw, true); |
| 6499 | } else { |
| 6500 | igb_vmdq_set_loopback_pf(hw, false); |
| 6501 | igb_vmdq_set_replication_pf(hw, false); |
| 6502 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6503 | } |
| 6504 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6505 | /* igb_main.c */ |