Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | 9497182 | 2012-01-06 03:24:16 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2012 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [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: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 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/types.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 35 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 36 | #include <linux/ip.h> |
| 37 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 38 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 39 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 40 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 42 | #include <net/checksum.h> |
| 43 | #include <net/ip6_checksum.h> |
| 44 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 45 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 46 | #include <linux/if_vlan.h> |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 47 | #include <linux/if_bridge.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 48 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 49 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 50 | |
| 51 | #include "ixgbe.h" |
| 52 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 53 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 54 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 55 | |
| 56 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 57 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 58 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 59 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 60 | char ixgbe_default_device_descr[] = |
| 61 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 62 | #else |
| 63 | static char ixgbe_default_device_descr[] = |
| 64 | "Intel(R) 10 Gigabit Network Connection"; |
| 65 | #endif |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 66 | #define MAJ 3 |
Don Skidmore | eef4560 | 2012-04-28 03:29:22 +0000 | [diff] [blame] | 67 | #define MIN 9 |
| 68 | #define BUILD 15 |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 69 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 70 | __stringify(BUILD) "-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 71 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 72 | static const char ixgbe_copyright[] = |
Don Skidmore | 9497182 | 2012-01-06 03:24:16 +0000 | [diff] [blame] | 73 | "Copyright (c) 1999-2012 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 74 | |
| 75 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 76 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 77 | [board_82599] = &ixgbe_82599_info, |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 78 | [board_X540] = &ixgbe_X540_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 82 | * |
| 83 | * Wildcard entries (PCI_ANY_ID) should come last |
| 84 | * Last entry must be all 0s |
| 85 | * |
| 86 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 87 | * Class, Class Mask, private data (not used) } |
| 88 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 89 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 }, |
joshua.a.hay@intel.com | df376f0 | 2012-09-21 00:08:21 +0000 | [diff] [blame] | 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 119 | /* required last entry */ |
| 120 | {0, } |
| 121 | }; |
| 122 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 123 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 124 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 125 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 126 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 127 | static struct notifier_block dca_notifier = { |
| 128 | .notifier_call = ixgbe_notify_dca, |
| 129 | .next = NULL, |
| 130 | .priority = 0 |
| 131 | }; |
| 132 | #endif |
| 133 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 134 | #ifdef CONFIG_PCI_IOV |
| 135 | static unsigned int max_vfs; |
| 136 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 137 | MODULE_PARM_DESC(max_vfs, |
Greg Rose | 6b42a9c | 2012-04-17 04:29:29 +0000 | [diff] [blame] | 138 | "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 139 | #endif /* CONFIG_PCI_IOV */ |
| 140 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 141 | static unsigned int allow_unsupported_sfp; |
| 142 | module_param(allow_unsupported_sfp, uint, 0); |
| 143 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 144 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 145 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 146 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 147 | static int debug = -1; |
| 148 | module_param(debug, int, 0); |
| 149 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 150 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 151 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 152 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 153 | MODULE_LICENSE("GPL"); |
| 154 | MODULE_VERSION(DRV_VERSION); |
| 155 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 156 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 157 | { |
| 158 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
| 159 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
| 160 | schedule_work(&adapter->service_task); |
| 161 | } |
| 162 | |
| 163 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 164 | { |
| 165 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 166 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 167 | /* flush memory to make sure state is correct before next watchdog */ |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 168 | smp_mb__before_clear_bit(); |
| 169 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 170 | } |
| 171 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 172 | struct ixgbe_reg_info { |
| 173 | u32 ofs; |
| 174 | char *name; |
| 175 | }; |
| 176 | |
| 177 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 178 | |
| 179 | /* General Registers */ |
| 180 | {IXGBE_CTRL, "CTRL"}, |
| 181 | {IXGBE_STATUS, "STATUS"}, |
| 182 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 183 | |
| 184 | /* Interrupt Registers */ |
| 185 | {IXGBE_EICR, "EICR"}, |
| 186 | |
| 187 | /* RX Registers */ |
| 188 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 189 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 190 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 191 | {IXGBE_RDH(0), "RDH"}, |
| 192 | {IXGBE_RDT(0), "RDT"}, |
| 193 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 194 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 195 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 196 | |
| 197 | /* TX Registers */ |
| 198 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 199 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 200 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 201 | {IXGBE_TDH(0), "TDH"}, |
| 202 | {IXGBE_TDT(0), "TDT"}, |
| 203 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 204 | |
| 205 | /* List Terminator */ |
| 206 | {} |
| 207 | }; |
| 208 | |
| 209 | |
| 210 | /* |
| 211 | * ixgbe_regdump - register printout routine |
| 212 | */ |
| 213 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 214 | { |
| 215 | int i = 0, j = 0; |
| 216 | char rname[16]; |
| 217 | u32 regs[64]; |
| 218 | |
| 219 | switch (reginfo->ofs) { |
| 220 | case IXGBE_SRRCTL(0): |
| 221 | for (i = 0; i < 64; i++) |
| 222 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 223 | break; |
| 224 | case IXGBE_DCA_RXCTRL(0): |
| 225 | for (i = 0; i < 64; i++) |
| 226 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 227 | break; |
| 228 | case IXGBE_RDLEN(0): |
| 229 | for (i = 0; i < 64; i++) |
| 230 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 231 | break; |
| 232 | case IXGBE_RDH(0): |
| 233 | for (i = 0; i < 64; i++) |
| 234 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 235 | break; |
| 236 | case IXGBE_RDT(0): |
| 237 | for (i = 0; i < 64; i++) |
| 238 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 239 | break; |
| 240 | case IXGBE_RXDCTL(0): |
| 241 | for (i = 0; i < 64; i++) |
| 242 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 243 | break; |
| 244 | case IXGBE_RDBAL(0): |
| 245 | for (i = 0; i < 64; i++) |
| 246 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 247 | break; |
| 248 | case IXGBE_RDBAH(0): |
| 249 | for (i = 0; i < 64; i++) |
| 250 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 251 | break; |
| 252 | case IXGBE_TDBAL(0): |
| 253 | for (i = 0; i < 64; i++) |
| 254 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 255 | break; |
| 256 | case IXGBE_TDBAH(0): |
| 257 | for (i = 0; i < 64; i++) |
| 258 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 259 | break; |
| 260 | case IXGBE_TDLEN(0): |
| 261 | for (i = 0; i < 64; i++) |
| 262 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 263 | break; |
| 264 | case IXGBE_TDH(0): |
| 265 | for (i = 0; i < 64; i++) |
| 266 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 267 | break; |
| 268 | case IXGBE_TDT(0): |
| 269 | for (i = 0; i < 64; i++) |
| 270 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 271 | break; |
| 272 | case IXGBE_TXDCTL(0): |
| 273 | for (i = 0; i < 64; i++) |
| 274 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 275 | break; |
| 276 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 277 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 278 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | for (i = 0; i < 8; i++) { |
| 283 | snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 284 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 285 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 286 | pr_cont(" %08x", regs[i*8+j]); |
| 287 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 294 | */ |
| 295 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 296 | { |
| 297 | struct net_device *netdev = adapter->netdev; |
| 298 | struct ixgbe_hw *hw = &adapter->hw; |
| 299 | struct ixgbe_reg_info *reginfo; |
| 300 | int n = 0; |
| 301 | struct ixgbe_ring *tx_ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 302 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 303 | union ixgbe_adv_tx_desc *tx_desc; |
| 304 | struct my_u0 { u64 a; u64 b; } *u0; |
| 305 | struct ixgbe_ring *rx_ring; |
| 306 | union ixgbe_adv_rx_desc *rx_desc; |
| 307 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 308 | u32 staterr; |
| 309 | int i = 0; |
| 310 | |
| 311 | if (!netif_msg_hw(adapter)) |
| 312 | return; |
| 313 | |
| 314 | /* Print netdevice Info */ |
| 315 | if (netdev) { |
| 316 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 317 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 318 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 319 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 320 | netdev->name, |
| 321 | netdev->state, |
| 322 | netdev->trans_start, |
| 323 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* Print Registers */ |
| 327 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 328 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 329 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 330 | reginfo->name; reginfo++) { |
| 331 | ixgbe_regdump(hw, reginfo); |
| 332 | } |
| 333 | |
| 334 | /* Print TX Ring Summary */ |
| 335 | if (!netdev || !netif_running(netdev)) |
| 336 | goto exit; |
| 337 | |
| 338 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 339 | pr_info(" %s %s %s %s\n", |
| 340 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 341 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 342 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 343 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 344 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 345 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 346 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 347 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 348 | dma_unmap_len(tx_buffer, len), |
| 349 | tx_buffer->next_to_watch, |
| 350 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* Print TX Rings */ |
| 354 | if (!netif_msg_tx_done(adapter)) |
| 355 | goto rx_ring_summary; |
| 356 | |
| 357 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 358 | |
| 359 | /* Transmit Descriptor Formats |
| 360 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 361 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 362 | * +--------------------------------------------------------------+ |
| 363 | * 0 | Buffer Address [63:0] | |
| 364 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 365 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 366 | * +--------------------------------------------------------------+ |
| 367 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 368 | * |
| 369 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 370 | * +--------------------------------------------------------------+ |
| 371 | * 0 | RSV [63:0] | |
| 372 | * +--------------------------------------------------------------+ |
| 373 | * 8 | RSV | STA | NXTSEQ | |
| 374 | * +--------------------------------------------------------------+ |
| 375 | * 63 36 35 32 31 0 |
| 376 | * |
| 377 | * 82599+ Advanced Transmit Descriptor |
| 378 | * +--------------------------------------------------------------+ |
| 379 | * 0 | Buffer Address [63:0] | |
| 380 | * +--------------------------------------------------------------+ |
| 381 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 382 | * +--------------------------------------------------------------+ |
| 383 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 384 | * |
| 385 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 386 | * +--------------------------------------------------------------+ |
| 387 | * 0 | RSV [63:0] | |
| 388 | * +--------------------------------------------------------------+ |
| 389 | * 8 | RSV | STA | RSV | |
| 390 | * +--------------------------------------------------------------+ |
| 391 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 392 | */ |
| 393 | |
| 394 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 395 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 396 | pr_info("------------------------------------\n"); |
| 397 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 398 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 399 | pr_info("%s%s %s %s %s %s\n", |
| 400 | "T [desc] [address 63:0 ] ", |
| 401 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 402 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 403 | |
| 404 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 405 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 406 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 407 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 408 | if (dma_unmap_len(tx_buffer, len) > 0) { |
| 409 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p", |
| 410 | i, |
| 411 | le64_to_cpu(u0->a), |
| 412 | le64_to_cpu(u0->b), |
| 413 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 414 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 415 | tx_buffer->next_to_watch, |
| 416 | (u64)tx_buffer->time_stamp, |
| 417 | tx_buffer->skb); |
| 418 | if (i == tx_ring->next_to_use && |
| 419 | i == tx_ring->next_to_clean) |
| 420 | pr_cont(" NTC/U\n"); |
| 421 | else if (i == tx_ring->next_to_use) |
| 422 | pr_cont(" NTU\n"); |
| 423 | else if (i == tx_ring->next_to_clean) |
| 424 | pr_cont(" NTC\n"); |
| 425 | else |
| 426 | pr_cont("\n"); |
| 427 | |
| 428 | if (netif_msg_pktdata(adapter) && |
| 429 | tx_buffer->skb) |
| 430 | print_hex_dump(KERN_INFO, "", |
| 431 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 432 | tx_buffer->skb->data, |
| 433 | dma_unmap_len(tx_buffer, len), |
| 434 | true); |
| 435 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
| 439 | /* Print RX Rings Summary */ |
| 440 | rx_ring_summary: |
| 441 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 442 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 443 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 444 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 445 | pr_info("%5d %5X %5X\n", |
| 446 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /* Print RX Rings */ |
| 450 | if (!netif_msg_rx_status(adapter)) |
| 451 | goto exit; |
| 452 | |
| 453 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 454 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 455 | /* Receive Descriptor Formats |
| 456 | * |
| 457 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 458 | * 63 1 0 |
| 459 | * +-----------------------------------------------------+ |
| 460 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 461 | * +----------------------------------------------+------+ |
| 462 | * 8 | Header Buffer Address [63:1] | DD | |
| 463 | * +-----------------------------------------------------+ |
| 464 | * |
| 465 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 466 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 467 | * |
| 468 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 469 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 470 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 471 | * | Packet | IP | | | | Type | Type | |
| 472 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 473 | * +------------------------------------------------------+ |
| 474 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 475 | * +------------------------------------------------------+ |
| 476 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 477 | * |
| 478 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 479 | * 63 1 0 |
| 480 | * +-----------------------------------------------------+ |
| 481 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 482 | * +----------------------------------------------+------+ |
| 483 | * 8 | Header Buffer Address [63:1] | DD | |
| 484 | * +-----------------------------------------------------+ |
| 485 | * |
| 486 | * |
| 487 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 488 | * |
| 489 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 490 | * +------------------------------------------------------+ |
| 491 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 492 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 493 | * |/ Flow Dir Flt ID | | | | | | |
| 494 | * +------------------------------------------------------+ |
| 495 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 496 | * +------------------------------------------------------+ |
| 497 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 498 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 499 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 500 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 501 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 502 | pr_info("------------------------------------\n"); |
| 503 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 504 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 505 | pr_info("%s%s%s", |
| 506 | "R [desc] [ PktBuf A0] ", |
| 507 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 508 | "<-- Adv Rx Read format\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 509 | pr_info("%s%s%s", |
| 510 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 511 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 512 | "<-- Adv Rx Write-Back format\n"); |
| 513 | |
| 514 | for (i = 0; i < rx_ring->count; i++) { |
| 515 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 516 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 517 | u0 = (struct my_u0 *)rx_desc; |
| 518 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 519 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 520 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 521 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 522 | "%016llX ---------------- %p", i, |
| 523 | le64_to_cpu(u0->a), |
| 524 | le64_to_cpu(u0->b), |
| 525 | rx_buffer_info->skb); |
| 526 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 527 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 528 | "%016llX %016llX %p", i, |
| 529 | le64_to_cpu(u0->a), |
| 530 | le64_to_cpu(u0->b), |
| 531 | (u64)rx_buffer_info->dma, |
| 532 | rx_buffer_info->skb); |
| 533 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 534 | if (netif_msg_pktdata(adapter) && |
| 535 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 536 | print_hex_dump(KERN_INFO, "", |
| 537 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 538 | page_address(rx_buffer_info->page) + |
| 539 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 540 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 545 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 546 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 547 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 548 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 549 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 550 | |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | exit: |
| 555 | return; |
| 556 | } |
| 557 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 558 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 559 | { |
| 560 | u32 ctrl_ext; |
| 561 | |
| 562 | /* Let firmware take over control of h/w */ |
| 563 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 564 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 565 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 569 | { |
| 570 | u32 ctrl_ext; |
| 571 | |
| 572 | /* Let firmware know the driver has taken over */ |
| 573 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 574 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 575 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 576 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 577 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 578 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 579 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 580 | * @adapter: pointer to adapter struct |
| 581 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 582 | * @queue: queue to map the corresponding interrupt to |
| 583 | * @msix_vector: the vector to map to the corresponding queue |
| 584 | * |
| 585 | */ |
| 586 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 587 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 588 | { |
| 589 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 590 | struct ixgbe_hw *hw = &adapter->hw; |
| 591 | switch (hw->mac.type) { |
| 592 | case ixgbe_mac_82598EB: |
| 593 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 594 | if (direction == -1) |
| 595 | direction = 0; |
| 596 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 597 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 598 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 599 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 600 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 601 | break; |
| 602 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 603 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 604 | if (direction == -1) { |
| 605 | /* other causes */ |
| 606 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 607 | index = ((queue & 1) * 8); |
| 608 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 609 | ivar &= ~(0xFF << index); |
| 610 | ivar |= (msix_vector << index); |
| 611 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 612 | break; |
| 613 | } else { |
| 614 | /* tx or rx causes */ |
| 615 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 616 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 617 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 618 | ivar &= ~(0xFF << index); |
| 619 | ivar |= (msix_vector << index); |
| 620 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 621 | break; |
| 622 | } |
| 623 | default: |
| 624 | break; |
| 625 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 628 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 629 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 630 | { |
| 631 | u32 mask; |
| 632 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 633 | switch (adapter->hw.mac.type) { |
| 634 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 635 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 636 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 637 | break; |
| 638 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 639 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 640 | mask = (qmask & 0xFFFFFFFF); |
| 641 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 642 | mask = (qmask >> 32); |
| 643 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 644 | break; |
| 645 | default: |
| 646 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 650 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring, |
| 651 | struct ixgbe_tx_buffer *tx_buffer) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 652 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 653 | if (tx_buffer->skb) { |
| 654 | dev_kfree_skb_any(tx_buffer->skb); |
| 655 | if (dma_unmap_len(tx_buffer, len)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 656 | dma_unmap_single(ring->dev, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 657 | dma_unmap_addr(tx_buffer, dma), |
| 658 | dma_unmap_len(tx_buffer, len), |
| 659 | DMA_TO_DEVICE); |
| 660 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 661 | dma_unmap_page(ring->dev, |
| 662 | dma_unmap_addr(tx_buffer, dma), |
| 663 | dma_unmap_len(tx_buffer, len), |
| 664 | DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 665 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 666 | tx_buffer->next_to_watch = NULL; |
| 667 | tx_buffer->skb = NULL; |
| 668 | dma_unmap_len_set(tx_buffer, len, 0); |
| 669 | /* tx_buffer must be completely set up in the transmit path */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 672 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 673 | { |
| 674 | struct ixgbe_hw *hw = &adapter->hw; |
| 675 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 676 | int i; |
| 677 | u32 data; |
| 678 | |
| 679 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 680 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 681 | return; |
| 682 | |
| 683 | switch (hw->mac.type) { |
| 684 | case ixgbe_mac_82598EB: |
| 685 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 686 | break; |
| 687 | default: |
| 688 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 689 | } |
| 690 | hwstats->lxoffrxc += data; |
| 691 | |
| 692 | /* refill credits (no tx hang) if we received xoff */ |
| 693 | if (!data) |
| 694 | return; |
| 695 | |
| 696 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 697 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 698 | &adapter->tx_ring[i]->state); |
| 699 | } |
| 700 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 701 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 702 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 703 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 704 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 705 | u32 xoff[8] = {0}; |
| 706 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 707 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 708 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 709 | if (adapter->ixgbe_ieee_pfc) |
| 710 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 711 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 712 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 713 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 714 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 715 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 716 | |
| 717 | /* update stats for each tc, only valid with PFC enabled */ |
| 718 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
| 719 | switch (hw->mac.type) { |
| 720 | case ixgbe_mac_82598EB: |
| 721 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 722 | break; |
| 723 | default: |
| 724 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 725 | } |
| 726 | hwstats->pxoffrxc[i] += xoff[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 727 | } |
| 728 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 729 | /* disarm tx queues that have received xoff frames */ |
| 730 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 731 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | fb5475f | 2011-04-26 07:26:36 +0000 | [diff] [blame] | 732 | u8 tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 733 | |
| 734 | if (xoff[tc]) |
| 735 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 740 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 741 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 745 | { |
| 746 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); |
| 747 | struct ixgbe_hw *hw = &adapter->hw; |
| 748 | |
| 749 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 750 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
| 751 | |
| 752 | if (head != tail) |
| 753 | return (head < tail) ? |
| 754 | tail - head : (tail + ring->count - head); |
| 755 | |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 760 | { |
| 761 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 762 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 763 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 764 | bool ret = false; |
| 765 | |
| 766 | clear_check_for_tx_hang(tx_ring); |
| 767 | |
| 768 | /* |
| 769 | * Check for a hung queue, but be thorough. This verifies |
| 770 | * that a transmit has been completed since the previous |
| 771 | * check AND there is at least one packet pending. The |
| 772 | * ARMED bit is set to indicate a potential hang. The |
| 773 | * bit is cleared if a pause frame is received to remove |
| 774 | * false hang detection due to PFC or 802.3x frames. By |
| 775 | * requiring this to fail twice we avoid races with |
| 776 | * pfc clearing the ARMED bit and conditions where we |
| 777 | * run the check_tx_hang logic with a transmit completion |
| 778 | * pending but without time to complete it yet. |
| 779 | */ |
| 780 | if ((tx_done_old == tx_done) && tx_pending) { |
| 781 | /* make sure it is true for two checks in a row */ |
| 782 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 783 | &tx_ring->state); |
| 784 | } else { |
| 785 | /* update completed stats and continue */ |
| 786 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 787 | /* reset the countdown */ |
| 788 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 789 | } |
| 790 | |
| 791 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 794 | /** |
| 795 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 796 | * @adapter: driver private struct |
| 797 | **/ |
| 798 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 799 | { |
| 800 | |
| 801 | /* Do the reset outside of interrupt context */ |
| 802 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 803 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 804 | ixgbe_service_event_schedule(adapter); |
| 805 | } |
| 806 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 807 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 808 | /** |
| 809 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 810 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 811 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 812 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 813 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 814 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 815 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 816 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 817 | struct ixgbe_tx_buffer *tx_buffer; |
| 818 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 819 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 820 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 821 | unsigned int i = tx_ring->next_to_clean; |
| 822 | |
| 823 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 824 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 825 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 826 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 827 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 828 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 829 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 830 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 831 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 832 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 833 | /* if next_to_watch is not set then there is no work pending */ |
| 834 | if (!eop_desc) |
| 835 | break; |
| 836 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 837 | /* prevent any other reads prior to eop_desc */ |
| 838 | rmb(); |
| 839 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 840 | /* if DD is not set pending work has not been completed */ |
| 841 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 842 | break; |
| 843 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 844 | /* clear next_to_watch to prevent false hangs */ |
| 845 | tx_buffer->next_to_watch = NULL; |
| 846 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 847 | /* update the statistics for this packet */ |
| 848 | total_bytes += tx_buffer->bytecount; |
| 849 | total_packets += tx_buffer->gso_segs; |
| 850 | |
Jacob Keller | 0ede4a6 | 2012-05-22 06:08:32 +0000 | [diff] [blame] | 851 | if (unlikely(tx_buffer->tx_flags & IXGBE_TX_FLAGS_TSTAMP)) |
| 852 | ixgbe_ptp_tx_hwtstamp(q_vector, tx_buffer->skb); |
Jacob Keller | 0ede4a6 | 2012-05-22 06:08:32 +0000 | [diff] [blame] | 853 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 854 | /* free the skb */ |
| 855 | dev_kfree_skb_any(tx_buffer->skb); |
| 856 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 857 | /* unmap skb header data */ |
| 858 | dma_unmap_single(tx_ring->dev, |
| 859 | dma_unmap_addr(tx_buffer, dma), |
| 860 | dma_unmap_len(tx_buffer, len), |
| 861 | DMA_TO_DEVICE); |
| 862 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 863 | /* clear tx_buffer data */ |
| 864 | tx_buffer->skb = NULL; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 865 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 866 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 867 | /* unmap remaining buffers */ |
| 868 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 869 | tx_buffer++; |
| 870 | tx_desc++; |
| 871 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 872 | if (unlikely(!i)) { |
| 873 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 874 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 875 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 876 | } |
| 877 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 878 | /* unmap any remaining paged data */ |
| 879 | if (dma_unmap_len(tx_buffer, len)) { |
| 880 | dma_unmap_page(tx_ring->dev, |
| 881 | dma_unmap_addr(tx_buffer, dma), |
| 882 | dma_unmap_len(tx_buffer, len), |
| 883 | DMA_TO_DEVICE); |
| 884 | dma_unmap_len_set(tx_buffer, len, 0); |
| 885 | } |
| 886 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 887 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 888 | /* move us one more past the eop_desc for start of next pkt */ |
| 889 | tx_buffer++; |
| 890 | tx_desc++; |
| 891 | i++; |
| 892 | if (unlikely(!i)) { |
| 893 | i -= tx_ring->count; |
| 894 | tx_buffer = tx_ring->tx_buffer_info; |
| 895 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 896 | } |
| 897 | |
| 898 | /* issue prefetch for next Tx descriptor */ |
| 899 | prefetch(tx_desc); |
| 900 | |
| 901 | /* update budget accounting */ |
| 902 | budget--; |
| 903 | } while (likely(budget)); |
| 904 | |
| 905 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 906 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 907 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 908 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 909 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 910 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 911 | q_vector->tx.total_bytes += total_bytes; |
| 912 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 913 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 914 | if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) { |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 915 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 916 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 917 | e_err(drv, "Detected Tx Unit Hang\n" |
| 918 | " Tx Queue <%d>\n" |
| 919 | " TDH, TDT <%x>, <%x>\n" |
| 920 | " next_to_use <%x>\n" |
| 921 | " next_to_clean <%x>\n" |
| 922 | "tx_buffer_info[next_to_clean]\n" |
| 923 | " time_stamp <%lx>\n" |
| 924 | " jiffies <%lx>\n", |
| 925 | tx_ring->queue_index, |
| 926 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 927 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 928 | tx_ring->next_to_use, i, |
| 929 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 930 | |
| 931 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 932 | |
| 933 | e_info(probe, |
| 934 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 935 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 936 | |
| 937 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 938 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 939 | |
| 940 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 941 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 942 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 943 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 944 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 945 | total_packets, total_bytes); |
| 946 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 947 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 948 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 949 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 950 | /* Make sure that anybody stopping the queue after this |
| 951 | * sees the new next_to_clean. |
| 952 | */ |
| 953 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 954 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 955 | tx_ring->queue_index) |
| 956 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 957 | netif_wake_subqueue(tx_ring->netdev, |
| 958 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 959 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 960 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 961 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 962 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 963 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 966 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 967 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 968 | struct ixgbe_ring *tx_ring, |
| 969 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 970 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 971 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 972 | u32 txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 973 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 974 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 975 | switch (hw->mac.type) { |
| 976 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 977 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 978 | break; |
| 979 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 980 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 981 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 982 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 983 | break; |
| 984 | default: |
| 985 | /* for unknown hardware do not write register */ |
| 986 | return; |
| 987 | } |
| 988 | |
| 989 | /* |
| 990 | * We can enable relaxed ordering for reads, but not writes when |
| 991 | * DCA is enabled. This is due to a known issue in some chipsets |
| 992 | * which will cause the DCA tag to be cleared. |
| 993 | */ |
| 994 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 995 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 996 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 997 | |
| 998 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 999 | } |
| 1000 | |
| 1001 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1002 | struct ixgbe_ring *rx_ring, |
| 1003 | int cpu) |
| 1004 | { |
| 1005 | struct ixgbe_hw *hw = &adapter->hw; |
| 1006 | u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
| 1007 | u8 reg_idx = rx_ring->reg_idx; |
| 1008 | |
| 1009 | |
| 1010 | switch (hw->mac.type) { |
| 1011 | case ixgbe_mac_82599EB: |
| 1012 | case ixgbe_mac_X540: |
| 1013 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1014 | break; |
| 1015 | default: |
| 1016 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1017 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1018 | |
| 1019 | /* |
| 1020 | * We can enable relaxed ordering for reads, but not writes when |
| 1021 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1022 | * which will cause the DCA tag to be cleared. |
| 1023 | */ |
| 1024 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1025 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1026 | |
| 1027 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1031 | { |
| 1032 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1033 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1034 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1035 | |
| 1036 | if (q_vector->cpu == cpu) |
| 1037 | goto out_no_update; |
| 1038 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1039 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1040 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1041 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1042 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1043 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1044 | |
| 1045 | q_vector->cpu = cpu; |
| 1046 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1047 | put_cpu(); |
| 1048 | } |
| 1049 | |
| 1050 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1051 | { |
| 1052 | int i; |
| 1053 | |
| 1054 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 1055 | return; |
| 1056 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1057 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 1058 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 1059 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1060 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1061 | adapter->q_vector[i]->cpu = -1; |
| 1062 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1067 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1068 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1069 | unsigned long event = *(unsigned long *)data; |
| 1070 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1071 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1072 | return 0; |
| 1073 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1074 | switch (event) { |
| 1075 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1076 | /* if we're already enabled, don't do it again */ |
| 1077 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1078 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1079 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1080 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1081 | ixgbe_setup_dca(adapter); |
| 1082 | break; |
| 1083 | } |
| 1084 | /* Fall Through since DCA is disabled. */ |
| 1085 | case DCA_PROVIDER_REMOVE: |
| 1086 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1087 | dca_remove_requester(dev); |
| 1088 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 1089 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 1090 | } |
| 1091 | break; |
| 1092 | } |
| 1093 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1094 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1095 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1096 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1097 | #endif /* CONFIG_IXGBE_DCA */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1098 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1099 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1100 | struct sk_buff *skb) |
| 1101 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1102 | if (ring->netdev->features & NETIF_F_RXHASH) |
| 1103 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1106 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1107 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1108 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1109 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1110 | * @rx_desc: advanced rx descriptor |
| 1111 | * |
| 1112 | * Returns : true if it is FCoE pkt |
| 1113 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1114 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1115 | union ixgbe_adv_rx_desc *rx_desc) |
| 1116 | { |
| 1117 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1118 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1119 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1120 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1121 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1122 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1123 | } |
| 1124 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1125 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1126 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1127 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1128 | * @ring: structure containing ring specific data |
| 1129 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1130 | * @skb: skb currently being received and modified |
| 1131 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1132 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1133 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1134 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1135 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1136 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1137 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1138 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1139 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1140 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1141 | |
| 1142 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1143 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1144 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1145 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1146 | return; |
| 1147 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1148 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1149 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1150 | return; |
| 1151 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1152 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1153 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1154 | |
| 1155 | /* |
| 1156 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1157 | * checksum errors. |
| 1158 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1159 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1160 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1161 | return; |
| 1162 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1163 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1164 | return; |
| 1165 | } |
| 1166 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1167 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1168 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1171 | static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1172 | { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1173 | rx_ring->next_to_use = val; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1174 | |
| 1175 | /* update next to alloc since we have filled the ring */ |
| 1176 | rx_ring->next_to_alloc = val; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1177 | /* |
| 1178 | * Force memory writes to complete before letting h/w |
| 1179 | * know there are new descriptors to fetch. (Only |
| 1180 | * applicable for weak-ordered memory model archs, |
| 1181 | * such as IA-64). |
| 1182 | */ |
| 1183 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1184 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1187 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1188 | struct ixgbe_rx_buffer *bi) |
| 1189 | { |
| 1190 | struct page *page = bi->page; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1191 | dma_addr_t dma = bi->dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1192 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1193 | /* since we are recycling buffers we should seldom need to alloc */ |
| 1194 | if (likely(dma)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1195 | return true; |
| 1196 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1197 | /* alloc new page for storage */ |
| 1198 | if (likely(!page)) { |
Mel Gorman | 0614002 | 2012-07-31 16:44:24 -0700 | [diff] [blame] | 1199 | page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP, |
| 1200 | bi->skb, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1201 | if (unlikely(!page)) { |
| 1202 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1203 | return false; |
| 1204 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1205 | bi->page = page; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1208 | /* map page for use */ |
| 1209 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1210 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1211 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1212 | /* |
| 1213 | * if mapping failed free memory back to system since |
| 1214 | * there isn't much point in holding memory we can't use |
| 1215 | */ |
| 1216 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1217 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1218 | bi->page = NULL; |
| 1219 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1220 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1221 | return false; |
| 1222 | } |
| 1223 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1224 | bi->dma = dma; |
Alexander Duyck | afaa945 | 2012-07-20 08:08:12 +0000 | [diff] [blame] | 1225 | bi->page_offset = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1226 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1227 | return true; |
| 1228 | } |
| 1229 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1230 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1231 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1232 | * @rx_ring: ring to place buffers on |
| 1233 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1234 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1235 | void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1236 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1237 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1238 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1239 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1240 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1241 | /* nothing to do */ |
| 1242 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1243 | return; |
| 1244 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1245 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1246 | bi = &rx_ring->rx_buffer_info[i]; |
| 1247 | i -= rx_ring->count; |
| 1248 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1249 | do { |
| 1250 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1251 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1252 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1253 | /* |
| 1254 | * Refresh the desc even if buffer_addrs didn't change |
| 1255 | * because each write-back erases this info. |
| 1256 | */ |
| 1257 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1258 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1259 | rx_desc++; |
| 1260 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1261 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1262 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1263 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1264 | bi = rx_ring->rx_buffer_info; |
| 1265 | i -= rx_ring->count; |
| 1266 | } |
| 1267 | |
| 1268 | /* clear the hdr_addr for the next_to_use descriptor */ |
| 1269 | rx_desc->read.hdr_addr = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1270 | |
| 1271 | cleaned_count--; |
| 1272 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1273 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1274 | i += rx_ring->count; |
| 1275 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1276 | if (rx_ring->next_to_use != i) |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1277 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1280 | /** |
| 1281 | * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE |
| 1282 | * @data: pointer to the start of the headers |
| 1283 | * @max_len: total length of section to find headers in |
| 1284 | * |
| 1285 | * This function is meant to determine the length of headers that will |
| 1286 | * be recognized by hardware for LRO, GRO, and RSC offloads. The main |
| 1287 | * motivation of doing this is to only perform one pull for IPv4 TCP |
| 1288 | * packets so that we can do basic things like calculating the gso_size |
| 1289 | * based on the average data per packet. |
| 1290 | **/ |
| 1291 | static unsigned int ixgbe_get_headlen(unsigned char *data, |
| 1292 | unsigned int max_len) |
| 1293 | { |
| 1294 | union { |
| 1295 | unsigned char *network; |
| 1296 | /* l2 headers */ |
| 1297 | struct ethhdr *eth; |
| 1298 | struct vlan_hdr *vlan; |
| 1299 | /* l3 headers */ |
| 1300 | struct iphdr *ipv4; |
Alexander Duyck | a048b40 | 2012-05-24 08:26:29 +0000 | [diff] [blame] | 1301 | struct ipv6hdr *ipv6; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1302 | } hdr; |
| 1303 | __be16 protocol; |
| 1304 | u8 nexthdr = 0; /* default to not TCP */ |
| 1305 | u8 hlen; |
| 1306 | |
| 1307 | /* this should never happen, but better safe than sorry */ |
| 1308 | if (max_len < ETH_HLEN) |
| 1309 | return max_len; |
| 1310 | |
| 1311 | /* initialize network frame pointer */ |
| 1312 | hdr.network = data; |
| 1313 | |
| 1314 | /* set first protocol and move network header forward */ |
| 1315 | protocol = hdr.eth->h_proto; |
| 1316 | hdr.network += ETH_HLEN; |
| 1317 | |
| 1318 | /* handle any vlan tag if present */ |
| 1319 | if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 1320 | if ((hdr.network - data) > (max_len - VLAN_HLEN)) |
| 1321 | return max_len; |
| 1322 | |
| 1323 | protocol = hdr.vlan->h_vlan_encapsulated_proto; |
| 1324 | hdr.network += VLAN_HLEN; |
| 1325 | } |
| 1326 | |
| 1327 | /* handle L3 protocols */ |
| 1328 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 1329 | if ((hdr.network - data) > (max_len - sizeof(struct iphdr))) |
| 1330 | return max_len; |
| 1331 | |
| 1332 | /* access ihl as a u8 to avoid unaligned access on ia64 */ |
| 1333 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 1334 | |
| 1335 | /* verify hlen meets minimum size requirements */ |
| 1336 | if (hlen < sizeof(struct iphdr)) |
| 1337 | return hdr.network - data; |
| 1338 | |
| 1339 | /* record next protocol */ |
| 1340 | nexthdr = hdr.ipv4->protocol; |
| 1341 | hdr.network += hlen; |
Alexander Duyck | a048b40 | 2012-05-24 08:26:29 +0000 | [diff] [blame] | 1342 | } else if (protocol == __constant_htons(ETH_P_IPV6)) { |
| 1343 | if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr))) |
| 1344 | return max_len; |
| 1345 | |
| 1346 | /* record next protocol */ |
| 1347 | nexthdr = hdr.ipv6->nexthdr; |
| 1348 | hdr.network += sizeof(struct ipv6hdr); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1349 | #ifdef IXGBE_FCOE |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1350 | } else if (protocol == __constant_htons(ETH_P_FCOE)) { |
| 1351 | if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN)) |
| 1352 | return max_len; |
| 1353 | hdr.network += FCOE_HEADER_LEN; |
| 1354 | #endif |
| 1355 | } else { |
| 1356 | return hdr.network - data; |
| 1357 | } |
| 1358 | |
Alexander Duyck | a048b40 | 2012-05-24 08:26:29 +0000 | [diff] [blame] | 1359 | /* finally sort out TCP/UDP */ |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1360 | if (nexthdr == IPPROTO_TCP) { |
| 1361 | if ((hdr.network - data) > (max_len - sizeof(struct tcphdr))) |
| 1362 | return max_len; |
| 1363 | |
| 1364 | /* access doff as a u8 to avoid unaligned access on ia64 */ |
| 1365 | hlen = (hdr.network[12] & 0xF0) >> 2; |
| 1366 | |
| 1367 | /* verify hlen meets minimum size requirements */ |
| 1368 | if (hlen < sizeof(struct tcphdr)) |
| 1369 | return hdr.network - data; |
| 1370 | |
| 1371 | hdr.network += hlen; |
Alexander Duyck | a048b40 | 2012-05-24 08:26:29 +0000 | [diff] [blame] | 1372 | } else if (nexthdr == IPPROTO_UDP) { |
| 1373 | if ((hdr.network - data) > (max_len - sizeof(struct udphdr))) |
| 1374 | return max_len; |
| 1375 | |
| 1376 | hdr.network += sizeof(struct udphdr); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | /* |
| 1380 | * If everything has gone correctly hdr.network should be the |
| 1381 | * data section of the packet and will be the end of the header. |
| 1382 | * If not then it probably represents the end of the last recognized |
| 1383 | * header. |
| 1384 | */ |
| 1385 | if ((hdr.network - data) < max_len) |
| 1386 | return hdr.network - data; |
| 1387 | else |
| 1388 | return max_len; |
| 1389 | } |
| 1390 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1391 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1392 | struct sk_buff *skb) |
| 1393 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1394 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1395 | |
| 1396 | /* set gso_size to avoid messing up TCP MSS */ |
| 1397 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1398 | IXGBE_CB(skb)->append_cnt); |
| 1399 | } |
| 1400 | |
| 1401 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1402 | struct sk_buff *skb) |
| 1403 | { |
| 1404 | /* if append_cnt is 0 then frame is not RSC */ |
| 1405 | if (!IXGBE_CB(skb)->append_cnt) |
| 1406 | return; |
| 1407 | |
| 1408 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1409 | rx_ring->rx_stats.rsc_flush++; |
| 1410 | |
| 1411 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1412 | |
| 1413 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1414 | IXGBE_CB(skb)->append_cnt = 0; |
| 1415 | } |
| 1416 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1417 | /** |
| 1418 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1419 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1420 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1421 | * @skb: pointer to current skb being populated |
| 1422 | * |
| 1423 | * This function checks the ring, descriptor, and packet information in |
| 1424 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1425 | * other fields within the skb. |
| 1426 | **/ |
| 1427 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1428 | union ixgbe_adv_rx_desc *rx_desc, |
| 1429 | struct sk_buff *skb) |
| 1430 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1431 | struct net_device *dev = rx_ring->netdev; |
| 1432 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1433 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1434 | |
| 1435 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1436 | |
| 1437 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1438 | |
Jacob Keller | 1d1a79b | 2012-05-22 06:18:08 +0000 | [diff] [blame] | 1439 | ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1440 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1441 | if ((dev->features & NETIF_F_HW_VLAN_RX) && |
| 1442 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1443 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
| 1444 | __vlan_hwaccel_put_tag(skb, vid); |
| 1445 | } |
| 1446 | |
| 1447 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1448 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1449 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1453 | struct sk_buff *skb) |
| 1454 | { |
| 1455 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1456 | |
| 1457 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1458 | napi_gro_receive(&q_vector->napi, skb); |
| 1459 | else |
| 1460 | netif_rx(skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1461 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1462 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1463 | /** |
| 1464 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1465 | * @rx_ring: Rx ring being processed |
| 1466 | * @rx_desc: Rx descriptor for current buffer |
| 1467 | * @skb: Current socket buffer containing buffer in progress |
| 1468 | * |
| 1469 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1470 | * this function exits returning false, otherwise it will place the |
| 1471 | * sk_buff in the next buffer to be chained and return true indicating |
| 1472 | * that this is in fact a non-EOP buffer. |
| 1473 | **/ |
| 1474 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1475 | union ixgbe_adv_rx_desc *rx_desc, |
| 1476 | struct sk_buff *skb) |
| 1477 | { |
| 1478 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1479 | |
| 1480 | /* fetch, update, and store next to clean */ |
| 1481 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1482 | rx_ring->next_to_clean = ntc; |
| 1483 | |
| 1484 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1485 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1486 | /* update RSC append count if present */ |
| 1487 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1488 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1489 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1490 | |
| 1491 | if (unlikely(rsc_enabled)) { |
| 1492 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1493 | |
| 1494 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1495 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1496 | |
| 1497 | /* update ntc based on RSC value */ |
| 1498 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1499 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1500 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | /* if we are the last buffer then there is nothing else to do */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1505 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1506 | return false; |
| 1507 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1508 | /* place skb in next buffer to be received */ |
| 1509 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1510 | rx_ring->rx_stats.non_eop_descs++; |
| 1511 | |
| 1512 | return true; |
| 1513 | } |
| 1514 | |
| 1515 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1516 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1517 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1518 | * @skb: pointer to current skb being adjusted |
| 1519 | * |
| 1520 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1521 | * main difference between this version and the original function is that |
| 1522 | * this function can make several assumptions about the state of things |
| 1523 | * that allow for significant optimizations versus the standard function. |
| 1524 | * As a result we can do things like drop a frag and maintain an accurate |
| 1525 | * truesize for the skb. |
| 1526 | */ |
| 1527 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1528 | struct sk_buff *skb) |
| 1529 | { |
| 1530 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1531 | unsigned char *va; |
| 1532 | unsigned int pull_len; |
| 1533 | |
| 1534 | /* |
| 1535 | * it is valid to use page_address instead of kmap since we are |
| 1536 | * working with pages allocated out of the lomem pool per |
| 1537 | * alloc_page(GFP_ATOMIC) |
| 1538 | */ |
| 1539 | va = skb_frag_address(frag); |
| 1540 | |
| 1541 | /* |
| 1542 | * we need the header to contain the greater of either ETH_HLEN or |
| 1543 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1544 | */ |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1545 | pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1546 | |
| 1547 | /* align pull length to size of long to optimize memcpy performance */ |
| 1548 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1549 | |
| 1550 | /* update all of the pointers */ |
| 1551 | skb_frag_size_sub(frag, pull_len); |
| 1552 | frag->page_offset += pull_len; |
| 1553 | skb->data_len -= pull_len; |
| 1554 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1558 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1559 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1560 | * @skb: pointer to current skb being updated |
| 1561 | * |
| 1562 | * This function provides a basic DMA sync up for the first fragment of an |
| 1563 | * skb. The reason for doing this is that the first fragment cannot be |
| 1564 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1565 | * chain. |
| 1566 | */ |
| 1567 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1568 | struct sk_buff *skb) |
| 1569 | { |
| 1570 | /* if the page was released unmap it, else just sync our portion */ |
| 1571 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1572 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1573 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1574 | IXGBE_CB(skb)->page_released = false; |
| 1575 | } else { |
| 1576 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1577 | |
| 1578 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1579 | IXGBE_CB(skb)->dma, |
| 1580 | frag->page_offset, |
| 1581 | ixgbe_rx_bufsz(rx_ring), |
| 1582 | DMA_FROM_DEVICE); |
| 1583 | } |
| 1584 | IXGBE_CB(skb)->dma = 0; |
| 1585 | } |
| 1586 | |
| 1587 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1588 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1589 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1590 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1591 | * @skb: pointer to current skb being fixed |
| 1592 | * |
| 1593 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1594 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1595 | * should be very rare. |
| 1596 | * |
| 1597 | * Also address the case where we are pulling data in on pages only |
| 1598 | * and as such no data is present in the skb header. |
| 1599 | * |
| 1600 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1601 | * it is large enough to qualify as a valid Ethernet frame. |
| 1602 | * |
| 1603 | * Returns true if an error was encountered and skb was freed. |
| 1604 | **/ |
| 1605 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1606 | union ixgbe_adv_rx_desc *rx_desc, |
| 1607 | struct sk_buff *skb) |
| 1608 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1609 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1610 | |
| 1611 | /* verify that the packet does not have any known errors */ |
| 1612 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1613 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1614 | !(netdev->features & NETIF_F_RXALL))) { |
| 1615 | dev_kfree_skb_any(skb); |
| 1616 | return true; |
| 1617 | } |
| 1618 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1619 | /* place header in linear portion of buffer */ |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1620 | if (skb_is_nonlinear(skb)) |
| 1621 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1622 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1623 | #ifdef IXGBE_FCOE |
| 1624 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1625 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1626 | return false; |
| 1627 | |
| 1628 | #endif |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1629 | /* if skb_pad returns an error the skb was freed */ |
| 1630 | if (unlikely(skb->len < 60)) { |
| 1631 | int pad_len = 60 - skb->len; |
| 1632 | |
| 1633 | if (skb_pad(skb, pad_len)) |
| 1634 | return true; |
| 1635 | __skb_put(skb, pad_len); |
| 1636 | } |
| 1637 | |
| 1638 | return false; |
| 1639 | } |
| 1640 | |
| 1641 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1642 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1643 | * @rx_ring: rx descriptor ring to store buffers on |
| 1644 | * @old_buff: donor buffer to have page reused |
| 1645 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1646 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1647 | **/ |
| 1648 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1649 | struct ixgbe_rx_buffer *old_buff) |
| 1650 | { |
| 1651 | struct ixgbe_rx_buffer *new_buff; |
| 1652 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1653 | |
| 1654 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1655 | |
| 1656 | /* update, and store next to alloc */ |
| 1657 | nta++; |
| 1658 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1659 | |
| 1660 | /* transfer page from old buffer to new buffer */ |
| 1661 | new_buff->page = old_buff->page; |
| 1662 | new_buff->dma = old_buff->dma; |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1663 | new_buff->page_offset = old_buff->page_offset; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1664 | |
| 1665 | /* sync the buffer for use by the device */ |
| 1666 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1667 | new_buff->page_offset, |
| 1668 | ixgbe_rx_bufsz(rx_ring), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1669 | DMA_FROM_DEVICE); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | /** |
| 1673 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1674 | * @rx_ring: rx descriptor ring to transact packets on |
| 1675 | * @rx_buffer: buffer containing page to add |
| 1676 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1677 | * @skb: sk_buff to place the data into |
| 1678 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1679 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1680 | * This is done either through a direct copy if the data in the buffer is |
| 1681 | * less than the skb header size, otherwise it will just attach the page as |
| 1682 | * a frag to the skb. |
| 1683 | * |
| 1684 | * The function will then update the page offset if necessary and return |
| 1685 | * true if the buffer can be reused by the adapter. |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1686 | **/ |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1687 | static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1688 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1689 | union ixgbe_adv_rx_desc *rx_desc, |
| 1690 | struct sk_buff *skb) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1691 | { |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1692 | struct page *page = rx_buffer->page; |
| 1693 | unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1694 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1695 | unsigned int truesize = ixgbe_rx_bufsz(rx_ring); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1696 | #else |
| 1697 | unsigned int truesize = ALIGN(size, L1_CACHE_BYTES); |
| 1698 | unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) - |
| 1699 | ixgbe_rx_bufsz(rx_ring); |
| 1700 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1701 | |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1702 | if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) { |
| 1703 | unsigned char *va = page_address(page) + rx_buffer->page_offset; |
| 1704 | |
| 1705 | memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); |
| 1706 | |
| 1707 | /* we can reuse buffer as-is, just make sure it is local */ |
| 1708 | if (likely(page_to_nid(page) == numa_node_id())) |
| 1709 | return true; |
| 1710 | |
| 1711 | /* this page cannot be reused so discard it */ |
| 1712 | put_page(page); |
| 1713 | return false; |
| 1714 | } |
| 1715 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1716 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, |
| 1717 | rx_buffer->page_offset, size, truesize); |
| 1718 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1719 | /* avoid re-using remote pages */ |
| 1720 | if (unlikely(page_to_nid(page) != numa_node_id())) |
| 1721 | return false; |
| 1722 | |
| 1723 | #if (PAGE_SIZE < 8192) |
| 1724 | /* if we are only owner of page we can reuse it */ |
| 1725 | if (unlikely(page_count(page) != 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1726 | return false; |
| 1727 | |
| 1728 | /* flip page offset to other buffer */ |
| 1729 | rx_buffer->page_offset ^= truesize; |
| 1730 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1731 | /* |
| 1732 | * since we are the only owner of the page and we need to |
| 1733 | * increment it, just set the value to 2 in order to avoid |
| 1734 | * an unecessary locked operation |
| 1735 | */ |
| 1736 | atomic_set(&page->_count, 2); |
| 1737 | #else |
| 1738 | /* move offset up to the next cache line */ |
| 1739 | rx_buffer->page_offset += truesize; |
| 1740 | |
| 1741 | if (rx_buffer->page_offset > last_offset) |
| 1742 | return false; |
| 1743 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1744 | /* bump ref count on page before it is given to the stack */ |
| 1745 | get_page(page); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1746 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1747 | |
| 1748 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1751 | static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring, |
| 1752 | union ixgbe_adv_rx_desc *rx_desc) |
| 1753 | { |
| 1754 | struct ixgbe_rx_buffer *rx_buffer; |
| 1755 | struct sk_buff *skb; |
| 1756 | struct page *page; |
| 1757 | |
| 1758 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
| 1759 | page = rx_buffer->page; |
| 1760 | prefetchw(page); |
| 1761 | |
| 1762 | skb = rx_buffer->skb; |
| 1763 | |
| 1764 | if (likely(!skb)) { |
| 1765 | void *page_addr = page_address(page) + |
| 1766 | rx_buffer->page_offset; |
| 1767 | |
| 1768 | /* prefetch first cache line of first page */ |
| 1769 | prefetch(page_addr); |
| 1770 | #if L1_CACHE_BYTES < 128 |
| 1771 | prefetch(page_addr + L1_CACHE_BYTES); |
| 1772 | #endif |
| 1773 | |
| 1774 | /* allocate a skb to store the frags */ |
| 1775 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
| 1776 | IXGBE_RX_HDR_SIZE); |
| 1777 | if (unlikely(!skb)) { |
| 1778 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 1779 | return NULL; |
| 1780 | } |
| 1781 | |
| 1782 | /* |
| 1783 | * we will be copying header into skb->data in |
| 1784 | * pskb_may_pull so it is in our interest to prefetch |
| 1785 | * it now to avoid a possible cache miss |
| 1786 | */ |
| 1787 | prefetchw(skb->data); |
| 1788 | |
| 1789 | /* |
| 1790 | * Delay unmapping of the first packet. It carries the |
| 1791 | * header information, HW may still access the header |
| 1792 | * after the writeback. Only unmap it when EOP is |
| 1793 | * reached |
| 1794 | */ |
| 1795 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1796 | goto dma_sync; |
| 1797 | |
| 1798 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 1799 | } else { |
| 1800 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 1801 | ixgbe_dma_sync_frag(rx_ring, skb); |
| 1802 | |
| 1803 | dma_sync: |
| 1804 | /* we are reusing so sync this buffer for CPU use */ |
| 1805 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1806 | rx_buffer->dma, |
| 1807 | rx_buffer->page_offset, |
| 1808 | ixgbe_rx_bufsz(rx_ring), |
| 1809 | DMA_FROM_DEVICE); |
| 1810 | } |
| 1811 | |
| 1812 | /* pull page into skb */ |
| 1813 | if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) { |
| 1814 | /* hand second half of page back to the ring */ |
| 1815 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 1816 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 1817 | /* the page has been released from the ring */ |
| 1818 | IXGBE_CB(skb)->page_released = true; |
| 1819 | } else { |
| 1820 | /* we are not reusing the buffer so unmap it */ |
| 1821 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 1822 | ixgbe_rx_pg_size(rx_ring), |
| 1823 | DMA_FROM_DEVICE); |
| 1824 | } |
| 1825 | |
| 1826 | /* clear contents of buffer_info */ |
| 1827 | rx_buffer->skb = NULL; |
| 1828 | rx_buffer->dma = 0; |
| 1829 | rx_buffer->page = NULL; |
| 1830 | |
| 1831 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | /** |
| 1835 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 1836 | * @q_vector: structure containing interrupt and ring information |
| 1837 | * @rx_ring: rx descriptor ring to transact packets on |
| 1838 | * @budget: Total limit on number of packets to process |
| 1839 | * |
| 1840 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 1841 | * processing. The advantage to this is that on systems that have |
| 1842 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 1843 | * it by maintaining the mapping of the page to the syste. |
| 1844 | * |
| 1845 | * Returns true if all work is completed without reaching budget |
| 1846 | **/ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1847 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1848 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 1849 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1850 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1851 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 1852 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1853 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 1854 | int ddp_bytes; |
| 1855 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1856 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1857 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1858 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1859 | do { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1860 | union ixgbe_adv_rx_desc *rx_desc; |
| 1861 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1862 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1863 | /* return some buffers to hardware, one at a time is too slow */ |
| 1864 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 1865 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1866 | cleaned_count = 0; |
| 1867 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1868 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1869 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1870 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1871 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) |
| 1872 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1873 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1874 | /* |
| 1875 | * This memory barrier is needed to keep us from reading |
| 1876 | * any other fields out of the rx_desc until we know the |
| 1877 | * RXD_STAT_DD bit is set |
| 1878 | */ |
| 1879 | rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1880 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1881 | /* retrieve a buffer from the ring */ |
| 1882 | skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1883 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1884 | /* exit if we failed to retrieve a buffer */ |
| 1885 | if (!skb) |
| 1886 | break; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1887 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1888 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1889 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1890 | /* place incomplete frames back on ring for completion */ |
| 1891 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 1892 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1893 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1894 | /* verify the packet layout is correct */ |
| 1895 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 1896 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1897 | |
| 1898 | /* probably a little skewed due to removing CRC */ |
| 1899 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1900 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1901 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 1902 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 1903 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1904 | #ifdef IXGBE_FCOE |
| 1905 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1906 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1907 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 1908 | /* include DDPed FCoE data */ |
| 1909 | if (ddp_bytes > 0) { |
| 1910 | if (!mss) { |
| 1911 | mss = rx_ring->netdev->mtu - |
| 1912 | sizeof(struct fcoe_hdr) - |
| 1913 | sizeof(struct fc_frame_header) - |
| 1914 | sizeof(struct fcoe_crc_eof); |
| 1915 | if (mss > 512) |
| 1916 | mss &= ~511; |
| 1917 | } |
| 1918 | total_rx_bytes += ddp_bytes; |
| 1919 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 1920 | mss); |
| 1921 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1922 | if (!ddp_bytes) { |
| 1923 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1924 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1925 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1926 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1927 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1928 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1929 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1930 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1931 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 1932 | total_rx_packets++; |
| 1933 | } while (likely(total_rx_packets < budget)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1934 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1935 | u64_stats_update_begin(&rx_ring->syncp); |
| 1936 | rx_ring->stats.packets += total_rx_packets; |
| 1937 | rx_ring->stats.bytes += total_rx_bytes; |
| 1938 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1939 | q_vector->rx.total_packets += total_rx_packets; |
| 1940 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1941 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1942 | if (cleaned_count) |
| 1943 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1944 | |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 1945 | return (total_rx_packets < budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1948 | /** |
| 1949 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1950 | * @adapter: board private structure |
| 1951 | * |
| 1952 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1953 | * interrupts. |
| 1954 | **/ |
| 1955 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1956 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1957 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1958 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1959 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1960 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 1961 | /* Populate MSIX to EITR Select */ |
| 1962 | if (adapter->num_vfs > 32) { |
| 1963 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 1964 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 1965 | } |
| 1966 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1967 | /* |
| 1968 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1969 | * corresponding register. |
| 1970 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1971 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1972 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1973 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1974 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1975 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1976 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1977 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1978 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1979 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1980 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1981 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1984 | switch (adapter->hw.mac.type) { |
| 1985 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1986 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1987 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1988 | break; |
| 1989 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1990 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1991 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1992 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1993 | default: |
| 1994 | break; |
| 1995 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1996 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1997 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1998 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1999 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2000 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2001 | IXGBE_EIMS_MAILBOX | |
| 2002 | IXGBE_EIMS_LSC); |
| 2003 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2004 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2007 | enum latency_range { |
| 2008 | lowest_latency = 0, |
| 2009 | low_latency = 1, |
| 2010 | bulk_latency = 2, |
| 2011 | latency_invalid = 255 |
| 2012 | }; |
| 2013 | |
| 2014 | /** |
| 2015 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2016 | * @q_vector: structure containing interrupt and ring information |
| 2017 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2018 | * |
| 2019 | * Stores a new ITR value based on packets and byte |
| 2020 | * counts during the last interrupt. The advantage of per interrupt |
| 2021 | * computation is faster updates and more accurate ITR for the current |
| 2022 | * traffic pattern. Constants in this function were computed |
| 2023 | * based on theoretical maximum wire speed and thresholds were set based |
| 2024 | * on testing data as well as attempting to minimize response time |
| 2025 | * while increasing bulk throughput. |
| 2026 | * this functionality is controlled by the InterruptThrottleRate module |
| 2027 | * parameter (see ixgbe_param.c) |
| 2028 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2029 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2030 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2031 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2032 | int bytes = ring_container->total_bytes; |
| 2033 | int packets = ring_container->total_packets; |
| 2034 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2035 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2036 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2037 | |
| 2038 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2039 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2040 | |
| 2041 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2042 | * 0-10MB/s lowest (100000 ints/s) |
| 2043 | * 10-20MB/s low (20000 ints/s) |
| 2044 | * 20-1249MB/s bulk (8000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2045 | */ |
| 2046 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2047 | timepassed_us = q_vector->itr >> 2; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2048 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 2049 | |
| 2050 | switch (itr_setting) { |
| 2051 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2052 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2053 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2054 | break; |
| 2055 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2056 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2057 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2058 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2059 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2060 | break; |
| 2061 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2062 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2063 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2064 | break; |
| 2065 | } |
| 2066 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2067 | /* clear work counters since we have the values we need */ |
| 2068 | ring_container->total_bytes = 0; |
| 2069 | ring_container->total_packets = 0; |
| 2070 | |
| 2071 | /* write updated itr to ring container */ |
| 2072 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2073 | } |
| 2074 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2075 | /** |
| 2076 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2077 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2078 | * |
| 2079 | * This function is made to be called by ethtool and by the driver |
| 2080 | * when it needs to update EITR registers at runtime. Hardware |
| 2081 | * specific quirks/differences are taken care of here. |
| 2082 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2083 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2084 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2085 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2086 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2087 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2088 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2089 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2090 | switch (adapter->hw.mac.type) { |
| 2091 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2092 | /* must write high and low 16 bits to reset counter */ |
| 2093 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2094 | break; |
| 2095 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2096 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2097 | /* |
| 2098 | * set the WDIS bit to not clear the timer bits and cause an |
| 2099 | * immediate assertion of the interrupt |
| 2100 | */ |
| 2101 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2102 | break; |
| 2103 | default: |
| 2104 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2105 | } |
| 2106 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2107 | } |
| 2108 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2109 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2110 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2111 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2112 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2113 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2114 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2115 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2116 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2117 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2118 | |
| 2119 | switch (current_itr) { |
| 2120 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2121 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2122 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2123 | break; |
| 2124 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2125 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2126 | break; |
| 2127 | case bulk_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2128 | new_itr = IXGBE_8K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2129 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2130 | default: |
| 2131 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2132 | } |
| 2133 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2134 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2135 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2136 | new_itr = (10 * new_itr * q_vector->itr) / |
| 2137 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2138 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2139 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2140 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2141 | |
| 2142 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2143 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2144 | } |
| 2145 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2146 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2147 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2148 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2149 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2150 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2151 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2152 | struct ixgbe_hw *hw = &adapter->hw; |
| 2153 | u32 eicr = adapter->interrupt_event; |
| 2154 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2155 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2156 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2157 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2158 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2159 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2160 | return; |
| 2161 | |
| 2162 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2163 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2164 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2165 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2166 | /* |
| 2167 | * Since the warning interrupt is for both ports |
| 2168 | * we don't have to check if: |
| 2169 | * - This interrupt wasn't for our port. |
| 2170 | * - We may have missed the interrupt so always have to |
| 2171 | * check if we got a LSC |
| 2172 | */ |
| 2173 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 2174 | !(eicr & IXGBE_EICR_LSC)) |
| 2175 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2176 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2177 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
| 2178 | u32 autoneg; |
| 2179 | bool link_up = false; |
| 2180 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2181 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2182 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2183 | if (link_up) |
| 2184 | return; |
| 2185 | } |
| 2186 | |
| 2187 | /* Check if this is not due to overtemp */ |
| 2188 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2189 | return; |
| 2190 | |
| 2191 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2192 | default: |
| 2193 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 2194 | return; |
| 2195 | break; |
| 2196 | } |
| 2197 | e_crit(drv, |
| 2198 | "Network adapter has been stopped because it has over heated. " |
| 2199 | "Restart the computer. If the problem persists, " |
| 2200 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2201 | |
| 2202 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2203 | } |
| 2204 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2205 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2206 | { |
| 2207 | struct ixgbe_hw *hw = &adapter->hw; |
| 2208 | |
| 2209 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 2210 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2211 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2212 | /* write to clear the interrupt */ |
| 2213 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 2214 | } |
| 2215 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2216 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2217 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2218 | { |
| 2219 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2220 | return; |
| 2221 | |
| 2222 | switch (adapter->hw.mac.type) { |
| 2223 | case ixgbe_mac_82599EB: |
| 2224 | /* |
| 2225 | * Need to check link state so complete overtemp check |
| 2226 | * on service task |
| 2227 | */ |
| 2228 | if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) && |
| 2229 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2230 | adapter->interrupt_event = eicr; |
| 2231 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2232 | ixgbe_service_event_schedule(adapter); |
| 2233 | return; |
| 2234 | } |
| 2235 | return; |
| 2236 | case ixgbe_mac_X540: |
| 2237 | if (!(eicr & IXGBE_EICR_TS)) |
| 2238 | return; |
| 2239 | break; |
| 2240 | default: |
| 2241 | return; |
| 2242 | } |
| 2243 | |
| 2244 | e_crit(drv, |
| 2245 | "Network adapter has been stopped because it has over heated. " |
| 2246 | "Restart the computer. If the problem persists, " |
| 2247 | "power off the system and replace the adapter\n"); |
| 2248 | } |
| 2249 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2250 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2251 | { |
| 2252 | struct ixgbe_hw *hw = &adapter->hw; |
| 2253 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2254 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 2255 | /* Clear the interrupt */ |
| 2256 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2257 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2258 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 2259 | ixgbe_service_event_schedule(adapter); |
| 2260 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2261 | } |
| 2262 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2263 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 2264 | /* Clear the interrupt */ |
| 2265 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2266 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2267 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2268 | ixgbe_service_event_schedule(adapter); |
| 2269 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2273 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2274 | { |
| 2275 | struct ixgbe_hw *hw = &adapter->hw; |
| 2276 | |
| 2277 | adapter->lsc_int++; |
| 2278 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2279 | adapter->link_check_timeout = jiffies; |
| 2280 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2281 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2282 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2283 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2284 | } |
| 2285 | } |
| 2286 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2287 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2288 | u64 qmask) |
| 2289 | { |
| 2290 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2291 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2292 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2293 | switch (hw->mac.type) { |
| 2294 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2295 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2296 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2297 | break; |
| 2298 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2299 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2300 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2301 | if (mask) |
| 2302 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2303 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2304 | if (mask) |
| 2305 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2306 | break; |
| 2307 | default: |
| 2308 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2309 | } |
| 2310 | /* skip the flush */ |
| 2311 | } |
| 2312 | |
| 2313 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2314 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2315 | { |
| 2316 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2317 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2318 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2319 | switch (hw->mac.type) { |
| 2320 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2321 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2322 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2323 | break; |
| 2324 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2325 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2326 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2327 | if (mask) |
| 2328 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2329 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2330 | if (mask) |
| 2331 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2332 | break; |
| 2333 | default: |
| 2334 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2335 | } |
| 2336 | /* skip the flush */ |
| 2337 | } |
| 2338 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2339 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2340 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2341 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2342 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2343 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2344 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2345 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2346 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2347 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2348 | /* don't reenable LSC while waiting for link */ |
| 2349 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2350 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2351 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2352 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2353 | switch (adapter->hw.mac.type) { |
| 2354 | case ixgbe_mac_82599EB: |
| 2355 | mask |= IXGBE_EIMS_GPI_SDP0; |
| 2356 | break; |
| 2357 | case ixgbe_mac_X540: |
| 2358 | mask |= IXGBE_EIMS_TS; |
| 2359 | break; |
| 2360 | default: |
| 2361 | break; |
| 2362 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2363 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2364 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2365 | switch (adapter->hw.mac.type) { |
| 2366 | case ixgbe_mac_82599EB: |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2367 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2368 | mask |= IXGBE_EIMS_GPI_SDP2; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2369 | case ixgbe_mac_X540: |
| 2370 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2371 | mask |= IXGBE_EIMS_MAILBOX; |
| 2372 | break; |
| 2373 | default: |
| 2374 | break; |
| 2375 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2376 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2377 | if (adapter->hw.mac.type == ixgbe_mac_X540) |
| 2378 | mask |= IXGBE_EIMS_TIMESYNC; |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2379 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2380 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2381 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2382 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2383 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2384 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2385 | if (queues) |
| 2386 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2387 | if (flush) |
| 2388 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2391 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2392 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2393 | struct ixgbe_adapter *adapter = data; |
| 2394 | struct ixgbe_hw *hw = &adapter->hw; |
| 2395 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2396 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2397 | /* |
| 2398 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2399 | * of clear-by-read. Reading with EICS will return the |
| 2400 | * interrupt causes without clearing, which later be done |
| 2401 | * with the write to EICR. |
| 2402 | */ |
| 2403 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 2404 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2405 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2406 | if (eicr & IXGBE_EICR_LSC) |
| 2407 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2408 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2409 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2410 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2411 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2412 | switch (hw->mac.type) { |
| 2413 | case ixgbe_mac_82599EB: |
| 2414 | case ixgbe_mac_X540: |
| 2415 | if (eicr & IXGBE_EICR_ECC) |
| 2416 | e_info(link, "Received unrecoverable ECC Err, please " |
| 2417 | "reboot\n"); |
| 2418 | /* Handle Flow Director Full threshold interrupt */ |
| 2419 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2420 | int reinit_count = 0; |
| 2421 | int i; |
| 2422 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2423 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2424 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2425 | &ring->state)) |
| 2426 | reinit_count++; |
| 2427 | } |
| 2428 | if (reinit_count) { |
| 2429 | /* no more flow director interrupts until after init */ |
| 2430 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2431 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2432 | ixgbe_service_event_schedule(adapter); |
| 2433 | } |
| 2434 | } |
| 2435 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2436 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2437 | break; |
| 2438 | default: |
| 2439 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2442 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2443 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2444 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
| 2445 | ixgbe_ptp_check_pps_event(adapter, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2446 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2447 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2448 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2449 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2450 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2451 | return IRQ_HANDLED; |
| 2452 | } |
| 2453 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2454 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2455 | { |
| 2456 | struct ixgbe_q_vector *q_vector = data; |
| 2457 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2458 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2459 | |
| 2460 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 2461 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2462 | |
| 2463 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2466 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2467 | * ixgbe_poll - NAPI Rx polling callback |
| 2468 | * @napi: structure for representing this polling device |
| 2469 | * @budget: how many packets driver is allowed to clean |
| 2470 | * |
| 2471 | * This function is used for legacy and MSI, NAPI mode |
| 2472 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 2473 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2474 | { |
| 2475 | struct ixgbe_q_vector *q_vector = |
| 2476 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2477 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2478 | struct ixgbe_ring *ring; |
| 2479 | int per_ring_budget; |
| 2480 | bool clean_complete = true; |
| 2481 | |
| 2482 | #ifdef CONFIG_IXGBE_DCA |
| 2483 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2484 | ixgbe_update_dca(q_vector); |
| 2485 | #endif |
| 2486 | |
| 2487 | ixgbe_for_each_ring(ring, q_vector->tx) |
| 2488 | clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring); |
| 2489 | |
| 2490 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2491 | * the budget to go below 1 because we'll exit polling */ |
| 2492 | if (q_vector->rx.count > 1) |
| 2493 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2494 | else |
| 2495 | per_ring_budget = budget; |
| 2496 | |
| 2497 | ixgbe_for_each_ring(ring, q_vector->rx) |
| 2498 | clean_complete &= ixgbe_clean_rx_irq(q_vector, ring, |
| 2499 | per_ring_budget); |
| 2500 | |
| 2501 | /* If all work not completed, return budget and keep polling */ |
| 2502 | if (!clean_complete) |
| 2503 | return budget; |
| 2504 | |
| 2505 | /* all work done, exit the polling mode */ |
| 2506 | napi_complete(napi); |
| 2507 | if (adapter->rx_itr_setting & 1) |
| 2508 | ixgbe_set_itr(q_vector); |
| 2509 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2510 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 2511 | |
| 2512 | return 0; |
| 2513 | } |
| 2514 | |
| 2515 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2516 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2517 | * @adapter: board private structure |
| 2518 | * |
| 2519 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2520 | * interrupts from the kernel. |
| 2521 | **/ |
| 2522 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2523 | { |
| 2524 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2525 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2526 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2527 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2528 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2529 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2530 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2531 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2532 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2533 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2534 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2535 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2536 | } else if (q_vector->rx.ring) { |
| 2537 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2538 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2539 | } else if (q_vector->tx.ring) { |
| 2540 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2541 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2542 | } else { |
| 2543 | /* skip this unused q_vector */ |
| 2544 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2545 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2546 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2547 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2548 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2549 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2550 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2551 | goto free_queue_irqs; |
| 2552 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2553 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2554 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2555 | /* assign the mask for this irq */ |
| 2556 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2557 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2558 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2561 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2562 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2563 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2564 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2565 | goto free_queue_irqs; |
| 2566 | } |
| 2567 | |
| 2568 | return 0; |
| 2569 | |
| 2570 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2571 | while (vector) { |
| 2572 | vector--; |
| 2573 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2574 | NULL); |
| 2575 | free_irq(adapter->msix_entries[vector].vector, |
| 2576 | adapter->q_vector[vector]); |
| 2577 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2578 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2579 | pci_disable_msix(adapter->pdev); |
| 2580 | kfree(adapter->msix_entries); |
| 2581 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2582 | return err; |
| 2583 | } |
| 2584 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2585 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2586 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2587 | * @irq: interrupt number |
| 2588 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2589 | **/ |
| 2590 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2591 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2592 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2593 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2594 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2595 | u32 eicr; |
| 2596 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2597 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2598 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2599 | * before the read of EICR. |
| 2600 | */ |
| 2601 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2602 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2603 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 2604 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2605 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2606 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2607 | /* |
| 2608 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2609 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2610 | * have disabled interrupts due to EIAM |
| 2611 | * finish the workaround of silicon errata on 82598. Unmask |
| 2612 | * the interrupt that we masked before the EICR read. |
| 2613 | */ |
| 2614 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2615 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2616 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2617 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2618 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2619 | if (eicr & IXGBE_EICR_LSC) |
| 2620 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2621 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2622 | switch (hw->mac.type) { |
| 2623 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2624 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 2625 | /* Fall through */ |
| 2626 | case ixgbe_mac_X540: |
| 2627 | if (eicr & IXGBE_EICR_ECC) |
| 2628 | e_info(link, "Received unrecoverable ECC err, please " |
| 2629 | "reboot\n"); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2630 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2631 | break; |
| 2632 | default: |
| 2633 | break; |
| 2634 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2635 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2636 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2637 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
| 2638 | ixgbe_ptp_check_pps_event(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2639 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 2640 | /* would disable interrupts here but EIAM disabled it */ |
| 2641 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2642 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2643 | /* |
| 2644 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2645 | * ixgbe_poll will re-enable the queue interrupts |
| 2646 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2647 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2648 | ixgbe_irq_enable(adapter, false, false); |
| 2649 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2650 | return IRQ_HANDLED; |
| 2651 | } |
| 2652 | |
| 2653 | /** |
| 2654 | * ixgbe_request_irq - initialize interrupts |
| 2655 | * @adapter: board private structure |
| 2656 | * |
| 2657 | * Attempts to configure interrupts using the best available |
| 2658 | * capabilities of the hardware and kernel. |
| 2659 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2660 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2661 | { |
| 2662 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2663 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2664 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2665 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2666 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2667 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2668 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2669 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2670 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2671 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2672 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2673 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2674 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2675 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2676 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2677 | return err; |
| 2678 | } |
| 2679 | |
| 2680 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2681 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2682 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2683 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2684 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2685 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2686 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2687 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2688 | |
| 2689 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 2690 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 2691 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 2692 | |
| 2693 | /* free only the irqs that were actually requested */ |
| 2694 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 2695 | continue; |
| 2696 | |
| 2697 | /* clear the affinity_mask in the IRQ descriptor */ |
| 2698 | irq_set_affinity_hint(entry->vector, NULL); |
| 2699 | |
| 2700 | free_irq(entry->vector, q_vector); |
| 2701 | } |
| 2702 | |
| 2703 | free_irq(adapter->msix_entries[vector++].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2707 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2708 | * @adapter: board private structure |
| 2709 | **/ |
| 2710 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2711 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2712 | switch (adapter->hw.mac.type) { |
| 2713 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2714 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2715 | break; |
| 2716 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2717 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2718 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2719 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2720 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2721 | break; |
| 2722 | default: |
| 2723 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2724 | } |
| 2725 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2726 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2727 | int vector; |
| 2728 | |
| 2729 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 2730 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 2731 | |
| 2732 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2733 | } else { |
| 2734 | synchronize_irq(adapter->pdev->irq); |
| 2735 | } |
| 2736 | } |
| 2737 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2738 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2739 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2740 | * |
| 2741 | **/ |
| 2742 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2743 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2744 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2745 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2746 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2747 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2748 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2749 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2750 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2751 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2754 | /** |
| 2755 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2756 | * @adapter: board private structure |
| 2757 | * @ring: structure containing ring specific data |
| 2758 | * |
| 2759 | * Configure the Tx descriptor ring after a reset. |
| 2760 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2761 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2762 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2763 | { |
| 2764 | struct ixgbe_hw *hw = &adapter->hw; |
| 2765 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2766 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2767 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2768 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2769 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2770 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2771 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2772 | IXGBE_WRITE_FLUSH(hw); |
| 2773 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2774 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2775 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2776 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2777 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2778 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2779 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2780 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2781 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2782 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2783 | /* |
| 2784 | * set WTHRESH to encourage burst writeback, it should not be set |
| 2785 | * higher than 1 when ITR is 0 as it could cause false TX hangs |
| 2786 | * |
| 2787 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 2788 | * to or less than the number of on chip descriptors, which is |
| 2789 | * currently 40. |
| 2790 | */ |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2791 | if (!ring->q_vector || (ring->q_vector->itr < 8)) |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2792 | txdctl |= (1 << 16); /* WTHRESH = 1 */ |
| 2793 | else |
| 2794 | txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 2795 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2796 | /* |
| 2797 | * Setting PTHRESH to 32 both improves performance |
| 2798 | * and avoids a TX hang with DFP enabled |
| 2799 | */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2800 | txdctl |= (1 << 8) | /* HTHRESH = 1 */ |
| 2801 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2802 | |
| 2803 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 2804 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2805 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2806 | ring->atr_count = 0; |
| 2807 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2808 | } else { |
| 2809 | ring->atr_sample_rate = 0; |
| 2810 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2811 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2812 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2813 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2814 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2815 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2816 | |
| 2817 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2818 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2819 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2820 | return; |
| 2821 | |
| 2822 | /* poll to verify queue is enabled */ |
| 2823 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2824 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2825 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2826 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2827 | if (!wait_loop) |
| 2828 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2831 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2832 | { |
| 2833 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 2834 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2835 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2836 | |
| 2837 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2838 | return; |
| 2839 | |
| 2840 | /* disable the arbiter while setting MTQC */ |
| 2841 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2842 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2843 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2844 | |
| 2845 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 2846 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 2847 | mtqc = IXGBE_MTQC_VT_ENA; |
| 2848 | if (tcs > 4) |
| 2849 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2850 | else if (tcs > 1) |
| 2851 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2852 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 2853 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2854 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 2855 | mtqc |= IXGBE_MTQC_64VF; |
| 2856 | } else { |
| 2857 | if (tcs > 4) |
| 2858 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2859 | else if (tcs > 1) |
| 2860 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2861 | else |
| 2862 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 2863 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2864 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 2865 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2866 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 2867 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 2868 | if (tcs) { |
| 2869 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 2870 | sectx |= IXGBE_SECTX_DCB; |
| 2871 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | /* re-enable the arbiter */ |
| 2875 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2876 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2877 | } |
| 2878 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2879 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2880 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2881 | * @adapter: board private structure |
| 2882 | * |
| 2883 | * Configure the Tx unit of the MAC after a reset. |
| 2884 | **/ |
| 2885 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2886 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2887 | struct ixgbe_hw *hw = &adapter->hw; |
| 2888 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2889 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2890 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2891 | ixgbe_setup_mtqc(adapter); |
| 2892 | |
| 2893 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2894 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2895 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2896 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2897 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2898 | } |
| 2899 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2900 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2901 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2902 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 2905 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 2906 | struct ixgbe_ring *ring) |
| 2907 | { |
| 2908 | struct ixgbe_hw *hw = &adapter->hw; |
| 2909 | u8 reg_idx = ring->reg_idx; |
| 2910 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 2911 | |
| 2912 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 2913 | |
| 2914 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 2915 | } |
| 2916 | |
| 2917 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 2918 | struct ixgbe_ring *ring) |
| 2919 | { |
| 2920 | struct ixgbe_hw *hw = &adapter->hw; |
| 2921 | u8 reg_idx = ring->reg_idx; |
| 2922 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 2923 | |
| 2924 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 2925 | |
| 2926 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 2927 | } |
| 2928 | |
| 2929 | #ifdef CONFIG_IXGBE_DCB |
| 2930 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 2931 | #else |
| 2932 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 2933 | #endif |
| 2934 | { |
| 2935 | int i; |
| 2936 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 2937 | |
| 2938 | if (adapter->ixgbe_ieee_pfc) |
| 2939 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 2940 | |
| 2941 | /* |
| 2942 | * We should set the drop enable bit if: |
| 2943 | * SR-IOV is enabled |
| 2944 | * or |
| 2945 | * Number of Rx queues > 1 and flow control is disabled |
| 2946 | * |
| 2947 | * This allows us to avoid head of line blocking for security |
| 2948 | * and performance reasons. |
| 2949 | */ |
| 2950 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 2951 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 2952 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2953 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 2954 | } else { |
| 2955 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2956 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 2957 | } |
| 2958 | } |
| 2959 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2960 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2961 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2962 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2963 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2964 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 2965 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2966 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2967 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2968 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 2969 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2970 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 2971 | |
| 2972 | /* |
| 2973 | * if VMDq is not active we must program one srrctl register |
| 2974 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 2975 | */ |
| 2976 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2977 | } |
| 2978 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 2979 | /* configure header buffer length, needed for RSC */ |
| 2980 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2981 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 2982 | /* configure the packet buffer length */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2983 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 2984 | |
| 2985 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2986 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2987 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 2988 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2991 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2992 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2993 | struct ixgbe_hw *hw = &adapter->hw; |
| 2994 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2995 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2996 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2997 | u32 mrqc = 0, reta = 0; |
| 2998 | u32 rxcsum; |
| 2999 | int i, j; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3000 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3001 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3002 | /* |
| 3003 | * Program table for at least 2 queues w/ SR-IOV so that VFs can |
| 3004 | * make full use of any rings they may have. We will use the |
| 3005 | * PSRTYPE register to control how many rings we use within the PF. |
| 3006 | */ |
| 3007 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2)) |
| 3008 | rss_i = 2; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3009 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3010 | /* Fill out hash function seeds */ |
| 3011 | for (i = 0; i < 10; i++) |
| 3012 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3013 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3014 | /* Fill out redirection table */ |
| 3015 | for (i = 0, j = 0; i < 128; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3016 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3017 | j = 0; |
| 3018 | /* reta = 4-byte sliding window of |
| 3019 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 3020 | reta = (reta << 8) | (j * 0x11); |
| 3021 | if ((i & 3) == 3) |
| 3022 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3023 | } |
| 3024 | |
| 3025 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3026 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3027 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3028 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3029 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3030 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3031 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3032 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3033 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3034 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3035 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3036 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3037 | if (tcs > 4) |
| 3038 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3039 | else if (tcs > 1) |
| 3040 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
| 3041 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3042 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3043 | else |
| 3044 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
| 3045 | } else { |
| 3046 | if (tcs > 4) |
| 3047 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3048 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3049 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3050 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3051 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3052 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3053 | } |
| 3054 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3055 | /* Perform hash on these packet types */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3056 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3057 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3058 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3059 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3060 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3061 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
| 3062 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
| 3063 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
| 3064 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
| 3065 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3066 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3067 | } |
| 3068 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3069 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3070 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3071 | * @adapter: address of board private structure |
| 3072 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3073 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3074 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3075 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3076 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3077 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3078 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3079 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3080 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3081 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3082 | return; |
| 3083 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3084 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3085 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3086 | /* |
| 3087 | * we must limit the number of descriptors so that the |
| 3088 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3089 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3090 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3091 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3092 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3095 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3096 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3097 | struct ixgbe_ring *ring) |
| 3098 | { |
| 3099 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3100 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3101 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3102 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3103 | |
| 3104 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3105 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3106 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3107 | return; |
| 3108 | |
| 3109 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3110 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3111 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3112 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3113 | |
| 3114 | if (!wait_loop) { |
| 3115 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3116 | "the polling period\n", reg_idx); |
| 3117 | } |
| 3118 | } |
| 3119 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3120 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3121 | struct ixgbe_ring *ring) |
| 3122 | { |
| 3123 | struct ixgbe_hw *hw = &adapter->hw; |
| 3124 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3125 | u32 rxdctl; |
| 3126 | u8 reg_idx = ring->reg_idx; |
| 3127 | |
| 3128 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3129 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3130 | |
| 3131 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3132 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3133 | |
| 3134 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3135 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3136 | return; |
| 3137 | |
| 3138 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3139 | do { |
| 3140 | udelay(10); |
| 3141 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3142 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3143 | |
| 3144 | if (!wait_loop) { |
| 3145 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3146 | "the polling period\n", reg_idx); |
| 3147 | } |
| 3148 | } |
| 3149 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3150 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3151 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3152 | { |
| 3153 | struct ixgbe_hw *hw = &adapter->hw; |
| 3154 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3155 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3156 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3157 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3158 | /* disable queue to avoid issues while updating state */ |
| 3159 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3160 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3161 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3162 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3163 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3164 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3165 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 3166 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3167 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3168 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3169 | |
| 3170 | ixgbe_configure_srrctl(adapter, ring); |
| 3171 | ixgbe_configure_rscctl(adapter, ring); |
| 3172 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 3173 | /* If operating in IOV mode set RLPML for X540 */ |
| 3174 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 3175 | hw->mac.type == ixgbe_mac_X540) { |
| 3176 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 3177 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 3178 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 3179 | } |
| 3180 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3181 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3182 | /* |
| 3183 | * enable cache line friendly hardware writes: |
| 3184 | * PTHRESH=32 descriptors (half the internal cache), |
| 3185 | * this also removes ugly rx_no_buffer_count increment |
| 3186 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3187 | * WTHRESH=8 burst writeback up to two cache lines |
| 3188 | */ |
| 3189 | rxdctl &= ~0x3FFFFF; |
| 3190 | rxdctl |= 0x080420; |
| 3191 | } |
| 3192 | |
| 3193 | /* enable receive descriptor ring */ |
| 3194 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3195 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3196 | |
| 3197 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3198 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3199 | } |
| 3200 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3201 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3202 | { |
| 3203 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3204 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3205 | int p; |
| 3206 | |
| 3207 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3208 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3209 | IXGBE_PSRTYPE_UDPHDR | |
| 3210 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3211 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3212 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3213 | |
| 3214 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3215 | return; |
| 3216 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3217 | if (rss_i > 3) |
| 3218 | psrtype |= 2 << 29; |
| 3219 | else if (rss_i > 1) |
| 3220 | psrtype |= 1 << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3221 | |
| 3222 | for (p = 0; p < adapter->num_rx_pools; p++) |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3223 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)), |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3224 | psrtype); |
| 3225 | } |
| 3226 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3227 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3228 | { |
| 3229 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3230 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3231 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3232 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3233 | |
| 3234 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3235 | return; |
| 3236 | |
| 3237 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3238 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 3239 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3240 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3241 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 3242 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3243 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3244 | vf_shift = VMDQ_P(0) % 32; |
| 3245 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3246 | |
| 3247 | /* Enable only the PF's pool for Tx/Rx */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3248 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift); |
| 3249 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
| 3250 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift); |
| 3251 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3252 | |
| 3253 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3254 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3255 | |
| 3256 | /* |
| 3257 | * Set up VF register offsets for selected VT Mode, |
| 3258 | * i.e. 32 or 64 VFs for SR-IOV |
| 3259 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 3260 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 3261 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 3262 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 3263 | break; |
| 3264 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 3265 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 3266 | break; |
| 3267 | default: |
| 3268 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 3269 | break; |
| 3270 | } |
| 3271 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3272 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3273 | |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3274 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3275 | /* Enable MAC Anti-Spoofing */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3276 | hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3277 | adapter->num_vfs); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3278 | /* For VFs that have spoof checking turned off */ |
| 3279 | for (i = 0; i < adapter->num_vfs; i++) { |
| 3280 | if (!adapter->vfinfo[i].spoofchk_enabled) |
| 3281 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false); |
| 3282 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3283 | } |
| 3284 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3285 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3286 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3287 | struct ixgbe_hw *hw = &adapter->hw; |
| 3288 | struct net_device *netdev = adapter->netdev; |
| 3289 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3290 | struct ixgbe_ring *rx_ring; |
| 3291 | int i; |
| 3292 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3293 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3294 | #ifdef IXGBE_FCOE |
| 3295 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3296 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3297 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3298 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3299 | |
| 3300 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 3301 | |
| 3302 | /* adjust max frame to be at least the size of a standard frame */ |
| 3303 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 3304 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 3305 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3306 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3307 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3308 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3309 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3310 | |
| 3311 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3314 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3315 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3316 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3317 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3318 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3319 | /* |
| 3320 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3321 | * the Base and Length of the Rx Descriptor Ring |
| 3322 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3323 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3324 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3325 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3326 | set_ring_rsc_enabled(rx_ring); |
| 3327 | else |
| 3328 | clear_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3329 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3330 | } |
| 3331 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3332 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3333 | { |
| 3334 | struct ixgbe_hw *hw = &adapter->hw; |
| 3335 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3336 | |
| 3337 | switch (hw->mac.type) { |
| 3338 | case ixgbe_mac_82598EB: |
| 3339 | /* |
| 3340 | * For VMDq support of different descriptor types or |
| 3341 | * buffer sizes through the use of multiple SRRCTL |
| 3342 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3343 | * |
| 3344 | * also, the manual doesn't mention it clearly but DCA hints |
| 3345 | * will only use queue 0's tags unless this bit is set. Side |
| 3346 | * effects of setting this bit are only that SRRCTL must be |
| 3347 | * fully programmed [0..15] |
| 3348 | */ |
| 3349 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3350 | break; |
| 3351 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3352 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3353 | /* Disable RSC for ACK packets */ |
| 3354 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3355 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3356 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3357 | /* hardware requires some bits to be set by default */ |
| 3358 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3359 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3360 | break; |
| 3361 | default: |
| 3362 | /* We should do nothing since we don't know this hardware */ |
| 3363 | return; |
| 3364 | } |
| 3365 | |
| 3366 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3367 | } |
| 3368 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3369 | /** |
| 3370 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3371 | * @adapter: board private structure |
| 3372 | * |
| 3373 | * Configure the Rx unit of the MAC after a reset. |
| 3374 | **/ |
| 3375 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3376 | { |
| 3377 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3378 | int i; |
| 3379 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3380 | |
| 3381 | /* disable receives while setting up the descriptors */ |
| 3382 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3383 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3384 | |
| 3385 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3386 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3387 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3388 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3389 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3390 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3391 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3392 | ixgbe_set_rx_buffer_len(adapter); |
| 3393 | |
| 3394 | /* |
| 3395 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3396 | * the Base and Length of the Rx Descriptor Ring |
| 3397 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3398 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3399 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3400 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3401 | /* disable drop enable for 82598 parts */ |
| 3402 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3403 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3404 | |
| 3405 | /* enable all receives */ |
| 3406 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3407 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3410 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3411 | { |
| 3412 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3413 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3414 | |
| 3415 | /* add VID to filter table */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3416 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3417 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3418 | |
| 3419 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3422 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3423 | { |
| 3424 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3425 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3426 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3427 | /* remove VID from filter table */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3428 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3429 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3430 | |
| 3431 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3434 | /** |
| 3435 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3436 | * @adapter: driver data |
| 3437 | */ |
| 3438 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3439 | { |
| 3440 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3441 | u32 vlnctrl; |
| 3442 | |
| 3443 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3444 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3445 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3446 | } |
| 3447 | |
| 3448 | /** |
| 3449 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3450 | * @adapter: driver data |
| 3451 | */ |
| 3452 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3453 | { |
| 3454 | struct ixgbe_hw *hw = &adapter->hw; |
| 3455 | u32 vlnctrl; |
| 3456 | |
| 3457 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3458 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3459 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3460 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3461 | } |
| 3462 | |
| 3463 | /** |
| 3464 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3465 | * @adapter: driver data |
| 3466 | */ |
| 3467 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3468 | { |
| 3469 | struct ixgbe_hw *hw = &adapter->hw; |
| 3470 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3471 | int i, j; |
| 3472 | |
| 3473 | switch (hw->mac.type) { |
| 3474 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3475 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3476 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3477 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3478 | break; |
| 3479 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3480 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3481 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3482 | j = adapter->rx_ring[i]->reg_idx; |
| 3483 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3484 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3485 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3486 | } |
| 3487 | break; |
| 3488 | default: |
| 3489 | break; |
| 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3494 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3495 | * @adapter: driver data |
| 3496 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3497 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3498 | { |
| 3499 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3500 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3501 | int i, j; |
| 3502 | |
| 3503 | switch (hw->mac.type) { |
| 3504 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3505 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3506 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3507 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3508 | break; |
| 3509 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3510 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3511 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3512 | j = adapter->rx_ring[i]->reg_idx; |
| 3513 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3514 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3515 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3516 | } |
| 3517 | break; |
| 3518 | default: |
| 3519 | break; |
| 3520 | } |
| 3521 | } |
| 3522 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3523 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3524 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3525 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3526 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3527 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3528 | |
| 3529 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3530 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3534 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3535 | * @netdev: network interface device structure |
| 3536 | * |
| 3537 | * Writes unicast address list to the RAR table. |
| 3538 | * Returns: -ENOMEM on failure/insufficient address space |
| 3539 | * 0 on no addresses written |
| 3540 | * X on writing X addresses to the RAR table |
| 3541 | **/ |
| 3542 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3543 | { |
| 3544 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3545 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 3546 | unsigned int rar_entries = hw->mac.num_rar_entries - 1; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3547 | int count = 0; |
| 3548 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 3549 | /* In SR-IOV mode significantly less RAR entries are available */ |
| 3550 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3551 | rar_entries = IXGBE_MAX_PF_MACVLANS - 1; |
| 3552 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3553 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3554 | if (netdev_uc_count(netdev) > rar_entries) |
| 3555 | return -ENOMEM; |
| 3556 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 3557 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3558 | struct netdev_hw_addr *ha; |
| 3559 | /* return error if we do not support writing to RAR table */ |
| 3560 | if (!hw->mac.ops.set_rar) |
| 3561 | return -ENOMEM; |
| 3562 | |
| 3563 | netdev_for_each_uc_addr(ha, netdev) { |
| 3564 | if (!rar_entries) |
| 3565 | break; |
| 3566 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3567 | VMDQ_P(0), IXGBE_RAH_AV); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3568 | count++; |
| 3569 | } |
| 3570 | } |
| 3571 | /* write the addresses in reverse order to avoid write combining */ |
| 3572 | for (; rar_entries > 0 ; rar_entries--) |
| 3573 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3574 | |
| 3575 | return count; |
| 3576 | } |
| 3577 | |
| 3578 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3579 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3580 | * @netdev: network interface device structure |
| 3581 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3582 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3583 | * address list or the network interface flags are updated. This routine is |
| 3584 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3585 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3586 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3587 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3588 | { |
| 3589 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3590 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3591 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3592 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3593 | |
| 3594 | /* Check for Promiscuous and All Multicast modes */ |
| 3595 | |
| 3596 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3597 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3598 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3599 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3600 | fctrl |= IXGBE_FCTRL_BAM; |
| 3601 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3602 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3603 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3604 | /* clear the bits we are changing the status of */ |
| 3605 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3606 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3607 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3608 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3609 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3610 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3611 | /* don't hardware filter vlans in promisc mode */ |
| 3612 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3613 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3614 | if (netdev->flags & IFF_ALLMULTI) { |
| 3615 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3616 | vmolr |= IXGBE_VMOLR_MPE; |
| 3617 | } else { |
| 3618 | /* |
| 3619 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3620 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3621 | * that we can at least receive multicast traffic |
| 3622 | */ |
| 3623 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3624 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3625 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3626 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3627 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | /* |
| 3631 | * Write addresses to available RAR registers, if there is not |
| 3632 | * sufficient space to store all the addresses then enable |
| 3633 | * unicast promiscuous mode |
| 3634 | */ |
| 3635 | count = ixgbe_write_uc_addr_list(netdev); |
| 3636 | if (count < 0) { |
| 3637 | fctrl |= IXGBE_FCTRL_UPE; |
| 3638 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3639 | } |
| 3640 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3641 | if (adapter->num_vfs) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3642 | ixgbe_restore_vf_multicasts(adapter); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3643 | |
| 3644 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3645 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3646 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3647 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3648 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3651 | /* This is useful for sniffing bad packets. */ |
| 3652 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3653 | /* UPE and MPE will be handled by normal PROMISC logic |
| 3654 | * in e1000e_set_rx_mode */ |
| 3655 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 3656 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 3657 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 3658 | |
| 3659 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 3660 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 3661 | } |
| 3662 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3663 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3664 | |
| 3665 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3666 | ixgbe_vlan_strip_enable(adapter); |
| 3667 | else |
| 3668 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3669 | } |
| 3670 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3671 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3672 | { |
| 3673 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3674 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3675 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
| 3676 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3680 | { |
| 3681 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3682 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3683 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
| 3684 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3685 | } |
| 3686 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3687 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3688 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3689 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3690 | * @adapter: ixgbe adapter struct |
| 3691 | * |
| 3692 | * This is called by the driver on open to configure the DCB hardware. |
| 3693 | * This is also called by the gennetlink interface when reconfiguring |
| 3694 | * the DCB state. |
| 3695 | */ |
| 3696 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3697 | { |
| 3698 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3699 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3700 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3701 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3702 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3703 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3704 | return; |
| 3705 | } |
| 3706 | |
| 3707 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3708 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3709 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3710 | #ifdef IXGBE_FCOE |
| 3711 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3712 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3713 | #endif |
| 3714 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3715 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3716 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3717 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3718 | DCB_TX_CONFIG); |
| 3719 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3720 | DCB_RX_CONFIG); |
| 3721 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3722 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 3723 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 3724 | adapter->ixgbe_ieee_ets, |
| 3725 | max_frame); |
| 3726 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 3727 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 3728 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3729 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3730 | |
| 3731 | /* Enable RSS Hash per TC */ |
| 3732 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 3733 | u32 msb = 0; |
| 3734 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3735 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 3736 | while (rss_i) { |
| 3737 | msb++; |
| 3738 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3739 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 3740 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 3741 | /* write msb to all 8 TCs in one write */ |
| 3742 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3743 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3744 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3745 | #endif |
| 3746 | |
| 3747 | /* Additional bittime to account for IXGBE framing */ |
| 3748 | #define IXGBE_ETH_FRAMING 20 |
| 3749 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3750 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3751 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 3752 | * |
| 3753 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3754 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3755 | */ |
| 3756 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 3757 | { |
| 3758 | struct ixgbe_hw *hw = &adapter->hw; |
| 3759 | struct net_device *dev = adapter->netdev; |
| 3760 | int link, tc, kb, marker; |
| 3761 | u32 dv_id, rx_pba; |
| 3762 | |
| 3763 | /* Calculate max LAN frame size */ |
| 3764 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 3765 | |
| 3766 | #ifdef IXGBE_FCOE |
| 3767 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 3768 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 3769 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 3770 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 3771 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3772 | |
| 3773 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3774 | /* Calculate delay value for device */ |
| 3775 | switch (hw->mac.type) { |
| 3776 | case ixgbe_mac_X540: |
| 3777 | dv_id = IXGBE_DV_X540(link, tc); |
| 3778 | break; |
| 3779 | default: |
| 3780 | dv_id = IXGBE_DV(link, tc); |
| 3781 | break; |
| 3782 | } |
| 3783 | |
| 3784 | /* Loopback switch introduces additional latency */ |
| 3785 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3786 | dv_id += IXGBE_B2BT(tc); |
| 3787 | |
| 3788 | /* Delay value is calculated in bit times convert to KB */ |
| 3789 | kb = IXGBE_BT2KB(dv_id); |
| 3790 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 3791 | |
| 3792 | marker = rx_pba - kb; |
| 3793 | |
| 3794 | /* It is possible that the packet buffer is not large enough |
| 3795 | * to provide required headroom. In this case throw an error |
| 3796 | * to user and a do the best we can. |
| 3797 | */ |
| 3798 | if (marker < 0) { |
| 3799 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 3800 | "headroom to support flow control." |
| 3801 | "Decrease MTU or number of traffic classes\n", pb); |
| 3802 | marker = tc + 1; |
| 3803 | } |
| 3804 | |
| 3805 | return marker; |
| 3806 | } |
| 3807 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3808 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3809 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 3810 | * |
| 3811 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3812 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3813 | */ |
| 3814 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter) |
| 3815 | { |
| 3816 | struct ixgbe_hw *hw = &adapter->hw; |
| 3817 | struct net_device *dev = adapter->netdev; |
| 3818 | int tc; |
| 3819 | u32 dv_id; |
| 3820 | |
| 3821 | /* Calculate max LAN frame size */ |
| 3822 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3823 | |
| 3824 | /* Calculate delay value for device */ |
| 3825 | switch (hw->mac.type) { |
| 3826 | case ixgbe_mac_X540: |
| 3827 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 3828 | break; |
| 3829 | default: |
| 3830 | dv_id = IXGBE_LOW_DV(tc); |
| 3831 | break; |
| 3832 | } |
| 3833 | |
| 3834 | /* Delay value is calculated in bit times convert to KB */ |
| 3835 | return IXGBE_BT2KB(dv_id); |
| 3836 | } |
| 3837 | |
| 3838 | /* |
| 3839 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 3840 | */ |
| 3841 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 3842 | { |
| 3843 | struct ixgbe_hw *hw = &adapter->hw; |
| 3844 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3845 | int i; |
| 3846 | |
| 3847 | if (!num_tc) |
| 3848 | num_tc = 1; |
| 3849 | |
| 3850 | hw->fc.low_water = ixgbe_lpbthresh(adapter); |
| 3851 | |
| 3852 | for (i = 0; i < num_tc; i++) { |
| 3853 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
| 3854 | |
| 3855 | /* Low water marks must not be larger than high water marks */ |
| 3856 | if (hw->fc.low_water > hw->fc.high_water[i]) |
| 3857 | hw->fc.low_water = 0; |
| 3858 | } |
| 3859 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3860 | |
| 3861 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3862 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3863 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3864 | int hdrm; |
| 3865 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3866 | |
| 3867 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3868 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3869 | hdrm = 32 << adapter->fdir_pballoc; |
| 3870 | else |
| 3871 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3872 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3873 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3874 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3875 | } |
| 3876 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3877 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 3878 | { |
| 3879 | struct ixgbe_hw *hw = &adapter->hw; |
| 3880 | struct hlist_node *node, *node2; |
| 3881 | struct ixgbe_fdir_filter *filter; |
| 3882 | |
| 3883 | spin_lock(&adapter->fdir_perfect_lock); |
| 3884 | |
| 3885 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 3886 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 3887 | |
| 3888 | hlist_for_each_entry_safe(filter, node, node2, |
| 3889 | &adapter->fdir_filter_list, fdir_node) { |
| 3890 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 3891 | &filter->filter, |
| 3892 | filter->sw_idx, |
| 3893 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 3894 | IXGBE_FDIR_DROP_QUEUE : |
| 3895 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | spin_unlock(&adapter->fdir_perfect_lock); |
| 3899 | } |
| 3900 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3901 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3902 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3903 | struct ixgbe_hw *hw = &adapter->hw; |
| 3904 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3905 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3906 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3907 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3908 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 3909 | /* |
| 3910 | * We must restore virtualization before VLANs or else |
| 3911 | * the VLVF registers will not be populated |
| 3912 | */ |
| 3913 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3914 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3915 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3916 | ixgbe_restore_vlan(adapter); |
| 3917 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3918 | switch (hw->mac.type) { |
| 3919 | case ixgbe_mac_82599EB: |
| 3920 | case ixgbe_mac_X540: |
| 3921 | hw->mac.ops.disable_rx_buff(hw); |
| 3922 | break; |
| 3923 | default: |
| 3924 | break; |
| 3925 | } |
| 3926 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3927 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3928 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 3929 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3930 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3931 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 3932 | adapter->fdir_pballoc); |
| 3933 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3934 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3935 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3936 | switch (hw->mac.type) { |
| 3937 | case ixgbe_mac_82599EB: |
| 3938 | case ixgbe_mac_X540: |
| 3939 | hw->mac.ops.enable_rx_buff(hw); |
| 3940 | break; |
| 3941 | default: |
| 3942 | break; |
| 3943 | } |
| 3944 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 3945 | #ifdef IXGBE_FCOE |
| 3946 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 3947 | ixgbe_configure_fcoe(adapter); |
| 3948 | |
| 3949 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3950 | ixgbe_configure_tx(adapter); |
| 3951 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3952 | } |
| 3953 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3954 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3955 | { |
| 3956 | switch (hw->phy.type) { |
| 3957 | case ixgbe_phy_sfp_avago: |
| 3958 | case ixgbe_phy_sfp_ftl: |
| 3959 | case ixgbe_phy_sfp_intel: |
| 3960 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3961 | case ixgbe_phy_sfp_passive_tyco: |
| 3962 | case ixgbe_phy_sfp_passive_unknown: |
| 3963 | case ixgbe_phy_sfp_active_unknown: |
| 3964 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3965 | return true; |
Alexander Duyck | 8917b44 | 2011-07-21 00:40:51 +0000 | [diff] [blame] | 3966 | case ixgbe_phy_nl: |
| 3967 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3968 | return true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3969 | default: |
| 3970 | return false; |
| 3971 | } |
| 3972 | } |
| 3973 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3974 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3975 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3976 | * @adapter: pointer to private adapter struct |
| 3977 | **/ |
| 3978 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3979 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3980 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3981 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3982 | * is that an SFP was inserted/removed after the reset |
| 3983 | * but before SFP detection was enabled. As such the best |
| 3984 | * solution is to just start searching as soon as we start |
| 3985 | */ |
| 3986 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3987 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3988 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3989 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | /** |
| 3993 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3994 | * @hw: pointer to private hardware struct |
| 3995 | * |
| 3996 | * Returns 0 on success, negative on failure |
| 3997 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3998 | static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw) |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3999 | { |
| 4000 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4001 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4002 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 4003 | |
| 4004 | if (hw->mac.ops.check_link) |
| 4005 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 4006 | |
| 4007 | if (ret) |
| 4008 | goto link_cfg_out; |
| 4009 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 4010 | autoneg = hw->phy.autoneg_advertised; |
| 4011 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4012 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 4013 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4014 | if (ret) |
| 4015 | goto link_cfg_out; |
| 4016 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4017 | if (hw->mac.ops.setup_link) |
| 4018 | ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4019 | link_cfg_out: |
| 4020 | return ret; |
| 4021 | } |
| 4022 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4023 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4024 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4025 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4026 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4027 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4028 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4029 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 4030 | IXGBE_GPIE_OCD; |
| 4031 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4032 | /* |
| 4033 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 4034 | * this saves a register write for every interrupt |
| 4035 | */ |
| 4036 | switch (hw->mac.type) { |
| 4037 | case ixgbe_mac_82598EB: |
| 4038 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 4039 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4040 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4041 | case ixgbe_mac_X540: |
| 4042 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4043 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 4044 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 4045 | break; |
| 4046 | } |
| 4047 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4048 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 4049 | * specifically only auto mask tx and rx interrupts */ |
| 4050 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4053 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 4054 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 4055 | |
| 4056 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 4057 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 4058 | |
| 4059 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 4060 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 4061 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 4062 | break; |
| 4063 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 4064 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 4065 | break; |
| 4066 | default: |
| 4067 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 4068 | break; |
| 4069 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 4072 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 4073 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 4074 | switch (adapter->hw.mac.type) { |
| 4075 | case ixgbe_mac_82599EB: |
| 4076 | gpie |= IXGBE_SDP0_GPIEN; |
| 4077 | break; |
| 4078 | case ixgbe_mac_X540: |
| 4079 | gpie |= IXGBE_EIMS_TS; |
| 4080 | break; |
| 4081 | default: |
| 4082 | break; |
| 4083 | } |
| 4084 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 4085 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4086 | /* Enable fan failure interrupt */ |
| 4087 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 4088 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 4089 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 4090 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4091 | gpie |= IXGBE_SDP1_GPIEN; |
| 4092 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 4093 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4094 | |
| 4095 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 4096 | } |
| 4097 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4098 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4099 | { |
| 4100 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4101 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4102 | u32 ctrl_ext; |
| 4103 | |
| 4104 | ixgbe_get_hw_control(adapter); |
| 4105 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4106 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4107 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4108 | ixgbe_configure_msix(adapter); |
| 4109 | else |
| 4110 | ixgbe_configure_msi_and_legacy(adapter); |
| 4111 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 4112 | /* enable the optics for 82599 SFP+ fiber */ |
| 4113 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 4114 | hw->mac.ops.enable_tx_laser(hw); |
| 4115 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4116 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4117 | ixgbe_napi_enable_all(adapter); |
| 4118 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 4119 | if (ixgbe_is_sfp(hw)) { |
| 4120 | ixgbe_sfp_link_config(adapter); |
| 4121 | } else { |
| 4122 | err = ixgbe_non_sfp_link_config(hw); |
| 4123 | if (err) |
| 4124 | e_err(probe, "link_config FAILED %d\n", err); |
| 4125 | } |
| 4126 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4127 | /* clear any pending interrupts, may auto mask */ |
| 4128 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 4129 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4130 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4131 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4132 | * If this adapter has a fan, check to see if we had a failure |
| 4133 | * before we enabled the interrupt. |
| 4134 | */ |
| 4135 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 4136 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 4137 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 4138 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4139 | } |
| 4140 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 4141 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4142 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 4143 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4144 | /* bring the link up in the watchdog, this could race with our first |
| 4145 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4146 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4147 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4148 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 4149 | |
| 4150 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 4151 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 4152 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 4153 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4154 | } |
| 4155 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4156 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 4157 | { |
| 4158 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4159 | /* put off any impending NetWatchDogTimeout */ |
| 4160 | adapter->netdev->trans_start = jiffies; |
| 4161 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4162 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4163 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4164 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 4165 | /* |
| 4166 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 4167 | * back up to give the VFs time to respond to the reset. The |
| 4168 | * two second wait is based upon the watchdog timer cycle in |
| 4169 | * the VF driver. |
| 4170 | */ |
| 4171 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4172 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4173 | ixgbe_up(adapter); |
| 4174 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 4175 | } |
| 4176 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4177 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4178 | { |
| 4179 | /* hardware has been reset, we need to reload some things */ |
| 4180 | ixgbe_configure(adapter); |
| 4181 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4182 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 4186 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4187 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4188 | int err; |
| 4189 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4190 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 4191 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 4192 | usleep_range(1000, 2000); |
| 4193 | |
| 4194 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 4195 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 4196 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 4197 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 4198 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4199 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4200 | switch (err) { |
| 4201 | case 0: |
| 4202 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4203 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4204 | break; |
| 4205 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4206 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4207 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4208 | case IXGBE_ERR_EEPROM_VERSION: |
| 4209 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4210 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 4211 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4212 | "your hardware. If you are experiencing problems " |
| 4213 | "please contact your Intel or hardware " |
| 4214 | "representative who provided you with this " |
| 4215 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4216 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4217 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4218 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4219 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4220 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4221 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 4222 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4223 | /* reprogram the RAR[0] in case user changed it. */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4224 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 4225 | |
| 4226 | /* update SAN MAC vmdq pool selection */ |
| 4227 | if (hw->mac.san_mac_rar_index) |
| 4228 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4229 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4230 | if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) |
| 4231 | ixgbe_ptp_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4234 | /** |
| 4235 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4236 | * @rx_ring: ring to free buffers from |
| 4237 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4238 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4239 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4240 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4241 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4242 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4243 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4244 | /* ring already cleared, nothing to do */ |
| 4245 | if (!rx_ring->rx_buffer_info) |
| 4246 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4247 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4248 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4249 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4250 | struct ixgbe_rx_buffer *rx_buffer; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4251 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4252 | rx_buffer = &rx_ring->rx_buffer_info[i]; |
| 4253 | if (rx_buffer->skb) { |
| 4254 | struct sk_buff *skb = rx_buffer->skb; |
| 4255 | if (IXGBE_CB(skb)->page_released) { |
| 4256 | dma_unmap_page(dev, |
| 4257 | IXGBE_CB(skb)->dma, |
| 4258 | ixgbe_rx_bufsz(rx_ring), |
| 4259 | DMA_FROM_DEVICE); |
| 4260 | IXGBE_CB(skb)->page_released = false; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 4261 | } |
| 4262 | dev_kfree_skb(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4263 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4264 | rx_buffer->skb = NULL; |
| 4265 | if (rx_buffer->dma) |
| 4266 | dma_unmap_page(dev, rx_buffer->dma, |
| 4267 | ixgbe_rx_pg_size(rx_ring), |
| 4268 | DMA_FROM_DEVICE); |
| 4269 | rx_buffer->dma = 0; |
| 4270 | if (rx_buffer->page) |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 4271 | __free_pages(rx_buffer->page, |
| 4272 | ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4273 | rx_buffer->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4277 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4278 | |
| 4279 | /* Zero out the descriptor ring */ |
| 4280 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4281 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4282 | rx_ring->next_to_alloc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4283 | rx_ring->next_to_clean = 0; |
| 4284 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | /** |
| 4288 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4289 | * @tx_ring: ring to be cleaned |
| 4290 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4291 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4292 | { |
| 4293 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4294 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4295 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4296 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4297 | /* ring already cleared, nothing to do */ |
| 4298 | if (!tx_ring->tx_buffer_info) |
| 4299 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4300 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4301 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4302 | for (i = 0; i < tx_ring->count; i++) { |
| 4303 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4304 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 4307 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 4308 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4309 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4310 | memset(tx_ring->tx_buffer_info, 0, size); |
| 4311 | |
| 4312 | /* Zero out the descriptor ring */ |
| 4313 | memset(tx_ring->desc, 0, tx_ring->size); |
| 4314 | |
| 4315 | tx_ring->next_to_use = 0; |
| 4316 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4320 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4321 | * @adapter: board private structure |
| 4322 | **/ |
| 4323 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4324 | { |
| 4325 | int i; |
| 4326 | |
| 4327 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4328 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4329 | } |
| 4330 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4331 | /** |
| 4332 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4333 | * @adapter: board private structure |
| 4334 | **/ |
| 4335 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4336 | { |
| 4337 | int i; |
| 4338 | |
| 4339 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4340 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4343 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4344 | { |
| 4345 | struct hlist_node *node, *node2; |
| 4346 | struct ixgbe_fdir_filter *filter; |
| 4347 | |
| 4348 | spin_lock(&adapter->fdir_perfect_lock); |
| 4349 | |
| 4350 | hlist_for_each_entry_safe(filter, node, node2, |
| 4351 | &adapter->fdir_filter_list, fdir_node) { |
| 4352 | hlist_del(&filter->fdir_node); |
| 4353 | kfree(filter); |
| 4354 | } |
| 4355 | adapter->fdir_filter_count = 0; |
| 4356 | |
| 4357 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4358 | } |
| 4359 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4360 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4361 | { |
| 4362 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4363 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4364 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4365 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4366 | |
| 4367 | /* signal that we are down to the interrupt handler */ |
| 4368 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4369 | |
| 4370 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4371 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4372 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4373 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4374 | /* disable all enabled rx queues */ |
| 4375 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4376 | /* this call also flushes the previous write */ |
| 4377 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4378 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4379 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4380 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4381 | netif_tx_stop_all_queues(netdev); |
| 4382 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4383 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4384 | netif_carrier_off(netdev); |
| 4385 | netif_tx_disable(netdev); |
| 4386 | |
| 4387 | ixgbe_irq_disable(adapter); |
| 4388 | |
| 4389 | ixgbe_napi_disable_all(adapter); |
| 4390 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4391 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4392 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4393 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4394 | |
| 4395 | del_timer_sync(&adapter->service_timer); |
| 4396 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4397 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4398 | /* Clear EITR Select mapping */ |
| 4399 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 4400 | |
| 4401 | /* Mark all the VFs as inactive */ |
| 4402 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4403 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4404 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4405 | /* ping all the active vfs to let them know we are going down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4406 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4407 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4408 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4409 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4412 | /* disable transmits in the hardware now that interrupts are off */ |
| 4413 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4414 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4415 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4416 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4417 | |
| 4418 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4419 | switch (hw->mac.type) { |
| 4420 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4421 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4422 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4423 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4424 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4425 | break; |
| 4426 | default: |
| 4427 | break; |
| 4428 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4429 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4430 | if (!pci_channel_offline(adapter->pdev)) |
| 4431 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4432 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 4433 | /* power down the optics for 82599 SFP+ fiber */ |
| 4434 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4435 | hw->mac.ops.disable_tx_laser(hw); |
| 4436 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4437 | ixgbe_clean_all_tx_rings(adapter); |
| 4438 | ixgbe_clean_all_rx_rings(adapter); |
| 4439 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4440 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4441 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4442 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4443 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4446 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4447 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4448 | * @netdev: network interface device structure |
| 4449 | **/ |
| 4450 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4451 | { |
| 4452 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4453 | |
| 4454 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4455 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4456 | } |
| 4457 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4458 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4459 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 4460 | * @adapter: board private structure to initialize |
| 4461 | * |
| 4462 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 4463 | * Fields are initialized based on PCI device information and |
| 4464 | * OS network device settings (MTU size). |
| 4465 | **/ |
| 4466 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 4467 | { |
| 4468 | struct ixgbe_hw *hw = &adapter->hw; |
| 4469 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4470 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4471 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4472 | int j; |
| 4473 | struct tc_configuration *tc; |
| 4474 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4475 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4476 | /* PCI config space info */ |
| 4477 | |
| 4478 | hw->vendor_id = pdev->vendor; |
| 4479 | hw->device_id = pdev->device; |
| 4480 | hw->revision_id = pdev->revision; |
| 4481 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 4482 | hw->subsystem_device_id = pdev->subsystem_device; |
| 4483 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4484 | /* Set capability flags */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4485 | rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 4486 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4487 | switch (hw->mac.type) { |
| 4488 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4489 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 4490 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4491 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4492 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4493 | case ixgbe_mac_X540: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 4494 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 4495 | case ixgbe_mac_82599EB: |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4496 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 4497 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 4498 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 4499 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 4500 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4501 | /* Flow Director hash filters enabled */ |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4502 | adapter->atr_sample_rate = 20; |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 4503 | adapter->ring_feature[RING_F_FDIR].limit = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4504 | IXGBE_MAX_FDIR_INDICES; |
Alexander Duyck | c04f6ca | 2011-05-11 07:18:36 +0000 | [diff] [blame] | 4505 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4506 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 4507 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 4508 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 4509 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 4510 | /* Default traffic class to use for FCoE */ |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 4511 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 4512 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4513 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4514 | break; |
| 4515 | default: |
| 4516 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4517 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4518 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 4519 | #ifdef IXGBE_FCOE |
| 4520 | /* FCoE support exists, always init the FCoE lock */ |
| 4521 | spin_lock_init(&adapter->fcoe.lock); |
| 4522 | |
| 4523 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 4524 | /* n-tuple support exists, always init our spinlock */ |
| 4525 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 4526 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4527 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 4528 | switch (hw->mac.type) { |
| 4529 | case ixgbe_mac_X540: |
| 4530 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 4531 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 4532 | break; |
| 4533 | default: |
| 4534 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 4535 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 4536 | break; |
| 4537 | } |
| 4538 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4539 | /* Configure DCB traffic classes */ |
| 4540 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 4541 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 4542 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 4543 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 4544 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 4545 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 4546 | tc->dcb_pfc = pfc_disabled; |
| 4547 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 4548 | |
| 4549 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 4550 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 4551 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 4552 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 4553 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4554 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 4555 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4556 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4557 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 4558 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
John Fastabend | f525c6d2 | 2012-04-18 22:42:27 +0000 | [diff] [blame] | 4559 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 4560 | sizeof(adapter->temp_dcb_cfg)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4561 | |
| 4562 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4563 | |
| 4564 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 4565 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4566 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4567 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 4568 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 4569 | hw->fc.send_xon = true; |
Jacob Keller | db2adc2 | 2012-10-24 07:26:02 +0000 | [diff] [blame^] | 4570 | hw->fc.disable_fc_autoneg = |
| 4571 | (ixgbe_device_supports_autoneg_fc(hw) == 0) ? false : true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4572 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 4573 | #ifdef CONFIG_PCI_IOV |
| 4574 | /* assign number of SR-IOV VFs */ |
| 4575 | if (hw->mac.type != ixgbe_mac_82598EB) |
| 4576 | adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs; |
| 4577 | |
| 4578 | #endif |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4579 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4580 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4581 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4582 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4583 | /* set default ring sizes */ |
| 4584 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 4585 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 4586 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 4587 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 4588 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 4589 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4590 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4591 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4592 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4593 | return -EIO; |
| 4594 | } |
| 4595 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4596 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4597 | |
| 4598 | return 0; |
| 4599 | } |
| 4600 | |
| 4601 | /** |
| 4602 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4603 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4604 | * |
| 4605 | * Return 0 on success, negative on failure |
| 4606 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4607 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4608 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4609 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4610 | int orig_node = dev_to_node(dev); |
| 4611 | int numa_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4612 | int size; |
| 4613 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4614 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4615 | |
| 4616 | if (tx_ring->q_vector) |
| 4617 | numa_node = tx_ring->q_vector->numa_node; |
| 4618 | |
| 4619 | tx_ring->tx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4620 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 4621 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4622 | if (!tx_ring->tx_buffer_info) |
| 4623 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4624 | |
| 4625 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 4626 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4627 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4628 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4629 | set_dev_node(dev, numa_node); |
| 4630 | tx_ring->desc = dma_alloc_coherent(dev, |
| 4631 | tx_ring->size, |
| 4632 | &tx_ring->dma, |
| 4633 | GFP_KERNEL); |
| 4634 | set_dev_node(dev, orig_node); |
| 4635 | if (!tx_ring->desc) |
| 4636 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 4637 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4638 | if (!tx_ring->desc) |
| 4639 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4640 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4641 | tx_ring->next_to_use = 0; |
| 4642 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4643 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4644 | |
| 4645 | err: |
| 4646 | vfree(tx_ring->tx_buffer_info); |
| 4647 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4648 | dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n"); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4649 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4653 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 4654 | * @adapter: board private structure |
| 4655 | * |
| 4656 | * If this function returns with an error, then it's possible one or |
| 4657 | * more of the rings is populated (while the rest are not). It is the |
| 4658 | * callers duty to clean those orphaned rings. |
| 4659 | * |
| 4660 | * Return 0 on success, negative on failure |
| 4661 | **/ |
| 4662 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4663 | { |
| 4664 | int i, err = 0; |
| 4665 | |
| 4666 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4667 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4668 | if (!err) |
| 4669 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 4670 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 4671 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 4672 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 4675 | return 0; |
| 4676 | err_setup_tx: |
| 4677 | /* rewind the index freeing the rings as we go */ |
| 4678 | while (i--) |
| 4679 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4680 | return err; |
| 4681 | } |
| 4682 | |
| 4683 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4684 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4685 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4686 | * |
| 4687 | * Returns 0 on success, negative on failure |
| 4688 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4689 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4690 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4691 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4692 | int orig_node = dev_to_node(dev); |
| 4693 | int numa_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4694 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4695 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4696 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4697 | |
| 4698 | if (rx_ring->q_vector) |
| 4699 | numa_node = rx_ring->q_vector->numa_node; |
| 4700 | |
| 4701 | rx_ring->rx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4702 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 4703 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4704 | if (!rx_ring->rx_buffer_info) |
| 4705 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4706 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4707 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4708 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 4709 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4710 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4711 | set_dev_node(dev, numa_node); |
| 4712 | rx_ring->desc = dma_alloc_coherent(dev, |
| 4713 | rx_ring->size, |
| 4714 | &rx_ring->dma, |
| 4715 | GFP_KERNEL); |
| 4716 | set_dev_node(dev, orig_node); |
| 4717 | if (!rx_ring->desc) |
| 4718 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 4719 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4720 | if (!rx_ring->desc) |
| 4721 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4722 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4723 | rx_ring->next_to_clean = 0; |
| 4724 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4725 | |
| 4726 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4727 | err: |
| 4728 | vfree(rx_ring->rx_buffer_info); |
| 4729 | rx_ring->rx_buffer_info = NULL; |
| 4730 | dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4731 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4735 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 4736 | * @adapter: board private structure |
| 4737 | * |
| 4738 | * If this function returns with an error, then it's possible one or |
| 4739 | * more of the rings is populated (while the rest are not). It is the |
| 4740 | * callers duty to clean those orphaned rings. |
| 4741 | * |
| 4742 | * Return 0 on success, negative on failure |
| 4743 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4744 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4745 | { |
| 4746 | int i, err = 0; |
| 4747 | |
| 4748 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4749 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4750 | if (!err) |
| 4751 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 4752 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 4753 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 4754 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 4757 | #ifdef IXGBE_FCOE |
| 4758 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 4759 | if (!err) |
| 4760 | #endif |
| 4761 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 4762 | err_setup_rx: |
| 4763 | /* rewind the index freeing the rings as we go */ |
| 4764 | while (i--) |
| 4765 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4766 | return err; |
| 4767 | } |
| 4768 | |
| 4769 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4770 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4771 | * @tx_ring: Tx descriptor ring for a specific queue |
| 4772 | * |
| 4773 | * Free all transmit software resources |
| 4774 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4775 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4776 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4777 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4778 | |
| 4779 | vfree(tx_ring->tx_buffer_info); |
| 4780 | tx_ring->tx_buffer_info = NULL; |
| 4781 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4782 | /* if not set, then don't free */ |
| 4783 | if (!tx_ring->desc) |
| 4784 | return; |
| 4785 | |
| 4786 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 4787 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4788 | |
| 4789 | tx_ring->desc = NULL; |
| 4790 | } |
| 4791 | |
| 4792 | /** |
| 4793 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 4794 | * @adapter: board private structure |
| 4795 | * |
| 4796 | * Free all transmit software resources |
| 4797 | **/ |
| 4798 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4799 | { |
| 4800 | int i; |
| 4801 | |
| 4802 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4803 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4804 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4808 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4809 | * @rx_ring: ring to clean the resources from |
| 4810 | * |
| 4811 | * Free all receive software resources |
| 4812 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4813 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4814 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4815 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4816 | |
| 4817 | vfree(rx_ring->rx_buffer_info); |
| 4818 | rx_ring->rx_buffer_info = NULL; |
| 4819 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4820 | /* if not set, then don't free */ |
| 4821 | if (!rx_ring->desc) |
| 4822 | return; |
| 4823 | |
| 4824 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 4825 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4826 | |
| 4827 | rx_ring->desc = NULL; |
| 4828 | } |
| 4829 | |
| 4830 | /** |
| 4831 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4832 | * @adapter: board private structure |
| 4833 | * |
| 4834 | * Free all receive software resources |
| 4835 | **/ |
| 4836 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4837 | { |
| 4838 | int i; |
| 4839 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 4840 | #ifdef IXGBE_FCOE |
| 4841 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 4842 | |
| 4843 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4844 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4845 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4846 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4850 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4851 | * @netdev: network interface device structure |
| 4852 | * @new_mtu: new value for maximum frame size |
| 4853 | * |
| 4854 | * Returns 0 on success, negative on failure |
| 4855 | **/ |
| 4856 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4857 | { |
| 4858 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4859 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4860 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4861 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 4862 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 4863 | return -EINVAL; |
| 4864 | |
| 4865 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 4866 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 4867 | * paths when MTU greater than 1500 is configured. So display a |
| 4868 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 4869 | */ |
| 4870 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 4871 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
| 4872 | (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 4873 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4874 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 4875 | e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 4876 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4877 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4878 | netdev->mtu = new_mtu; |
| 4879 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4880 | if (netif_running(netdev)) |
| 4881 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4882 | |
| 4883 | return 0; |
| 4884 | } |
| 4885 | |
| 4886 | /** |
| 4887 | * ixgbe_open - Called when a network interface is made active |
| 4888 | * @netdev: network interface device structure |
| 4889 | * |
| 4890 | * Returns 0 on success, negative value on failure |
| 4891 | * |
| 4892 | * The open entry point is called when a network interface is made |
| 4893 | * active by the system (IFF_UP). At this point all resources needed |
| 4894 | * for transmit and receive operations are allocated, the interrupt |
| 4895 | * handler is registered with the OS, the watchdog timer is started, |
| 4896 | * and the stack is notified that the interface is ready. |
| 4897 | **/ |
| 4898 | static int ixgbe_open(struct net_device *netdev) |
| 4899 | { |
| 4900 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4901 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4902 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4903 | /* disallow open during test */ |
| 4904 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4905 | return -EBUSY; |
| 4906 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4907 | netif_carrier_off(netdev); |
| 4908 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4909 | /* allocate transmit descriptors */ |
| 4910 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4911 | if (err) |
| 4912 | goto err_setup_tx; |
| 4913 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4914 | /* allocate receive descriptors */ |
| 4915 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4916 | if (err) |
| 4917 | goto err_setup_rx; |
| 4918 | |
| 4919 | ixgbe_configure(adapter); |
| 4920 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4921 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4922 | if (err) |
| 4923 | goto err_req_irq; |
| 4924 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 4925 | /* Notify the stack of the actual queue counts. */ |
| 4926 | err = netif_set_real_num_tx_queues(netdev, |
| 4927 | adapter->num_rx_pools > 1 ? 1 : |
| 4928 | adapter->num_tx_queues); |
| 4929 | if (err) |
| 4930 | goto err_set_queues; |
| 4931 | |
| 4932 | |
| 4933 | err = netif_set_real_num_rx_queues(netdev, |
| 4934 | adapter->num_rx_pools > 1 ? 1 : |
| 4935 | adapter->num_rx_queues); |
| 4936 | if (err) |
| 4937 | goto err_set_queues; |
| 4938 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4939 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4940 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4941 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4942 | |
| 4943 | return 0; |
| 4944 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 4945 | err_set_queues: |
| 4946 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4947 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4948 | ixgbe_free_all_rx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 4949 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4950 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 4951 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4952 | ixgbe_reset(adapter); |
| 4953 | |
| 4954 | return err; |
| 4955 | } |
| 4956 | |
| 4957 | /** |
| 4958 | * ixgbe_close - Disables a network interface |
| 4959 | * @netdev: network interface device structure |
| 4960 | * |
| 4961 | * Returns 0, this is not allowed to fail |
| 4962 | * |
| 4963 | * The close entry point is called when an interface is de-activated |
| 4964 | * by the OS. The hardware is still under the drivers control, but |
| 4965 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4966 | * hardware, and all transmit and receive resources are freed. |
| 4967 | **/ |
| 4968 | static int ixgbe_close(struct net_device *netdev) |
| 4969 | { |
| 4970 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4971 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4972 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4973 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4974 | ixgbe_down(adapter); |
| 4975 | ixgbe_free_irq(adapter); |
| 4976 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4977 | ixgbe_fdir_filter_exit(adapter); |
| 4978 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4979 | ixgbe_free_all_tx_resources(adapter); |
| 4980 | ixgbe_free_all_rx_resources(adapter); |
| 4981 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4982 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4983 | |
| 4984 | return 0; |
| 4985 | } |
| 4986 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4987 | #ifdef CONFIG_PM |
| 4988 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4989 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 4990 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 4991 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4992 | u32 err; |
| 4993 | |
| 4994 | pci_set_power_state(pdev, PCI_D0); |
| 4995 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 4996 | /* |
| 4997 | * pci_restore_state clears dev->state_saved so call |
| 4998 | * pci_save_state to restore it. |
| 4999 | */ |
| 5000 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5001 | |
| 5002 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5003 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5004 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5005 | return err; |
| 5006 | } |
| 5007 | pci_set_master(pdev); |
| 5008 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5009 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5010 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5011 | ixgbe_reset(adapter); |
| 5012 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5013 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5014 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5015 | rtnl_lock(); |
| 5016 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5017 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5018 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5019 | |
| 5020 | rtnl_unlock(); |
| 5021 | |
| 5022 | if (err) |
| 5023 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5024 | |
| 5025 | netif_device_attach(netdev); |
| 5026 | |
| 5027 | return 0; |
| 5028 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5029 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5030 | |
| 5031 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5032 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5033 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5034 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5035 | struct ixgbe_hw *hw = &adapter->hw; |
| 5036 | u32 ctrl, fctrl; |
| 5037 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5038 | #ifdef CONFIG_PM |
| 5039 | int retval = 0; |
| 5040 | #endif |
| 5041 | |
| 5042 | netif_device_detach(netdev); |
| 5043 | |
| 5044 | if (netif_running(netdev)) { |
Don Skidmore | ab6039a | 2012-03-17 05:51:52 +0000 | [diff] [blame] | 5045 | rtnl_lock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5046 | ixgbe_down(adapter); |
| 5047 | ixgbe_free_irq(adapter); |
| 5048 | ixgbe_free_all_tx_resources(adapter); |
| 5049 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | ab6039a | 2012-03-17 05:51:52 +0000 | [diff] [blame] | 5050 | rtnl_unlock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5051 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5052 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5053 | ixgbe_clear_interrupt_scheme(adapter); |
| 5054 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5055 | #ifdef CONFIG_PM |
| 5056 | retval = pci_save_state(pdev); |
| 5057 | if (retval) |
| 5058 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5059 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5060 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5061 | if (wufc) { |
| 5062 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5063 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5064 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 5065 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 5066 | hw->mac.ops.enable_tx_laser(hw); |
| 5067 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5068 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5069 | if (wufc & IXGBE_WUFC_MC) { |
| 5070 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5071 | fctrl |= IXGBE_FCTRL_MPE; |
| 5072 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5073 | } |
| 5074 | |
| 5075 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5076 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5077 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5078 | |
| 5079 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5080 | } else { |
| 5081 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5082 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5083 | } |
| 5084 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5085 | switch (hw->mac.type) { |
| 5086 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5087 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5088 | break; |
| 5089 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5090 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5091 | pci_wake_from_d3(pdev, !!wufc); |
| 5092 | break; |
| 5093 | default: |
| 5094 | break; |
| 5095 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5096 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5097 | *enable_wake = !!wufc; |
| 5098 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5099 | ixgbe_release_hw_control(adapter); |
| 5100 | |
| 5101 | pci_disable_device(pdev); |
| 5102 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5103 | return 0; |
| 5104 | } |
| 5105 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5106 | #ifdef CONFIG_PM |
| 5107 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5108 | { |
| 5109 | int retval; |
| 5110 | bool wake; |
| 5111 | |
| 5112 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5113 | if (retval) |
| 5114 | return retval; |
| 5115 | |
| 5116 | if (wake) { |
| 5117 | pci_prepare_to_sleep(pdev); |
| 5118 | } else { |
| 5119 | pci_wake_from_d3(pdev, false); |
| 5120 | pci_set_power_state(pdev, PCI_D3hot); |
| 5121 | } |
| 5122 | |
| 5123 | return 0; |
| 5124 | } |
| 5125 | #endif /* CONFIG_PM */ |
| 5126 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5127 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5128 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5129 | bool wake; |
| 5130 | |
| 5131 | __ixgbe_shutdown(pdev, &wake); |
| 5132 | |
| 5133 | if (system_state == SYSTEM_POWER_OFF) { |
| 5134 | pci_wake_from_d3(pdev, wake); |
| 5135 | pci_set_power_state(pdev, PCI_D3hot); |
| 5136 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5137 | } |
| 5138 | |
| 5139 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5140 | * ixgbe_update_stats - Update the board statistics counters. |
| 5141 | * @adapter: board private structure |
| 5142 | **/ |
| 5143 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5144 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5145 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5146 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5147 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5148 | u64 total_mpc = 0; |
| 5149 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5150 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5151 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5152 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5153 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5154 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5155 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5156 | return; |
| 5157 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5158 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5159 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5160 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5161 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5162 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5163 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5164 | } |
| 5165 | adapter->rsc_total_count = rsc_count; |
| 5166 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5167 | } |
| 5168 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5169 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5170 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5171 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5172 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5173 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5174 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5175 | bytes += rx_ring->stats.bytes; |
| 5176 | packets += rx_ring->stats.packets; |
| 5177 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5178 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5179 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5180 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5181 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5182 | netdev->stats.rx_bytes = bytes; |
| 5183 | netdev->stats.rx_packets = packets; |
| 5184 | |
| 5185 | bytes = 0; |
| 5186 | packets = 0; |
| 5187 | /* gather some stats to the adapter struct that are per queue */ |
| 5188 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5189 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5190 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5191 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5192 | bytes += tx_ring->stats.bytes; |
| 5193 | packets += tx_ring->stats.packets; |
| 5194 | } |
| 5195 | adapter->restart_queue = restart_queue; |
| 5196 | adapter->tx_busy = tx_busy; |
| 5197 | netdev->stats.tx_bytes = bytes; |
| 5198 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5199 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5200 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5201 | |
| 5202 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5203 | for (i = 0; i < 8; i++) { |
| 5204 | /* for packet buffers not used, the register should read 0 */ |
| 5205 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5206 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5207 | hwstats->mpc[i] += mpc; |
| 5208 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5209 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5210 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5211 | switch (hw->mac.type) { |
| 5212 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5213 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5214 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5215 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5216 | hwstats->pxonrxc[i] += |
| 5217 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5218 | break; |
| 5219 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5220 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5221 | hwstats->pxonrxc[i] += |
| 5222 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5223 | break; |
| 5224 | default: |
| 5225 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5226 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5227 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5228 | |
| 5229 | /*16 register reads */ |
| 5230 | for (i = 0; i < 16; i++) { |
| 5231 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5232 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5233 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
| 5234 | (hw->mac.type == ixgbe_mac_X540)) { |
| 5235 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 5236 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 5237 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 5238 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 5239 | } |
| 5240 | } |
| 5241 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5242 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5243 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5244 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5245 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5246 | ixgbe_update_xoff_received(adapter); |
| 5247 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5248 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5249 | switch (hw->mac.type) { |
| 5250 | case ixgbe_mac_82598EB: |
| 5251 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5252 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5253 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5254 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5255 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5256 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5257 | /* OS2BMC stats are X540 only*/ |
| 5258 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5259 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5260 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5261 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5262 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 5263 | for (i = 0; i < 16; i++) |
| 5264 | adapter->hw_rx_no_dma_resources += |
| 5265 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5266 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5267 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5268 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5269 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5270 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5271 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5272 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5273 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5274 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5275 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5276 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5277 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5278 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5279 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5280 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5281 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5282 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 5283 | if (adapter->fcoe.ddp_pool) { |
| 5284 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 5285 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 5286 | unsigned int cpu; |
| 5287 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5288 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 5289 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 5290 | noddp += ddp_pool->noddp; |
| 5291 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5292 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 5293 | hwstats->fcoe_noddp = noddp; |
| 5294 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5295 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5296 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5297 | break; |
| 5298 | default: |
| 5299 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5300 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5301 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5302 | hwstats->bprc += bprc; |
| 5303 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5304 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5305 | hwstats->mprc -= bprc; |
| 5306 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5307 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5308 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5309 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5310 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5311 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5312 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5313 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5314 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5315 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5316 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5317 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5318 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5319 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5320 | /* |
| 5321 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5322 | */ |
| 5323 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5324 | hwstats->gptc -= xon_off_tot; |
| 5325 | hwstats->mptc -= xon_off_tot; |
| 5326 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5327 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5328 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 5329 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 5330 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 5331 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 5332 | hwstats->ptc64 -= xon_off_tot; |
| 5333 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 5334 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 5335 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 5336 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 5337 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 5338 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5339 | |
| 5340 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5341 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5342 | |
| 5343 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5344 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5345 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5346 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 5347 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5348 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5352 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5353 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5354 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5355 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5356 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5357 | struct ixgbe_hw *hw = &adapter->hw; |
| 5358 | int i; |
| 5359 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5360 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 5361 | return; |
| 5362 | |
| 5363 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 5364 | |
| 5365 | /* if interface is down do nothing */ |
| 5366 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 5367 | return; |
| 5368 | |
| 5369 | /* do nothing if we are not using signature filters */ |
| 5370 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 5371 | return; |
| 5372 | |
| 5373 | adapter->fdir_overflow++; |
| 5374 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5375 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 5376 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 5377 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 5378 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5379 | /* re-enable flow director interrupts */ |
| 5380 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5381 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5382 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5383 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5384 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5385 | } |
| 5386 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5387 | /** |
| 5388 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5389 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5390 | * |
| 5391 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5392 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5393 | * bits needed to check for TX hangs. As a result we should immediately |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5394 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5395 | */ |
| 5396 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 5397 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5398 | struct ixgbe_hw *hw = &adapter->hw; |
| 5399 | u64 eics = 0; |
| 5400 | int i; |
| 5401 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5402 | /* If we're down or resetting, just bail */ |
| 5403 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5404 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5405 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5406 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5407 | /* Force detection of hung controller */ |
| 5408 | if (netif_carrier_ok(adapter->netdev)) { |
| 5409 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 5410 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 5411 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5412 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5413 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5414 | /* |
| 5415 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5416 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5417 | * would set *both* EIMS and EICS for any bit in EIAM |
| 5418 | */ |
| 5419 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 5420 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5421 | } else { |
| 5422 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 5423 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5424 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 5425 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5426 | eics |= ((u64)1 << i); |
| 5427 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5428 | } |
| 5429 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5430 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5431 | ixgbe_irq_rearm_queues(adapter, eics); |
| 5432 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5436 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5437 | * @adapter: pointer to the device adapter structure |
| 5438 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5439 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5440 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5441 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5442 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5443 | u32 link_speed = adapter->link_speed; |
| 5444 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 5445 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5446 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5447 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 5448 | return; |
| 5449 | |
| 5450 | if (hw->mac.ops.check_link) { |
| 5451 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5452 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5453 | /* always assume link is up, if no check link function */ |
| 5454 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 5455 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5456 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 5457 | |
| 5458 | if (adapter->ixgbe_ieee_pfc) |
| 5459 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 5460 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 5461 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 5462 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 5463 | ixgbe_set_rx_drop_en(adapter); |
| 5464 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5465 | |
| 5466 | if (link_up || |
| 5467 | time_after(jiffies, (adapter->link_check_timeout + |
| 5468 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 5469 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5470 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 5471 | IXGBE_WRITE_FLUSH(hw); |
| 5472 | } |
| 5473 | |
| 5474 | adapter->link_up = link_up; |
| 5475 | adapter->link_speed = link_speed; |
| 5476 | } |
| 5477 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 5478 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 5479 | { |
| 5480 | #ifdef CONFIG_IXGBE_DCB |
| 5481 | struct net_device *netdev = adapter->netdev; |
| 5482 | struct dcb_app app = { |
| 5483 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 5484 | .protocol = 0, |
| 5485 | }; |
| 5486 | u8 up = 0; |
| 5487 | |
| 5488 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 5489 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 5490 | |
| 5491 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 5492 | #endif |
| 5493 | } |
| 5494 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5495 | /** |
| 5496 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 5497 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5498 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5499 | **/ |
| 5500 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 5501 | { |
| 5502 | struct net_device *netdev = adapter->netdev; |
| 5503 | struct ixgbe_hw *hw = &adapter->hw; |
| 5504 | u32 link_speed = adapter->link_speed; |
| 5505 | bool flow_rx, flow_tx; |
| 5506 | |
| 5507 | /* only continue if link was previously down */ |
| 5508 | if (netif_carrier_ok(netdev)) |
| 5509 | return; |
| 5510 | |
| 5511 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 5512 | |
| 5513 | switch (hw->mac.type) { |
| 5514 | case ixgbe_mac_82598EB: { |
| 5515 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5516 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 5517 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 5518 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 5519 | } |
| 5520 | break; |
| 5521 | case ixgbe_mac_X540: |
| 5522 | case ixgbe_mac_82599EB: { |
| 5523 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 5524 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 5525 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 5526 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 5527 | } |
| 5528 | break; |
| 5529 | default: |
| 5530 | flow_tx = false; |
| 5531 | flow_rx = false; |
| 5532 | break; |
| 5533 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 5534 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5535 | if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) |
| 5536 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 5537 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5538 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 5539 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 5540 | "10 Gbps" : |
| 5541 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 5542 | "1 Gbps" : |
| 5543 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 5544 | "100 Mbps" : |
| 5545 | "unknown speed"))), |
| 5546 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 5547 | (flow_rx ? "RX" : |
| 5548 | (flow_tx ? "TX" : "None")))); |
| 5549 | |
| 5550 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5551 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 5552 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 5553 | /* update the default user priority for VFs */ |
| 5554 | ixgbe_update_default_up(adapter); |
| 5555 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 5556 | /* ping all the active vfs to let them know link has changed */ |
| 5557 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | /** |
| 5561 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 5562 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5563 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5564 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 5565 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5566 | { |
| 5567 | struct net_device *netdev = adapter->netdev; |
| 5568 | struct ixgbe_hw *hw = &adapter->hw; |
| 5569 | |
| 5570 | adapter->link_up = false; |
| 5571 | adapter->link_speed = 0; |
| 5572 | |
| 5573 | /* only continue if link was up previously */ |
| 5574 | if (!netif_carrier_ok(netdev)) |
| 5575 | return; |
| 5576 | |
| 5577 | /* poll for SFP+ cable when link is down */ |
| 5578 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 5579 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 5580 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5581 | if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) |
| 5582 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 5583 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5584 | e_info(drv, "NIC Link is Down\n"); |
| 5585 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 5586 | |
| 5587 | /* ping all the active vfs to let them know link has changed */ |
| 5588 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | /** |
| 5592 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5593 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5594 | **/ |
| 5595 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 5596 | { |
| 5597 | int i; |
| 5598 | int some_tx_pending = 0; |
| 5599 | |
| 5600 | if (!netif_carrier_ok(adapter->netdev)) { |
| 5601 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5602 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5603 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 5604 | some_tx_pending = 1; |
| 5605 | break; |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | if (some_tx_pending) { |
| 5610 | /* We've lost link, so the controller stops DMA, |
| 5611 | * but we've got queued Tx work that's never going |
| 5612 | * to get done, so reset controller to flush Tx. |
| 5613 | * (Do the reset outside of interrupt context). |
| 5614 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5615 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5616 | } |
| 5617 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5618 | } |
| 5619 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 5620 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 5621 | { |
| 5622 | u32 ssvpc; |
| 5623 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 5624 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 5625 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 5626 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 5627 | return; |
| 5628 | |
| 5629 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 5630 | |
| 5631 | /* |
| 5632 | * ssvpc register is cleared on read, if zero then no |
| 5633 | * spoofed packets in the last interval. |
| 5634 | */ |
| 5635 | if (!ssvpc) |
| 5636 | return; |
| 5637 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 5638 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 5639 | } |
| 5640 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5641 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5642 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5643 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5644 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5645 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5646 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5647 | /* if interface is down do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 5648 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5649 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5650 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5651 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5652 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 5653 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5654 | if (adapter->link_up) |
| 5655 | ixgbe_watchdog_link_is_up(adapter); |
| 5656 | else |
| 5657 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 5658 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 5659 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5660 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5661 | |
| 5662 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5663 | } |
| 5664 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5665 | /** |
| 5666 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5667 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5668 | **/ |
| 5669 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 5670 | { |
| 5671 | struct ixgbe_hw *hw = &adapter->hw; |
| 5672 | s32 err; |
| 5673 | |
| 5674 | /* not searching for SFP so there is nothing to do here */ |
| 5675 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 5676 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 5677 | return; |
| 5678 | |
| 5679 | /* someone else is in init, wait until next service event */ |
| 5680 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5681 | return; |
| 5682 | |
| 5683 | err = hw->phy.ops.identify_sfp(hw); |
| 5684 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 5685 | goto sfp_out; |
| 5686 | |
| 5687 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 5688 | /* If no cable is present, then we need to reset |
| 5689 | * the next time we find a good cable. */ |
| 5690 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 5691 | } |
| 5692 | |
| 5693 | /* exit on error */ |
| 5694 | if (err) |
| 5695 | goto sfp_out; |
| 5696 | |
| 5697 | /* exit if reset not needed */ |
| 5698 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 5699 | goto sfp_out; |
| 5700 | |
| 5701 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 5702 | |
| 5703 | /* |
| 5704 | * A module may be identified correctly, but the EEPROM may not have |
| 5705 | * support for that module. setup_sfp() will fail in that case, so |
| 5706 | * we should not allow that module to load. |
| 5707 | */ |
| 5708 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 5709 | err = hw->phy.ops.reset(hw); |
| 5710 | else |
| 5711 | err = hw->mac.ops.setup_sfp(hw); |
| 5712 | |
| 5713 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 5714 | goto sfp_out; |
| 5715 | |
| 5716 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5717 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 5718 | |
| 5719 | sfp_out: |
| 5720 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 5721 | |
| 5722 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 5723 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 5724 | e_dev_err("failed to initialize because an unsupported " |
| 5725 | "SFP+ module type was detected.\n"); |
| 5726 | e_dev_err("Reload the driver after installing a " |
| 5727 | "supported module.\n"); |
| 5728 | unregister_netdev(adapter->netdev); |
| 5729 | } |
| 5730 | } |
| 5731 | |
| 5732 | /** |
| 5733 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5734 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5735 | **/ |
| 5736 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 5737 | { |
| 5738 | struct ixgbe_hw *hw = &adapter->hw; |
| 5739 | u32 autoneg; |
| 5740 | bool negotiation; |
| 5741 | |
| 5742 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 5743 | return; |
| 5744 | |
| 5745 | /* someone else is in init, wait until next service event */ |
| 5746 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5747 | return; |
| 5748 | |
| 5749 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5750 | |
| 5751 | autoneg = hw->phy.autoneg_advertised; |
| 5752 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 5753 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5754 | if (hw->mac.ops.setup_link) |
| 5755 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 5756 | |
| 5757 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5758 | adapter->link_check_timeout = jiffies; |
| 5759 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 5760 | } |
| 5761 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 5762 | #ifdef CONFIG_PCI_IOV |
| 5763 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 5764 | { |
| 5765 | int vf; |
| 5766 | struct ixgbe_hw *hw = &adapter->hw; |
| 5767 | struct net_device *netdev = adapter->netdev; |
| 5768 | u32 gpc; |
| 5769 | u32 ciaa, ciad; |
| 5770 | |
| 5771 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 5772 | if (gpc) /* If incrementing then no need for the check below */ |
| 5773 | return; |
| 5774 | /* |
| 5775 | * Check to see if a bad DMA write target from an errant or |
| 5776 | * malicious VF has caused a PCIe error. If so then we can |
| 5777 | * issue a VFLR to the offending VF(s) and then resume without |
| 5778 | * requesting a full slot reset. |
| 5779 | */ |
| 5780 | |
| 5781 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 5782 | ciaa = (vf << 16) | 0x80000000; |
| 5783 | /* 32 bit read so align, we really want status at offset 6 */ |
| 5784 | ciaa |= PCI_COMMAND; |
| 5785 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 5786 | ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599); |
| 5787 | ciaa &= 0x7FFFFFFF; |
| 5788 | /* disable debug mode asap after reading data */ |
| 5789 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 5790 | /* Get the upper 16 bits which will be the PCI status reg */ |
| 5791 | ciad >>= 16; |
| 5792 | if (ciad & PCI_STATUS_REC_MASTER_ABORT) { |
| 5793 | netdev_err(netdev, "VF %d Hung DMA\n", vf); |
| 5794 | /* Issue VFLR */ |
| 5795 | ciaa = (vf << 16) | 0x80000000; |
| 5796 | ciaa |= 0xA8; |
| 5797 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 5798 | ciad = 0x00008000; /* VFLR */ |
| 5799 | IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad); |
| 5800 | ciaa &= 0x7FFFFFFF; |
| 5801 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 5802 | } |
| 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5807 | /** |
| 5808 | * ixgbe_service_timer - Timer Call-back |
| 5809 | * @data: pointer to adapter cast into an unsigned long |
| 5810 | **/ |
| 5811 | static void ixgbe_service_timer(unsigned long data) |
| 5812 | { |
| 5813 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 5814 | unsigned long next_event_offset; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 5815 | bool ready = true; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5816 | |
| 5817 | /* poll faster when waiting for link */ |
| 5818 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 5819 | next_event_offset = HZ / 10; |
| 5820 | else |
| 5821 | next_event_offset = HZ * 2; |
| 5822 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 5823 | #ifdef CONFIG_PCI_IOV |
Alexander Duyck | 6bb78cf | 2012-02-08 07:51:22 +0000 | [diff] [blame] | 5824 | /* |
| 5825 | * don't bother with SR-IOV VF DMA hang check if there are |
| 5826 | * no VFs or the link is down |
| 5827 | */ |
| 5828 | if (!adapter->num_vfs || |
| 5829 | (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 5830 | goto normal_timer_service; |
| 5831 | |
| 5832 | /* If we have VFs allocated then we must check for DMA hangs */ |
| 5833 | ixgbe_check_for_bad_vf(adapter); |
| 5834 | next_event_offset = HZ / 50; |
| 5835 | adapter->timer_event_accumulator++; |
| 5836 | |
| 5837 | if (adapter->timer_event_accumulator >= 100) |
| 5838 | adapter->timer_event_accumulator = 0; |
| 5839 | else |
| 5840 | ready = false; |
| 5841 | |
| 5842 | normal_timer_service: |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 5843 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5844 | /* Reset the timer */ |
| 5845 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 5846 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 5847 | if (ready) |
| 5848 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5851 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 5852 | { |
| 5853 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 5854 | return; |
| 5855 | |
| 5856 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 5857 | |
| 5858 | /* If we're already down or resetting, just bail */ |
| 5859 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5860 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5861 | return; |
| 5862 | |
| 5863 | ixgbe_dump(adapter); |
| 5864 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 5865 | adapter->tx_timeout_count++; |
| 5866 | |
| 5867 | ixgbe_reinit_locked(adapter); |
| 5868 | } |
| 5869 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5870 | /** |
| 5871 | * ixgbe_service_task - manages and runs subtasks |
| 5872 | * @work: pointer to work_struct containing our data |
| 5873 | **/ |
| 5874 | static void ixgbe_service_task(struct work_struct *work) |
| 5875 | { |
| 5876 | struct ixgbe_adapter *adapter = container_of(work, |
| 5877 | struct ixgbe_adapter, |
| 5878 | service_task); |
| 5879 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5880 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5881 | ixgbe_sfp_detection_subtask(adapter); |
| 5882 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 5883 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5884 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5885 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5886 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 5887 | ixgbe_ptp_overflow_check(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5888 | |
| 5889 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 5892 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 5893 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5894 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5895 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 5896 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5897 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5898 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5899 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5900 | if (!skb_is_gso(skb)) |
| 5901 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5902 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5903 | if (skb_header_cloned(skb)) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5904 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5905 | if (err) |
| 5906 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5907 | } |
| 5908 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5909 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 5910 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 5911 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5912 | if (first->protocol == __constant_htons(ETH_P_IP)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5913 | struct iphdr *iph = ip_hdr(skb); |
| 5914 | iph->tot_len = 0; |
| 5915 | iph->check = 0; |
| 5916 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 5917 | iph->daddr, 0, |
| 5918 | IPPROTO_TCP, |
| 5919 | 0); |
| 5920 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5921 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 5922 | IXGBE_TX_FLAGS_CSUM | |
| 5923 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5924 | } else if (skb_is_gso_v6(skb)) { |
| 5925 | ipv6_hdr(skb)->payload_len = 0; |
| 5926 | tcp_hdr(skb)->check = |
| 5927 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 5928 | &ipv6_hdr(skb)->daddr, |
| 5929 | 0, IPPROTO_TCP, 0); |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5930 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 5931 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 5934 | /* compute header lengths */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5935 | l4len = tcp_hdrlen(skb); |
| 5936 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 5937 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 5938 | /* update gso size and bytecount with header size */ |
| 5939 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 5940 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 5941 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5942 | /* mss_l4len_id: use 1 as index for TSO */ |
| 5943 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 5944 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 5945 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 5946 | |
| 5947 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 5948 | vlan_macip_lens = skb_network_header_len(skb); |
| 5949 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5950 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5951 | |
| 5952 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5953 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5954 | |
| 5955 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5956 | } |
| 5957 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5958 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 5959 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5960 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 5961 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5962 | u32 vlan_macip_lens = 0; |
| 5963 | u32 mss_l4len_idx = 0; |
| 5964 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5965 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5966 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 5967 | if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN)) { |
| 5968 | if (unlikely(skb->no_fcs)) |
| 5969 | first->tx_flags |= IXGBE_TX_FLAGS_NO_IFCS; |
| 5970 | if (!(first->tx_flags & IXGBE_TX_FLAGS_TXSW)) |
| 5971 | return; |
| 5972 | } |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5973 | } else { |
| 5974 | u8 l4_hdr = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5975 | switch (first->protocol) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5976 | case __constant_htons(ETH_P_IP): |
| 5977 | vlan_macip_lens |= skb_network_header_len(skb); |
| 5978 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 5979 | l4_hdr = ip_hdr(skb)->protocol; |
| 5980 | break; |
| 5981 | case __constant_htons(ETH_P_IPV6): |
| 5982 | vlan_macip_lens |= skb_network_header_len(skb); |
| 5983 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 5984 | break; |
| 5985 | default: |
| 5986 | if (unlikely(net_ratelimit())) { |
| 5987 | dev_warn(tx_ring->dev, |
| 5988 | "partial checksum but proto=%x!\n", |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 5989 | first->protocol); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5990 | } |
| 5991 | break; |
| 5992 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5993 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 5994 | switch (l4_hdr) { |
| 5995 | case IPPROTO_TCP: |
| 5996 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 5997 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 5998 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 5999 | break; |
| 6000 | case IPPROTO_SCTP: |
| 6001 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6002 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6003 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6004 | break; |
| 6005 | case IPPROTO_UDP: |
| 6006 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6007 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6008 | break; |
| 6009 | default: |
| 6010 | if (unlikely(net_ratelimit())) { |
| 6011 | dev_warn(tx_ring->dev, |
| 6012 | "partial checksum but l4 proto=%x!\n", |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6013 | l4_hdr); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6014 | } |
| 6015 | break; |
| 6016 | } |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6017 | |
| 6018 | /* update TX checksum flag */ |
| 6019 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6020 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6021 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6022 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6023 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6024 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6025 | |
| 6026 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6027 | type_tucmd, mss_l4len_idx); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6028 | } |
| 6029 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6030 | static __le32 ixgbe_tx_cmd_type(u32 tx_flags) |
| 6031 | { |
| 6032 | /* set type for advanced descriptor with frame checksum insertion */ |
| 6033 | __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6034 | IXGBE_ADVTXD_DCMD_DEXT); |
| 6035 | |
| 6036 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6037 | if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6038 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE); |
| 6039 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6040 | if (tx_flags & IXGBE_TX_FLAGS_TSTAMP) |
| 6041 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_MAC_TSTAMP); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6042 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6043 | /* set segmentation enable bits for TSO/FSO */ |
| 6044 | #ifdef IXGBE_FCOE |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6045 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6046 | #else |
| 6047 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6048 | #endif |
| 6049 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE); |
| 6050 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 6051 | /* insert frame checksum */ |
| 6052 | if (!(tx_flags & IXGBE_TX_FLAGS_NO_IFCS)) |
| 6053 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS); |
| 6054 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6055 | return cmd_type; |
| 6056 | } |
| 6057 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6058 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 6059 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6060 | { |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6061 | __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6062 | |
| 6063 | /* enable L4 checksum for TSO and TX checksum offload */ |
| 6064 | if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6065 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM); |
| 6066 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6067 | /* enble IPv4 checksum for TSO */ |
| 6068 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6069 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6070 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6071 | /* use index 1 context for TSO/FSO/FCOE */ |
| 6072 | #ifdef IXGBE_FCOE |
| 6073 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE)) |
| 6074 | #else |
| 6075 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6076 | #endif |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6077 | olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 6078 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6079 | /* |
| 6080 | * Check Context must be set if Tx switch is enabled, which it |
| 6081 | * always is for case where virtual functions are running |
| 6082 | */ |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6083 | #ifdef IXGBE_FCOE |
| 6084 | if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE)) |
| 6085 | #else |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6086 | if (tx_flags & IXGBE_TX_FLAGS_TXSW) |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6087 | #endif |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6088 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC); |
| 6089 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6090 | tx_desc->read.olinfo_status = olinfo_status; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6091 | } |
| 6092 | |
| 6093 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 6094 | IXGBE_TXD_CMD_RS) |
| 6095 | |
| 6096 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6097 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6098 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6099 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6100 | dma_addr_t dma; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6101 | struct sk_buff *skb = first->skb; |
| 6102 | struct ixgbe_tx_buffer *tx_buffer; |
| 6103 | union ixgbe_adv_tx_desc *tx_desc; |
| 6104 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6105 | unsigned int data_len = skb->data_len; |
| 6106 | unsigned int size = skb_headlen(skb); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6107 | unsigned int paylen = skb->len - hdr_len; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6108 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6109 | __le32 cmd_type; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6110 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6111 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6112 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 6113 | |
| 6114 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen); |
| 6115 | cmd_type = ixgbe_tx_cmd_type(tx_flags); |
| 6116 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6117 | #ifdef IXGBE_FCOE |
| 6118 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6119 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6120 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 6121 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6122 | } else { |
| 6123 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6124 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6125 | } |
| 6126 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6127 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6128 | dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE); |
| 6129 | if (dma_mapping_error(tx_ring->dev, dma)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6130 | goto dma_error; |
| 6131 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6132 | /* record length, and DMA address */ |
| 6133 | dma_unmap_len_set(first, len, size); |
| 6134 | dma_unmap_addr_set(first, dma, dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6135 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6136 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6137 | |
| 6138 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6139 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6140 | tx_desc->read.cmd_type_len = |
| 6141 | cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6142 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6143 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6144 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6145 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6146 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6147 | i = 0; |
| 6148 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6149 | |
| 6150 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 6151 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 6152 | |
| 6153 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 6154 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6155 | } |
| 6156 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6157 | if (likely(!data_len)) |
| 6158 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6159 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6160 | tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6161 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6162 | i++; |
| 6163 | tx_desc++; |
| 6164 | if (i == tx_ring->count) { |
| 6165 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 6166 | i = 0; |
| 6167 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6168 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6169 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6170 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6171 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6172 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6173 | #endif |
| 6174 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6175 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6176 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 6177 | DMA_TO_DEVICE); |
| 6178 | if (dma_mapping_error(tx_ring->dev, dma)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6179 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6180 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6181 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 6182 | dma_unmap_len_set(tx_buffer, len, size); |
| 6183 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 6184 | |
| 6185 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 6186 | tx_desc->read.olinfo_status = 0; |
| 6187 | |
| 6188 | frag++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6189 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6190 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6191 | /* write last descriptor with RS and EOP bits */ |
| 6192 | cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD); |
| 6193 | tx_desc->read.cmd_type_len = cmd_type; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6194 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6195 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 6196 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6197 | /* set the timestamp */ |
| 6198 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6199 | |
| 6200 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6201 | * Force memory writes to complete before letting h/w know there |
| 6202 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 6203 | * memory model archs, such as IA-64). |
| 6204 | * |
| 6205 | * We also need this memory barrier to make certain all of the |
| 6206 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6207 | */ |
| 6208 | wmb(); |
| 6209 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6210 | /* set next_to_watch value indicating a packet is present */ |
| 6211 | first->next_to_watch = tx_desc; |
| 6212 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6213 | i++; |
| 6214 | if (i == tx_ring->count) |
| 6215 | i = 0; |
| 6216 | |
| 6217 | tx_ring->next_to_use = i; |
| 6218 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6219 | /* notify HW of packet */ |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6220 | writel(i, tx_ring->tail); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6221 | |
| 6222 | return; |
| 6223 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6224 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6225 | |
| 6226 | /* clear dma mappings for failed tx_buffer_info map */ |
| 6227 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6228 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 6229 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
| 6230 | if (tx_buffer == first) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6231 | break; |
| 6232 | if (i == 0) |
| 6233 | i = tx_ring->count; |
| 6234 | i--; |
| 6235 | } |
| 6236 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6237 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6238 | } |
| 6239 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6240 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6241 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6242 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6243 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6244 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6245 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6246 | union { |
| 6247 | unsigned char *network; |
| 6248 | struct iphdr *ipv4; |
| 6249 | struct ipv6hdr *ipv6; |
| 6250 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6251 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6252 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6253 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6254 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6255 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6256 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6257 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6258 | /* do nothing if sampling is disabled */ |
| 6259 | if (!ring->atr_sample_rate) |
| 6260 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6261 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6262 | ring->atr_count++; |
| 6263 | |
| 6264 | /* snag network header to get L4 type and address */ |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6265 | hdr.network = skb_network_header(first->skb); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6266 | |
| 6267 | /* Currently only IPv4/IPv6 with TCP is supported */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6268 | if ((first->protocol != __constant_htons(ETH_P_IPV6) || |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6269 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6270 | (first->protocol != __constant_htons(ETH_P_IP) || |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6271 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6272 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6273 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6274 | th = tcp_hdr(first->skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6275 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6276 | /* skip this packet since it is invalid or the socket is closing */ |
| 6277 | if (!th || th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6278 | return; |
| 6279 | |
| 6280 | /* sample on all syn packets or once every atr sample count */ |
| 6281 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6282 | return; |
| 6283 | |
| 6284 | /* reset sample count */ |
| 6285 | ring->atr_count = 0; |
| 6286 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6287 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6288 | |
| 6289 | /* |
| 6290 | * src and dst are inverted, think how the receiver sees them |
| 6291 | * |
| 6292 | * The input is broken into two sections, a non-compressed section |
| 6293 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6294 | * is XORed together and stored in the compressed dword. |
| 6295 | */ |
| 6296 | input.formatted.vlan_id = vlan_id; |
| 6297 | |
| 6298 | /* |
| 6299 | * since src port and flex bytes occupy the same word XOR them together |
| 6300 | * and write the value to source port portion of compressed dword |
| 6301 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6302 | if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN)) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6303 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6304 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6305 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6306 | common.port.dst ^= th->source; |
| 6307 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6308 | if (first->protocol == __constant_htons(ETH_P_IP)) { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6309 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6310 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6311 | } else { |
| 6312 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6313 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6314 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6315 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6316 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6317 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6318 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6319 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6320 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6321 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6322 | |
| 6323 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6324 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6325 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6326 | } |
| 6327 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6328 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6329 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6330 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6331 | /* Herbert's original patch had: |
| 6332 | * smp_mb__after_netif_stop_queue(); |
| 6333 | * but since that doesn't exist yet, just open code it. */ |
| 6334 | smp_mb(); |
| 6335 | |
| 6336 | /* We need to check again in a case another CPU has just |
| 6337 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6338 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6339 | return -EBUSY; |
| 6340 | |
| 6341 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6342 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6343 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6344 | return 0; |
| 6345 | } |
| 6346 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 6347 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6348 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6349 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6350 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6351 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6352 | } |
| 6353 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6354 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 6355 | { |
| 6356 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 6357 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 6358 | smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6359 | #ifdef IXGBE_FCOE |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 6360 | __be16 protocol = vlan_get_protocol(skb); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6361 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6362 | if (((protocol == htons(ETH_P_FCOE)) || |
| 6363 | (protocol == htons(ETH_P_FIP))) && |
| 6364 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 6365 | struct ixgbe_ring_feature *f; |
| 6366 | |
| 6367 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 6368 | |
| 6369 | while (txq >= f->indices) |
| 6370 | txq -= f->indices; |
Alexander Duyck | e4b317e | 2012-05-05 05:30:53 +0000 | [diff] [blame] | 6371 | txq += adapter->ring_feature[RING_F_FCOE].offset; |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 6372 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6373 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6374 | } |
| 6375 | #endif |
| 6376 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6377 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 6378 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 6379 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6380 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6381 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6382 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6383 | return skb_tx_hash(dev, skb); |
| 6384 | } |
| 6385 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6386 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6387 | struct ixgbe_adapter *adapter, |
| 6388 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6389 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6390 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6391 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6392 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6393 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 6394 | unsigned short f; |
| 6395 | #endif |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6396 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6397 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6398 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6399 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6400 | /* |
| 6401 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 6402 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6403 | * + 2 desc gap to keep tail from touching head, |
| 6404 | * + 1 desc for context descriptor, |
| 6405 | * otherwise try next time |
| 6406 | */ |
| 6407 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 6408 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 6409 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 6410 | #else |
| 6411 | count += skb_shinfo(skb)->nr_frags; |
| 6412 | #endif |
| 6413 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 6414 | tx_ring->tx_stats.tx_busy++; |
| 6415 | return NETDEV_TX_BUSY; |
| 6416 | } |
| 6417 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6418 | /* record the location of the first descriptor for this packet */ |
| 6419 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 6420 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6421 | first->bytecount = skb->len; |
| 6422 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6423 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6424 | /* if we have a HW VLAN tag being added default to the HW one */ |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 6425 | if (vlan_tx_tag_present(skb)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6426 | tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6427 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 6428 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
| 6429 | } else if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 6430 | struct vlan_hdr *vhdr, _vhdr; |
| 6431 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 6432 | if (!vhdr) |
| 6433 | goto out_drop; |
| 6434 | |
| 6435 | protocol = vhdr->h_vlan_encapsulated_proto; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 6436 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 6437 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6438 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6439 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6440 | |
Jacob Keller | aa7bd46 | 2012-05-04 01:55:23 +0000 | [diff] [blame] | 6441 | skb_tx_timestamp(skb); |
| 6442 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6443 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { |
| 6444 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 6445 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
| 6446 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6447 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 6448 | #ifdef CONFIG_PCI_IOV |
| 6449 | /* |
| 6450 | * Use the l2switch_enable flag - would be false if the DMA |
| 6451 | * Tx switch had been disabled. |
| 6452 | */ |
| 6453 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 6454 | tx_flags |= IXGBE_TX_FLAGS_TXSW; |
| 6455 | |
| 6456 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 6457 | /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6458 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 6459 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 6460 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6461 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 6462 | tx_flags |= (skb->priority & 0x7) << |
| 6463 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6464 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 6465 | struct vlan_ethhdr *vhdr; |
| 6466 | if (skb_header_cloned(skb) && |
| 6467 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 6468 | goto out_drop; |
| 6469 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 6470 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 6471 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6472 | } else { |
| 6473 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 6474 | } |
| 6475 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6476 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6477 | /* record initial flags and protocol */ |
| 6478 | first->tx_flags = tx_flags; |
| 6479 | first->protocol = protocol; |
| 6480 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6481 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6482 | /* setup tx offload for FCoE */ |
| 6483 | if ((protocol == __constant_htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 6484 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6485 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6486 | if (tso < 0) |
| 6487 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6488 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6489 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6490 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6491 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6492 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6493 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6494 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6495 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6496 | else if (!tso) |
| 6497 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6498 | |
| 6499 | /* add the ATR filter if ATR is on */ |
| 6500 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6501 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6502 | |
| 6503 | #ifdef IXGBE_FCOE |
| 6504 | xmit_fcoe: |
| 6505 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6506 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6507 | |
| 6508 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6509 | |
| 6510 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6511 | |
| 6512 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6513 | dev_kfree_skb_any(first->skb); |
| 6514 | first->skb = NULL; |
| 6515 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6516 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6517 | } |
| 6518 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 6519 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 6520 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6521 | { |
| 6522 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6523 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6524 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 6525 | /* |
| 6526 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 6527 | * in order to meet this minimum size requirement. |
| 6528 | */ |
Stephen Hemminger | f73332f | 2012-06-21 02:15:10 +0000 | [diff] [blame] | 6529 | if (unlikely(skb->len < 17)) { |
| 6530 | if (skb_pad(skb, 17 - skb->len)) |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 6531 | return NETDEV_TX_OK; |
| 6532 | skb->len = 17; |
Tushar Dave | 71a49f7 | 2012-09-14 04:24:49 +0000 | [diff] [blame] | 6533 | skb_set_tail_pointer(skb, 17); |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 6534 | } |
| 6535 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6536 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
| 6537 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 6538 | } |
| 6539 | |
| 6540 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6541 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6542 | * @netdev: network interface device structure |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6543 | * @p: pointer to an address structure |
| 6544 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6545 | * Returns 0 on success, negative on failure |
| 6546 | **/ |
| 6547 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 6548 | { |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 6549 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6550 | struct ixgbe_hw *hw = &adapter->hw; |
| 6551 | struct sockaddr *addr = p; |
| 6552 | |
| 6553 | if (!is_valid_ether_addr(addr->sa_data)) |
| 6554 | return -EADDRNOTAVAIL; |
| 6555 | |
| 6556 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 6557 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
| 6558 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 6559 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6560 | |
| 6561 | return 0; |
| 6562 | } |
| 6563 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 6564 | static int |
| 6565 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 6566 | { |
| 6567 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6568 | struct ixgbe_hw *hw = &adapter->hw; |
| 6569 | u16 value; |
| 6570 | int rc; |
| 6571 | |
| 6572 | if (prtad != hw->phy.mdio.prtad) |
| 6573 | return -EINVAL; |
| 6574 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 6575 | if (!rc) |
| 6576 | rc = value; |
| 6577 | return rc; |
| 6578 | } |
| 6579 | |
| 6580 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 6581 | u16 addr, u16 value) |
| 6582 | { |
| 6583 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6584 | struct ixgbe_hw *hw = &adapter->hw; |
| 6585 | |
| 6586 | if (prtad != hw->phy.mdio.prtad) |
| 6587 | return -EINVAL; |
| 6588 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 6589 | } |
| 6590 | |
| 6591 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 6592 | { |
| 6593 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6594 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6595 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6596 | case SIOCSHWTSTAMP: |
| 6597 | return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6598 | default: |
| 6599 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 6600 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 6601 | } |
| 6602 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6603 | /** |
| 6604 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 6605 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6606 | * @netdev: network interface device structure |
| 6607 | * |
| 6608 | * Returns non-zero on failure |
| 6609 | **/ |
| 6610 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 6611 | { |
| 6612 | int err = 0; |
| 6613 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 6614 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6615 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 6616 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6617 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 6618 | err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6619 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 6620 | |
| 6621 | /* update SAN MAC vmdq pool selection */ |
| 6622 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6623 | } |
| 6624 | return err; |
| 6625 | } |
| 6626 | |
| 6627 | /** |
| 6628 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 6629 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6630 | * @netdev: network interface device structure |
| 6631 | * |
| 6632 | * Returns non-zero on failure |
| 6633 | **/ |
| 6634 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 6635 | { |
| 6636 | int err = 0; |
| 6637 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6638 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 6639 | |
| 6640 | if (is_valid_ether_addr(mac->san_addr)) { |
| 6641 | rtnl_lock(); |
| 6642 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 6643 | rtnl_unlock(); |
| 6644 | } |
| 6645 | return err; |
| 6646 | } |
| 6647 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6648 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6649 | /* |
| 6650 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 6651 | * without having to re-enable interrupts. It's not called while |
| 6652 | * the interrupt routine is executing. |
| 6653 | */ |
| 6654 | static void ixgbe_netpoll(struct net_device *netdev) |
| 6655 | { |
| 6656 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6657 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6658 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 6659 | /* if interface is down do nothing */ |
| 6660 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6661 | return; |
| 6662 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6663 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6664 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6665 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 6666 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6667 | } else { |
| 6668 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 6669 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6670 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6671 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6672 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 6673 | #endif |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6674 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 6675 | struct rtnl_link_stats64 *stats) |
| 6676 | { |
| 6677 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6678 | int i; |
| 6679 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6680 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6681 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6682 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6683 | u64 bytes, packets; |
| 6684 | unsigned int start; |
| 6685 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6686 | if (ring) { |
| 6687 | do { |
| 6688 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 6689 | packets = ring->stats.packets; |
| 6690 | bytes = ring->stats.bytes; |
| 6691 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 6692 | stats->rx_packets += packets; |
| 6693 | stats->rx_bytes += bytes; |
| 6694 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6695 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 6696 | |
| 6697 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6698 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 6699 | u64 bytes, packets; |
| 6700 | unsigned int start; |
| 6701 | |
| 6702 | if (ring) { |
| 6703 | do { |
| 6704 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 6705 | packets = ring->stats.packets; |
| 6706 | bytes = ring->stats.bytes; |
| 6707 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 6708 | stats->tx_packets += packets; |
| 6709 | stats->tx_bytes += bytes; |
| 6710 | } |
| 6711 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6712 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6713 | /* following stats updated by ixgbe_watchdog_task() */ |
| 6714 | stats->multicast = netdev->stats.multicast; |
| 6715 | stats->rx_errors = netdev->stats.rx_errors; |
| 6716 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 6717 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 6718 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 6719 | return stats; |
| 6720 | } |
| 6721 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 6722 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6723 | /** |
| 6724 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 6725 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6726 | * @tc: number of traffic classes currently enabled |
| 6727 | * |
| 6728 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 6729 | * 802.1Q priority maps to a packet buffer that exists. |
| 6730 | */ |
| 6731 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 6732 | { |
| 6733 | struct ixgbe_hw *hw = &adapter->hw; |
| 6734 | u32 reg, rsave; |
| 6735 | int i; |
| 6736 | |
| 6737 | /* 82598 have a static priority to TC mapping that can not |
| 6738 | * be changed so no validation is needed. |
| 6739 | */ |
| 6740 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6741 | return; |
| 6742 | |
| 6743 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 6744 | rsave = reg; |
| 6745 | |
| 6746 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 6747 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 6748 | |
| 6749 | /* If up2tc is out of bounds default to zero */ |
| 6750 | if (up2tc > tc) |
| 6751 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 6752 | } |
| 6753 | |
| 6754 | if (reg != rsave) |
| 6755 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 6756 | |
| 6757 | return; |
| 6758 | } |
| 6759 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6760 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 6761 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 6762 | * @adapter: Pointer to adapter struct |
| 6763 | * |
| 6764 | * Populate the netdev user priority to tc map |
| 6765 | */ |
| 6766 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 6767 | { |
| 6768 | struct net_device *dev = adapter->netdev; |
| 6769 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 6770 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 6771 | u8 prio; |
| 6772 | |
| 6773 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 6774 | u8 tc = 0; |
| 6775 | |
| 6776 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 6777 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 6778 | else if (ets) |
| 6779 | tc = ets->prio_tc[prio]; |
| 6780 | |
| 6781 | netdev_set_prio_tc_map(dev, prio, tc); |
| 6782 | } |
| 6783 | } |
| 6784 | |
| 6785 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6786 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6787 | * |
| 6788 | * @netdev: net device to configure |
| 6789 | * @tc: number of traffic classes to enable |
| 6790 | */ |
| 6791 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 6792 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6793 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6794 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6795 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6796 | /* Hardware supports up to 8 traffic classes */ |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 6797 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs || |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 6798 | (hw->mac.type == ixgbe_mac_82598EB && |
| 6799 | tc < MAX_TRAFFIC_CLASS)) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6800 | return -EINVAL; |
| 6801 | |
| 6802 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6803 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6804 | * hardware is not flexible enough to do this dynamically. |
| 6805 | */ |
| 6806 | if (netif_running(dev)) |
| 6807 | ixgbe_close(dev); |
| 6808 | ixgbe_clear_interrupt_scheme(adapter); |
| 6809 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 6810 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6811 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 6812 | ixgbe_set_prio_tc_map(adapter); |
| 6813 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 6814 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 6815 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 6816 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 6817 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 6818 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 6819 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 6820 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6821 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 6822 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 6823 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6824 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 6825 | |
| 6826 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 6827 | |
| 6828 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 6829 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 6830 | } |
| 6831 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 6832 | ixgbe_init_interrupt_scheme(adapter); |
| 6833 | ixgbe_validate_rtr(adapter, tc); |
| 6834 | if (netif_running(dev)) |
| 6835 | ixgbe_open(dev); |
| 6836 | |
| 6837 | return 0; |
| 6838 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6839 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 6840 | #endif /* CONFIG_IXGBE_DCB */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6841 | void ixgbe_do_reset(struct net_device *netdev) |
| 6842 | { |
| 6843 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6844 | |
| 6845 | if (netif_running(netdev)) |
| 6846 | ixgbe_reinit_locked(adapter); |
| 6847 | else |
| 6848 | ixgbe_reset(adapter); |
| 6849 | } |
| 6850 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 6851 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6852 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6853 | { |
| 6854 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6855 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6856 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6857 | if (!(features & NETIF_F_RXCSUM)) |
| 6858 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6859 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6860 | /* Turn off LRO if not RSC capable */ |
| 6861 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 6862 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 6863 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6864 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6865 | } |
| 6866 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 6867 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6868 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6869 | { |
| 6870 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6871 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6872 | bool need_reset = false; |
| 6873 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6874 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6875 | if (!(features & NETIF_F_LRO)) { |
| 6876 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6877 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6878 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 6879 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 6880 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 6881 | if (adapter->rx_itr_setting == 1 || |
| 6882 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 6883 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 6884 | need_reset = true; |
| 6885 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 6886 | e_info(probe, "rx-usecs set too low, " |
| 6887 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6888 | } |
| 6889 | } |
| 6890 | |
| 6891 | /* |
| 6892 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 6893 | * the state changed, we need to reset. |
| 6894 | */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 6895 | switch (features & NETIF_F_NTUPLE) { |
| 6896 | case NETIF_F_NTUPLE: |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6897 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 6898 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 6899 | need_reset = true; |
| 6900 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6901 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 6902 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 6903 | break; |
| 6904 | default: |
| 6905 | /* turn off perfect filters, enable ATR and reset */ |
| 6906 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 6907 | need_reset = true; |
| 6908 | |
| 6909 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 6910 | |
| 6911 | /* We cannot enable ATR if SR-IOV is enabled */ |
| 6912 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 6913 | break; |
| 6914 | |
| 6915 | /* We cannot enable ATR if we have 2 or more traffic classes */ |
| 6916 | if (netdev_get_num_tc(netdev) > 1) |
| 6917 | break; |
| 6918 | |
| 6919 | /* We cannot enable ATR if RSS is disabled */ |
| 6920 | if (adapter->ring_feature[RING_F_RSS].limit <= 1) |
| 6921 | break; |
| 6922 | |
| 6923 | /* A sample rate of 0 indicates ATR disabled */ |
| 6924 | if (!adapter->atr_sample_rate) |
| 6925 | break; |
| 6926 | |
| 6927 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 6928 | break; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6929 | } |
| 6930 | |
John Fastabend | 146d4cc | 2012-05-15 05:59:26 +0000 | [diff] [blame] | 6931 | if (features & NETIF_F_HW_VLAN_RX) |
| 6932 | ixgbe_vlan_strip_enable(adapter); |
| 6933 | else |
| 6934 | ixgbe_vlan_strip_disable(adapter); |
| 6935 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 6936 | if (changed & NETIF_F_RXALL) |
| 6937 | need_reset = true; |
| 6938 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 6939 | netdev->features = features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6940 | if (need_reset) |
| 6941 | ixgbe_do_reset(netdev); |
| 6942 | |
| 6943 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 6944 | } |
| 6945 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 6946 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 6947 | struct net_device *dev, |
stephen hemminger | 6b6e272 | 2012-09-17 10:03:26 +0000 | [diff] [blame] | 6948 | const unsigned char *addr, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 6949 | u16 flags) |
| 6950 | { |
| 6951 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 6952 | int err; |
| 6953 | |
| 6954 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 6955 | return -EOPNOTSUPP; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 6956 | |
| 6957 | if (ndm->ndm_state & NUD_PERMANENT) { |
| 6958 | pr_info("%s: FDB only supports static addresses\n", |
| 6959 | ixgbe_driver_name); |
| 6960 | return -EINVAL; |
| 6961 | } |
| 6962 | |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 6963 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 6964 | u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS; |
| 6965 | |
| 6966 | if (netdev_uc_count(dev) < rar_uc_entries) |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 6967 | err = dev_uc_add_excl(dev, addr); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 6968 | else |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 6969 | err = -ENOMEM; |
| 6970 | } else if (is_multicast_ether_addr(addr)) { |
| 6971 | err = dev_mc_add_excl(dev, addr); |
| 6972 | } else { |
| 6973 | err = -EINVAL; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 6974 | } |
| 6975 | |
| 6976 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 6977 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 6978 | err = 0; |
| 6979 | |
| 6980 | return err; |
| 6981 | } |
| 6982 | |
| 6983 | static int ixgbe_ndo_fdb_del(struct ndmsg *ndm, |
| 6984 | struct net_device *dev, |
stephen hemminger | 6b6e272 | 2012-09-17 10:03:26 +0000 | [diff] [blame] | 6985 | const unsigned char *addr) |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 6986 | { |
| 6987 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6988 | int err = -EOPNOTSUPP; |
| 6989 | |
| 6990 | if (ndm->ndm_state & NUD_PERMANENT) { |
| 6991 | pr_info("%s: FDB only supports static addresses\n", |
| 6992 | ixgbe_driver_name); |
| 6993 | return -EINVAL; |
| 6994 | } |
| 6995 | |
| 6996 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 6997 | if (is_unicast_ether_addr(addr)) |
| 6998 | err = dev_uc_del(dev, addr); |
| 6999 | else if (is_multicast_ether_addr(addr)) |
| 7000 | err = dev_mc_del(dev, addr); |
| 7001 | else |
| 7002 | err = -EINVAL; |
| 7003 | } |
| 7004 | |
| 7005 | return err; |
| 7006 | } |
| 7007 | |
| 7008 | static int ixgbe_ndo_fdb_dump(struct sk_buff *skb, |
| 7009 | struct netlink_callback *cb, |
| 7010 | struct net_device *dev, |
| 7011 | int idx) |
| 7012 | { |
| 7013 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7014 | |
| 7015 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7016 | idx = ndo_dflt_fdb_dump(skb, cb, dev, idx); |
| 7017 | |
| 7018 | return idx; |
| 7019 | } |
| 7020 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7021 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
| 7022 | struct nlmsghdr *nlh) |
| 7023 | { |
| 7024 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7025 | struct nlattr *attr, *br_spec; |
| 7026 | int rem; |
| 7027 | |
| 7028 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 7029 | return -EOPNOTSUPP; |
| 7030 | |
| 7031 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 7032 | |
| 7033 | nla_for_each_nested(attr, br_spec, rem) { |
| 7034 | __u16 mode; |
| 7035 | u32 reg = 0; |
| 7036 | |
| 7037 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 7038 | continue; |
| 7039 | |
| 7040 | mode = nla_get_u16(attr); |
| 7041 | if (mode == BRIDGE_MODE_VEPA) |
| 7042 | reg = 0; |
| 7043 | else if (mode == BRIDGE_MODE_VEB) |
| 7044 | reg = IXGBE_PFDTXGSWC_VT_LBEN; |
| 7045 | else |
| 7046 | return -EINVAL; |
| 7047 | |
| 7048 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg); |
| 7049 | |
| 7050 | e_info(drv, "enabling bridge mode: %s\n", |
| 7051 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 7052 | } |
| 7053 | |
| 7054 | return 0; |
| 7055 | } |
| 7056 | |
| 7057 | static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 7058 | struct net_device *dev) |
| 7059 | { |
| 7060 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7061 | u16 mode; |
| 7062 | |
| 7063 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 7064 | return 0; |
| 7065 | |
| 7066 | if (IXGBE_READ_REG(&adapter->hw, IXGBE_PFDTXGSWC) & 1) |
| 7067 | mode = BRIDGE_MODE_VEB; |
| 7068 | else |
| 7069 | mode = BRIDGE_MODE_VEPA; |
| 7070 | |
| 7071 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode); |
| 7072 | } |
| 7073 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7074 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7075 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7076 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7077 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7078 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7079 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7080 | .ndo_validate_addr = eth_validate_addr, |
| 7081 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7082 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7083 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7084 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7085 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7086 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7087 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7088 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7089 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7090 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7091 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7092 | .ndo_get_stats64 = ixgbe_get_stats64, |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 7093 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7094 | .ndo_setup_tc = ixgbe_setup_tc, |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 7095 | #endif |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7096 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7097 | .ndo_poll_controller = ixgbe_netpoll, |
| 7098 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7099 | #ifdef IXGBE_FCOE |
| 7100 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7101 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7102 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7103 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7104 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7105 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 7106 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7107 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7108 | .ndo_set_features = ixgbe_set_features, |
| 7109 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7110 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
| 7111 | .ndo_fdb_del = ixgbe_ndo_fdb_del, |
| 7112 | .ndo_fdb_dump = ixgbe_ndo_fdb_dump, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7113 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 7114 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7115 | }; |
| 7116 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7117 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7118 | * ixgbe_wol_supported - Check whether device supports WoL |
| 7119 | * @hw: hw specific details |
| 7120 | * @device_id: the device ID |
| 7121 | * @subdev_id: the subsystem device ID |
| 7122 | * |
| 7123 | * This function is used by probe and ethtool to determine |
| 7124 | * which devices have WoL support |
| 7125 | * |
| 7126 | **/ |
| 7127 | int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 7128 | u16 subdevice_id) |
| 7129 | { |
| 7130 | struct ixgbe_hw *hw = &adapter->hw; |
| 7131 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 7132 | int is_wol_supported = 0; |
| 7133 | |
| 7134 | switch (device_id) { |
| 7135 | case IXGBE_DEV_ID_82599_SFP: |
| 7136 | /* Only these subdevices could supports WOL */ |
| 7137 | switch (subdevice_id) { |
| 7138 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 7139 | /* only support first port */ |
| 7140 | if (hw->bus.func != 0) |
| 7141 | break; |
| 7142 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 7143 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 7144 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7145 | is_wol_supported = 1; |
| 7146 | break; |
| 7147 | } |
| 7148 | break; |
| 7149 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7150 | /* All except this subdevice support WOL */ |
| 7151 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
| 7152 | is_wol_supported = 1; |
| 7153 | break; |
| 7154 | case IXGBE_DEV_ID_82599_KX4: |
| 7155 | is_wol_supported = 1; |
| 7156 | break; |
| 7157 | case IXGBE_DEV_ID_X540T: |
joshua.a.hay@intel.com | df376f0 | 2012-09-21 00:08:21 +0000 | [diff] [blame] | 7158 | case IXGBE_DEV_ID_X540T1: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7159 | /* check eeprom to see if enabled wol */ |
| 7160 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 7161 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 7162 | (hw->bus.func == 0))) { |
| 7163 | is_wol_supported = 1; |
| 7164 | } |
| 7165 | break; |
| 7166 | } |
| 7167 | |
| 7168 | return is_wol_supported; |
| 7169 | } |
| 7170 | |
| 7171 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7172 | * ixgbe_probe - Device Initialization Routine |
| 7173 | * @pdev: PCI device information struct |
| 7174 | * @ent: entry in ixgbe_pci_tbl |
| 7175 | * |
| 7176 | * Returns 0 on success, negative on failure |
| 7177 | * |
| 7178 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7179 | * The OS initialization, configuring of the adapter private structure, |
| 7180 | * and a hardware reset occur. |
| 7181 | **/ |
| 7182 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7183 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7184 | { |
| 7185 | struct net_device *netdev; |
| 7186 | struct ixgbe_adapter *adapter = NULL; |
| 7187 | struct ixgbe_hw *hw; |
| 7188 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7189 | static int cards_found; |
| 7190 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7191 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7192 | unsigned int indices = num_possible_cpus(); |
John Fastabend | 3f4a6f0 | 2012-06-05 05:58:52 +0000 | [diff] [blame] | 7193 | unsigned int dcb_max = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7194 | #ifdef IXGBE_FCOE |
| 7195 | u16 device_caps; |
| 7196 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7197 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7198 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7199 | /* Catch broken hardware that put the wrong VF device ID in |
| 7200 | * the PCIe SR-IOV capability. |
| 7201 | */ |
| 7202 | if (pdev->is_virtfn) { |
| 7203 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7204 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7205 | return -EINVAL; |
| 7206 | } |
| 7207 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7208 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7209 | if (err) |
| 7210 | return err; |
| 7211 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7212 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7213 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7214 | pci_using_dac = 1; |
| 7215 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7216 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7217 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7218 | err = dma_set_coherent_mask(&pdev->dev, |
| 7219 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7220 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7221 | dev_err(&pdev->dev, |
| 7222 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7223 | goto err_dma; |
| 7224 | } |
| 7225 | } |
| 7226 | pci_using_dac = 0; |
| 7227 | } |
| 7228 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7229 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7230 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7231 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7232 | dev_err(&pdev->dev, |
| 7233 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7234 | goto err_pci_reg; |
| 7235 | } |
| 7236 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7237 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7238 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7239 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7240 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7241 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7242 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 3f4a6f0 | 2012-06-05 05:58:52 +0000 | [diff] [blame] | 7243 | if (ii->mac == ixgbe_mac_82598EB) |
| 7244 | dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS, |
| 7245 | IXGBE_MAX_RSS_INDICES); |
| 7246 | else |
| 7247 | dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS, |
| 7248 | IXGBE_MAX_FDIR_INDICES); |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7249 | #endif |
| 7250 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7251 | if (ii->mac == ixgbe_mac_82598EB) |
| 7252 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7253 | else |
| 7254 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7255 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7256 | #ifdef IXGBE_FCOE |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7257 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7258 | IXGBE_MAX_FCOE_INDICES); |
| 7259 | #endif |
John Fastabend | 3f4a6f0 | 2012-06-05 05:58:52 +0000 | [diff] [blame] | 7260 | indices = max_t(unsigned int, dcb_max, indices); |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7261 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7262 | if (!netdev) { |
| 7263 | err = -ENOMEM; |
| 7264 | goto err_alloc_etherdev; |
| 7265 | } |
| 7266 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7267 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7268 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7269 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7270 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7271 | |
| 7272 | adapter->netdev = netdev; |
| 7273 | adapter->pdev = pdev; |
| 7274 | hw = &adapter->hw; |
| 7275 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 7276 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7277 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7278 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7279 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7280 | if (!hw->hw_addr) { |
| 7281 | err = -EIO; |
| 7282 | goto err_ioremap; |
| 7283 | } |
| 7284 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7285 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7286 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7287 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7288 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7289 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7290 | adapter->bd_number = cards_found; |
| 7291 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7292 | /* Setup hw api */ |
| 7293 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7294 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7295 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7296 | /* EEPROM */ |
| 7297 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7298 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7299 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7300 | if (!(eec & (1 << 8))) |
| 7301 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7302 | |
| 7303 | /* PHY */ |
| 7304 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7305 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7306 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7307 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7308 | hw->phy.mdio.mmds = 0; |
| 7309 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7310 | hw->phy.mdio.dev = netdev; |
| 7311 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7312 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7313 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7314 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7315 | |
| 7316 | /* setup the private structure */ |
| 7317 | err = ixgbe_sw_init(adapter); |
| 7318 | if (err) |
| 7319 | goto err_sw_init; |
| 7320 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7321 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7322 | switch (adapter->hw.mac.type) { |
| 7323 | case ixgbe_mac_82599EB: |
| 7324 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7325 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7326 | break; |
| 7327 | default: |
| 7328 | break; |
| 7329 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7330 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7331 | /* |
| 7332 | * If there is a fan on this device and it has failed log the |
| 7333 | * failure. |
| 7334 | */ |
| 7335 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7336 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7337 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7338 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7339 | } |
| 7340 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 7341 | if (allow_unsupported_sfp) |
| 7342 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 7343 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7344 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7345 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7346 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7347 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7348 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7349 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7350 | err = 0; |
| 7351 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7352 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7353 | "module type was detected.\n"); |
| 7354 | e_dev_err("Reload the driver after installing a supported " |
| 7355 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7356 | goto err_sw_init; |
| 7357 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7358 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7359 | goto err_sw_init; |
| 7360 | } |
| 7361 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 7362 | #ifdef CONFIG_PCI_IOV |
| 7363 | ixgbe_enable_sriov(adapter, ii); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7364 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 7365 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7366 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7367 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7368 | NETIF_F_IPV6_CSUM | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7369 | NETIF_F_HW_VLAN_TX | |
| 7370 | NETIF_F_HW_VLAN_RX | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7371 | NETIF_F_HW_VLAN_FILTER | |
| 7372 | NETIF_F_TSO | |
| 7373 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7374 | NETIF_F_RXHASH | |
| 7375 | NETIF_F_RXCSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7376 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7377 | netdev->hw_features = netdev->features; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7378 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7379 | switch (adapter->hw.mac.type) { |
| 7380 | case ixgbe_mac_82599EB: |
| 7381 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7382 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7383 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 7384 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7385 | break; |
| 7386 | default: |
| 7387 | break; |
| 7388 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7389 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7390 | netdev->hw_features |= NETIF_F_RXALL; |
| 7391 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7392 | netdev->vlan_features |= NETIF_F_TSO; |
| 7393 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7394 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7395 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7396 | netdev->vlan_features |= NETIF_F_SG; |
| 7397 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7398 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 7399 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7400 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7401 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7402 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7403 | #endif |
| 7404 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7405 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7406 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7407 | if (hw->mac.ops.get_device_caps) { |
| 7408 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7409 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7410 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7411 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 7412 | |
| 7413 | adapter->ring_feature[RING_F_FCOE].limit = IXGBE_FCRETA_SIZE; |
| 7414 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 7415 | netdev->features |= NETIF_F_FSO | |
| 7416 | NETIF_F_FCOE_CRC; |
| 7417 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 7418 | netdev->vlan_features |= NETIF_F_FSO | |
| 7419 | NETIF_F_FCOE_CRC | |
| 7420 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7421 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7422 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7423 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7424 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7425 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7426 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7427 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7428 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 7429 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7430 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7431 | netdev->features |= NETIF_F_LRO; |
| 7432 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7433 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7434 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7435 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7436 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 7437 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7438 | } |
| 7439 | |
| 7440 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7441 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7442 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7443 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7444 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7445 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 7446 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7447 | } |
| 7448 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7449 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7450 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7451 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7452 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7453 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7454 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7455 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7456 | if (err) |
| 7457 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7458 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7459 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7460 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7461 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
| 7462 | if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device)) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7463 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7464 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7465 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7466 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 7467 | /* save off EEPROM version number */ |
| 7468 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 7469 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 7470 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7471 | /* pick up the PCI bus settings for reporting later */ |
| 7472 | hw->mac.ops.get_bus_info(hw); |
| 7473 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7474 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7475 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7476 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7477 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7478 | "Unknown"), |
| 7479 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7480 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7481 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7482 | "Unknown"), |
| 7483 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7484 | |
| 7485 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7486 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7487 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7488 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7489 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7490 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7491 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7492 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7493 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7494 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7495 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7496 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7497 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7498 | "not sufficient for optimal performance.\n"); |
| 7499 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7500 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7501 | } |
| 7502 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7503 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7504 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7505 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7506 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7507 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7508 | "Please be aware there may be issues associated " |
| 7509 | "with your hardware. If you are experiencing " |
| 7510 | "problems please contact your Intel or hardware " |
| 7511 | "representative who provided you with this " |
| 7512 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7513 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7514 | strcpy(netdev->name, "eth%d"); |
| 7515 | err = register_netdev(netdev); |
| 7516 | if (err) |
| 7517 | goto err_register; |
| 7518 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 7519 | /* power down the optics for 82599 SFP+ fiber */ |
| 7520 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 7521 | hw->mac.ops.disable_tx_laser(hw); |
| 7522 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 7523 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7524 | netif_carrier_off(netdev); |
| 7525 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7526 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 7527 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7528 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7529 | ixgbe_setup_dca(adapter); |
| 7530 | } |
| 7531 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7532 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7533 | e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7534 | for (i = 0; i < adapter->num_vfs; i++) |
| 7535 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 7536 | } |
| 7537 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 7538 | /* firmware requires driver version to be 0xFFFFFFFF |
| 7539 | * since os does not support feature |
| 7540 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 7541 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 7542 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 7543 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 7544 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7545 | /* add san mac addr to netdev */ |
| 7546 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7547 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 7548 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7549 | cards_found++; |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 7550 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 7551 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 7552 | if (ixgbe_sysfs_init(adapter)) |
| 7553 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 7554 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 7555 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 7556 | #ifdef CONFIG_DEBUG_FS |
| 7557 | ixgbe_dbg_adapter_init(adapter); |
| 7558 | #endif /* CONFIG_DEBUG_FS */ |
| 7559 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7560 | return 0; |
| 7561 | |
| 7562 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7563 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7564 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7565 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 7566 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7567 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7568 | iounmap(hw->hw_addr); |
| 7569 | err_ioremap: |
| 7570 | free_netdev(netdev); |
| 7571 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7572 | pci_release_selected_regions(pdev, |
| 7573 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7574 | err_pci_reg: |
| 7575 | err_dma: |
| 7576 | pci_disable_device(pdev); |
| 7577 | return err; |
| 7578 | } |
| 7579 | |
| 7580 | /** |
| 7581 | * ixgbe_remove - Device Removal Routine |
| 7582 | * @pdev: PCI device information struct |
| 7583 | * |
| 7584 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 7585 | * that it should release a PCI device. The could be caused by a |
| 7586 | * Hot-Plug event, or because the driver is going to be removed from |
| 7587 | * memory. |
| 7588 | **/ |
| 7589 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 7590 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7591 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7592 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7593 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 7594 | #ifdef CONFIG_DEBUG_FS |
| 7595 | ixgbe_dbg_adapter_exit(adapter); |
| 7596 | #endif /*CONFIG_DEBUG_FS */ |
| 7597 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7598 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7599 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7600 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7601 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7602 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7603 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 7604 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 7605 | dca_remove_requester(&pdev->dev); |
| 7606 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 7607 | } |
| 7608 | |
| 7609 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 7610 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 7611 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 7612 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 7613 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7614 | /* remove the added san mac */ |
| 7615 | ixgbe_del_sanmac_netdev(netdev); |
| 7616 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7617 | if (netdev->reg_state == NETREG_REGISTERED) |
| 7618 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7619 | |
Alexander Duyck | 9297127 | 2012-05-23 02:58:40 +0000 | [diff] [blame] | 7620 | ixgbe_disable_sriov(adapter); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7621 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7622 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7623 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7624 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7625 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 7626 | #ifdef CONFIG_DCB |
| 7627 | kfree(adapter->ixgbe_ieee_pfc); |
| 7628 | kfree(adapter->ixgbe_ieee_ets); |
| 7629 | |
| 7630 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7631 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7632 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7633 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7634 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7635 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7636 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7637 | free_netdev(netdev); |
| 7638 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7639 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7640 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7641 | pci_disable_device(pdev); |
| 7642 | } |
| 7643 | |
| 7644 | /** |
| 7645 | * ixgbe_io_error_detected - called when PCI error is detected |
| 7646 | * @pdev: Pointer to PCI device |
| 7647 | * @state: The current pci connection state |
| 7648 | * |
| 7649 | * This function is called after a PCI bus error affecting |
| 7650 | * this device has been detected. |
| 7651 | */ |
| 7652 | static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7653 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7654 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7655 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7656 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7657 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 7658 | #ifdef CONFIG_PCI_IOV |
| 7659 | struct pci_dev *bdev, *vfdev; |
| 7660 | u32 dw0, dw1, dw2, dw3; |
| 7661 | int vf, pos; |
| 7662 | u16 req_id, pf_func; |
| 7663 | |
| 7664 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 7665 | adapter->num_vfs == 0) |
| 7666 | goto skip_bad_vf_detection; |
| 7667 | |
| 7668 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 7669 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 7670 | bdev = bdev->bus->self; |
| 7671 | |
| 7672 | if (!bdev) |
| 7673 | goto skip_bad_vf_detection; |
| 7674 | |
| 7675 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 7676 | if (!pos) |
| 7677 | goto skip_bad_vf_detection; |
| 7678 | |
| 7679 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0); |
| 7680 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1); |
| 7681 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2); |
| 7682 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3); |
| 7683 | |
| 7684 | req_id = dw1 >> 16; |
| 7685 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 7686 | if (!(req_id & 0x0080)) |
| 7687 | goto skip_bad_vf_detection; |
| 7688 | |
| 7689 | pf_func = req_id & 0x01; |
| 7690 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 7691 | unsigned int device_id; |
| 7692 | |
| 7693 | vf = (req_id & 0x7F) >> 1; |
| 7694 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 7695 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 7696 | "%8.8x\tdw3: %8.8x\n", |
| 7697 | dw0, dw1, dw2, dw3); |
| 7698 | switch (adapter->hw.mac.type) { |
| 7699 | case ixgbe_mac_82599EB: |
| 7700 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 7701 | break; |
| 7702 | case ixgbe_mac_X540: |
| 7703 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 7704 | break; |
| 7705 | default: |
| 7706 | device_id = 0; |
| 7707 | break; |
| 7708 | } |
| 7709 | |
| 7710 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 7711 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 7712 | while (vfdev) { |
| 7713 | if (vfdev->devfn == (req_id & 0xFF)) |
| 7714 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 7715 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 7716 | device_id, vfdev); |
| 7717 | } |
| 7718 | /* |
| 7719 | * There's a slim chance the VF could have been hot plugged, |
| 7720 | * so if it is no longer present we don't need to issue the |
| 7721 | * VFLR. Just clean up the AER in that case. |
| 7722 | */ |
| 7723 | if (vfdev) { |
| 7724 | e_dev_err("Issuing VFLR to VF %d\n", vf); |
| 7725 | pci_write_config_dword(vfdev, 0xA8, 0x00008000); |
| 7726 | } |
| 7727 | |
| 7728 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7729 | } |
| 7730 | |
| 7731 | /* |
| 7732 | * Even though the error may have occurred on the other port |
| 7733 | * we still need to increment the vf error reference count for |
| 7734 | * both ports because the I/O resume function will be called |
| 7735 | * for both of them. |
| 7736 | */ |
| 7737 | adapter->vferr_refcount++; |
| 7738 | |
| 7739 | return PCI_ERS_RESULT_RECOVERED; |
| 7740 | |
| 7741 | skip_bad_vf_detection: |
| 7742 | #endif /* CONFIG_PCI_IOV */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7743 | netif_device_detach(netdev); |
| 7744 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 7745 | if (state == pci_channel_io_perm_failure) |
| 7746 | return PCI_ERS_RESULT_DISCONNECT; |
| 7747 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7748 | if (netif_running(netdev)) |
| 7749 | ixgbe_down(adapter); |
| 7750 | pci_disable_device(pdev); |
| 7751 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7752 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7753 | return PCI_ERS_RESULT_NEED_RESET; |
| 7754 | } |
| 7755 | |
| 7756 | /** |
| 7757 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 7758 | * @pdev: Pointer to PCI device |
| 7759 | * |
| 7760 | * Restart the card from scratch, as if from a cold-boot. |
| 7761 | */ |
| 7762 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 7763 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7764 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7765 | pci_ers_result_t result; |
| 7766 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7767 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7768 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7769 | e_err(probe, "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7770 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7771 | } else { |
| 7772 | pci_set_master(pdev); |
| 7773 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 7774 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7775 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 7776 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7777 | |
| 7778 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 7779 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7780 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7781 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7782 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7783 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7784 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7785 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 7786 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7787 | /* non-fatal, continue */ |
| 7788 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7789 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7790 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7791 | } |
| 7792 | |
| 7793 | /** |
| 7794 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 7795 | * @pdev: Pointer to PCI device |
| 7796 | * |
| 7797 | * This callback is called when the error recovery driver tells us that |
| 7798 | * its OK to resume normal operation. |
| 7799 | */ |
| 7800 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 7801 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7802 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7803 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7804 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 7805 | #ifdef CONFIG_PCI_IOV |
| 7806 | if (adapter->vferr_refcount) { |
| 7807 | e_info(drv, "Resuming after VF err\n"); |
| 7808 | adapter->vferr_refcount--; |
| 7809 | return; |
| 7810 | } |
| 7811 | |
| 7812 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 7813 | if (netif_running(netdev)) |
| 7814 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7815 | |
| 7816 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7817 | } |
| 7818 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 7819 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7820 | .error_detected = ixgbe_io_error_detected, |
| 7821 | .slot_reset = ixgbe_io_slot_reset, |
| 7822 | .resume = ixgbe_io_resume, |
| 7823 | }; |
| 7824 | |
| 7825 | static struct pci_driver ixgbe_driver = { |
| 7826 | .name = ixgbe_driver_name, |
| 7827 | .id_table = ixgbe_pci_tbl, |
| 7828 | .probe = ixgbe_probe, |
| 7829 | .remove = __devexit_p(ixgbe_remove), |
| 7830 | #ifdef CONFIG_PM |
| 7831 | .suspend = ixgbe_suspend, |
| 7832 | .resume = ixgbe_resume, |
| 7833 | #endif |
| 7834 | .shutdown = ixgbe_shutdown, |
| 7835 | .err_handler = &ixgbe_err_handler |
| 7836 | }; |
| 7837 | |
| 7838 | /** |
| 7839 | * ixgbe_init_module - Driver Registration Routine |
| 7840 | * |
| 7841 | * ixgbe_init_module is the first routine called when the driver is |
| 7842 | * loaded. All it does is register with the PCI subsystem. |
| 7843 | **/ |
| 7844 | static int __init ixgbe_init_module(void) |
| 7845 | { |
| 7846 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 7847 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7848 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7849 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 7850 | #ifdef CONFIG_DEBUG_FS |
| 7851 | ixgbe_dbg_init(); |
| 7852 | #endif /* CONFIG_DEBUG_FS */ |
| 7853 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7854 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7855 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7856 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7857 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7858 | ret = pci_register_driver(&ixgbe_driver); |
| 7859 | return ret; |
| 7860 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7861 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7862 | module_init(ixgbe_init_module); |
| 7863 | |
| 7864 | /** |
| 7865 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 7866 | * |
| 7867 | * ixgbe_exit_module is called just before the driver is removed |
| 7868 | * from memory. |
| 7869 | **/ |
| 7870 | static void __exit ixgbe_exit_module(void) |
| 7871 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7872 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7873 | dca_unregister_notify(&dca_notifier); |
| 7874 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7875 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 7876 | |
| 7877 | #ifdef CONFIG_DEBUG_FS |
| 7878 | ixgbe_dbg_exit(); |
| 7879 | #endif /* CONFIG_DEBUG_FS */ |
| 7880 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7881 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7882 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7883 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7884 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7885 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7886 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7887 | { |
| 7888 | int ret_val; |
| 7889 | |
| 7890 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7891 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7892 | |
| 7893 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 7894 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7895 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 7896 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7897 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7898 | module_exit(ixgbe_exit_module); |
| 7899 | |
| 7900 | /* ixgbe_main.c */ |