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> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 47 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 48 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | |
| 50 | #include "ixgbe.h" |
| 51 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 52 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 53 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 54 | |
| 55 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 56 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 57 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 58 | char ixgbe_default_device_descr[] = |
| 59 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 60 | #define MAJ 3 |
Don Skidmore | 19d478b | 2011-10-07 03:53:51 +0000 | [diff] [blame] | 61 | #define MIN 6 |
| 62 | #define BUILD 7 |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 63 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 64 | __stringify(BUILD) "-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 65 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 66 | static const char ixgbe_copyright[] = |
Don Skidmore | 9497182 | 2012-01-06 03:24:16 +0000 | [diff] [blame] | 67 | "Copyright (c) 1999-2012 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 68 | |
| 69 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 70 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 71 | [board_82599] = &ixgbe_82599_info, |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 72 | [board_X540] = &ixgbe_X540_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 76 | * |
| 77 | * Wildcard entries (PCI_ANY_ID) should come last |
| 78 | * Last entry must be all 0s |
| 79 | * |
| 80 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 81 | * Class, Class Mask, private data (not used) } |
| 82 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 83 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 84 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 86 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 112 | /* required last entry */ |
| 113 | {0, } |
| 114 | }; |
| 115 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 116 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 117 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 118 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 119 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 120 | static struct notifier_block dca_notifier = { |
| 121 | .notifier_call = ixgbe_notify_dca, |
| 122 | .next = NULL, |
| 123 | .priority = 0 |
| 124 | }; |
| 125 | #endif |
| 126 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 127 | #ifdef CONFIG_PCI_IOV |
| 128 | static unsigned int max_vfs; |
| 129 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 130 | MODULE_PARM_DESC(max_vfs, |
| 131 | "Maximum number of virtual functions to allocate per physical function"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 132 | #endif /* CONFIG_PCI_IOV */ |
| 133 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 134 | static unsigned int allow_unsupported_sfp; |
| 135 | module_param(allow_unsupported_sfp, uint, 0); |
| 136 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 137 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 138 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 139 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 140 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 141 | MODULE_LICENSE("GPL"); |
| 142 | MODULE_VERSION(DRV_VERSION); |
| 143 | |
| 144 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 145 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 146 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 147 | { |
| 148 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
| 149 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
| 150 | schedule_work(&adapter->service_task); |
| 151 | } |
| 152 | |
| 153 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 154 | { |
| 155 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 156 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 157 | /* flush memory to make sure state is correct before next watchdog */ |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 158 | smp_mb__before_clear_bit(); |
| 159 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 160 | } |
| 161 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 162 | struct ixgbe_reg_info { |
| 163 | u32 ofs; |
| 164 | char *name; |
| 165 | }; |
| 166 | |
| 167 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 168 | |
| 169 | /* General Registers */ |
| 170 | {IXGBE_CTRL, "CTRL"}, |
| 171 | {IXGBE_STATUS, "STATUS"}, |
| 172 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 173 | |
| 174 | /* Interrupt Registers */ |
| 175 | {IXGBE_EICR, "EICR"}, |
| 176 | |
| 177 | /* RX Registers */ |
| 178 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 179 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 180 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 181 | {IXGBE_RDH(0), "RDH"}, |
| 182 | {IXGBE_RDT(0), "RDT"}, |
| 183 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 184 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 185 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 186 | |
| 187 | /* TX Registers */ |
| 188 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 189 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 190 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 191 | {IXGBE_TDH(0), "TDH"}, |
| 192 | {IXGBE_TDT(0), "TDT"}, |
| 193 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 194 | |
| 195 | /* List Terminator */ |
| 196 | {} |
| 197 | }; |
| 198 | |
| 199 | |
| 200 | /* |
| 201 | * ixgbe_regdump - register printout routine |
| 202 | */ |
| 203 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 204 | { |
| 205 | int i = 0, j = 0; |
| 206 | char rname[16]; |
| 207 | u32 regs[64]; |
| 208 | |
| 209 | switch (reginfo->ofs) { |
| 210 | case IXGBE_SRRCTL(0): |
| 211 | for (i = 0; i < 64; i++) |
| 212 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 213 | break; |
| 214 | case IXGBE_DCA_RXCTRL(0): |
| 215 | for (i = 0; i < 64; i++) |
| 216 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 217 | break; |
| 218 | case IXGBE_RDLEN(0): |
| 219 | for (i = 0; i < 64; i++) |
| 220 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 221 | break; |
| 222 | case IXGBE_RDH(0): |
| 223 | for (i = 0; i < 64; i++) |
| 224 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 225 | break; |
| 226 | case IXGBE_RDT(0): |
| 227 | for (i = 0; i < 64; i++) |
| 228 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 229 | break; |
| 230 | case IXGBE_RXDCTL(0): |
| 231 | for (i = 0; i < 64; i++) |
| 232 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 233 | break; |
| 234 | case IXGBE_RDBAL(0): |
| 235 | for (i = 0; i < 64; i++) |
| 236 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 237 | break; |
| 238 | case IXGBE_RDBAH(0): |
| 239 | for (i = 0; i < 64; i++) |
| 240 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 241 | break; |
| 242 | case IXGBE_TDBAL(0): |
| 243 | for (i = 0; i < 64; i++) |
| 244 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 245 | break; |
| 246 | case IXGBE_TDBAH(0): |
| 247 | for (i = 0; i < 64; i++) |
| 248 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 249 | break; |
| 250 | case IXGBE_TDLEN(0): |
| 251 | for (i = 0; i < 64; i++) |
| 252 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 253 | break; |
| 254 | case IXGBE_TDH(0): |
| 255 | for (i = 0; i < 64; i++) |
| 256 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 257 | break; |
| 258 | case IXGBE_TDT(0): |
| 259 | for (i = 0; i < 64; i++) |
| 260 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 261 | break; |
| 262 | case IXGBE_TXDCTL(0): |
| 263 | for (i = 0; i < 64; i++) |
| 264 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 265 | break; |
| 266 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 267 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 268 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | for (i = 0; i < 8; i++) { |
| 273 | 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] | 274 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 275 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 276 | pr_cont(" %08x", regs[i*8+j]); |
| 277 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 284 | */ |
| 285 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 286 | { |
| 287 | struct net_device *netdev = adapter->netdev; |
| 288 | struct ixgbe_hw *hw = &adapter->hw; |
| 289 | struct ixgbe_reg_info *reginfo; |
| 290 | int n = 0; |
| 291 | struct ixgbe_ring *tx_ring; |
| 292 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 293 | union ixgbe_adv_tx_desc *tx_desc; |
| 294 | struct my_u0 { u64 a; u64 b; } *u0; |
| 295 | struct ixgbe_ring *rx_ring; |
| 296 | union ixgbe_adv_rx_desc *rx_desc; |
| 297 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 298 | u32 staterr; |
| 299 | int i = 0; |
| 300 | |
| 301 | if (!netif_msg_hw(adapter)) |
| 302 | return; |
| 303 | |
| 304 | /* Print netdevice Info */ |
| 305 | if (netdev) { |
| 306 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 307 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 308 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 309 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 310 | netdev->name, |
| 311 | netdev->state, |
| 312 | netdev->trans_start, |
| 313 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /* Print Registers */ |
| 317 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 318 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 319 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 320 | reginfo->name; reginfo++) { |
| 321 | ixgbe_regdump(hw, reginfo); |
| 322 | } |
| 323 | |
| 324 | /* Print TX Ring Summary */ |
| 325 | if (!netdev || !netif_running(netdev)) |
| 326 | goto exit; |
| 327 | |
| 328 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 329 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 330 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 331 | tx_ring = adapter->tx_ring[n]; |
| 332 | tx_buffer_info = |
| 333 | &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 334 | pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 335 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 336 | (u64)tx_buffer_info->dma, |
| 337 | tx_buffer_info->length, |
| 338 | tx_buffer_info->next_to_watch, |
| 339 | (u64)tx_buffer_info->time_stamp); |
| 340 | } |
| 341 | |
| 342 | /* Print TX Rings */ |
| 343 | if (!netif_msg_tx_done(adapter)) |
| 344 | goto rx_ring_summary; |
| 345 | |
| 346 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 347 | |
| 348 | /* Transmit Descriptor Formats |
| 349 | * |
| 350 | * Advanced Transmit Descriptor |
| 351 | * +--------------------------------------------------------------+ |
| 352 | * 0 | Buffer Address [63:0] | |
| 353 | * +--------------------------------------------------------------+ |
| 354 | * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
| 355 | * +--------------------------------------------------------------+ |
| 356 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 |
| 357 | */ |
| 358 | |
| 359 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 360 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 361 | pr_info("------------------------------------\n"); |
| 362 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 363 | pr_info("------------------------------------\n"); |
| 364 | pr_info("T [desc] [address 63:0 ] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 365 | "[PlPOIdStDDt Ln] [bi->dma ] " |
| 366 | "leng ntw timestamp bi->skb\n"); |
| 367 | |
| 368 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 369 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 370 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 371 | u0 = (struct my_u0 *)tx_desc; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 372 | pr_info("T [0x%03X] %016llX %016llX %016llX" |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 373 | " %04X %p %016llX %p", i, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 374 | le64_to_cpu(u0->a), |
| 375 | le64_to_cpu(u0->b), |
| 376 | (u64)tx_buffer_info->dma, |
| 377 | tx_buffer_info->length, |
| 378 | tx_buffer_info->next_to_watch, |
| 379 | (u64)tx_buffer_info->time_stamp, |
| 380 | tx_buffer_info->skb); |
| 381 | if (i == tx_ring->next_to_use && |
| 382 | i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 383 | pr_cont(" NTC/U\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 384 | else if (i == tx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 385 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 386 | else if (i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 387 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 388 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 389 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 390 | |
| 391 | if (netif_msg_pktdata(adapter) && |
| 392 | tx_buffer_info->dma != 0) |
| 393 | print_hex_dump(KERN_INFO, "", |
| 394 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 395 | phys_to_virt(tx_buffer_info->dma), |
| 396 | tx_buffer_info->length, true); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | /* Print RX Rings Summary */ |
| 401 | rx_ring_summary: |
| 402 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 403 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 404 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 405 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 406 | pr_info("%5d %5X %5X\n", |
| 407 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* Print RX Rings */ |
| 411 | if (!netif_msg_rx_status(adapter)) |
| 412 | goto exit; |
| 413 | |
| 414 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 415 | |
| 416 | /* Advanced Receive Descriptor (Read) Format |
| 417 | * 63 1 0 |
| 418 | * +-----------------------------------------------------+ |
| 419 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 420 | * +----------------------------------------------+------+ |
| 421 | * 8 | Header Buffer Address [63:1] | DD | |
| 422 | * +-----------------------------------------------------+ |
| 423 | * |
| 424 | * |
| 425 | * Advanced Receive Descriptor (Write-Back) Format |
| 426 | * |
| 427 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 428 | * +------------------------------------------------------+ |
| 429 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | |
| 430 | * | Checksum Ident | | | | Type | Type | |
| 431 | * +------------------------------------------------------+ |
| 432 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 433 | * +------------------------------------------------------+ |
| 434 | * 63 48 47 32 31 20 19 0 |
| 435 | */ |
| 436 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 437 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 438 | pr_info("------------------------------------\n"); |
| 439 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 440 | pr_info("------------------------------------\n"); |
| 441 | pr_info("R [desc] [ PktBuf A0] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 442 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " |
| 443 | "<-- Adv Rx Read format\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 444 | pr_info("RWB[desc] [PcsmIpSHl PtRs] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 445 | "[vl er S cks ln] ---------------- [bi->skb] " |
| 446 | "<-- Adv Rx Write-Back format\n"); |
| 447 | |
| 448 | for (i = 0; i < rx_ring->count; i++) { |
| 449 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 450 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 451 | u0 = (struct my_u0 *)rx_desc; |
| 452 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 453 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 454 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 455 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 456 | "%016llX ---------------- %p", i, |
| 457 | le64_to_cpu(u0->a), |
| 458 | le64_to_cpu(u0->b), |
| 459 | rx_buffer_info->skb); |
| 460 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 461 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 462 | "%016llX %016llX %p", i, |
| 463 | le64_to_cpu(u0->a), |
| 464 | le64_to_cpu(u0->b), |
| 465 | (u64)rx_buffer_info->dma, |
| 466 | rx_buffer_info->skb); |
| 467 | |
| 468 | if (netif_msg_pktdata(adapter)) { |
| 469 | print_hex_dump(KERN_INFO, "", |
| 470 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 471 | phys_to_virt(rx_buffer_info->dma), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 472 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
| 476 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 477 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 478 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 479 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 480 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 481 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 482 | |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | exit: |
| 487 | return; |
| 488 | } |
| 489 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 490 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 491 | { |
| 492 | u32 ctrl_ext; |
| 493 | |
| 494 | /* Let firmware take over control of h/w */ |
| 495 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 496 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 497 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 501 | { |
| 502 | u32 ctrl_ext; |
| 503 | |
| 504 | /* Let firmware know the driver has taken over */ |
| 505 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 506 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 507 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 508 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 509 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 510 | /* |
| 511 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 512 | * @adapter: pointer to adapter struct |
| 513 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 514 | * @queue: queue to map the corresponding interrupt to |
| 515 | * @msix_vector: the vector to map to the corresponding queue |
| 516 | * |
| 517 | */ |
| 518 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 519 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 520 | { |
| 521 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 522 | struct ixgbe_hw *hw = &adapter->hw; |
| 523 | switch (hw->mac.type) { |
| 524 | case ixgbe_mac_82598EB: |
| 525 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 526 | if (direction == -1) |
| 527 | direction = 0; |
| 528 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 529 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 530 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 531 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 532 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 533 | break; |
| 534 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 535 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 536 | if (direction == -1) { |
| 537 | /* other causes */ |
| 538 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 539 | index = ((queue & 1) * 8); |
| 540 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 541 | ivar &= ~(0xFF << index); |
| 542 | ivar |= (msix_vector << index); |
| 543 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 544 | break; |
| 545 | } else { |
| 546 | /* tx or rx causes */ |
| 547 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 548 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 549 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 550 | ivar &= ~(0xFF << index); |
| 551 | ivar |= (msix_vector << index); |
| 552 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 553 | break; |
| 554 | } |
| 555 | default: |
| 556 | break; |
| 557 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 560 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 561 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 562 | { |
| 563 | u32 mask; |
| 564 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 565 | switch (adapter->hw.mac.type) { |
| 566 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 567 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 568 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 569 | break; |
| 570 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 571 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 572 | mask = (qmask & 0xFFFFFFFF); |
| 573 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 574 | mask = (qmask >> 32); |
| 575 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 576 | break; |
| 577 | default: |
| 578 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 582 | static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring, |
| 583 | struct ixgbe_tx_buffer *tx_buffer) |
| 584 | { |
| 585 | if (tx_buffer->dma) { |
| 586 | if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE) |
| 587 | dma_unmap_page(ring->dev, |
| 588 | tx_buffer->dma, |
| 589 | tx_buffer->length, |
| 590 | DMA_TO_DEVICE); |
| 591 | else |
| 592 | dma_unmap_single(ring->dev, |
| 593 | tx_buffer->dma, |
| 594 | tx_buffer->length, |
| 595 | DMA_TO_DEVICE); |
| 596 | } |
| 597 | tx_buffer->dma = 0; |
| 598 | } |
| 599 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 600 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring, |
| 601 | struct ixgbe_tx_buffer *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 602 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 603 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info); |
| 604 | if (tx_buffer_info->skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 605 | dev_kfree_skb_any(tx_buffer_info->skb); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 606 | tx_buffer_info->skb = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 607 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 608 | } |
| 609 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 610 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 611 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 612 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 613 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 614 | u32 data = 0; |
| 615 | u32 xoff[8] = {0}; |
| 616 | int i; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 617 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 618 | if ((hw->fc.current_mode == ixgbe_fc_full) || |
| 619 | (hw->fc.current_mode == ixgbe_fc_rx_pause)) { |
| 620 | switch (hw->mac.type) { |
| 621 | case ixgbe_mac_82598EB: |
| 622 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 623 | break; |
| 624 | default: |
| 625 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 626 | } |
| 627 | hwstats->lxoffrxc += data; |
| 628 | |
| 629 | /* refill credits (no tx hang) if we received xoff */ |
| 630 | if (!data) |
| 631 | return; |
| 632 | |
| 633 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 634 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 635 | &adapter->tx_ring[i]->state); |
| 636 | return; |
| 637 | } else if (!(adapter->dcb_cfg.pfc_mode_enable)) |
| 638 | return; |
| 639 | |
| 640 | /* update stats for each tc, only valid with PFC enabled */ |
| 641 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
| 642 | switch (hw->mac.type) { |
| 643 | case ixgbe_mac_82598EB: |
| 644 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 645 | break; |
| 646 | default: |
| 647 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 648 | } |
| 649 | hwstats->pxoffrxc[i] += xoff[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 650 | } |
| 651 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 652 | /* disarm tx queues that have received xoff frames */ |
| 653 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 654 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | fb5475f | 2011-04-26 07:26:36 +0000 | [diff] [blame] | 655 | u8 tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 656 | |
| 657 | if (xoff[tc]) |
| 658 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 663 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 664 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 668 | { |
| 669 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); |
| 670 | struct ixgbe_hw *hw = &adapter->hw; |
| 671 | |
| 672 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 673 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
| 674 | |
| 675 | if (head != tail) |
| 676 | return (head < tail) ? |
| 677 | tail - head : (tail + ring->count - head); |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 683 | { |
| 684 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 685 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 686 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 687 | bool ret = false; |
| 688 | |
| 689 | clear_check_for_tx_hang(tx_ring); |
| 690 | |
| 691 | /* |
| 692 | * Check for a hung queue, but be thorough. This verifies |
| 693 | * that a transmit has been completed since the previous |
| 694 | * check AND there is at least one packet pending. The |
| 695 | * ARMED bit is set to indicate a potential hang. The |
| 696 | * bit is cleared if a pause frame is received to remove |
| 697 | * false hang detection due to PFC or 802.3x frames. By |
| 698 | * requiring this to fail twice we avoid races with |
| 699 | * pfc clearing the ARMED bit and conditions where we |
| 700 | * run the check_tx_hang logic with a transmit completion |
| 701 | * pending but without time to complete it yet. |
| 702 | */ |
| 703 | if ((tx_done_old == tx_done) && tx_pending) { |
| 704 | /* make sure it is true for two checks in a row */ |
| 705 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 706 | &tx_ring->state); |
| 707 | } else { |
| 708 | /* update completed stats and continue */ |
| 709 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 710 | /* reset the countdown */ |
| 711 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 712 | } |
| 713 | |
| 714 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 717 | /** |
| 718 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 719 | * @adapter: driver private struct |
| 720 | **/ |
| 721 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 722 | { |
| 723 | |
| 724 | /* Do the reset outside of interrupt context */ |
| 725 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 726 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 727 | ixgbe_service_event_schedule(adapter); |
| 728 | } |
| 729 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 730 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 731 | /** |
| 732 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 733 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 734 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 735 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 736 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 737 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 738 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 739 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 740 | struct ixgbe_tx_buffer *tx_buffer; |
| 741 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 742 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 743 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 744 | u16 i = tx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 745 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 746 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 747 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 748 | |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 749 | for (; budget; budget--) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 750 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 751 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 752 | /* if next_to_watch is not set then there is no work pending */ |
| 753 | if (!eop_desc) |
| 754 | break; |
| 755 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 756 | /* prevent any other reads prior to eop_desc */ |
| 757 | rmb(); |
| 758 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 759 | /* if DD is not set pending work has not been completed */ |
| 760 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 761 | break; |
| 762 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 763 | /* clear next_to_watch to prevent false hangs */ |
| 764 | tx_buffer->next_to_watch = NULL; |
| 765 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame^] | 766 | /* update the statistics for this packet */ |
| 767 | total_bytes += tx_buffer->bytecount; |
| 768 | total_packets += tx_buffer->gso_segs; |
| 769 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 770 | /* free the skb */ |
| 771 | dev_kfree_skb_any(tx_buffer->skb); |
| 772 | |
| 773 | /* clear tx_buffer data */ |
| 774 | tx_buffer->skb = NULL; |
| 775 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 776 | do { |
| 777 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer); |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame^] | 778 | if (likely(tx_desc == eop_desc)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 779 | eop_desc = NULL; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 780 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 781 | tx_buffer++; |
| 782 | tx_desc++; |
| 783 | i++; |
| 784 | if (unlikely(i == tx_ring->count)) { |
| 785 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 786 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 787 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 788 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | } while (eop_desc); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 792 | } |
| 793 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 794 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 795 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 796 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 797 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 798 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 799 | q_vector->tx.total_bytes += total_bytes; |
| 800 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 801 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 802 | 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] | 803 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 804 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 805 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 806 | e_err(drv, "Detected Tx Unit Hang\n" |
| 807 | " Tx Queue <%d>\n" |
| 808 | " TDH, TDT <%x>, <%x>\n" |
| 809 | " next_to_use <%x>\n" |
| 810 | " next_to_clean <%x>\n" |
| 811 | "tx_buffer_info[next_to_clean]\n" |
| 812 | " time_stamp <%lx>\n" |
| 813 | " jiffies <%lx>\n", |
| 814 | tx_ring->queue_index, |
| 815 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 816 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 817 | tx_ring->next_to_use, i, |
| 818 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 819 | |
| 820 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 821 | |
| 822 | e_info(probe, |
| 823 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 824 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 825 | |
| 826 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 827 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 828 | |
| 829 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 830 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 831 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 832 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 833 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 834 | total_packets, total_bytes); |
| 835 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 836 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 837 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 838 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 839 | /* Make sure that anybody stopping the queue after this |
| 840 | * sees the new next_to_clean. |
| 841 | */ |
| 842 | smp_mb(); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 843 | if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) && |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 844 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 845 | netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 846 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 847 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 848 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 849 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 850 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 853 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 854 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 855 | struct ixgbe_ring *tx_ring, |
| 856 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 857 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 858 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 859 | u32 txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 860 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 861 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 862 | switch (hw->mac.type) { |
| 863 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 864 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 865 | break; |
| 866 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 867 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 868 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 869 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 870 | break; |
| 871 | default: |
| 872 | /* for unknown hardware do not write register */ |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | /* |
| 877 | * We can enable relaxed ordering for reads, but not writes when |
| 878 | * DCA is enabled. This is due to a known issue in some chipsets |
| 879 | * which will cause the DCA tag to be cleared. |
| 880 | */ |
| 881 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 882 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 883 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 884 | |
| 885 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 886 | } |
| 887 | |
| 888 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 889 | struct ixgbe_ring *rx_ring, |
| 890 | int cpu) |
| 891 | { |
| 892 | struct ixgbe_hw *hw = &adapter->hw; |
| 893 | u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
| 894 | u8 reg_idx = rx_ring->reg_idx; |
| 895 | |
| 896 | |
| 897 | switch (hw->mac.type) { |
| 898 | case ixgbe_mac_82599EB: |
| 899 | case ixgbe_mac_X540: |
| 900 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 901 | break; |
| 902 | default: |
| 903 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 904 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 905 | |
| 906 | /* |
| 907 | * We can enable relaxed ordering for reads, but not writes when |
| 908 | * DCA is enabled. This is due to a known issue in some chipsets |
| 909 | * which will cause the DCA tag to be cleared. |
| 910 | */ |
| 911 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
| 912 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
| 913 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 914 | |
| 915 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 919 | { |
| 920 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 921 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 922 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 923 | |
| 924 | if (q_vector->cpu == cpu) |
| 925 | goto out_no_update; |
| 926 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 927 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 928 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 929 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 930 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 931 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 932 | |
| 933 | q_vector->cpu = cpu; |
| 934 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 935 | put_cpu(); |
| 936 | } |
| 937 | |
| 938 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 939 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 940 | int num_q_vectors; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 941 | int i; |
| 942 | |
| 943 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 944 | return; |
| 945 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 946 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 947 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 948 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 949 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 950 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 951 | else |
| 952 | num_q_vectors = 1; |
| 953 | |
| 954 | for (i = 0; i < num_q_vectors; i++) { |
| 955 | adapter->q_vector[i]->cpu = -1; |
| 956 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
| 960 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 961 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 962 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 963 | unsigned long event = *(unsigned long *)data; |
| 964 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 965 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 966 | return 0; |
| 967 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 968 | switch (event) { |
| 969 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 970 | /* if we're already enabled, don't do it again */ |
| 971 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 972 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 973 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 974 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 975 | ixgbe_setup_dca(adapter); |
| 976 | break; |
| 977 | } |
| 978 | /* Fall Through since DCA is disabled. */ |
| 979 | case DCA_PROVIDER_REMOVE: |
| 980 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 981 | dca_remove_requester(dev); |
| 982 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 983 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 984 | } |
| 985 | break; |
| 986 | } |
| 987 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 988 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 989 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 990 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 991 | #endif /* CONFIG_IXGBE_DCA */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 992 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 993 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 994 | struct sk_buff *skb) |
| 995 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 996 | if (ring->netdev->features & NETIF_F_RXHASH) |
| 997 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1000 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1001 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1002 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
| 1003 | * @adapter: address of board private structure |
| 1004 | * @rx_desc: advanced rx descriptor |
| 1005 | * |
| 1006 | * Returns : true if it is FCoE pkt |
| 1007 | */ |
| 1008 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter, |
| 1009 | union ixgbe_adv_rx_desc *rx_desc) |
| 1010 | { |
| 1011 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1012 | |
| 1013 | return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 1014 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1015 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1016 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1017 | } |
| 1018 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1019 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1020 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1021 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1022 | * @ring: structure containing ring specific data |
| 1023 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1024 | * @skb: skb currently being received and modified |
| 1025 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1026 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1027 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1028 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1029 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1030 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1031 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1032 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1033 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1034 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1035 | |
| 1036 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1037 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1038 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1039 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1040 | return; |
| 1041 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1042 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1043 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1044 | return; |
| 1045 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1046 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1047 | __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] | 1048 | |
| 1049 | /* |
| 1050 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1051 | * checksum errors. |
| 1052 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1053 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1054 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1055 | return; |
| 1056 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1057 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1058 | return; |
| 1059 | } |
| 1060 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1061 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1062 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1065 | 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] | 1066 | { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1067 | rx_ring->next_to_use = val; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1068 | |
| 1069 | /* update next to alloc since we have filled the ring */ |
| 1070 | rx_ring->next_to_alloc = val; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1071 | /* |
| 1072 | * Force memory writes to complete before letting h/w |
| 1073 | * know there are new descriptors to fetch. (Only |
| 1074 | * applicable for weak-ordered memory model archs, |
| 1075 | * such as IA-64). |
| 1076 | */ |
| 1077 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1078 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1081 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1082 | struct ixgbe_rx_buffer *bi) |
| 1083 | { |
| 1084 | struct page *page = bi->page; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1085 | dma_addr_t dma = bi->dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1086 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1087 | /* since we are recycling buffers we should seldom need to alloc */ |
| 1088 | if (likely(dma)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1089 | return true; |
| 1090 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1091 | /* alloc new page for storage */ |
| 1092 | if (likely(!page)) { |
| 1093 | page = alloc_pages(GFP_ATOMIC | __GFP_COLD, |
| 1094 | ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1095 | if (unlikely(!page)) { |
| 1096 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1097 | return false; |
| 1098 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1099 | bi->page = page; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1102 | /* map page for use */ |
| 1103 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1104 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1105 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1106 | /* |
| 1107 | * if mapping failed free memory back to system since |
| 1108 | * there isn't much point in holding memory we can't use |
| 1109 | */ |
| 1110 | if (dma_mapping_error(rx_ring->dev, dma)) { |
| 1111 | put_page(page); |
| 1112 | bi->page = NULL; |
| 1113 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1114 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1115 | return false; |
| 1116 | } |
| 1117 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1118 | bi->dma = dma; |
| 1119 | bi->page_offset ^= ixgbe_rx_bufsz(rx_ring); |
| 1120 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1121 | return true; |
| 1122 | } |
| 1123 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1124 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1125 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1126 | * @rx_ring: ring to place buffers on |
| 1127 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1128 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1129 | 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] | 1130 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1131 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1132 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1133 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1134 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1135 | /* nothing to do */ |
| 1136 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1137 | return; |
| 1138 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1139 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1140 | bi = &rx_ring->rx_buffer_info[i]; |
| 1141 | i -= rx_ring->count; |
| 1142 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1143 | do { |
| 1144 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1145 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1146 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1147 | /* |
| 1148 | * Refresh the desc even if buffer_addrs didn't change |
| 1149 | * because each write-back erases this info. |
| 1150 | */ |
| 1151 | 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] | 1152 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1153 | rx_desc++; |
| 1154 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1155 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1156 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1157 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1158 | bi = rx_ring->rx_buffer_info; |
| 1159 | i -= rx_ring->count; |
| 1160 | } |
| 1161 | |
| 1162 | /* clear the hdr_addr for the next_to_use descriptor */ |
| 1163 | rx_desc->read.hdr_addr = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1164 | |
| 1165 | cleaned_count--; |
| 1166 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1167 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1168 | i += rx_ring->count; |
| 1169 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1170 | if (rx_ring->next_to_use != i) |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1171 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1174 | /** |
| 1175 | * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE |
| 1176 | * @data: pointer to the start of the headers |
| 1177 | * @max_len: total length of section to find headers in |
| 1178 | * |
| 1179 | * This function is meant to determine the length of headers that will |
| 1180 | * be recognized by hardware for LRO, GRO, and RSC offloads. The main |
| 1181 | * motivation of doing this is to only perform one pull for IPv4 TCP |
| 1182 | * packets so that we can do basic things like calculating the gso_size |
| 1183 | * based on the average data per packet. |
| 1184 | **/ |
| 1185 | static unsigned int ixgbe_get_headlen(unsigned char *data, |
| 1186 | unsigned int max_len) |
| 1187 | { |
| 1188 | union { |
| 1189 | unsigned char *network; |
| 1190 | /* l2 headers */ |
| 1191 | struct ethhdr *eth; |
| 1192 | struct vlan_hdr *vlan; |
| 1193 | /* l3 headers */ |
| 1194 | struct iphdr *ipv4; |
| 1195 | } hdr; |
| 1196 | __be16 protocol; |
| 1197 | u8 nexthdr = 0; /* default to not TCP */ |
| 1198 | u8 hlen; |
| 1199 | |
| 1200 | /* this should never happen, but better safe than sorry */ |
| 1201 | if (max_len < ETH_HLEN) |
| 1202 | return max_len; |
| 1203 | |
| 1204 | /* initialize network frame pointer */ |
| 1205 | hdr.network = data; |
| 1206 | |
| 1207 | /* set first protocol and move network header forward */ |
| 1208 | protocol = hdr.eth->h_proto; |
| 1209 | hdr.network += ETH_HLEN; |
| 1210 | |
| 1211 | /* handle any vlan tag if present */ |
| 1212 | if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 1213 | if ((hdr.network - data) > (max_len - VLAN_HLEN)) |
| 1214 | return max_len; |
| 1215 | |
| 1216 | protocol = hdr.vlan->h_vlan_encapsulated_proto; |
| 1217 | hdr.network += VLAN_HLEN; |
| 1218 | } |
| 1219 | |
| 1220 | /* handle L3 protocols */ |
| 1221 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 1222 | if ((hdr.network - data) > (max_len - sizeof(struct iphdr))) |
| 1223 | return max_len; |
| 1224 | |
| 1225 | /* access ihl as a u8 to avoid unaligned access on ia64 */ |
| 1226 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 1227 | |
| 1228 | /* verify hlen meets minimum size requirements */ |
| 1229 | if (hlen < sizeof(struct iphdr)) |
| 1230 | return hdr.network - data; |
| 1231 | |
| 1232 | /* record next protocol */ |
| 1233 | nexthdr = hdr.ipv4->protocol; |
| 1234 | hdr.network += hlen; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1235 | #ifdef IXGBE_FCOE |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1236 | } else if (protocol == __constant_htons(ETH_P_FCOE)) { |
| 1237 | if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN)) |
| 1238 | return max_len; |
| 1239 | hdr.network += FCOE_HEADER_LEN; |
| 1240 | #endif |
| 1241 | } else { |
| 1242 | return hdr.network - data; |
| 1243 | } |
| 1244 | |
| 1245 | /* finally sort out TCP */ |
| 1246 | if (nexthdr == IPPROTO_TCP) { |
| 1247 | if ((hdr.network - data) > (max_len - sizeof(struct tcphdr))) |
| 1248 | return max_len; |
| 1249 | |
| 1250 | /* access doff as a u8 to avoid unaligned access on ia64 */ |
| 1251 | hlen = (hdr.network[12] & 0xF0) >> 2; |
| 1252 | |
| 1253 | /* verify hlen meets minimum size requirements */ |
| 1254 | if (hlen < sizeof(struct tcphdr)) |
| 1255 | return hdr.network - data; |
| 1256 | |
| 1257 | hdr.network += hlen; |
| 1258 | } |
| 1259 | |
| 1260 | /* |
| 1261 | * If everything has gone correctly hdr.network should be the |
| 1262 | * data section of the packet and will be the end of the header. |
| 1263 | * If not then it probably represents the end of the last recognized |
| 1264 | * header. |
| 1265 | */ |
| 1266 | if ((hdr.network - data) < max_len) |
| 1267 | return hdr.network - data; |
| 1268 | else |
| 1269 | return max_len; |
| 1270 | } |
| 1271 | |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1272 | static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring, |
| 1273 | union ixgbe_adv_rx_desc *rx_desc, |
| 1274 | struct sk_buff *skb) |
| 1275 | { |
| 1276 | __le32 rsc_enabled; |
| 1277 | u32 rsc_cnt; |
| 1278 | |
| 1279 | if (!ring_is_rsc_enabled(rx_ring)) |
| 1280 | return; |
| 1281 | |
| 1282 | rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1283 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1284 | |
| 1285 | /* If this is an RSC frame rsc_cnt should be non-zero */ |
| 1286 | if (!rsc_enabled) |
| 1287 | return; |
| 1288 | |
| 1289 | rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1290 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1291 | |
| 1292 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1293 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1294 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1295 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1296 | struct sk_buff *skb) |
| 1297 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1298 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1299 | |
| 1300 | /* set gso_size to avoid messing up TCP MSS */ |
| 1301 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1302 | IXGBE_CB(skb)->append_cnt); |
| 1303 | } |
| 1304 | |
| 1305 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1306 | struct sk_buff *skb) |
| 1307 | { |
| 1308 | /* if append_cnt is 0 then frame is not RSC */ |
| 1309 | if (!IXGBE_CB(skb)->append_cnt) |
| 1310 | return; |
| 1311 | |
| 1312 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1313 | rx_ring->rx_stats.rsc_flush++; |
| 1314 | |
| 1315 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1316 | |
| 1317 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1318 | IXGBE_CB(skb)->append_cnt = 0; |
| 1319 | } |
| 1320 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1321 | /** |
| 1322 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1323 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1324 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1325 | * @skb: pointer to current skb being populated |
| 1326 | * |
| 1327 | * This function checks the ring, descriptor, and packet information in |
| 1328 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1329 | * other fields within the skb. |
| 1330 | **/ |
| 1331 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1332 | union ixgbe_adv_rx_desc *rx_desc, |
| 1333 | struct sk_buff *skb) |
| 1334 | { |
| 1335 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1336 | |
| 1337 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1338 | |
| 1339 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1340 | |
| 1341 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
| 1342 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
| 1343 | __vlan_hwaccel_put_tag(skb, vid); |
| 1344 | } |
| 1345 | |
| 1346 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1347 | |
| 1348 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
| 1349 | } |
| 1350 | |
| 1351 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1352 | struct sk_buff *skb) |
| 1353 | { |
| 1354 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1355 | |
| 1356 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1357 | napi_gro_receive(&q_vector->napi, skb); |
| 1358 | else |
| 1359 | netif_rx(skb); |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1362 | /** |
| 1363 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1364 | * @rx_ring: Rx ring being processed |
| 1365 | * @rx_desc: Rx descriptor for current buffer |
| 1366 | * @skb: Current socket buffer containing buffer in progress |
| 1367 | * |
| 1368 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1369 | * this function exits returning false, otherwise it will place the |
| 1370 | * sk_buff in the next buffer to be chained and return true indicating |
| 1371 | * that this is in fact a non-EOP buffer. |
| 1372 | **/ |
| 1373 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1374 | union ixgbe_adv_rx_desc *rx_desc, |
| 1375 | struct sk_buff *skb) |
| 1376 | { |
| 1377 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1378 | |
| 1379 | /* fetch, update, and store next to clean */ |
| 1380 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1381 | rx_ring->next_to_clean = ntc; |
| 1382 | |
| 1383 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1384 | |
| 1385 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1386 | return false; |
| 1387 | |
| 1388 | /* append_cnt indicates packet is RSC, if so fetch nextp */ |
| 1389 | if (IXGBE_CB(skb)->append_cnt) { |
| 1390 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1391 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1392 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1393 | } |
| 1394 | |
| 1395 | /* place skb in next buffer to be received */ |
| 1396 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1397 | rx_ring->rx_stats.non_eop_descs++; |
| 1398 | |
| 1399 | return true; |
| 1400 | } |
| 1401 | |
| 1402 | /** |
| 1403 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1404 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1405 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1406 | * @skb: pointer to current skb being fixed |
| 1407 | * |
| 1408 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1409 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1410 | * should be very rare. |
| 1411 | * |
| 1412 | * Also address the case where we are pulling data in on pages only |
| 1413 | * and as such no data is present in the skb header. |
| 1414 | * |
| 1415 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1416 | * it is large enough to qualify as a valid Ethernet frame. |
| 1417 | * |
| 1418 | * Returns true if an error was encountered and skb was freed. |
| 1419 | **/ |
| 1420 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1421 | union ixgbe_adv_rx_desc *rx_desc, |
| 1422 | struct sk_buff *skb) |
| 1423 | { |
| 1424 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1425 | struct net_device *netdev = rx_ring->netdev; |
| 1426 | unsigned char *va; |
| 1427 | unsigned int pull_len; |
| 1428 | |
| 1429 | /* if the page was released unmap it, else just sync our portion */ |
| 1430 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1431 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1432 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1433 | IXGBE_CB(skb)->page_released = false; |
| 1434 | } else { |
| 1435 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1436 | IXGBE_CB(skb)->dma, |
| 1437 | frag->page_offset, |
| 1438 | ixgbe_rx_bufsz(rx_ring), |
| 1439 | DMA_FROM_DEVICE); |
| 1440 | } |
| 1441 | IXGBE_CB(skb)->dma = 0; |
| 1442 | |
| 1443 | /* verify that the packet does not have any known errors */ |
| 1444 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1445 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1446 | !(netdev->features & NETIF_F_RXALL))) { |
| 1447 | dev_kfree_skb_any(skb); |
| 1448 | return true; |
| 1449 | } |
| 1450 | |
| 1451 | /* |
| 1452 | * it is valid to use page_address instead of kmap since we are |
| 1453 | * working with pages allocated out of the lomem pool per |
| 1454 | * alloc_page(GFP_ATOMIC) |
| 1455 | */ |
| 1456 | va = skb_frag_address(frag); |
| 1457 | |
| 1458 | /* |
| 1459 | * we need the header to contain the greater of either ETH_HLEN or |
| 1460 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1461 | */ |
| 1462 | pull_len = skb_frag_size(frag); |
| 1463 | if (pull_len > 256) |
| 1464 | pull_len = ixgbe_get_headlen(va, pull_len); |
| 1465 | |
| 1466 | /* align pull length to size of long to optimize memcpy performance */ |
| 1467 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1468 | |
| 1469 | /* update all of the pointers */ |
| 1470 | skb_frag_size_sub(frag, pull_len); |
| 1471 | frag->page_offset += pull_len; |
| 1472 | skb->data_len -= pull_len; |
| 1473 | skb->tail += pull_len; |
| 1474 | |
| 1475 | /* |
| 1476 | * if we sucked the frag empty then we should free it, |
| 1477 | * if there are other frags here something is screwed up in hardware |
| 1478 | */ |
| 1479 | if (skb_frag_size(frag) == 0) { |
| 1480 | BUG_ON(skb_shinfo(skb)->nr_frags != 1); |
| 1481 | skb_shinfo(skb)->nr_frags = 0; |
| 1482 | __skb_frag_unref(frag); |
| 1483 | skb->truesize -= ixgbe_rx_bufsz(rx_ring); |
| 1484 | } |
| 1485 | |
| 1486 | /* if skb_pad returns an error the skb was freed */ |
| 1487 | if (unlikely(skb->len < 60)) { |
| 1488 | int pad_len = 60 - skb->len; |
| 1489 | |
| 1490 | if (skb_pad(skb, pad_len)) |
| 1491 | return true; |
| 1492 | __skb_put(skb, pad_len); |
| 1493 | } |
| 1494 | |
| 1495 | return false; |
| 1496 | } |
| 1497 | |
| 1498 | /** |
| 1499 | * ixgbe_can_reuse_page - determine if we can reuse a page |
| 1500 | * @rx_buffer: pointer to rx_buffer containing the page we want to reuse |
| 1501 | * |
| 1502 | * Returns true if page can be reused in another Rx buffer |
| 1503 | **/ |
| 1504 | static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer) |
| 1505 | { |
| 1506 | struct page *page = rx_buffer->page; |
| 1507 | |
| 1508 | /* if we are only owner of page and it is local we can reuse it */ |
| 1509 | return likely(page_count(page) == 1) && |
| 1510 | likely(page_to_nid(page) == numa_node_id()); |
| 1511 | } |
| 1512 | |
| 1513 | /** |
| 1514 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1515 | * @rx_ring: rx descriptor ring to store buffers on |
| 1516 | * @old_buff: donor buffer to have page reused |
| 1517 | * |
| 1518 | * Syncronizes page for reuse by the adapter |
| 1519 | **/ |
| 1520 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1521 | struct ixgbe_rx_buffer *old_buff) |
| 1522 | { |
| 1523 | struct ixgbe_rx_buffer *new_buff; |
| 1524 | u16 nta = rx_ring->next_to_alloc; |
| 1525 | u16 bufsz = ixgbe_rx_bufsz(rx_ring); |
| 1526 | |
| 1527 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1528 | |
| 1529 | /* update, and store next to alloc */ |
| 1530 | nta++; |
| 1531 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1532 | |
| 1533 | /* transfer page from old buffer to new buffer */ |
| 1534 | new_buff->page = old_buff->page; |
| 1535 | new_buff->dma = old_buff->dma; |
| 1536 | |
| 1537 | /* flip page offset to other buffer and store to new_buff */ |
| 1538 | new_buff->page_offset = old_buff->page_offset ^ bufsz; |
| 1539 | |
| 1540 | /* sync the buffer for use by the device */ |
| 1541 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
| 1542 | new_buff->page_offset, bufsz, |
| 1543 | DMA_FROM_DEVICE); |
| 1544 | |
| 1545 | /* bump ref count on page before it is given to the stack */ |
| 1546 | get_page(new_buff->page); |
| 1547 | } |
| 1548 | |
| 1549 | /** |
| 1550 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1551 | * @rx_ring: rx descriptor ring to transact packets on |
| 1552 | * @rx_buffer: buffer containing page to add |
| 1553 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1554 | * @skb: sk_buff to place the data into |
| 1555 | * |
| 1556 | * This function is based on skb_add_rx_frag. I would have used that |
| 1557 | * function however it doesn't handle the truesize case correctly since we |
| 1558 | * are allocating more memory than might be used for a single receive. |
| 1559 | **/ |
| 1560 | static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
| 1561 | struct ixgbe_rx_buffer *rx_buffer, |
| 1562 | struct sk_buff *skb, int size) |
| 1563 | { |
| 1564 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
| 1565 | rx_buffer->page, rx_buffer->page_offset, |
| 1566 | size); |
| 1567 | skb->len += size; |
| 1568 | skb->data_len += size; |
| 1569 | skb->truesize += ixgbe_rx_bufsz(rx_ring); |
| 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 1574 | * @q_vector: structure containing interrupt and ring information |
| 1575 | * @rx_ring: rx descriptor ring to transact packets on |
| 1576 | * @budget: Total limit on number of packets to process |
| 1577 | * |
| 1578 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 1579 | * processing. The advantage to this is that on systems that have |
| 1580 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 1581 | * it by maintaining the mapping of the page to the syste. |
| 1582 | * |
| 1583 | * Returns true if all work is completed without reaching budget |
| 1584 | **/ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1585 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1586 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1587 | int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1588 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1589 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 1590 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1591 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1592 | int ddp_bytes = 0; |
| 1593 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1594 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1595 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1596 | do { |
| 1597 | struct ixgbe_rx_buffer *rx_buffer; |
| 1598 | union ixgbe_adv_rx_desc *rx_desc; |
| 1599 | struct sk_buff *skb; |
| 1600 | struct page *page; |
| 1601 | u16 ntc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1602 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1603 | /* return some buffers to hardware, one at a time is too slow */ |
| 1604 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 1605 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1606 | cleaned_count = 0; |
| 1607 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1608 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1609 | ntc = rx_ring->next_to_clean; |
| 1610 | rx_desc = IXGBE_RX_DESC(rx_ring, ntc); |
| 1611 | rx_buffer = &rx_ring->rx_buffer_info[ntc]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1612 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1613 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) |
| 1614 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1615 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1616 | /* |
| 1617 | * This memory barrier is needed to keep us from reading |
| 1618 | * any other fields out of the rx_desc until we know the |
| 1619 | * RXD_STAT_DD bit is set |
| 1620 | */ |
| 1621 | rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1622 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1623 | page = rx_buffer->page; |
| 1624 | prefetchw(page); |
| 1625 | |
| 1626 | skb = rx_buffer->skb; |
| 1627 | |
| 1628 | if (likely(!skb)) { |
| 1629 | void *page_addr = page_address(page) + |
| 1630 | rx_buffer->page_offset; |
| 1631 | |
| 1632 | /* prefetch first cache line of first page */ |
| 1633 | prefetch(page_addr); |
| 1634 | #if L1_CACHE_BYTES < 128 |
| 1635 | prefetch(page_addr + L1_CACHE_BYTES); |
| 1636 | #endif |
| 1637 | |
| 1638 | /* allocate a skb to store the frags */ |
| 1639 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
| 1640 | IXGBE_RX_HDR_SIZE); |
| 1641 | if (unlikely(!skb)) { |
| 1642 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 1643 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1644 | } |
| 1645 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1646 | /* |
| 1647 | * we will be copying header into skb->data in |
| 1648 | * pskb_may_pull so it is in our interest to prefetch |
| 1649 | * it now to avoid a possible cache miss |
| 1650 | */ |
| 1651 | prefetchw(skb->data); |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1652 | |
| 1653 | /* |
| 1654 | * Delay unmapping of the first packet. It carries the |
| 1655 | * header information, HW may still access the header |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1656 | * after the writeback. Only unmap it when EOP is |
| 1657 | * reached |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1658 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1659 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1660 | } else { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1661 | /* we are reusing so sync this buffer for CPU use */ |
| 1662 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1663 | rx_buffer->dma, |
| 1664 | rx_buffer->page_offset, |
| 1665 | ixgbe_rx_bufsz(rx_ring), |
| 1666 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1669 | /* pull page into skb */ |
| 1670 | ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, |
| 1671 | le16_to_cpu(rx_desc->wb.upper.length)); |
| 1672 | |
| 1673 | if (ixgbe_can_reuse_page(rx_buffer)) { |
| 1674 | /* hand second half of page back to the ring */ |
| 1675 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 1676 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 1677 | /* the page has been released from the ring */ |
| 1678 | IXGBE_CB(skb)->page_released = true; |
| 1679 | } else { |
| 1680 | /* we are not reusing the buffer so unmap it */ |
| 1681 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 1682 | ixgbe_rx_pg_size(rx_ring), |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1683 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1686 | /* clear contents of buffer_info */ |
| 1687 | rx_buffer->skb = NULL; |
| 1688 | rx_buffer->dma = 0; |
| 1689 | rx_buffer->page = NULL; |
| 1690 | |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1691 | ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb); |
| 1692 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1693 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1694 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1695 | /* place incomplete frames back on ring for completion */ |
| 1696 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 1697 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1698 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1699 | /* verify the packet layout is correct */ |
| 1700 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 1701 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1702 | |
| 1703 | /* probably a little skewed due to removing CRC */ |
| 1704 | total_rx_bytes += skb->len; |
| 1705 | total_rx_packets++; |
| 1706 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1707 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 1708 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 1709 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1710 | #ifdef IXGBE_FCOE |
| 1711 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1712 | if (ixgbe_rx_is_fcoe(adapter, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1713 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1714 | if (!ddp_bytes) { |
| 1715 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1716 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1717 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1718 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1719 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1720 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1721 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1722 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1723 | /* update budget accounting */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1724 | budget--; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1725 | } while (likely(budget)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1726 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1727 | #ifdef IXGBE_FCOE |
| 1728 | /* include DDPed FCoE data */ |
| 1729 | if (ddp_bytes > 0) { |
| 1730 | unsigned int mss; |
| 1731 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1732 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1733 | sizeof(struct fc_frame_header) - |
| 1734 | sizeof(struct fcoe_crc_eof); |
| 1735 | if (mss > 512) |
| 1736 | mss &= ~511; |
| 1737 | total_rx_bytes += ddp_bytes; |
| 1738 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1739 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1740 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1741 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1742 | u64_stats_update_begin(&rx_ring->syncp); |
| 1743 | rx_ring->stats.packets += total_rx_packets; |
| 1744 | rx_ring->stats.bytes += total_rx_bytes; |
| 1745 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1746 | q_vector->rx.total_packets += total_rx_packets; |
| 1747 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1748 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1749 | if (cleaned_count) |
| 1750 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1751 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1752 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1755 | /** |
| 1756 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1757 | * @adapter: board private structure |
| 1758 | * |
| 1759 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1760 | * interrupts. |
| 1761 | **/ |
| 1762 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1763 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1764 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1765 | int q_vectors, v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1766 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1767 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1768 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1769 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 1770 | /* Populate MSIX to EITR Select */ |
| 1771 | if (adapter->num_vfs > 32) { |
| 1772 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 1773 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 1774 | } |
| 1775 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1776 | /* |
| 1777 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1778 | * corresponding register. |
| 1779 | */ |
| 1780 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1781 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1782 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1783 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1784 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1785 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1786 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1787 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1788 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1789 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1790 | if (q_vector->tx.ring && !q_vector->rx.ring) { |
| 1791 | /* tx only vector */ |
| 1792 | if (adapter->tx_itr_setting == 1) |
| 1793 | q_vector->itr = IXGBE_10K_ITR; |
| 1794 | else |
| 1795 | q_vector->itr = adapter->tx_itr_setting; |
| 1796 | } else { |
| 1797 | /* rx or rx/tx vector */ |
| 1798 | if (adapter->rx_itr_setting == 1) |
| 1799 | q_vector->itr = IXGBE_20K_ITR; |
| 1800 | else |
| 1801 | q_vector->itr = adapter->rx_itr_setting; |
| 1802 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1803 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1804 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1807 | switch (adapter->hw.mac.type) { |
| 1808 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1809 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1810 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1811 | break; |
| 1812 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1813 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1814 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1815 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1816 | default: |
| 1817 | break; |
| 1818 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1819 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1820 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1821 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1822 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1823 | mask &= ~(IXGBE_EIMS_OTHER | |
| 1824 | IXGBE_EIMS_MAILBOX | |
| 1825 | IXGBE_EIMS_LSC); |
| 1826 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1827 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1830 | enum latency_range { |
| 1831 | lowest_latency = 0, |
| 1832 | low_latency = 1, |
| 1833 | bulk_latency = 2, |
| 1834 | latency_invalid = 255 |
| 1835 | }; |
| 1836 | |
| 1837 | /** |
| 1838 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1839 | * @q_vector: structure containing interrupt and ring information |
| 1840 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1841 | * |
| 1842 | * Stores a new ITR value based on packets and byte |
| 1843 | * counts during the last interrupt. The advantage of per interrupt |
| 1844 | * computation is faster updates and more accurate ITR for the current |
| 1845 | * traffic pattern. Constants in this function were computed |
| 1846 | * based on theoretical maximum wire speed and thresholds were set based |
| 1847 | * on testing data as well as attempting to minimize response time |
| 1848 | * while increasing bulk throughput. |
| 1849 | * this functionality is controlled by the InterruptThrottleRate module |
| 1850 | * parameter (see ixgbe_param.c) |
| 1851 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1852 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 1853 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1854 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1855 | int bytes = ring_container->total_bytes; |
| 1856 | int packets = ring_container->total_packets; |
| 1857 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1858 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1859 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1860 | |
| 1861 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1862 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1863 | |
| 1864 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1865 | * 0-10MB/s lowest (100000 ints/s) |
| 1866 | * 10-20MB/s low (20000 ints/s) |
| 1867 | * 20-1249MB/s bulk (8000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1868 | */ |
| 1869 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1870 | timepassed_us = q_vector->itr >> 2; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1871 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1872 | |
| 1873 | switch (itr_setting) { |
| 1874 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1875 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1876 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1877 | break; |
| 1878 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1879 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1880 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1881 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1882 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1883 | break; |
| 1884 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1885 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1886 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1887 | break; |
| 1888 | } |
| 1889 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1890 | /* clear work counters since we have the values we need */ |
| 1891 | ring_container->total_bytes = 0; |
| 1892 | ring_container->total_packets = 0; |
| 1893 | |
| 1894 | /* write updated itr to ring container */ |
| 1895 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1896 | } |
| 1897 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1898 | /** |
| 1899 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1900 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1901 | * |
| 1902 | * This function is made to be called by ethtool and by the driver |
| 1903 | * when it needs to update EITR registers at runtime. Hardware |
| 1904 | * specific quirks/differences are taken care of here. |
| 1905 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1906 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1907 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1908 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1909 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1910 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 1911 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1912 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1913 | switch (adapter->hw.mac.type) { |
| 1914 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1915 | /* must write high and low 16 bits to reset counter */ |
| 1916 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1917 | break; |
| 1918 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1919 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1920 | /* |
| 1921 | * set the WDIS bit to not clear the timer bits and cause an |
| 1922 | * immediate assertion of the interrupt |
| 1923 | */ |
| 1924 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1925 | break; |
| 1926 | default: |
| 1927 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1928 | } |
| 1929 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1930 | } |
| 1931 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1932 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1933 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1934 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1935 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1936 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1937 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 1938 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1939 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1940 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1941 | |
| 1942 | switch (current_itr) { |
| 1943 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1944 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1945 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1946 | break; |
| 1947 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1948 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1949 | break; |
| 1950 | case bulk_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1951 | new_itr = IXGBE_8K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1952 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1953 | default: |
| 1954 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1955 | } |
| 1956 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1957 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1958 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1959 | new_itr = (10 * new_itr * q_vector->itr) / |
| 1960 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1961 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1962 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 1963 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1964 | |
| 1965 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1966 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1967 | } |
| 1968 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1969 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 1970 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1971 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1972 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1973 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1974 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1975 | struct ixgbe_hw *hw = &adapter->hw; |
| 1976 | u32 eicr = adapter->interrupt_event; |
| 1977 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1978 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1979 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1980 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1981 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1982 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 1983 | return; |
| 1984 | |
| 1985 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1986 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1987 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1988 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 1989 | /* |
| 1990 | * Since the warning interrupt is for both ports |
| 1991 | * we don't have to check if: |
| 1992 | * - This interrupt wasn't for our port. |
| 1993 | * - We may have missed the interrupt so always have to |
| 1994 | * check if we got a LSC |
| 1995 | */ |
| 1996 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 1997 | !(eicr & IXGBE_EICR_LSC)) |
| 1998 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1999 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2000 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
| 2001 | u32 autoneg; |
| 2002 | bool link_up = false; |
| 2003 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2004 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2005 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2006 | if (link_up) |
| 2007 | return; |
| 2008 | } |
| 2009 | |
| 2010 | /* Check if this is not due to overtemp */ |
| 2011 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2012 | return; |
| 2013 | |
| 2014 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2015 | default: |
| 2016 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 2017 | return; |
| 2018 | break; |
| 2019 | } |
| 2020 | e_crit(drv, |
| 2021 | "Network adapter has been stopped because it has over heated. " |
| 2022 | "Restart the computer. If the problem persists, " |
| 2023 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2024 | |
| 2025 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2028 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2029 | { |
| 2030 | struct ixgbe_hw *hw = &adapter->hw; |
| 2031 | |
| 2032 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 2033 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2034 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2035 | /* write to clear the interrupt */ |
| 2036 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 2037 | } |
| 2038 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2039 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2040 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2041 | { |
| 2042 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2043 | return; |
| 2044 | |
| 2045 | switch (adapter->hw.mac.type) { |
| 2046 | case ixgbe_mac_82599EB: |
| 2047 | /* |
| 2048 | * Need to check link state so complete overtemp check |
| 2049 | * on service task |
| 2050 | */ |
| 2051 | if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) && |
| 2052 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2053 | adapter->interrupt_event = eicr; |
| 2054 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2055 | ixgbe_service_event_schedule(adapter); |
| 2056 | return; |
| 2057 | } |
| 2058 | return; |
| 2059 | case ixgbe_mac_X540: |
| 2060 | if (!(eicr & IXGBE_EICR_TS)) |
| 2061 | return; |
| 2062 | break; |
| 2063 | default: |
| 2064 | return; |
| 2065 | } |
| 2066 | |
| 2067 | e_crit(drv, |
| 2068 | "Network adapter has been stopped because it has over heated. " |
| 2069 | "Restart the computer. If the problem persists, " |
| 2070 | "power off the system and replace the adapter\n"); |
| 2071 | } |
| 2072 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2073 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2074 | { |
| 2075 | struct ixgbe_hw *hw = &adapter->hw; |
| 2076 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2077 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 2078 | /* Clear the interrupt */ |
| 2079 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2080 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2081 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 2082 | ixgbe_service_event_schedule(adapter); |
| 2083 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2084 | } |
| 2085 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2086 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 2087 | /* Clear the interrupt */ |
| 2088 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2089 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2090 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2091 | ixgbe_service_event_schedule(adapter); |
| 2092 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2093 | } |
| 2094 | } |
| 2095 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2096 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2097 | { |
| 2098 | struct ixgbe_hw *hw = &adapter->hw; |
| 2099 | |
| 2100 | adapter->lsc_int++; |
| 2101 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2102 | adapter->link_check_timeout = jiffies; |
| 2103 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2104 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2105 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2106 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2107 | } |
| 2108 | } |
| 2109 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2110 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2111 | u64 qmask) |
| 2112 | { |
| 2113 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2114 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2115 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2116 | switch (hw->mac.type) { |
| 2117 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2118 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2119 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2120 | break; |
| 2121 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2122 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2123 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2124 | if (mask) |
| 2125 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2126 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2127 | if (mask) |
| 2128 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2129 | break; |
| 2130 | default: |
| 2131 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2132 | } |
| 2133 | /* skip the flush */ |
| 2134 | } |
| 2135 | |
| 2136 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2137 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2138 | { |
| 2139 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2140 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2141 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2142 | switch (hw->mac.type) { |
| 2143 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2144 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2145 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2146 | break; |
| 2147 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2148 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2149 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2150 | if (mask) |
| 2151 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2152 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2153 | if (mask) |
| 2154 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2155 | break; |
| 2156 | default: |
| 2157 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2158 | } |
| 2159 | /* skip the flush */ |
| 2160 | } |
| 2161 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2162 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2163 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2164 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2165 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2166 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2167 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2168 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2169 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2170 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2171 | /* don't reenable LSC while waiting for link */ |
| 2172 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2173 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2174 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2175 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2176 | switch (adapter->hw.mac.type) { |
| 2177 | case ixgbe_mac_82599EB: |
| 2178 | mask |= IXGBE_EIMS_GPI_SDP0; |
| 2179 | break; |
| 2180 | case ixgbe_mac_X540: |
| 2181 | mask |= IXGBE_EIMS_TS; |
| 2182 | break; |
| 2183 | default: |
| 2184 | break; |
| 2185 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2186 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2187 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2188 | switch (adapter->hw.mac.type) { |
| 2189 | case ixgbe_mac_82599EB: |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2190 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2191 | mask |= IXGBE_EIMS_GPI_SDP2; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2192 | case ixgbe_mac_X540: |
| 2193 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2194 | mask |= IXGBE_EIMS_MAILBOX; |
| 2195 | break; |
| 2196 | default: |
| 2197 | break; |
| 2198 | } |
| 2199 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2200 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2201 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2202 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2203 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2204 | if (queues) |
| 2205 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2206 | if (flush) |
| 2207 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2210 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2211 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2212 | struct ixgbe_adapter *adapter = data; |
| 2213 | struct ixgbe_hw *hw = &adapter->hw; |
| 2214 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2215 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2216 | /* |
| 2217 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2218 | * of clear-by-read. Reading with EICS will return the |
| 2219 | * interrupt causes without clearing, which later be done |
| 2220 | * with the write to EICR. |
| 2221 | */ |
| 2222 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 2223 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2224 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2225 | if (eicr & IXGBE_EICR_LSC) |
| 2226 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2227 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2228 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2229 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2230 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2231 | switch (hw->mac.type) { |
| 2232 | case ixgbe_mac_82599EB: |
| 2233 | case ixgbe_mac_X540: |
| 2234 | if (eicr & IXGBE_EICR_ECC) |
| 2235 | e_info(link, "Received unrecoverable ECC Err, please " |
| 2236 | "reboot\n"); |
| 2237 | /* Handle Flow Director Full threshold interrupt */ |
| 2238 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2239 | int reinit_count = 0; |
| 2240 | int i; |
| 2241 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2242 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2243 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2244 | &ring->state)) |
| 2245 | reinit_count++; |
| 2246 | } |
| 2247 | if (reinit_count) { |
| 2248 | /* no more flow director interrupts until after init */ |
| 2249 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2250 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2251 | ixgbe_service_event_schedule(adapter); |
| 2252 | } |
| 2253 | } |
| 2254 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2255 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2256 | break; |
| 2257 | default: |
| 2258 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2261 | ixgbe_check_fan_failure(adapter, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2262 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2263 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2264 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2265 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2266 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2267 | return IRQ_HANDLED; |
| 2268 | } |
| 2269 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2270 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2271 | { |
| 2272 | struct ixgbe_q_vector *q_vector = data; |
| 2273 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2274 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2275 | |
| 2276 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 2277 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2278 | |
| 2279 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2282 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2283 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2284 | * @adapter: board private structure |
| 2285 | * |
| 2286 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2287 | * interrupts from the kernel. |
| 2288 | **/ |
| 2289 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2290 | { |
| 2291 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2292 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2293 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2294 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2295 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2296 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2297 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2298 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2299 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2300 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2301 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2302 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2303 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2304 | } else if (q_vector->rx.ring) { |
| 2305 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2306 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2307 | } else if (q_vector->tx.ring) { |
| 2308 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2309 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2310 | } else { |
| 2311 | /* skip this unused q_vector */ |
| 2312 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2313 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2314 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2315 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2316 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2317 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2318 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2319 | goto free_queue_irqs; |
| 2320 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2321 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2322 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2323 | /* assign the mask for this irq */ |
| 2324 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2325 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2326 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2327 | } |
| 2328 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2329 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2330 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2331 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2332 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2333 | goto free_queue_irqs; |
| 2334 | } |
| 2335 | |
| 2336 | return 0; |
| 2337 | |
| 2338 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2339 | while (vector) { |
| 2340 | vector--; |
| 2341 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2342 | NULL); |
| 2343 | free_irq(adapter->msix_entries[vector].vector, |
| 2344 | adapter->q_vector[vector]); |
| 2345 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2346 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2347 | pci_disable_msix(adapter->pdev); |
| 2348 | kfree(adapter->msix_entries); |
| 2349 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2350 | return err; |
| 2351 | } |
| 2352 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2353 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2354 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2355 | * @irq: interrupt number |
| 2356 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2357 | **/ |
| 2358 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2359 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2360 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2361 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2362 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2363 | u32 eicr; |
| 2364 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2365 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2366 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2367 | * before the read of EICR. |
| 2368 | */ |
| 2369 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2370 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2371 | /* 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] | 2372 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2373 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2374 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2375 | /* |
| 2376 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2377 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2378 | * have disabled interrupts due to EIAM |
| 2379 | * finish the workaround of silicon errata on 82598. Unmask |
| 2380 | * the interrupt that we masked before the EICR read. |
| 2381 | */ |
| 2382 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2383 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2384 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2385 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2386 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2387 | if (eicr & IXGBE_EICR_LSC) |
| 2388 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2389 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2390 | switch (hw->mac.type) { |
| 2391 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2392 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 2393 | /* Fall through */ |
| 2394 | case ixgbe_mac_X540: |
| 2395 | if (eicr & IXGBE_EICR_ECC) |
| 2396 | e_info(link, "Received unrecoverable ECC err, please " |
| 2397 | "reboot\n"); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2398 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2399 | break; |
| 2400 | default: |
| 2401 | break; |
| 2402 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2403 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2404 | ixgbe_check_fan_failure(adapter, eicr); |
| 2405 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 2406 | /* would disable interrupts here but EIAM disabled it */ |
| 2407 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2408 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2409 | /* |
| 2410 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2411 | * ixgbe_poll will re-enable the queue interrupts |
| 2412 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2413 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2414 | ixgbe_irq_enable(adapter, false, false); |
| 2415 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2416 | return IRQ_HANDLED; |
| 2417 | } |
| 2418 | |
| 2419 | /** |
| 2420 | * ixgbe_request_irq - initialize interrupts |
| 2421 | * @adapter: board private structure |
| 2422 | * |
| 2423 | * Attempts to configure interrupts using the best available |
| 2424 | * capabilities of the hardware and kernel. |
| 2425 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2426 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2427 | { |
| 2428 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2429 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2430 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2431 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2432 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2433 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2434 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2435 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2436 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2437 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2438 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2439 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2440 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2441 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2442 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2443 | return err; |
| 2444 | } |
| 2445 | |
| 2446 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2447 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2448 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2449 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2450 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2451 | q_vectors = adapter->num_msix_vectors; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2452 | i = q_vectors - 1; |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2453 | free_irq(adapter->msix_entries[i].vector, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2454 | i--; |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2455 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2456 | for (; i >= 0; i--) { |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2457 | /* free only the irqs that were actually requested */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2458 | if (!adapter->q_vector[i]->rx.ring && |
| 2459 | !adapter->q_vector[i]->tx.ring) |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2460 | continue; |
| 2461 | |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2462 | /* clear the affinity_mask in the IRQ descriptor */ |
| 2463 | irq_set_affinity_hint(adapter->msix_entries[i].vector, |
| 2464 | NULL); |
| 2465 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2466 | free_irq(adapter->msix_entries[i].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2467 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2468 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2469 | } else { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2470 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | |
| 2474 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2475 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2476 | * @adapter: board private structure |
| 2477 | **/ |
| 2478 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2479 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2480 | switch (adapter->hw.mac.type) { |
| 2481 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2482 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2483 | break; |
| 2484 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2485 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2486 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2487 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2488 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2489 | break; |
| 2490 | default: |
| 2491 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2492 | } |
| 2493 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2494 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2495 | int i; |
| 2496 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 2497 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2498 | } else { |
| 2499 | synchronize_irq(adapter->pdev->irq); |
| 2500 | } |
| 2501 | } |
| 2502 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2503 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2504 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2505 | * |
| 2506 | **/ |
| 2507 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2508 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2509 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2510 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2511 | /* rx/tx vector */ |
| 2512 | if (adapter->rx_itr_setting == 1) |
| 2513 | q_vector->itr = IXGBE_20K_ITR; |
| 2514 | else |
| 2515 | q_vector->itr = adapter->rx_itr_setting; |
| 2516 | |
| 2517 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2518 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2519 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2520 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2521 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2522 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2525 | /** |
| 2526 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2527 | * @adapter: board private structure |
| 2528 | * @ring: structure containing ring specific data |
| 2529 | * |
| 2530 | * Configure the Tx descriptor ring after a reset. |
| 2531 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2532 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2533 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2534 | { |
| 2535 | struct ixgbe_hw *hw = &adapter->hw; |
| 2536 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2537 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2538 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2539 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2540 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2541 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2542 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2543 | IXGBE_WRITE_FLUSH(hw); |
| 2544 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2545 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2546 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2547 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2548 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2549 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2550 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2551 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2552 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2553 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2554 | /* |
| 2555 | * set WTHRESH to encourage burst writeback, it should not be set |
| 2556 | * higher than 1 when ITR is 0 as it could cause false TX hangs |
| 2557 | * |
| 2558 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 2559 | * to or less than the number of on chip descriptors, which is |
| 2560 | * currently 40. |
| 2561 | */ |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2562 | if (!ring->q_vector || (ring->q_vector->itr < 8)) |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2563 | txdctl |= (1 << 16); /* WTHRESH = 1 */ |
| 2564 | else |
| 2565 | txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 2566 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2567 | /* |
| 2568 | * Setting PTHRESH to 32 both improves performance |
| 2569 | * and avoids a TX hang with DFP enabled |
| 2570 | */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2571 | txdctl |= (1 << 8) | /* HTHRESH = 1 */ |
| 2572 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2573 | |
| 2574 | /* reinitialize flowdirector state */ |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2575 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2576 | adapter->atr_sample_rate) { |
| 2577 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2578 | ring->atr_count = 0; |
| 2579 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2580 | } else { |
| 2581 | ring->atr_sample_rate = 0; |
| 2582 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2583 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2584 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2585 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2586 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2587 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2588 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 2589 | netdev_tx_reset_queue(txring_txq(ring)); |
| 2590 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2591 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2592 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2593 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2594 | return; |
| 2595 | |
| 2596 | /* poll to verify queue is enabled */ |
| 2597 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2598 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2599 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2600 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2601 | if (!wait_loop) |
| 2602 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2603 | } |
| 2604 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2605 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2606 | { |
| 2607 | struct ixgbe_hw *hw = &adapter->hw; |
| 2608 | u32 rttdcs; |
John Fastabend | 72a32f1 | 2011-04-26 07:25:58 +0000 | [diff] [blame] | 2609 | u32 reg; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2610 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2611 | |
| 2612 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2613 | return; |
| 2614 | |
| 2615 | /* disable the arbiter while setting MTQC */ |
| 2616 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2617 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2618 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2619 | |
| 2620 | /* set transmit pool layout */ |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2621 | switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2622 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2623 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2624 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2625 | break; |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2626 | default: |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2627 | if (!tcs) |
| 2628 | reg = IXGBE_MTQC_64Q_1PB; |
| 2629 | else if (tcs <= 4) |
| 2630 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2631 | else |
| 2632 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2633 | |
| 2634 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg); |
| 2635 | |
| 2636 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 2637 | if (tcs) { |
| 2638 | reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 2639 | reg |= IXGBE_SECTX_DCB; |
| 2640 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg); |
| 2641 | } |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2642 | break; |
| 2643 | } |
| 2644 | |
| 2645 | /* re-enable the arbiter */ |
| 2646 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2647 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2648 | } |
| 2649 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2650 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2651 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2652 | * @adapter: board private structure |
| 2653 | * |
| 2654 | * Configure the Tx unit of the MAC after a reset. |
| 2655 | **/ |
| 2656 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2657 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2658 | struct ixgbe_hw *hw = &adapter->hw; |
| 2659 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2660 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2661 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2662 | ixgbe_setup_mtqc(adapter); |
| 2663 | |
| 2664 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2665 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2666 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2667 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2668 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2669 | } |
| 2670 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2671 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2672 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2673 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2676 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2677 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2678 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2679 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2680 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2681 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2682 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2683 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2684 | switch (adapter->hw.mac.type) { |
| 2685 | case ixgbe_mac_82598EB: { |
| 2686 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
| 2687 | const int mask = feature[RING_F_RSS].mask; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2688 | reg_idx = reg_idx & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2689 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2690 | break; |
| 2691 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2692 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2693 | default: |
| 2694 | break; |
| 2695 | } |
| 2696 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2697 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2698 | |
| 2699 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2700 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2701 | if (adapter->num_vfs) |
| 2702 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2703 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2704 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2705 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2706 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2707 | #if PAGE_SIZE > IXGBE_MAX_RXBUFFER |
| 2708 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2709 | #else |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2710 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2711 | #endif |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2712 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2713 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2714 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2717 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2718 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2719 | struct ixgbe_hw *hw = &adapter->hw; |
| 2720 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2721 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2722 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2723 | u32 mrqc = 0, reta = 0; |
| 2724 | u32 rxcsum; |
| 2725 | int i, j; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2726 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2727 | int maxq = adapter->ring_feature[RING_F_RSS].indices; |
| 2728 | |
| 2729 | if (tcs) |
| 2730 | maxq = min(maxq, adapter->num_tx_queues / tcs); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2731 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2732 | /* Fill out hash function seeds */ |
| 2733 | for (i = 0; i < 10; i++) |
| 2734 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2735 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2736 | /* Fill out redirection table */ |
| 2737 | for (i = 0, j = 0; i < 128; i++, j++) { |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2738 | if (j == maxq) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2739 | j = 0; |
| 2740 | /* reta = 4-byte sliding window of |
| 2741 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2742 | reta = (reta << 8) | (j * 0x11); |
| 2743 | if ((i & 3) == 3) |
| 2744 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 2745 | } |
| 2746 | |
| 2747 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 2748 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2749 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2750 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 2751 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2752 | if (adapter->hw.mac.type == ixgbe_mac_82598EB && |
| 2753 | (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2754 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2755 | } else { |
| 2756 | int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2757 | | IXGBE_FLAG_SRIOV_ENABLED); |
| 2758 | |
| 2759 | switch (mask) { |
| 2760 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2761 | if (!tcs) |
| 2762 | mrqc = IXGBE_MRQC_RSSEN; |
| 2763 | else if (tcs <= 4) |
| 2764 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 2765 | else |
| 2766 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 2767 | break; |
| 2768 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2769 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2770 | break; |
| 2771 | default: |
| 2772 | break; |
| 2773 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2776 | /* Perform hash on these packet types */ |
| 2777 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2778 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2779 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2780 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2781 | |
| 2782 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2785 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2786 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2787 | * @adapter: address of board private structure |
| 2788 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2789 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 2790 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2791 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2792 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2793 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2794 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2795 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2796 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2797 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2798 | return; |
| 2799 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2800 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2801 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2802 | /* |
| 2803 | * we must limit the number of descriptors so that the |
| 2804 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 2805 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2806 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2807 | #if (PAGE_SIZE <= 8192) |
| 2808 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2809 | #elif (PAGE_SIZE <= 16384) |
| 2810 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2811 | #else |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2812 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2813 | #endif |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2814 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2817 | /** |
| 2818 | * ixgbe_set_uta - Set unicast filter table address |
| 2819 | * @adapter: board private structure |
| 2820 | * |
| 2821 | * The unicast table address is a register array of 32-bit registers. |
| 2822 | * The table is meant to be used in a way similar to how the MTA is used |
| 2823 | * however due to certain limitations in the hardware it is necessary to |
| 2824 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 2825 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
| 2826 | **/ |
| 2827 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) |
| 2828 | { |
| 2829 | struct ixgbe_hw *hw = &adapter->hw; |
| 2830 | int i; |
| 2831 | |
| 2832 | /* The UTA table only exists on 82599 hardware and newer */ |
| 2833 | if (hw->mac.type < ixgbe_mac_82599EB) |
| 2834 | return; |
| 2835 | |
| 2836 | /* we only need to do this if VMDq is enabled */ |
| 2837 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2838 | return; |
| 2839 | |
| 2840 | for (i = 0; i < 128; i++) |
| 2841 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); |
| 2842 | } |
| 2843 | |
| 2844 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2845 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2846 | struct ixgbe_ring *ring) |
| 2847 | { |
| 2848 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2849 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2850 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2851 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2852 | |
| 2853 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2854 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2855 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2856 | return; |
| 2857 | |
| 2858 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2859 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2860 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2861 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2862 | |
| 2863 | if (!wait_loop) { |
| 2864 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 2865 | "the polling period\n", reg_idx); |
| 2866 | } |
| 2867 | } |
| 2868 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2869 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 2870 | struct ixgbe_ring *ring) |
| 2871 | { |
| 2872 | struct ixgbe_hw *hw = &adapter->hw; |
| 2873 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2874 | u32 rxdctl; |
| 2875 | u8 reg_idx = ring->reg_idx; |
| 2876 | |
| 2877 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2878 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 2879 | |
| 2880 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 2881 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2882 | |
| 2883 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2884 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2885 | return; |
| 2886 | |
| 2887 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 2888 | do { |
| 2889 | udelay(10); |
| 2890 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2891 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2892 | |
| 2893 | if (!wait_loop) { |
| 2894 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 2895 | "the polling period\n", reg_idx); |
| 2896 | } |
| 2897 | } |
| 2898 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2899 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 2900 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2901 | { |
| 2902 | struct ixgbe_hw *hw = &adapter->hw; |
| 2903 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2904 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2905 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2906 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2907 | /* disable queue to avoid issues while updating state */ |
| 2908 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2909 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2910 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2911 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 2912 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 2913 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 2914 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 2915 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 2916 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2917 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2918 | |
| 2919 | ixgbe_configure_srrctl(adapter, ring); |
| 2920 | ixgbe_configure_rscctl(adapter, ring); |
| 2921 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 2922 | /* If operating in IOV mode set RLPML for X540 */ |
| 2923 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 2924 | hw->mac.type == ixgbe_mac_X540) { |
| 2925 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 2926 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 2927 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 2928 | } |
| 2929 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2930 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2931 | /* |
| 2932 | * enable cache line friendly hardware writes: |
| 2933 | * PTHRESH=32 descriptors (half the internal cache), |
| 2934 | * this also removes ugly rx_no_buffer_count increment |
| 2935 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 2936 | * WTHRESH=8 burst writeback up to two cache lines |
| 2937 | */ |
| 2938 | rxdctl &= ~0x3FFFFF; |
| 2939 | rxdctl |= 0x080420; |
| 2940 | } |
| 2941 | |
| 2942 | /* enable receive descriptor ring */ |
| 2943 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 2944 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2945 | |
| 2946 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 2947 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2950 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 2951 | { |
| 2952 | struct ixgbe_hw *hw = &adapter->hw; |
| 2953 | int p; |
| 2954 | |
| 2955 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 2956 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2957 | IXGBE_PSRTYPE_UDPHDR | |
| 2958 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2959 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2960 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2961 | |
| 2962 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2963 | return; |
| 2964 | |
| 2965 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) |
| 2966 | psrtype |= (adapter->num_rx_queues_per_pool << 29); |
| 2967 | |
| 2968 | for (p = 0; p < adapter->num_rx_pools; p++) |
| 2969 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), |
| 2970 | psrtype); |
| 2971 | } |
| 2972 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2973 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 2974 | { |
| 2975 | struct ixgbe_hw *hw = &adapter->hw; |
| 2976 | u32 gcr_ext; |
| 2977 | u32 vt_reg_bits; |
| 2978 | u32 reg_offset, vf_shift; |
| 2979 | u32 vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 2980 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2981 | |
| 2982 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2983 | return; |
| 2984 | |
| 2985 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 2986 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; |
| 2987 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); |
| 2988 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 2989 | |
| 2990 | vf_shift = adapter->num_vfs % 32; |
Greg Rose | 4cd6923 | 2012-01-25 07:59:37 +0000 | [diff] [blame] | 2991 | reg_offset = (adapter->num_vfs >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2992 | |
| 2993 | /* Enable only the PF's pool for Tx/Rx */ |
| 2994 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 2995 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); |
| 2996 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 2997 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); |
| 2998 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 2999 | |
| 3000 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
| 3001 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 3002 | |
| 3003 | /* |
| 3004 | * Set up VF register offsets for selected VT Mode, |
| 3005 | * i.e. 32 or 64 VFs for SR-IOV |
| 3006 | */ |
| 3007 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3008 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; |
| 3009 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; |
| 3010 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3011 | |
| 3012 | /* enable Tx loopback for VF/PF communication */ |
| 3013 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3014 | /* Enable MAC Anti-Spoofing */ |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3015 | hw->mac.ops.set_mac_anti_spoofing(hw, |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3016 | (adapter->num_vfs != 0), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3017 | adapter->num_vfs); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3018 | /* For VFs that have spoof checking turned off */ |
| 3019 | for (i = 0; i < adapter->num_vfs; i++) { |
| 3020 | if (!adapter->vfinfo[i].spoofchk_enabled) |
| 3021 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false); |
| 3022 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3025 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3026 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3027 | struct ixgbe_hw *hw = &adapter->hw; |
| 3028 | struct net_device *netdev = adapter->netdev; |
| 3029 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3030 | struct ixgbe_ring *rx_ring; |
| 3031 | int i; |
| 3032 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3033 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3034 | #ifdef IXGBE_FCOE |
| 3035 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3036 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3037 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3038 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3039 | |
| 3040 | #endif /* IXGBE_FCOE */ |
| 3041 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3042 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3043 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3044 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3045 | |
| 3046 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
Alexander Duyck | 919e78a | 2011-08-26 09:52:38 +0000 | [diff] [blame] | 3049 | /* MHADD will allow an extra 4 bytes past for vlan tagged frames */ |
| 3050 | max_frame += VLAN_HLEN; |
| 3051 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3052 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3053 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3054 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3055 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3056 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3057 | /* |
| 3058 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3059 | * the Base and Length of the Rx Descriptor Ring |
| 3060 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3061 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3062 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3063 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3064 | set_ring_rsc_enabled(rx_ring); |
| 3065 | else |
| 3066 | clear_ring_rsc_enabled(rx_ring); |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3067 | #ifdef IXGBE_FCOE |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3068 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3069 | struct ixgbe_ring_feature *f; |
| 3070 | f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3071 | if ((i >= f->mask) && (i < f->mask + f->indices)) |
| 3072 | set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state); |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3073 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3074 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3075 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3078 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3079 | { |
| 3080 | struct ixgbe_hw *hw = &adapter->hw; |
| 3081 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3082 | |
| 3083 | switch (hw->mac.type) { |
| 3084 | case ixgbe_mac_82598EB: |
| 3085 | /* |
| 3086 | * For VMDq support of different descriptor types or |
| 3087 | * buffer sizes through the use of multiple SRRCTL |
| 3088 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3089 | * |
| 3090 | * also, the manual doesn't mention it clearly but DCA hints |
| 3091 | * will only use queue 0's tags unless this bit is set. Side |
| 3092 | * effects of setting this bit are only that SRRCTL must be |
| 3093 | * fully programmed [0..15] |
| 3094 | */ |
| 3095 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3096 | break; |
| 3097 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3098 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3099 | /* Disable RSC for ACK packets */ |
| 3100 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3101 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3102 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3103 | /* hardware requires some bits to be set by default */ |
| 3104 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3105 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3106 | break; |
| 3107 | default: |
| 3108 | /* We should do nothing since we don't know this hardware */ |
| 3109 | return; |
| 3110 | } |
| 3111 | |
| 3112 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3113 | } |
| 3114 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3115 | /** |
| 3116 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3117 | * @adapter: board private structure |
| 3118 | * |
| 3119 | * Configure the Rx unit of the MAC after a reset. |
| 3120 | **/ |
| 3121 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3122 | { |
| 3123 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3124 | int i; |
| 3125 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3126 | |
| 3127 | /* disable receives while setting up the descriptors */ |
| 3128 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3129 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3130 | |
| 3131 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3132 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3133 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3134 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3135 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3136 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3137 | ixgbe_set_uta(adapter); |
| 3138 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3139 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3140 | ixgbe_set_rx_buffer_len(adapter); |
| 3141 | |
| 3142 | /* |
| 3143 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3144 | * the Base and Length of the Rx Descriptor Ring |
| 3145 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3146 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3147 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3148 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3149 | /* disable drop enable for 82598 parts */ |
| 3150 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3151 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3152 | |
| 3153 | /* enable all receives */ |
| 3154 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3155 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3158 | 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] | 3159 | { |
| 3160 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3161 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3162 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3163 | |
| 3164 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3165 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3166 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3167 | |
| 3168 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3169 | } |
| 3170 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3171 | 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] | 3172 | { |
| 3173 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3174 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3175 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3176 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3177 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3178 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3179 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3180 | |
| 3181 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3184 | /** |
| 3185 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3186 | * @adapter: driver data |
| 3187 | */ |
| 3188 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3189 | { |
| 3190 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3191 | u32 vlnctrl; |
| 3192 | |
| 3193 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3194 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3195 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3196 | } |
| 3197 | |
| 3198 | /** |
| 3199 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3200 | * @adapter: driver data |
| 3201 | */ |
| 3202 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3203 | { |
| 3204 | struct ixgbe_hw *hw = &adapter->hw; |
| 3205 | u32 vlnctrl; |
| 3206 | |
| 3207 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3208 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3209 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3210 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3211 | } |
| 3212 | |
| 3213 | /** |
| 3214 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3215 | * @adapter: driver data |
| 3216 | */ |
| 3217 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3218 | { |
| 3219 | struct ixgbe_hw *hw = &adapter->hw; |
| 3220 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3221 | int i, j; |
| 3222 | |
| 3223 | switch (hw->mac.type) { |
| 3224 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3225 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3226 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3227 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3228 | break; |
| 3229 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3230 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3231 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3232 | j = adapter->rx_ring[i]->reg_idx; |
| 3233 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3234 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3235 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3236 | } |
| 3237 | break; |
| 3238 | default: |
| 3239 | break; |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3244 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3245 | * @adapter: driver data |
| 3246 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3247 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3248 | { |
| 3249 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3250 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3251 | int i, j; |
| 3252 | |
| 3253 | switch (hw->mac.type) { |
| 3254 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3255 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3256 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3257 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3258 | break; |
| 3259 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3260 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3261 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3262 | j = adapter->rx_ring[i]->reg_idx; |
| 3263 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3264 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3265 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3266 | } |
| 3267 | break; |
| 3268 | default: |
| 3269 | break; |
| 3270 | } |
| 3271 | } |
| 3272 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3273 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3274 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3275 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3276 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3277 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3278 | |
| 3279 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3280 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3284 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3285 | * @netdev: network interface device structure |
| 3286 | * |
| 3287 | * Writes unicast address list to the RAR table. |
| 3288 | * Returns: -ENOMEM on failure/insufficient address space |
| 3289 | * 0 on no addresses written |
| 3290 | * X on writing X addresses to the RAR table |
| 3291 | **/ |
| 3292 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3293 | { |
| 3294 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3295 | struct ixgbe_hw *hw = &adapter->hw; |
| 3296 | unsigned int vfn = adapter->num_vfs; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3297 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3298 | int count = 0; |
| 3299 | |
| 3300 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3301 | if (netdev_uc_count(netdev) > rar_entries) |
| 3302 | return -ENOMEM; |
| 3303 | |
| 3304 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3305 | struct netdev_hw_addr *ha; |
| 3306 | /* return error if we do not support writing to RAR table */ |
| 3307 | if (!hw->mac.ops.set_rar) |
| 3308 | return -ENOMEM; |
| 3309 | |
| 3310 | netdev_for_each_uc_addr(ha, netdev) { |
| 3311 | if (!rar_entries) |
| 3312 | break; |
| 3313 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
| 3314 | vfn, IXGBE_RAH_AV); |
| 3315 | count++; |
| 3316 | } |
| 3317 | } |
| 3318 | /* write the addresses in reverse order to avoid write combining */ |
| 3319 | for (; rar_entries > 0 ; rar_entries--) |
| 3320 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3321 | |
| 3322 | return count; |
| 3323 | } |
| 3324 | |
| 3325 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3326 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3327 | * @netdev: network interface device structure |
| 3328 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3329 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3330 | * address list or the network interface flags are updated. This routine is |
| 3331 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3332 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3333 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3334 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3335 | { |
| 3336 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3337 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3338 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3339 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3340 | |
| 3341 | /* Check for Promiscuous and All Multicast modes */ |
| 3342 | |
| 3343 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3344 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3345 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3346 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3347 | fctrl |= IXGBE_FCTRL_BAM; |
| 3348 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3349 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3350 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3351 | /* clear the bits we are changing the status of */ |
| 3352 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3353 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3354 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3355 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3356 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3357 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3358 | /* don't hardware filter vlans in promisc mode */ |
| 3359 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3360 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3361 | if (netdev->flags & IFF_ALLMULTI) { |
| 3362 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3363 | vmolr |= IXGBE_VMOLR_MPE; |
| 3364 | } else { |
| 3365 | /* |
| 3366 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3367 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3368 | * that we can at least receive multicast traffic |
| 3369 | */ |
| 3370 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3371 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3372 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3373 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3374 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3375 | /* |
| 3376 | * Write addresses to available RAR registers, if there is not |
| 3377 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3378 | * unicast promiscuous mode |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3379 | */ |
| 3380 | count = ixgbe_write_uc_addr_list(netdev); |
| 3381 | if (count < 0) { |
| 3382 | fctrl |= IXGBE_FCTRL_UPE; |
| 3383 | vmolr |= IXGBE_VMOLR_ROPE; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | if (adapter->num_vfs) { |
| 3388 | ixgbe_restore_vf_multicasts(adapter); |
| 3389 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & |
| 3390 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3391 | IXGBE_VMOLR_ROPE); |
| 3392 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3395 | /* This is useful for sniffing bad packets. */ |
| 3396 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3397 | /* UPE and MPE will be handled by normal PROMISC logic |
| 3398 | * in e1000e_set_rx_mode */ |
| 3399 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 3400 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 3401 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 3402 | |
| 3403 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 3404 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 3405 | } |
| 3406 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3407 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3408 | |
| 3409 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3410 | ixgbe_vlan_strip_enable(adapter); |
| 3411 | else |
| 3412 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3415 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3416 | { |
| 3417 | int q_idx; |
| 3418 | struct ixgbe_q_vector *q_vector; |
| 3419 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3420 | |
| 3421 | /* legacy and MSI only use one vector */ |
| 3422 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3423 | q_vectors = 1; |
| 3424 | |
| 3425 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3426 | q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3427 | napi_enable(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3432 | { |
| 3433 | int q_idx; |
| 3434 | struct ixgbe_q_vector *q_vector; |
| 3435 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3436 | |
| 3437 | /* legacy and MSI only use one vector */ |
| 3438 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3439 | q_vectors = 1; |
| 3440 | |
| 3441 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3442 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3443 | napi_disable(&q_vector->napi); |
| 3444 | } |
| 3445 | } |
| 3446 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3447 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3448 | /* |
| 3449 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3450 | * @adapter: ixgbe adapter struct |
| 3451 | * |
| 3452 | * This is called by the driver on open to configure the DCB hardware. |
| 3453 | * This is also called by the gennetlink interface when reconfiguring |
| 3454 | * the DCB state. |
| 3455 | */ |
| 3456 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3457 | { |
| 3458 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3459 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3460 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3461 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3462 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3463 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3464 | return; |
| 3465 | } |
| 3466 | |
| 3467 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3468 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3469 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3470 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3471 | /* Enable VLAN tag insert/strip */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3472 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3473 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3474 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3475 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3476 | #ifdef IXGBE_FCOE |
| 3477 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3478 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3479 | #endif |
| 3480 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3481 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3482 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3483 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3484 | DCB_TX_CONFIG); |
| 3485 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3486 | DCB_RX_CONFIG); |
| 3487 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3488 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 3489 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 3490 | adapter->ixgbe_ieee_ets, |
| 3491 | max_frame); |
| 3492 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 3493 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 3494 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3495 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3496 | |
| 3497 | /* Enable RSS Hash per TC */ |
| 3498 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3499 | int i; |
| 3500 | u32 reg = 0; |
| 3501 | |
| 3502 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 3503 | u8 msb = 0; |
| 3504 | u8 cnt = adapter->netdev->tc_to_txq[i].count; |
| 3505 | |
| 3506 | while (cnt >>= 1) |
| 3507 | msb++; |
| 3508 | |
| 3509 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); |
| 3510 | } |
| 3511 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); |
| 3512 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3513 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3514 | #endif |
| 3515 | |
| 3516 | /* Additional bittime to account for IXGBE framing */ |
| 3517 | #define IXGBE_ETH_FRAMING 20 |
| 3518 | |
| 3519 | /* |
| 3520 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 3521 | * |
| 3522 | * @adapter: board private structure to calculate for |
| 3523 | * @pb - packet buffer to calculate |
| 3524 | */ |
| 3525 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 3526 | { |
| 3527 | struct ixgbe_hw *hw = &adapter->hw; |
| 3528 | struct net_device *dev = adapter->netdev; |
| 3529 | int link, tc, kb, marker; |
| 3530 | u32 dv_id, rx_pba; |
| 3531 | |
| 3532 | /* Calculate max LAN frame size */ |
| 3533 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 3534 | |
| 3535 | #ifdef IXGBE_FCOE |
| 3536 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 3537 | if (dev->features & NETIF_F_FCOE_MTU) { |
| 3538 | int fcoe_pb = 0; |
| 3539 | |
| 3540 | #ifdef CONFIG_IXGBE_DCB |
| 3541 | fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3542 | |
| 3543 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3544 | if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 3545 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3546 | } |
| 3547 | #endif |
| 3548 | |
| 3549 | /* Calculate delay value for device */ |
| 3550 | switch (hw->mac.type) { |
| 3551 | case ixgbe_mac_X540: |
| 3552 | dv_id = IXGBE_DV_X540(link, tc); |
| 3553 | break; |
| 3554 | default: |
| 3555 | dv_id = IXGBE_DV(link, tc); |
| 3556 | break; |
| 3557 | } |
| 3558 | |
| 3559 | /* Loopback switch introduces additional latency */ |
| 3560 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3561 | dv_id += IXGBE_B2BT(tc); |
| 3562 | |
| 3563 | /* Delay value is calculated in bit times convert to KB */ |
| 3564 | kb = IXGBE_BT2KB(dv_id); |
| 3565 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 3566 | |
| 3567 | marker = rx_pba - kb; |
| 3568 | |
| 3569 | /* It is possible that the packet buffer is not large enough |
| 3570 | * to provide required headroom. In this case throw an error |
| 3571 | * to user and a do the best we can. |
| 3572 | */ |
| 3573 | if (marker < 0) { |
| 3574 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 3575 | "headroom to support flow control." |
| 3576 | "Decrease MTU or number of traffic classes\n", pb); |
| 3577 | marker = tc + 1; |
| 3578 | } |
| 3579 | |
| 3580 | return marker; |
| 3581 | } |
| 3582 | |
| 3583 | /* |
| 3584 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 3585 | * |
| 3586 | * @adapter: board private structure to calculate for |
| 3587 | * @pb - packet buffer to calculate |
| 3588 | */ |
| 3589 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter) |
| 3590 | { |
| 3591 | struct ixgbe_hw *hw = &adapter->hw; |
| 3592 | struct net_device *dev = adapter->netdev; |
| 3593 | int tc; |
| 3594 | u32 dv_id; |
| 3595 | |
| 3596 | /* Calculate max LAN frame size */ |
| 3597 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3598 | |
| 3599 | /* Calculate delay value for device */ |
| 3600 | switch (hw->mac.type) { |
| 3601 | case ixgbe_mac_X540: |
| 3602 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 3603 | break; |
| 3604 | default: |
| 3605 | dv_id = IXGBE_LOW_DV(tc); |
| 3606 | break; |
| 3607 | } |
| 3608 | |
| 3609 | /* Delay value is calculated in bit times convert to KB */ |
| 3610 | return IXGBE_BT2KB(dv_id); |
| 3611 | } |
| 3612 | |
| 3613 | /* |
| 3614 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 3615 | */ |
| 3616 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 3617 | { |
| 3618 | struct ixgbe_hw *hw = &adapter->hw; |
| 3619 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3620 | int i; |
| 3621 | |
| 3622 | if (!num_tc) |
| 3623 | num_tc = 1; |
| 3624 | |
| 3625 | hw->fc.low_water = ixgbe_lpbthresh(adapter); |
| 3626 | |
| 3627 | for (i = 0; i < num_tc; i++) { |
| 3628 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
| 3629 | |
| 3630 | /* Low water marks must not be larger than high water marks */ |
| 3631 | if (hw->fc.low_water > hw->fc.high_water[i]) |
| 3632 | hw->fc.low_water = 0; |
| 3633 | } |
| 3634 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3635 | |
| 3636 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3637 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3638 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3639 | int hdrm; |
| 3640 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3641 | |
| 3642 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3643 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3644 | hdrm = 32 << adapter->fdir_pballoc; |
| 3645 | else |
| 3646 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3647 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3648 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3649 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3650 | } |
| 3651 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3652 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 3653 | { |
| 3654 | struct ixgbe_hw *hw = &adapter->hw; |
| 3655 | struct hlist_node *node, *node2; |
| 3656 | struct ixgbe_fdir_filter *filter; |
| 3657 | |
| 3658 | spin_lock(&adapter->fdir_perfect_lock); |
| 3659 | |
| 3660 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 3661 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 3662 | |
| 3663 | hlist_for_each_entry_safe(filter, node, node2, |
| 3664 | &adapter->fdir_filter_list, fdir_node) { |
| 3665 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 3666 | &filter->filter, |
| 3667 | filter->sw_idx, |
| 3668 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 3669 | IXGBE_FDIR_DROP_QUEUE : |
| 3670 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | spin_unlock(&adapter->fdir_perfect_lock); |
| 3674 | } |
| 3675 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3676 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3677 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3678 | struct ixgbe_hw *hw = &adapter->hw; |
| 3679 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3680 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3681 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3682 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3683 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3684 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3685 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3686 | ixgbe_restore_vlan(adapter); |
| 3687 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3688 | #ifdef IXGBE_FCOE |
| 3689 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 3690 | ixgbe_configure_fcoe(adapter); |
| 3691 | |
| 3692 | #endif /* IXGBE_FCOE */ |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3693 | |
| 3694 | switch (hw->mac.type) { |
| 3695 | case ixgbe_mac_82599EB: |
| 3696 | case ixgbe_mac_X540: |
| 3697 | hw->mac.ops.disable_rx_buff(hw); |
| 3698 | break; |
| 3699 | default: |
| 3700 | break; |
| 3701 | } |
| 3702 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3703 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3704 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 3705 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3706 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3707 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 3708 | adapter->fdir_pballoc); |
| 3709 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3710 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3711 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3712 | switch (hw->mac.type) { |
| 3713 | case ixgbe_mac_82599EB: |
| 3714 | case ixgbe_mac_X540: |
| 3715 | hw->mac.ops.enable_rx_buff(hw); |
| 3716 | break; |
| 3717 | default: |
| 3718 | break; |
| 3719 | } |
| 3720 | |
Alexander Duyck | 933d41f | 2010-09-07 21:34:29 +0000 | [diff] [blame] | 3721 | ixgbe_configure_virtualization(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3722 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3723 | ixgbe_configure_tx(adapter); |
| 3724 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3725 | } |
| 3726 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3727 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3728 | { |
| 3729 | switch (hw->phy.type) { |
| 3730 | case ixgbe_phy_sfp_avago: |
| 3731 | case ixgbe_phy_sfp_ftl: |
| 3732 | case ixgbe_phy_sfp_intel: |
| 3733 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3734 | case ixgbe_phy_sfp_passive_tyco: |
| 3735 | case ixgbe_phy_sfp_passive_unknown: |
| 3736 | case ixgbe_phy_sfp_active_unknown: |
| 3737 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3738 | return true; |
Alexander Duyck | 8917b44 | 2011-07-21 00:40:51 +0000 | [diff] [blame] | 3739 | case ixgbe_phy_nl: |
| 3740 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3741 | return true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3742 | default: |
| 3743 | return false; |
| 3744 | } |
| 3745 | } |
| 3746 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3747 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3748 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3749 | * @adapter: pointer to private adapter struct |
| 3750 | **/ |
| 3751 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3752 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3753 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3754 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3755 | * is that an SFP was inserted/removed after the reset |
| 3756 | * but before SFP detection was enabled. As such the best |
| 3757 | * solution is to just start searching as soon as we start |
| 3758 | */ |
| 3759 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3760 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3761 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3762 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | /** |
| 3766 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3767 | * @hw: pointer to private hardware struct |
| 3768 | * |
| 3769 | * Returns 0 on success, negative on failure |
| 3770 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3771 | 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] | 3772 | { |
| 3773 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3774 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3775 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 3776 | |
| 3777 | if (hw->mac.ops.check_link) |
| 3778 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 3779 | |
| 3780 | if (ret) |
| 3781 | goto link_cfg_out; |
| 3782 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 3783 | autoneg = hw->phy.autoneg_advertised; |
| 3784 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3785 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3786 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3787 | if (ret) |
| 3788 | goto link_cfg_out; |
| 3789 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3790 | if (hw->mac.ops.setup_link) |
| 3791 | 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] | 3792 | link_cfg_out: |
| 3793 | return ret; |
| 3794 | } |
| 3795 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3796 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3797 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3798 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3799 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3800 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3801 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3802 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 3803 | IXGBE_GPIE_OCD; |
| 3804 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3805 | /* |
| 3806 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 3807 | * this saves a register write for every interrupt |
| 3808 | */ |
| 3809 | switch (hw->mac.type) { |
| 3810 | case ixgbe_mac_82598EB: |
| 3811 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 3812 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3813 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3814 | case ixgbe_mac_X540: |
| 3815 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3816 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 3817 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 3818 | break; |
| 3819 | } |
| 3820 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3821 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 3822 | * specifically only auto mask tx and rx interrupts */ |
| 3823 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3826 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 3827 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 3828 | |
| 3829 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3830 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 3831 | gpie |= IXGBE_GPIE_VTMODE_64; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 3832 | } |
| 3833 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 3834 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 3835 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 3836 | switch (adapter->hw.mac.type) { |
| 3837 | case ixgbe_mac_82599EB: |
| 3838 | gpie |= IXGBE_SDP0_GPIEN; |
| 3839 | break; |
| 3840 | case ixgbe_mac_X540: |
| 3841 | gpie |= IXGBE_EIMS_TS; |
| 3842 | break; |
| 3843 | default: |
| 3844 | break; |
| 3845 | } |
| 3846 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 3847 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3848 | /* Enable fan failure interrupt */ |
| 3849 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3850 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3851 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3852 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3853 | gpie |= IXGBE_SDP1_GPIEN; |
| 3854 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3855 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3856 | |
| 3857 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 3858 | } |
| 3859 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3860 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3861 | { |
| 3862 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3863 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3864 | u32 ctrl_ext; |
| 3865 | |
| 3866 | ixgbe_get_hw_control(adapter); |
| 3867 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3868 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3869 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3870 | ixgbe_configure_msix(adapter); |
| 3871 | else |
| 3872 | ixgbe_configure_msi_and_legacy(adapter); |
| 3873 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3874 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ |
| 3875 | if (hw->mac.ops.enable_tx_laser && |
| 3876 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 3877 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3878 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 3879 | hw->mac.ops.enable_tx_laser(hw); |
| 3880 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3881 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3882 | ixgbe_napi_enable_all(adapter); |
| 3883 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 3884 | if (ixgbe_is_sfp(hw)) { |
| 3885 | ixgbe_sfp_link_config(adapter); |
| 3886 | } else { |
| 3887 | err = ixgbe_non_sfp_link_config(hw); |
| 3888 | if (err) |
| 3889 | e_err(probe, "link_config FAILED %d\n", err); |
| 3890 | } |
| 3891 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3892 | /* clear any pending interrupts, may auto mask */ |
| 3893 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3894 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3895 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3896 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3897 | * If this adapter has a fan, check to see if we had a failure |
| 3898 | * before we enabled the interrupt. |
| 3899 | */ |
| 3900 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 3901 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 3902 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3903 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3904 | } |
| 3905 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3906 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3907 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3908 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3909 | /* bring the link up in the watchdog, this could race with our first |
| 3910 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3911 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3912 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3913 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 3914 | |
| 3915 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 3916 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 3917 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 3918 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3921 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 3922 | { |
| 3923 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3924 | /* put off any impending NetWatchDogTimeout */ |
| 3925 | adapter->netdev->trans_start = jiffies; |
| 3926 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3927 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3928 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3929 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 3930 | /* |
| 3931 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 3932 | * back up to give the VFs time to respond to the reset. The |
| 3933 | * two second wait is based upon the watchdog timer cycle in |
| 3934 | * the VF driver. |
| 3935 | */ |
| 3936 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3937 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3938 | ixgbe_up(adapter); |
| 3939 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 3940 | } |
| 3941 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3942 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3943 | { |
| 3944 | /* hardware has been reset, we need to reload some things */ |
| 3945 | ixgbe_configure(adapter); |
| 3946 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3947 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 3951 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3952 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3953 | int err; |
| 3954 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3955 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 3956 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 3957 | usleep_range(1000, 2000); |
| 3958 | |
| 3959 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 3960 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 3961 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 3962 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 3963 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3964 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3965 | switch (err) { |
| 3966 | case 0: |
| 3967 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3968 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3969 | break; |
| 3970 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3971 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3972 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3973 | case IXGBE_ERR_EEPROM_VERSION: |
| 3974 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3975 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3976 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3977 | "your hardware. If you are experiencing problems " |
| 3978 | "please contact your Intel or hardware " |
| 3979 | "representative who provided you with this " |
| 3980 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3981 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3982 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3983 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3984 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3985 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3986 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 3987 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3988 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3989 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 3990 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3991 | } |
| 3992 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3993 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3994 | * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers |
| 3995 | * @rx_ring: ring to setup |
| 3996 | * |
| 3997 | * On many IA platforms the L1 cache has a critical stride of 4K, this |
| 3998 | * results in each receive buffer starting in the same cache set. To help |
| 3999 | * reduce the pressure on this cache set we can interleave the offsets so |
| 4000 | * that only every other buffer will be in the same cache set. |
| 4001 | **/ |
| 4002 | static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring) |
| 4003 | { |
| 4004 | struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info; |
| 4005 | u16 i; |
| 4006 | |
| 4007 | for (i = 0; i < rx_ring->count; i += 2) { |
| 4008 | rx_buffer[0].page_offset = 0; |
| 4009 | rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring); |
| 4010 | rx_buffer = &rx_buffer[2]; |
| 4011 | } |
| 4012 | } |
| 4013 | |
| 4014 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4015 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4016 | * @rx_ring: ring to free buffers from |
| 4017 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4018 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4019 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4020 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4021 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4022 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4023 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4024 | /* ring already cleared, nothing to do */ |
| 4025 | if (!rx_ring->rx_buffer_info) |
| 4026 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4027 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4028 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4029 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4030 | struct ixgbe_rx_buffer *rx_buffer; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4031 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4032 | rx_buffer = &rx_ring->rx_buffer_info[i]; |
| 4033 | if (rx_buffer->skb) { |
| 4034 | struct sk_buff *skb = rx_buffer->skb; |
| 4035 | if (IXGBE_CB(skb)->page_released) { |
| 4036 | dma_unmap_page(dev, |
| 4037 | IXGBE_CB(skb)->dma, |
| 4038 | ixgbe_rx_bufsz(rx_ring), |
| 4039 | DMA_FROM_DEVICE); |
| 4040 | IXGBE_CB(skb)->page_released = false; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 4041 | } |
| 4042 | dev_kfree_skb(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4043 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4044 | rx_buffer->skb = NULL; |
| 4045 | if (rx_buffer->dma) |
| 4046 | dma_unmap_page(dev, rx_buffer->dma, |
| 4047 | ixgbe_rx_pg_size(rx_ring), |
| 4048 | DMA_FROM_DEVICE); |
| 4049 | rx_buffer->dma = 0; |
| 4050 | if (rx_buffer->page) |
| 4051 | put_page(rx_buffer->page); |
| 4052 | rx_buffer->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4056 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4057 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4058 | ixgbe_init_rx_page_offset(rx_ring); |
| 4059 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4060 | /* Zero out the descriptor ring */ |
| 4061 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4062 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4063 | rx_ring->next_to_alloc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4064 | rx_ring->next_to_clean = 0; |
| 4065 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | /** |
| 4069 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4070 | * @tx_ring: ring to be cleaned |
| 4071 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4072 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4073 | { |
| 4074 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4075 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4076 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4077 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4078 | /* ring already cleared, nothing to do */ |
| 4079 | if (!tx_ring->tx_buffer_info) |
| 4080 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4081 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4082 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4083 | for (i = 0; i < tx_ring->count; i++) { |
| 4084 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4085 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4089 | memset(tx_ring->tx_buffer_info, 0, size); |
| 4090 | |
| 4091 | /* Zero out the descriptor ring */ |
| 4092 | memset(tx_ring->desc, 0, tx_ring->size); |
| 4093 | |
| 4094 | tx_ring->next_to_use = 0; |
| 4095 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4099 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4100 | * @adapter: board private structure |
| 4101 | **/ |
| 4102 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4103 | { |
| 4104 | int i; |
| 4105 | |
| 4106 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4107 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4110 | /** |
| 4111 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4112 | * @adapter: board private structure |
| 4113 | **/ |
| 4114 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4115 | { |
| 4116 | int i; |
| 4117 | |
| 4118 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4119 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4120 | } |
| 4121 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4122 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4123 | { |
| 4124 | struct hlist_node *node, *node2; |
| 4125 | struct ixgbe_fdir_filter *filter; |
| 4126 | |
| 4127 | spin_lock(&adapter->fdir_perfect_lock); |
| 4128 | |
| 4129 | hlist_for_each_entry_safe(filter, node, node2, |
| 4130 | &adapter->fdir_filter_list, fdir_node) { |
| 4131 | hlist_del(&filter->fdir_node); |
| 4132 | kfree(filter); |
| 4133 | } |
| 4134 | adapter->fdir_filter_count = 0; |
| 4135 | |
| 4136 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4137 | } |
| 4138 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4139 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4140 | { |
| 4141 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4142 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4143 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4144 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4145 | |
| 4146 | /* signal that we are down to the interrupt handler */ |
| 4147 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4148 | |
| 4149 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4150 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4151 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4152 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4153 | /* disable all enabled rx queues */ |
| 4154 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4155 | /* this call also flushes the previous write */ |
| 4156 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4157 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4158 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4159 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4160 | netif_tx_stop_all_queues(netdev); |
| 4161 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4162 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4163 | netif_carrier_off(netdev); |
| 4164 | netif_tx_disable(netdev); |
| 4165 | |
| 4166 | ixgbe_irq_disable(adapter); |
| 4167 | |
| 4168 | ixgbe_napi_disable_all(adapter); |
| 4169 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4170 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4171 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4172 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4173 | |
| 4174 | del_timer_sync(&adapter->service_timer); |
| 4175 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4176 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4177 | /* Clear EITR Select mapping */ |
| 4178 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 4179 | |
| 4180 | /* Mark all the VFs as inactive */ |
| 4181 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4182 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4183 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4184 | /* 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] | 4185 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4186 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4187 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4188 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4191 | /* disable transmits in the hardware now that interrupts are off */ |
| 4192 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4193 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4194 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4195 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4196 | |
| 4197 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4198 | switch (hw->mac.type) { |
| 4199 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4200 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4201 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4202 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4203 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4204 | break; |
| 4205 | default: |
| 4206 | break; |
| 4207 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4208 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4209 | if (!pci_channel_offline(adapter->pdev)) |
| 4210 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4211 | |
| 4212 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 4213 | if (hw->mac.ops.disable_tx_laser && |
| 4214 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 4215 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4216 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 4217 | hw->mac.ops.disable_tx_laser(hw); |
| 4218 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4219 | ixgbe_clean_all_tx_rings(adapter); |
| 4220 | ixgbe_clean_all_rx_rings(adapter); |
| 4221 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4222 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4223 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4224 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4225 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4226 | } |
| 4227 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4228 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4229 | * ixgbe_poll - NAPI Rx polling callback |
| 4230 | * @napi: structure for representing this polling device |
| 4231 | * @budget: how many packets driver is allowed to clean |
| 4232 | * |
| 4233 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4234 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4235 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4236 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4237 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4238 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4239 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4240 | struct ixgbe_ring *ring; |
| 4241 | int per_ring_budget; |
| 4242 | bool clean_complete = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4243 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4244 | #ifdef CONFIG_IXGBE_DCA |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 4245 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 4246 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4247 | #endif |
| 4248 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4249 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4250 | clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4251 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4252 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 4253 | * the budget to go below 1 because we'll exit polling */ |
| 4254 | if (q_vector->rx.count > 1) |
| 4255 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 4256 | else |
| 4257 | per_ring_budget = budget; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4258 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4259 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4260 | clean_complete &= ixgbe_clean_rx_irq(q_vector, ring, |
| 4261 | per_ring_budget); |
| 4262 | |
| 4263 | /* If all work not completed, return budget and keep polling */ |
| 4264 | if (!clean_complete) |
| 4265 | return budget; |
| 4266 | |
| 4267 | /* all work done, exit the polling mode */ |
| 4268 | napi_complete(napi); |
| 4269 | if (adapter->rx_itr_setting & 1) |
| 4270 | ixgbe_set_itr(q_vector); |
| 4271 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4272 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 4273 | |
| 4274 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | /** |
| 4278 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4279 | * @netdev: network interface device structure |
| 4280 | **/ |
| 4281 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4282 | { |
| 4283 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4284 | |
| 4285 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4286 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4287 | } |
| 4288 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4289 | /** |
| 4290 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 4291 | * @adapter: board private structure to initialize |
| 4292 | * |
| 4293 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 4294 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 4295 | * |
| 4296 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4297 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 4298 | { |
| 4299 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4300 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS]; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4301 | |
| 4302 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4303 | f->mask = 0xF; |
| 4304 | adapter->num_rx_queues = f->indices; |
| 4305 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4306 | ret = true; |
| 4307 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4308 | ret = false; |
| 4309 | } |
| 4310 | |
| 4311 | return ret; |
| 4312 | } |
| 4313 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4314 | /** |
| 4315 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 4316 | * @adapter: board private structure to initialize |
| 4317 | * |
| 4318 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 4319 | * to the original CPU that initiated the Tx session. This runs in addition |
| 4320 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 4321 | * Rx load across CPUs using RSS. |
| 4322 | * |
| 4323 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4324 | static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4325 | { |
| 4326 | bool ret = false; |
| 4327 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 4328 | |
| 4329 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 4330 | f_fdir->mask = 0; |
| 4331 | |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 4332 | /* |
| 4333 | * Use RSS in addition to Flow Director to ensure the best |
| 4334 | * distribution of flows across cores, even when an FDIR flow |
| 4335 | * isn't matched. |
| 4336 | */ |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4337 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4338 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4339 | adapter->num_tx_queues = f_fdir->indices; |
| 4340 | adapter->num_rx_queues = f_fdir->indices; |
| 4341 | ret = true; |
| 4342 | } else { |
| 4343 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4344 | } |
| 4345 | return ret; |
| 4346 | } |
| 4347 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4348 | #ifdef IXGBE_FCOE |
| 4349 | /** |
| 4350 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 4351 | * @adapter: board private structure to initialize |
| 4352 | * |
| 4353 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 4354 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 4355 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 4356 | * index of the first rx queue used by FCoE. |
| 4357 | * |
| 4358 | **/ |
| 4359 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 4360 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4361 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 4362 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4363 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4364 | return false; |
| 4365 | |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4366 | f->indices = min_t(int, num_online_cpus(), f->indices); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4367 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4368 | adapter->num_rx_queues = 1; |
| 4369 | adapter->num_tx_queues = 1; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4370 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4371 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 4372 | e_info(probe, "FCoE enabled with RSS\n"); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4373 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4374 | ixgbe_set_fdir_queues(adapter); |
| 4375 | else |
| 4376 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4377 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4378 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4379 | /* adding FCoE rx rings to the end */ |
| 4380 | f->mask = adapter->num_rx_queues; |
| 4381 | adapter->num_rx_queues += f->indices; |
| 4382 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4383 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4384 | return true; |
| 4385 | } |
| 4386 | #endif /* IXGBE_FCOE */ |
| 4387 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4388 | /* Artificial max queue cap per traffic class in DCB mode */ |
| 4389 | #define DCB_QUEUE_CAP 8 |
| 4390 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4391 | #ifdef CONFIG_IXGBE_DCB |
| 4392 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
| 4393 | { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4394 | int per_tc_q, q, i, offset = 0; |
| 4395 | struct net_device *dev = adapter->netdev; |
| 4396 | int tcs = netdev_get_num_tc(dev); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4397 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4398 | if (!tcs) |
| 4399 | return false; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4400 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4401 | /* Map queue offset and counts onto allocated tx queues */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4402 | per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP); |
| 4403 | q = min_t(int, num_online_cpus(), per_tc_q); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4404 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4405 | for (i = 0; i < tcs; i++) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4406 | netdev_set_tc_queue(dev, i, q, offset); |
| 4407 | offset += q; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4410 | adapter->num_tx_queues = q * tcs; |
| 4411 | adapter->num_rx_queues = q * tcs; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4412 | |
| 4413 | #ifdef IXGBE_FCOE |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4414 | /* FCoE enabled queues require special configuration indexed |
| 4415 | * by feature specific indices and mask. Here we map FCoE |
| 4416 | * indices onto the DCB queue pairs allowing FCoE to own |
| 4417 | * configuration later. |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4418 | */ |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4419 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
John Fastabend | cdf485b | 2012-02-11 06:26:00 +0000 | [diff] [blame] | 4420 | u8 prio_tc[MAX_USER_PRIORITY] = {0}; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4421 | int tc; |
| 4422 | struct ixgbe_ring_feature *f = |
| 4423 | &adapter->ring_feature[RING_F_FCOE]; |
| 4424 | |
John Fastabend | cdf485b | 2012-02-11 06:26:00 +0000 | [diff] [blame] | 4425 | ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc); |
| 4426 | tc = prio_tc[adapter->fcoe.up]; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4427 | f->indices = dev->tc_to_txq[tc].count; |
| 4428 | f->mask = dev->tc_to_txq[tc].offset; |
| 4429 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4430 | #endif |
| 4431 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4432 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4433 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4434 | #endif |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4435 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4436 | /** |
| 4437 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 4438 | * @adapter: board private structure to initialize |
| 4439 | * |
| 4440 | * IOV doesn't actually use anything, so just NAK the |
| 4441 | * request for now and let the other queue routines |
| 4442 | * figure out what to do. |
| 4443 | */ |
| 4444 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 4445 | { |
| 4446 | return false; |
| 4447 | } |
| 4448 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4449 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4450 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4451 | * @adapter: board private structure to initialize |
| 4452 | * |
| 4453 | * This is the top level queue allocation routine. The order here is very |
| 4454 | * important, starting with the "most" number of features turned on at once, |
| 4455 | * and ending with the smallest set of features. This way large combinations |
| 4456 | * can be allocated if they're turned on, and smaller combinations are the |
| 4457 | * fallthrough conditions. |
| 4458 | * |
| 4459 | **/ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4460 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4461 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4462 | /* Start with base case */ |
| 4463 | adapter->num_rx_queues = 1; |
| 4464 | adapter->num_tx_queues = 1; |
| 4465 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 4466 | adapter->num_rx_queues_per_pool = 1; |
| 4467 | |
| 4468 | if (ixgbe_set_sriov_queues(adapter)) |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4469 | goto done; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4470 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4471 | #ifdef CONFIG_IXGBE_DCB |
| 4472 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4473 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4474 | |
| 4475 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4476 | #ifdef IXGBE_FCOE |
| 4477 | if (ixgbe_set_fcoe_queues(adapter)) |
| 4478 | goto done; |
| 4479 | |
| 4480 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4481 | if (ixgbe_set_fdir_queues(adapter)) |
| 4482 | goto done; |
| 4483 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4484 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4485 | goto done; |
| 4486 | |
| 4487 | /* fallback to base case */ |
| 4488 | adapter->num_rx_queues = 1; |
| 4489 | adapter->num_tx_queues = 1; |
| 4490 | |
| 4491 | done: |
Yi Zou | 9d837ea | 2012-01-07 08:39:50 +0000 | [diff] [blame] | 4492 | if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) || |
| 4493 | (adapter->netdev->reg_state == NETREG_UNREGISTERING)) |
| 4494 | return 0; |
| 4495 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4496 | /* Notify the stack of the (possibly) reduced queue counts. */ |
John Fastabend | f0796d5 | 2010-07-01 13:21:57 +0000 | [diff] [blame] | 4497 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4498 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 4499 | adapter->num_rx_queues); |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4502 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4503 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4504 | { |
| 4505 | int err, vector_threshold; |
| 4506 | |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4507 | /* We'll want at least 2 (vector_threshold): |
| 4508 | * 1) TxQ[0] + RxQ[0] handler |
| 4509 | * 2) Other (Link Status Change, etc.) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4510 | */ |
| 4511 | vector_threshold = MIN_MSIX_COUNT; |
| 4512 | |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 4513 | /* |
| 4514 | * The more we get, the more we will assign to Tx/Rx Cleanup |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4515 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 4516 | * Right now, we simply care about how many we'll get; we'll |
| 4517 | * set them up later while requesting irq's. |
| 4518 | */ |
| 4519 | while (vectors >= vector_threshold) { |
| 4520 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4521 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4522 | if (!err) /* Success in acquiring all requested vectors. */ |
| 4523 | break; |
| 4524 | else if (err < 0) |
| 4525 | vectors = 0; /* Nasty failure, quit now */ |
| 4526 | else /* err == number of vectors we should try again with */ |
| 4527 | vectors = err; |
| 4528 | } |
| 4529 | |
| 4530 | if (vectors < vector_threshold) { |
| 4531 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 4532 | * This just means we'll go with either a single MSI |
| 4533 | * vector or fall back to legacy interrupts. |
| 4534 | */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4535 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4536 | "Unable to allocate MSI-X interrupts\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4537 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4538 | kfree(adapter->msix_entries); |
| 4539 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4540 | } else { |
| 4541 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 4542 | /* |
| 4543 | * Adjust for only the vectors we'll use, which is minimum |
| 4544 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 4545 | * vectors we were allocated. |
| 4546 | */ |
| 4547 | adapter->num_msix_vectors = min(vectors, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4548 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4549 | } |
| 4550 | } |
| 4551 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4552 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4553 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4554 | * @adapter: board private structure to initialize |
| 4555 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4556 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 4557 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4558 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4559 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4560 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4561 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4562 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4563 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 4564 | return false; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4565 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4566 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4567 | adapter->rx_ring[i]->reg_idx = i; |
| 4568 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4569 | adapter->tx_ring[i]->reg_idx = i; |
| 4570 | |
| 4571 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4572 | } |
| 4573 | |
| 4574 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4575 | |
| 4576 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 4577 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, |
| 4578 | unsigned int *tx, unsigned int *rx) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4579 | { |
| 4580 | struct net_device *dev = adapter->netdev; |
| 4581 | struct ixgbe_hw *hw = &adapter->hw; |
| 4582 | u8 num_tcs = netdev_get_num_tc(dev); |
| 4583 | |
| 4584 | *tx = 0; |
| 4585 | *rx = 0; |
| 4586 | |
| 4587 | switch (hw->mac.type) { |
| 4588 | case ixgbe_mac_82598EB: |
John Fastabend | aba70d5 | 2011-04-26 07:26:14 +0000 | [diff] [blame] | 4589 | *tx = tc << 2; |
| 4590 | *rx = tc << 3; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4591 | break; |
| 4592 | case ixgbe_mac_82599EB: |
| 4593 | case ixgbe_mac_X540: |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4594 | if (num_tcs > 4) { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4595 | if (tc < 3) { |
| 4596 | *tx = tc << 5; |
| 4597 | *rx = tc << 4; |
| 4598 | } else if (tc < 5) { |
| 4599 | *tx = ((tc + 2) << 4); |
| 4600 | *rx = tc << 4; |
| 4601 | } else if (tc < num_tcs) { |
| 4602 | *tx = ((tc + 8) << 3); |
| 4603 | *rx = tc << 4; |
| 4604 | } |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4605 | } else { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4606 | *rx = tc << 5; |
| 4607 | switch (tc) { |
| 4608 | case 0: |
| 4609 | *tx = 0; |
| 4610 | break; |
| 4611 | case 1: |
| 4612 | *tx = 64; |
| 4613 | break; |
| 4614 | case 2: |
| 4615 | *tx = 96; |
| 4616 | break; |
| 4617 | case 3: |
| 4618 | *tx = 112; |
| 4619 | break; |
| 4620 | default: |
| 4621 | break; |
| 4622 | } |
| 4623 | } |
| 4624 | break; |
| 4625 | default: |
| 4626 | break; |
| 4627 | } |
| 4628 | } |
| 4629 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4630 | /** |
| 4631 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 4632 | * @adapter: board private structure to initialize |
| 4633 | * |
| 4634 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 4635 | * |
| 4636 | **/ |
| 4637 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 4638 | { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4639 | struct net_device *dev = adapter->netdev; |
| 4640 | int i, j, k; |
| 4641 | u8 num_tcs = netdev_get_num_tc(dev); |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4642 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4643 | if (!num_tcs) |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4644 | return false; |
| 4645 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4646 | for (i = 0, k = 0; i < num_tcs; i++) { |
| 4647 | unsigned int tx_s, rx_s; |
| 4648 | u16 count = dev->tc_to_txq[i].count; |
| 4649 | |
| 4650 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); |
| 4651 | for (j = 0; j < count; j++, k++) { |
| 4652 | adapter->tx_ring[k]->reg_idx = tx_s + j; |
| 4653 | adapter->rx_ring[k]->reg_idx = rx_s + j; |
| 4654 | adapter->tx_ring[k]->dcb_tc = i; |
| 4655 | adapter->rx_ring[k]->dcb_tc = i; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4656 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4657 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4658 | |
| 4659 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4660 | } |
| 4661 | #endif |
| 4662 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4663 | /** |
| 4664 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 4665 | * @adapter: board private structure to initialize |
| 4666 | * |
| 4667 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 4668 | * |
| 4669 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4670 | static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4671 | { |
| 4672 | int i; |
| 4673 | bool ret = false; |
| 4674 | |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4675 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4676 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4677 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4678 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4679 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4680 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4681 | ret = true; |
| 4682 | } |
| 4683 | |
| 4684 | return ret; |
| 4685 | } |
| 4686 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4687 | #ifdef IXGBE_FCOE |
| 4688 | /** |
| 4689 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 4690 | * @adapter: board private structure to initialize |
| 4691 | * |
| 4692 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 4693 | * |
| 4694 | */ |
| 4695 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 4696 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4697 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4698 | int i; |
| 4699 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4700 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4701 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4702 | return false; |
| 4703 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4704 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4705 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4706 | ixgbe_cache_ring_fdir(adapter); |
| 4707 | else |
| 4708 | ixgbe_cache_ring_rss(adapter); |
| 4709 | |
| 4710 | fcoe_rx_i = f->mask; |
| 4711 | fcoe_tx_i = f->mask; |
| 4712 | } |
| 4713 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 4714 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 4715 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
| 4716 | } |
| 4717 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4721 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4722 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 4723 | * @adapter: board private structure to initialize |
| 4724 | * |
| 4725 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 4726 | * no other mapping is used. |
| 4727 | * |
| 4728 | */ |
| 4729 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 4730 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4731 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 4732 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4733 | if (adapter->num_vfs) |
| 4734 | return true; |
| 4735 | else |
| 4736 | return false; |
| 4737 | } |
| 4738 | |
| 4739 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4740 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 4741 | * @adapter: board private structure to initialize |
| 4742 | * |
| 4743 | * Once we know the feature-set enabled for the device, we'll cache |
| 4744 | * the register offset the descriptor ring is assigned to. |
| 4745 | * |
| 4746 | * Note, the order the various feature calls is important. It must start with |
| 4747 | * the "most" features enabled at the same time, then trickle down to the |
| 4748 | * least amount of features turned on at once. |
| 4749 | **/ |
| 4750 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 4751 | { |
| 4752 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4753 | adapter->rx_ring[0]->reg_idx = 0; |
| 4754 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4755 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4756 | if (ixgbe_cache_ring_sriov(adapter)) |
| 4757 | return; |
| 4758 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4759 | #ifdef CONFIG_IXGBE_DCB |
| 4760 | if (ixgbe_cache_ring_dcb(adapter)) |
| 4761 | return; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4762 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4763 | |
| 4764 | #ifdef IXGBE_FCOE |
| 4765 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 4766 | return; |
| 4767 | #endif /* IXGBE_FCOE */ |
| 4768 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4769 | if (ixgbe_cache_ring_fdir(adapter)) |
| 4770 | return; |
| 4771 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4772 | if (ixgbe_cache_ring_rss(adapter)) |
| 4773 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4774 | } |
| 4775 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4776 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4777 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 4778 | * @adapter: board private structure to initialize |
| 4779 | * |
| 4780 | * Attempt to configure the interrupts using the best available |
| 4781 | * capabilities of the hardware and the kernel. |
| 4782 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 4783 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4784 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4785 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4786 | int err = 0; |
| 4787 | int vector, v_budget; |
| 4788 | |
| 4789 | /* |
| 4790 | * It's easy to be greedy for MSI-X vectors, but it really |
| 4791 | * doesn't do us much good if we have a lot more vectors |
| 4792 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 4793 | * (roughly) the same number of vectors as there are CPU's. |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4794 | * The default is to use pairs of vectors. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4795 | */ |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4796 | v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues); |
| 4797 | v_budget = min_t(int, v_budget, num_online_cpus()); |
| 4798 | v_budget += NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4799 | |
| 4800 | /* |
| 4801 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4802 | * hw.mac->max_msix_vectors vectors. With features |
| 4803 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 4804 | * descriptor queues supported by our device. Thus, we cap it off in |
| 4805 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4806 | */ |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4807 | v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4808 | |
| 4809 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 4810 | * mean we disable MSI-X capabilities of the adapter. */ |
| 4811 | adapter->msix_entries = kcalloc(v_budget, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4812 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4813 | if (adapter->msix_entries) { |
| 4814 | for (vector = 0; vector < v_budget; vector++) |
| 4815 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4816 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4817 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 4818 | |
| 4819 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4820 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4821 | } |
David S. Miller | 26d2784 | 2010-05-03 15:18:22 -0700 | [diff] [blame] | 4822 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4823 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 4824 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4825 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4826 | e_err(probe, |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4827 | "ATR is not supported while multiple " |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4828 | "queues are disabled. Disabling Flow Director\n"); |
| 4829 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4830 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4831 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4832 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4833 | ixgbe_disable_sriov(adapter); |
| 4834 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4835 | err = ixgbe_set_num_queues(adapter); |
| 4836 | if (err) |
| 4837 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4838 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4839 | err = pci_enable_msi(adapter->pdev); |
| 4840 | if (!err) { |
| 4841 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 4842 | } else { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4843 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4844 | "Unable to allocate MSI interrupt, " |
| 4845 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4846 | /* reset err */ |
| 4847 | err = 0; |
| 4848 | } |
| 4849 | |
| 4850 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4851 | return err; |
| 4852 | } |
| 4853 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4854 | static void ixgbe_add_ring(struct ixgbe_ring *ring, |
| 4855 | struct ixgbe_ring_container *head) |
| 4856 | { |
| 4857 | ring->next = head->ring; |
| 4858 | head->ring = ring; |
| 4859 | head->count++; |
| 4860 | } |
| 4861 | |
| 4862 | /** |
| 4863 | * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector |
| 4864 | * @adapter: board private structure to initialize |
| 4865 | * @v_idx: index of vector in adapter struct |
| 4866 | * |
| 4867 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 4868 | **/ |
| 4869 | static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx, |
| 4870 | int txr_count, int txr_idx, |
| 4871 | int rxr_count, int rxr_idx) |
| 4872 | { |
| 4873 | struct ixgbe_q_vector *q_vector; |
| 4874 | struct ixgbe_ring *ring; |
| 4875 | int node = -1; |
| 4876 | int cpu = -1; |
| 4877 | int ring_count, size; |
| 4878 | |
| 4879 | ring_count = txr_count + rxr_count; |
| 4880 | size = sizeof(struct ixgbe_q_vector) + |
| 4881 | (sizeof(struct ixgbe_ring) * ring_count); |
| 4882 | |
| 4883 | /* customize cpu for Flow Director mapping */ |
| 4884 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 4885 | if (cpu_online(v_idx)) { |
| 4886 | cpu = v_idx; |
| 4887 | node = cpu_to_node(cpu); |
| 4888 | } |
| 4889 | } |
| 4890 | |
| 4891 | /* allocate q_vector and rings */ |
| 4892 | q_vector = kzalloc_node(size, GFP_KERNEL, node); |
| 4893 | if (!q_vector) |
| 4894 | q_vector = kzalloc(size, GFP_KERNEL); |
| 4895 | if (!q_vector) |
| 4896 | return -ENOMEM; |
| 4897 | |
| 4898 | /* setup affinity mask and node */ |
| 4899 | if (cpu != -1) |
| 4900 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 4901 | else |
| 4902 | cpumask_copy(&q_vector->affinity_mask, cpu_online_mask); |
| 4903 | q_vector->numa_node = node; |
| 4904 | |
| 4905 | /* initialize NAPI */ |
| 4906 | netif_napi_add(adapter->netdev, &q_vector->napi, |
| 4907 | ixgbe_poll, 64); |
| 4908 | |
| 4909 | /* tie q_vector and adapter together */ |
| 4910 | adapter->q_vector[v_idx] = q_vector; |
| 4911 | q_vector->adapter = adapter; |
| 4912 | q_vector->v_idx = v_idx; |
| 4913 | |
| 4914 | /* initialize work limits */ |
| 4915 | q_vector->tx.work_limit = adapter->tx_work_limit; |
| 4916 | |
| 4917 | /* initialize pointer to rings */ |
| 4918 | ring = q_vector->ring; |
| 4919 | |
| 4920 | while (txr_count) { |
| 4921 | /* assign generic ring traits */ |
| 4922 | ring->dev = &adapter->pdev->dev; |
| 4923 | ring->netdev = adapter->netdev; |
| 4924 | |
| 4925 | /* configure backlink on ring */ |
| 4926 | ring->q_vector = q_vector; |
| 4927 | |
| 4928 | /* update q_vector Tx values */ |
| 4929 | ixgbe_add_ring(ring, &q_vector->tx); |
| 4930 | |
| 4931 | /* apply Tx specific ring traits */ |
| 4932 | ring->count = adapter->tx_ring_count; |
| 4933 | ring->queue_index = txr_idx; |
| 4934 | |
| 4935 | /* assign ring to adapter */ |
| 4936 | adapter->tx_ring[txr_idx] = ring; |
| 4937 | |
| 4938 | /* update count and index */ |
| 4939 | txr_count--; |
| 4940 | txr_idx++; |
| 4941 | |
| 4942 | /* push pointer to next ring */ |
| 4943 | ring++; |
| 4944 | } |
| 4945 | |
| 4946 | while (rxr_count) { |
| 4947 | /* assign generic ring traits */ |
| 4948 | ring->dev = &adapter->pdev->dev; |
| 4949 | ring->netdev = adapter->netdev; |
| 4950 | |
| 4951 | /* configure backlink on ring */ |
| 4952 | ring->q_vector = q_vector; |
| 4953 | |
| 4954 | /* update q_vector Rx values */ |
| 4955 | ixgbe_add_ring(ring, &q_vector->rx); |
| 4956 | |
| 4957 | /* |
| 4958 | * 82599 errata, UDP frames with a 0 checksum |
| 4959 | * can be marked as checksum errors. |
| 4960 | */ |
| 4961 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 4962 | set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state); |
| 4963 | |
| 4964 | /* apply Rx specific ring traits */ |
| 4965 | ring->count = adapter->rx_ring_count; |
| 4966 | ring->queue_index = rxr_idx; |
| 4967 | |
| 4968 | /* assign ring to adapter */ |
| 4969 | adapter->rx_ring[rxr_idx] = ring; |
| 4970 | |
| 4971 | /* update count and index */ |
| 4972 | rxr_count--; |
| 4973 | rxr_idx++; |
| 4974 | |
| 4975 | /* push pointer to next ring */ |
| 4976 | ring++; |
| 4977 | } |
| 4978 | |
| 4979 | return 0; |
| 4980 | } |
| 4981 | |
| 4982 | /** |
| 4983 | * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector |
| 4984 | * @adapter: board private structure to initialize |
| 4985 | * @v_idx: Index of vector to be freed |
| 4986 | * |
| 4987 | * This function frees the memory allocated to the q_vector. In addition if |
| 4988 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4989 | * to freeing the q_vector. |
| 4990 | **/ |
| 4991 | static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx) |
| 4992 | { |
| 4993 | struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 4994 | struct ixgbe_ring *ring; |
| 4995 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4996 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4997 | adapter->tx_ring[ring->queue_index] = NULL; |
| 4998 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4999 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5000 | adapter->rx_ring[ring->queue_index] = NULL; |
| 5001 | |
| 5002 | adapter->q_vector[v_idx] = NULL; |
| 5003 | netif_napi_del(&q_vector->napi); |
| 5004 | |
| 5005 | /* |
| 5006 | * ixgbe_get_stats64() might access the rings on this vector, |
| 5007 | * we must wait a grace period before freeing it. |
| 5008 | */ |
| 5009 | kfree_rcu(q_vector, rcu); |
| 5010 | } |
| 5011 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5012 | /** |
| 5013 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 5014 | * @adapter: board private structure to initialize |
| 5015 | * |
| 5016 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 5017 | * return -ENOMEM. |
| 5018 | **/ |
| 5019 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 5020 | { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5021 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5022 | int rxr_remaining = adapter->num_rx_queues; |
| 5023 | int txr_remaining = adapter->num_tx_queues; |
| 5024 | int rxr_idx = 0, txr_idx = 0, v_idx = 0; |
| 5025 | int err; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5026 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5027 | /* only one q_vector if MSI-X is disabled. */ |
| 5028 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 5029 | q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5030 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5031 | if (q_vectors >= (rxr_remaining + txr_remaining)) { |
| 5032 | for (; rxr_remaining; v_idx++, q_vectors--) { |
| 5033 | int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 5034 | err = ixgbe_alloc_q_vector(adapter, v_idx, |
| 5035 | 0, 0, rqpv, rxr_idx); |
| 5036 | |
| 5037 | if (err) |
| 5038 | goto err_out; |
| 5039 | |
| 5040 | /* update counts and index */ |
| 5041 | rxr_remaining -= rqpv; |
| 5042 | rxr_idx += rqpv; |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | for (; q_vectors; v_idx++, q_vectors--) { |
| 5047 | int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 5048 | int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors); |
| 5049 | err = ixgbe_alloc_q_vector(adapter, v_idx, |
| 5050 | tqpv, txr_idx, |
| 5051 | rqpv, rxr_idx); |
| 5052 | |
| 5053 | if (err) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5054 | goto err_out; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 5055 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5056 | /* update counts and index */ |
| 5057 | rxr_remaining -= rqpv; |
| 5058 | rxr_idx += rqpv; |
| 5059 | txr_remaining -= tqpv; |
| 5060 | txr_idx += tqpv; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5061 | } |
| 5062 | |
| 5063 | return 0; |
| 5064 | |
| 5065 | err_out: |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 5066 | while (v_idx) { |
| 5067 | v_idx--; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5068 | ixgbe_free_q_vector(adapter, v_idx); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5069 | } |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5070 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5071 | return -ENOMEM; |
| 5072 | } |
| 5073 | |
| 5074 | /** |
| 5075 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 5076 | * @adapter: board private structure to initialize |
| 5077 | * |
| 5078 | * This function frees the memory allocated to the q_vectors. In addition if |
| 5079 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 5080 | * to freeing the q_vector. |
| 5081 | **/ |
| 5082 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 5083 | { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5084 | int v_idx, q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5085 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5086 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5087 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5088 | else |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5089 | q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5090 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5091 | for (v_idx = 0; v_idx < q_vectors; v_idx++) |
| 5092 | ixgbe_free_q_vector(adapter, v_idx); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5093 | } |
| 5094 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 5095 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5096 | { |
| 5097 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5098 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 5099 | pci_disable_msix(adapter->pdev); |
| 5100 | kfree(adapter->msix_entries); |
| 5101 | adapter->msix_entries = NULL; |
| 5102 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 5103 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 5104 | pci_disable_msi(adapter->pdev); |
| 5105 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | /** |
| 5109 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 5110 | * @adapter: board private structure to initialize |
| 5111 | * |
| 5112 | * We determine which interrupt scheme to use based on... |
| 5113 | * - Kernel support (MSI, MSI-X) |
| 5114 | * - which can be user-defined (via MODULE_PARAM) |
| 5115 | * - Hardware queue count (num_*_queues) |
| 5116 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 5117 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5118 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5119 | { |
| 5120 | int err; |
| 5121 | |
| 5122 | /* Number of supported queues */ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 5123 | err = ixgbe_set_num_queues(adapter); |
| 5124 | if (err) |
| 5125 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5126 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5127 | err = ixgbe_set_interrupt_capability(adapter); |
| 5128 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5129 | e_dev_err("Unable to setup interrupt capabilities\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5130 | goto err_set_interrupt; |
| 5131 | } |
| 5132 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5133 | err = ixgbe_alloc_q_vectors(adapter); |
| 5134 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5135 | e_dev_err("Unable to allocate memory for queue vectors\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5136 | goto err_alloc_q_vectors; |
| 5137 | } |
| 5138 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5139 | ixgbe_cache_ring_register(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5140 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5141 | e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n", |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5142 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 5143 | adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5144 | |
| 5145 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5146 | |
| 5147 | return 0; |
| 5148 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5149 | err_alloc_q_vectors: |
| 5150 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5151 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5152 | return err; |
| 5153 | } |
| 5154 | |
| 5155 | /** |
| 5156 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 5157 | * @adapter: board private structure to clear interrupt scheme on |
| 5158 | * |
| 5159 | * We go through and clear interrupt specific resources and reset the structure |
| 5160 | * to pre-load conditions |
| 5161 | **/ |
| 5162 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 5163 | { |
Don Skidmore | b8eb3a1 | 2010-12-01 20:54:53 +0000 | [diff] [blame] | 5164 | adapter->num_tx_queues = 0; |
| 5165 | adapter->num_rx_queues = 0; |
| 5166 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5167 | ixgbe_free_q_vectors(adapter); |
| 5168 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | /** |
| 5172 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5173 | * @adapter: board private structure to initialize |
| 5174 | * |
| 5175 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5176 | * Fields are initialized based on PCI device information and |
| 5177 | * OS network device settings (MTU size). |
| 5178 | **/ |
| 5179 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 5180 | { |
| 5181 | struct ixgbe_hw *hw = &adapter->hw; |
| 5182 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5183 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5184 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5185 | int j; |
| 5186 | struct tc_configuration *tc; |
| 5187 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5188 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5189 | /* PCI config space info */ |
| 5190 | |
| 5191 | hw->vendor_id = pdev->vendor; |
| 5192 | hw->device_id = pdev->device; |
| 5193 | hw->revision_id = pdev->revision; |
| 5194 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5195 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5196 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5197 | /* Set capability flags */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 5198 | rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus()); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5199 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 5200 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5201 | switch (hw->mac.type) { |
| 5202 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5203 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5204 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5205 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5206 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5207 | case ixgbe_mac_X540: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 5208 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 5209 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5210 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5211 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5212 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5213 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5214 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 5215 | /* Flow Director hash filters enabled */ |
| 5216 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5217 | adapter->atr_sample_rate = 20; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5218 | adapter->ring_feature[RING_F_FDIR].indices = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5219 | IXGBE_MAX_FDIR_INDICES; |
Alexander Duyck | c04f6ca | 2011-05-11 07:18:36 +0000 | [diff] [blame] | 5220 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5221 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5222 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5223 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5224 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5225 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 5226 | /* Default traffic class to use for FCoE */ |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 5227 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5228 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5229 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5230 | break; |
| 5231 | default: |
| 5232 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5233 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5234 | |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5235 | /* n-tuple support exists, always init our spinlock */ |
| 5236 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5237 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5238 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5239 | switch (hw->mac.type) { |
| 5240 | case ixgbe_mac_X540: |
| 5241 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5242 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5243 | break; |
| 5244 | default: |
| 5245 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5246 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5247 | break; |
| 5248 | } |
| 5249 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5250 | /* Configure DCB traffic classes */ |
| 5251 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5252 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5253 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5254 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5255 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5256 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5257 | tc->dcb_pfc = pfc_disabled; |
| 5258 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5259 | |
| 5260 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5261 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5262 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5263 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5264 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5265 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5266 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5267 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5268 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5269 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5270 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 5271 | MAX_TRAFFIC_CLASS); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5272 | |
| 5273 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5274 | |
| 5275 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5276 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5277 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5278 | #ifdef CONFIG_DCB |
| 5279 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 5280 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5281 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5282 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5283 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5284 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5285 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5286 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5287 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5288 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5289 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5290 | /* set default ring sizes */ |
| 5291 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5292 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5293 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5294 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5295 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5296 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5297 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5298 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5299 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5300 | return -EIO; |
| 5301 | } |
| 5302 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5303 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5304 | |
| 5305 | return 0; |
| 5306 | } |
| 5307 | |
| 5308 | /** |
| 5309 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5310 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5311 | * |
| 5312 | * Return 0 on success, negative on failure |
| 5313 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5314 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5315 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5316 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5317 | int orig_node = dev_to_node(dev); |
| 5318 | int numa_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5319 | int size; |
| 5320 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5321 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5322 | |
| 5323 | if (tx_ring->q_vector) |
| 5324 | numa_node = tx_ring->q_vector->numa_node; |
| 5325 | |
| 5326 | tx_ring->tx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5327 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5328 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5329 | if (!tx_ring->tx_buffer_info) |
| 5330 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5331 | |
| 5332 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5333 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5334 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5335 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5336 | set_dev_node(dev, numa_node); |
| 5337 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5338 | tx_ring->size, |
| 5339 | &tx_ring->dma, |
| 5340 | GFP_KERNEL); |
| 5341 | set_dev_node(dev, orig_node); |
| 5342 | if (!tx_ring->desc) |
| 5343 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5344 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5345 | if (!tx_ring->desc) |
| 5346 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5347 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5348 | tx_ring->next_to_use = 0; |
| 5349 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5350 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5351 | |
| 5352 | err: |
| 5353 | vfree(tx_ring->tx_buffer_info); |
| 5354 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5355 | 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] | 5356 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5360 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5361 | * @adapter: board private structure |
| 5362 | * |
| 5363 | * If this function returns with an error, then it's possible one or |
| 5364 | * more of the rings is populated (while the rest are not). It is the |
| 5365 | * callers duty to clean those orphaned rings. |
| 5366 | * |
| 5367 | * Return 0 on success, negative on failure |
| 5368 | **/ |
| 5369 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5370 | { |
| 5371 | int i, err = 0; |
| 5372 | |
| 5373 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5374 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5375 | if (!err) |
| 5376 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5377 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5378 | break; |
| 5379 | } |
| 5380 | |
| 5381 | return err; |
| 5382 | } |
| 5383 | |
| 5384 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5385 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5386 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5387 | * |
| 5388 | * Returns 0 on success, negative on failure |
| 5389 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5390 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5391 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5392 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5393 | int orig_node = dev_to_node(dev); |
| 5394 | int numa_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5395 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5396 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5397 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5398 | |
| 5399 | if (rx_ring->q_vector) |
| 5400 | numa_node = rx_ring->q_vector->numa_node; |
| 5401 | |
| 5402 | rx_ring->rx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5403 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5404 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5405 | if (!rx_ring->rx_buffer_info) |
| 5406 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5407 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5408 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5409 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5410 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5411 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5412 | set_dev_node(dev, numa_node); |
| 5413 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5414 | rx_ring->size, |
| 5415 | &rx_ring->dma, |
| 5416 | GFP_KERNEL); |
| 5417 | set_dev_node(dev, orig_node); |
| 5418 | if (!rx_ring->desc) |
| 5419 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5420 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5421 | if (!rx_ring->desc) |
| 5422 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5423 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5424 | rx_ring->next_to_clean = 0; |
| 5425 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5426 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 5427 | ixgbe_init_rx_page_offset(rx_ring); |
| 5428 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5429 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5430 | err: |
| 5431 | vfree(rx_ring->rx_buffer_info); |
| 5432 | rx_ring->rx_buffer_info = NULL; |
| 5433 | 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] | 5434 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5438 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5439 | * @adapter: board private structure |
| 5440 | * |
| 5441 | * If this function returns with an error, then it's possible one or |
| 5442 | * more of the rings is populated (while the rest are not). It is the |
| 5443 | * callers duty to clean those orphaned rings. |
| 5444 | * |
| 5445 | * Return 0 on success, negative on failure |
| 5446 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5447 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5448 | { |
| 5449 | int i, err = 0; |
| 5450 | |
| 5451 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5452 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5453 | if (!err) |
| 5454 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5455 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5456 | break; |
| 5457 | } |
| 5458 | |
| 5459 | return err; |
| 5460 | } |
| 5461 | |
| 5462 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5463 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5464 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5465 | * |
| 5466 | * Free all transmit software resources |
| 5467 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5468 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5469 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5470 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5471 | |
| 5472 | vfree(tx_ring->tx_buffer_info); |
| 5473 | tx_ring->tx_buffer_info = NULL; |
| 5474 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5475 | /* if not set, then don't free */ |
| 5476 | if (!tx_ring->desc) |
| 5477 | return; |
| 5478 | |
| 5479 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5480 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5481 | |
| 5482 | tx_ring->desc = NULL; |
| 5483 | } |
| 5484 | |
| 5485 | /** |
| 5486 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5487 | * @adapter: board private structure |
| 5488 | * |
| 5489 | * Free all transmit software resources |
| 5490 | **/ |
| 5491 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5492 | { |
| 5493 | int i; |
| 5494 | |
| 5495 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5496 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5497 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5501 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5502 | * @rx_ring: ring to clean the resources from |
| 5503 | * |
| 5504 | * Free all receive software resources |
| 5505 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5506 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5507 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5508 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5509 | |
| 5510 | vfree(rx_ring->rx_buffer_info); |
| 5511 | rx_ring->rx_buffer_info = NULL; |
| 5512 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5513 | /* if not set, then don't free */ |
| 5514 | if (!rx_ring->desc) |
| 5515 | return; |
| 5516 | |
| 5517 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5518 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5519 | |
| 5520 | rx_ring->desc = NULL; |
| 5521 | } |
| 5522 | |
| 5523 | /** |
| 5524 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5525 | * @adapter: board private structure |
| 5526 | * |
| 5527 | * Free all receive software resources |
| 5528 | **/ |
| 5529 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5530 | { |
| 5531 | int i; |
| 5532 | |
| 5533 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5534 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5535 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5539 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5540 | * @netdev: network interface device structure |
| 5541 | * @new_mtu: new value for maximum frame size |
| 5542 | * |
| 5543 | * Returns 0 on success, negative on failure |
| 5544 | **/ |
| 5545 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5546 | { |
| 5547 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5548 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5549 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5550 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5551 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5552 | return -EINVAL; |
| 5553 | |
| 5554 | /* |
| 5555 | * For 82599EB we cannot allow PF to change MTU greater than 1500 |
| 5556 | * in SR-IOV mode as it may cause buffer overruns in guest VFs that |
| 5557 | * don't allocate and chain buffers correctly. |
| 5558 | */ |
| 5559 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 5560 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
| 5561 | (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 5562 | return -EINVAL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5563 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5564 | 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] | 5565 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5566 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5567 | netdev->mtu = new_mtu; |
| 5568 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5569 | if (netif_running(netdev)) |
| 5570 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5571 | |
| 5572 | return 0; |
| 5573 | } |
| 5574 | |
| 5575 | /** |
| 5576 | * ixgbe_open - Called when a network interface is made active |
| 5577 | * @netdev: network interface device structure |
| 5578 | * |
| 5579 | * Returns 0 on success, negative value on failure |
| 5580 | * |
| 5581 | * The open entry point is called when a network interface is made |
| 5582 | * active by the system (IFF_UP). At this point all resources needed |
| 5583 | * for transmit and receive operations are allocated, the interrupt |
| 5584 | * handler is registered with the OS, the watchdog timer is started, |
| 5585 | * and the stack is notified that the interface is ready. |
| 5586 | **/ |
| 5587 | static int ixgbe_open(struct net_device *netdev) |
| 5588 | { |
| 5589 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5590 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5591 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5592 | /* disallow open during test */ |
| 5593 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5594 | return -EBUSY; |
| 5595 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5596 | netif_carrier_off(netdev); |
| 5597 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5598 | /* allocate transmit descriptors */ |
| 5599 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5600 | if (err) |
| 5601 | goto err_setup_tx; |
| 5602 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5603 | /* allocate receive descriptors */ |
| 5604 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5605 | if (err) |
| 5606 | goto err_setup_rx; |
| 5607 | |
| 5608 | ixgbe_configure(adapter); |
| 5609 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5610 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5611 | if (err) |
| 5612 | goto err_req_irq; |
| 5613 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5614 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5615 | |
| 5616 | return 0; |
| 5617 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5618 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5619 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5620 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5621 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5622 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5623 | ixgbe_reset(adapter); |
| 5624 | |
| 5625 | return err; |
| 5626 | } |
| 5627 | |
| 5628 | /** |
| 5629 | * ixgbe_close - Disables a network interface |
| 5630 | * @netdev: network interface device structure |
| 5631 | * |
| 5632 | * Returns 0, this is not allowed to fail |
| 5633 | * |
| 5634 | * The close entry point is called when an interface is de-activated |
| 5635 | * by the OS. The hardware is still under the drivers control, but |
| 5636 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5637 | * hardware, and all transmit and receive resources are freed. |
| 5638 | **/ |
| 5639 | static int ixgbe_close(struct net_device *netdev) |
| 5640 | { |
| 5641 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5642 | |
| 5643 | ixgbe_down(adapter); |
| 5644 | ixgbe_free_irq(adapter); |
| 5645 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5646 | ixgbe_fdir_filter_exit(adapter); |
| 5647 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5648 | ixgbe_free_all_tx_resources(adapter); |
| 5649 | ixgbe_free_all_rx_resources(adapter); |
| 5650 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5651 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5652 | |
| 5653 | return 0; |
| 5654 | } |
| 5655 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5656 | #ifdef CONFIG_PM |
| 5657 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5658 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5659 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5660 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5661 | u32 err; |
| 5662 | |
| 5663 | pci_set_power_state(pdev, PCI_D0); |
| 5664 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5665 | /* |
| 5666 | * pci_restore_state clears dev->state_saved so call |
| 5667 | * pci_save_state to restore it. |
| 5668 | */ |
| 5669 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5670 | |
| 5671 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5672 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5673 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5674 | return err; |
| 5675 | } |
| 5676 | pci_set_master(pdev); |
| 5677 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5678 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5679 | |
| 5680 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5681 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5682 | e_dev_err("Cannot initialize interrupts for device\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5683 | return err; |
| 5684 | } |
| 5685 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5686 | ixgbe_reset(adapter); |
| 5687 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5688 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5689 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5690 | if (netif_running(netdev)) { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5691 | err = ixgbe_open(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5692 | if (err) |
| 5693 | return err; |
| 5694 | } |
| 5695 | |
| 5696 | netif_device_attach(netdev); |
| 5697 | |
| 5698 | return 0; |
| 5699 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5700 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5701 | |
| 5702 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5703 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5704 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5705 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5706 | struct ixgbe_hw *hw = &adapter->hw; |
| 5707 | u32 ctrl, fctrl; |
| 5708 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5709 | #ifdef CONFIG_PM |
| 5710 | int retval = 0; |
| 5711 | #endif |
| 5712 | |
| 5713 | netif_device_detach(netdev); |
| 5714 | |
| 5715 | if (netif_running(netdev)) { |
| 5716 | ixgbe_down(adapter); |
| 5717 | ixgbe_free_irq(adapter); |
| 5718 | ixgbe_free_all_tx_resources(adapter); |
| 5719 | ixgbe_free_all_rx_resources(adapter); |
| 5720 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5721 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5722 | ixgbe_clear_interrupt_scheme(adapter); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 5723 | #ifdef CONFIG_DCB |
| 5724 | kfree(adapter->ixgbe_ieee_pfc); |
| 5725 | kfree(adapter->ixgbe_ieee_ets); |
| 5726 | #endif |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5727 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5728 | #ifdef CONFIG_PM |
| 5729 | retval = pci_save_state(pdev); |
| 5730 | if (retval) |
| 5731 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5732 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5733 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5734 | if (wufc) { |
| 5735 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5736 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5737 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5738 | if (wufc & IXGBE_WUFC_MC) { |
| 5739 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5740 | fctrl |= IXGBE_FCTRL_MPE; |
| 5741 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5742 | } |
| 5743 | |
| 5744 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5745 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5746 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5747 | |
| 5748 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5749 | } else { |
| 5750 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5751 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5752 | } |
| 5753 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5754 | switch (hw->mac.type) { |
| 5755 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5756 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5757 | break; |
| 5758 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5759 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5760 | pci_wake_from_d3(pdev, !!wufc); |
| 5761 | break; |
| 5762 | default: |
| 5763 | break; |
| 5764 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5765 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5766 | *enable_wake = !!wufc; |
| 5767 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5768 | ixgbe_release_hw_control(adapter); |
| 5769 | |
| 5770 | pci_disable_device(pdev); |
| 5771 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5772 | return 0; |
| 5773 | } |
| 5774 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5775 | #ifdef CONFIG_PM |
| 5776 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5777 | { |
| 5778 | int retval; |
| 5779 | bool wake; |
| 5780 | |
| 5781 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5782 | if (retval) |
| 5783 | return retval; |
| 5784 | |
| 5785 | if (wake) { |
| 5786 | pci_prepare_to_sleep(pdev); |
| 5787 | } else { |
| 5788 | pci_wake_from_d3(pdev, false); |
| 5789 | pci_set_power_state(pdev, PCI_D3hot); |
| 5790 | } |
| 5791 | |
| 5792 | return 0; |
| 5793 | } |
| 5794 | #endif /* CONFIG_PM */ |
| 5795 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5796 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5797 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5798 | bool wake; |
| 5799 | |
| 5800 | __ixgbe_shutdown(pdev, &wake); |
| 5801 | |
| 5802 | if (system_state == SYSTEM_POWER_OFF) { |
| 5803 | pci_wake_from_d3(pdev, wake); |
| 5804 | pci_set_power_state(pdev, PCI_D3hot); |
| 5805 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5809 | * ixgbe_update_stats - Update the board statistics counters. |
| 5810 | * @adapter: board private structure |
| 5811 | **/ |
| 5812 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5813 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5814 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5815 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5816 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5817 | u64 total_mpc = 0; |
| 5818 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5819 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5820 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5821 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5822 | #ifdef IXGBE_FCOE |
| 5823 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 5824 | unsigned int cpu; |
| 5825 | u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0; |
| 5826 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5827 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5828 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5829 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5830 | return; |
| 5831 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5832 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5833 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5834 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5835 | for (i = 0; i < 16; i++) |
| 5836 | adapter->hw_rx_no_dma_resources += |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5837 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5838 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5839 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5840 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5841 | } |
| 5842 | adapter->rsc_total_count = rsc_count; |
| 5843 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5844 | } |
| 5845 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5846 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5847 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5848 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5849 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5850 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5851 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5852 | bytes += rx_ring->stats.bytes; |
| 5853 | packets += rx_ring->stats.packets; |
| 5854 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5855 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5856 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5857 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5858 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5859 | netdev->stats.rx_bytes = bytes; |
| 5860 | netdev->stats.rx_packets = packets; |
| 5861 | |
| 5862 | bytes = 0; |
| 5863 | packets = 0; |
| 5864 | /* gather some stats to the adapter struct that are per queue */ |
| 5865 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5866 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5867 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5868 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5869 | bytes += tx_ring->stats.bytes; |
| 5870 | packets += tx_ring->stats.packets; |
| 5871 | } |
| 5872 | adapter->restart_queue = restart_queue; |
| 5873 | adapter->tx_busy = tx_busy; |
| 5874 | netdev->stats.tx_bytes = bytes; |
| 5875 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5876 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5877 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5878 | |
| 5879 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5880 | for (i = 0; i < 8; i++) { |
| 5881 | /* for packet buffers not used, the register should read 0 */ |
| 5882 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5883 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5884 | hwstats->mpc[i] += mpc; |
| 5885 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5886 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5887 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5888 | switch (hw->mac.type) { |
| 5889 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5890 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5891 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5892 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5893 | hwstats->pxonrxc[i] += |
| 5894 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5895 | break; |
| 5896 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5897 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5898 | hwstats->pxonrxc[i] += |
| 5899 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5900 | break; |
| 5901 | default: |
| 5902 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5903 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5904 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5905 | |
| 5906 | /*16 register reads */ |
| 5907 | for (i = 0; i < 16; i++) { |
| 5908 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5909 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5910 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
| 5911 | (hw->mac.type == ixgbe_mac_X540)) { |
| 5912 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 5913 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 5914 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 5915 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 5916 | } |
| 5917 | } |
| 5918 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5919 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5920 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5921 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5922 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5923 | ixgbe_update_xoff_received(adapter); |
| 5924 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5925 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5926 | switch (hw->mac.type) { |
| 5927 | case ixgbe_mac_82598EB: |
| 5928 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5929 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5930 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5931 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5932 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5933 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5934 | /* OS2BMC stats are X540 only*/ |
| 5935 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5936 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5937 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5938 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5939 | case ixgbe_mac_82599EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5940 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5941 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5942 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5943 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5944 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5945 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5946 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5947 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5948 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5949 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5950 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5951 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5952 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5953 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5954 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5955 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5956 | /* Add up per cpu counters for total ddp aloc fail */ |
| 5957 | if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) { |
| 5958 | for_each_possible_cpu(cpu) { |
| 5959 | fcoe_noddp_counts_sum += |
| 5960 | *per_cpu_ptr(fcoe->pcpu_noddp, cpu); |
| 5961 | fcoe_noddp_ext_buff_counts_sum += |
| 5962 | *per_cpu_ptr(fcoe-> |
| 5963 | pcpu_noddp_ext_buff, cpu); |
| 5964 | } |
| 5965 | } |
| 5966 | hwstats->fcoe_noddp = fcoe_noddp_counts_sum; |
| 5967 | hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum; |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5968 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5969 | break; |
| 5970 | default: |
| 5971 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5972 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5973 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5974 | hwstats->bprc += bprc; |
| 5975 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5976 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5977 | hwstats->mprc -= bprc; |
| 5978 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5979 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5980 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5981 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5982 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5983 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5984 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5985 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5986 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5987 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5988 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5989 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5990 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5991 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5992 | /* |
| 5993 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5994 | */ |
| 5995 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5996 | hwstats->gptc -= xon_off_tot; |
| 5997 | hwstats->mptc -= xon_off_tot; |
| 5998 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5999 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6000 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6001 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6002 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6003 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6004 | hwstats->ptc64 -= xon_off_tot; |
| 6005 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6006 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6007 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6008 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6009 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6010 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6011 | |
| 6012 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6013 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6014 | |
| 6015 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6016 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6017 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6018 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6019 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6020 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6021 | } |
| 6022 | |
| 6023 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6024 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
| 6025 | * @adapter - pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6026 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6027 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6028 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6029 | struct ixgbe_hw *hw = &adapter->hw; |
| 6030 | int i; |
| 6031 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6032 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6033 | return; |
| 6034 | |
| 6035 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6036 | |
| 6037 | /* if interface is down do nothing */ |
| 6038 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6039 | return; |
| 6040 | |
| 6041 | /* do nothing if we are not using signature filters */ |
| 6042 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6043 | return; |
| 6044 | |
| 6045 | adapter->fdir_overflow++; |
| 6046 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6047 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6048 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6049 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6050 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6051 | /* re-enable flow director interrupts */ |
| 6052 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6053 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6054 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6055 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6056 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6057 | } |
| 6058 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6059 | /** |
| 6060 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
| 6061 | * @adapter - pointer to the device adapter structure |
| 6062 | * |
| 6063 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6064 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6065 | * 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] | 6066 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6067 | */ |
| 6068 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6069 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6070 | struct ixgbe_hw *hw = &adapter->hw; |
| 6071 | u64 eics = 0; |
| 6072 | int i; |
| 6073 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6074 | /* If we're down or resetting, just bail */ |
| 6075 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6076 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6077 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6078 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6079 | /* Force detection of hung controller */ |
| 6080 | if (netif_carrier_ok(adapter->netdev)) { |
| 6081 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6082 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6083 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6084 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6085 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6086 | /* |
| 6087 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6088 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6089 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6090 | */ |
| 6091 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6092 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6093 | } else { |
| 6094 | /* get one bit for every active tx/rx interrupt vector */ |
| 6095 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 6096 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6097 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6098 | eics |= ((u64)1 << i); |
| 6099 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6102 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6103 | ixgbe_irq_rearm_queues(adapter, eics); |
| 6104 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6108 | * ixgbe_watchdog_update_link - update the link status |
| 6109 | * @adapter - pointer to the device adapter structure |
| 6110 | * @link_speed - pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6111 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6112 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6113 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6114 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6115 | u32 link_speed = adapter->link_speed; |
| 6116 | bool link_up = adapter->link_up; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6117 | int i; |
| 6118 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6119 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6120 | return; |
| 6121 | |
| 6122 | if (hw->mac.ops.check_link) { |
| 6123 | 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] | 6124 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6125 | /* always assume link is up, if no check link function */ |
| 6126 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6127 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6128 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6129 | if (link_up) { |
| 6130 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 6131 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 6132 | hw->mac.ops.fc_enable(hw, i); |
| 6133 | } else { |
| 6134 | hw->mac.ops.fc_enable(hw, 0); |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | if (link_up || |
| 6139 | time_after(jiffies, (adapter->link_check_timeout + |
| 6140 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6141 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6142 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6143 | IXGBE_WRITE_FLUSH(hw); |
| 6144 | } |
| 6145 | |
| 6146 | adapter->link_up = link_up; |
| 6147 | adapter->link_speed = link_speed; |
| 6148 | } |
| 6149 | |
| 6150 | /** |
| 6151 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6152 | * print link up message |
| 6153 | * @adapter - pointer to the device adapter structure |
| 6154 | **/ |
| 6155 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6156 | { |
| 6157 | struct net_device *netdev = adapter->netdev; |
| 6158 | struct ixgbe_hw *hw = &adapter->hw; |
| 6159 | u32 link_speed = adapter->link_speed; |
| 6160 | bool flow_rx, flow_tx; |
| 6161 | |
| 6162 | /* only continue if link was previously down */ |
| 6163 | if (netif_carrier_ok(netdev)) |
| 6164 | return; |
| 6165 | |
| 6166 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6167 | |
| 6168 | switch (hw->mac.type) { |
| 6169 | case ixgbe_mac_82598EB: { |
| 6170 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6171 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6172 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6173 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6174 | } |
| 6175 | break; |
| 6176 | case ixgbe_mac_X540: |
| 6177 | case ixgbe_mac_82599EB: { |
| 6178 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6179 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6180 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6181 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6182 | } |
| 6183 | break; |
| 6184 | default: |
| 6185 | flow_tx = false; |
| 6186 | flow_rx = false; |
| 6187 | break; |
| 6188 | } |
| 6189 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 6190 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 6191 | "10 Gbps" : |
| 6192 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 6193 | "1 Gbps" : |
| 6194 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6195 | "100 Mbps" : |
| 6196 | "unknown speed"))), |
| 6197 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6198 | (flow_rx ? "RX" : |
| 6199 | (flow_tx ? "TX" : "None")))); |
| 6200 | |
| 6201 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6202 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6203 | } |
| 6204 | |
| 6205 | /** |
| 6206 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6207 | * print link down message |
| 6208 | * @adapter - pointer to the adapter structure |
| 6209 | **/ |
| 6210 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) |
| 6211 | { |
| 6212 | struct net_device *netdev = adapter->netdev; |
| 6213 | struct ixgbe_hw *hw = &adapter->hw; |
| 6214 | |
| 6215 | adapter->link_up = false; |
| 6216 | adapter->link_speed = 0; |
| 6217 | |
| 6218 | /* only continue if link was up previously */ |
| 6219 | if (!netif_carrier_ok(netdev)) |
| 6220 | return; |
| 6221 | |
| 6222 | /* poll for SFP+ cable when link is down */ |
| 6223 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6224 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6225 | |
| 6226 | e_info(drv, "NIC Link is Down\n"); |
| 6227 | netif_carrier_off(netdev); |
| 6228 | } |
| 6229 | |
| 6230 | /** |
| 6231 | * ixgbe_watchdog_flush_tx - flush queues on link down |
| 6232 | * @adapter - pointer to the device adapter structure |
| 6233 | **/ |
| 6234 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6235 | { |
| 6236 | int i; |
| 6237 | int some_tx_pending = 0; |
| 6238 | |
| 6239 | if (!netif_carrier_ok(adapter->netdev)) { |
| 6240 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6241 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6242 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 6243 | some_tx_pending = 1; |
| 6244 | break; |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | if (some_tx_pending) { |
| 6249 | /* We've lost link, so the controller stops DMA, |
| 6250 | * but we've got queued Tx work that's never going |
| 6251 | * to get done, so reset controller to flush Tx. |
| 6252 | * (Do the reset outside of interrupt context). |
| 6253 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6254 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6255 | } |
| 6256 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6257 | } |
| 6258 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6259 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6260 | { |
| 6261 | u32 ssvpc; |
| 6262 | |
| 6263 | /* Do not perform spoof check for 82598 */ |
| 6264 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6265 | return; |
| 6266 | |
| 6267 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6268 | |
| 6269 | /* |
| 6270 | * ssvpc register is cleared on read, if zero then no |
| 6271 | * spoofed packets in the last interval. |
| 6272 | */ |
| 6273 | if (!ssvpc) |
| 6274 | return; |
| 6275 | |
| 6276 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); |
| 6277 | } |
| 6278 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6279 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6280 | * ixgbe_watchdog_subtask - check and bring link up |
| 6281 | * @adapter - pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6282 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6283 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6284 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6285 | /* if interface is down do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6286 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6287 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6288 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6289 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6290 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6291 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6292 | if (adapter->link_up) |
| 6293 | ixgbe_watchdog_link_is_up(adapter); |
| 6294 | else |
| 6295 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6296 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6297 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6298 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6299 | |
| 6300 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6301 | } |
| 6302 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6303 | /** |
| 6304 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
| 6305 | * @adapter - the ixgbe adapter structure |
| 6306 | **/ |
| 6307 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6308 | { |
| 6309 | struct ixgbe_hw *hw = &adapter->hw; |
| 6310 | s32 err; |
| 6311 | |
| 6312 | /* not searching for SFP so there is nothing to do here */ |
| 6313 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6314 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6315 | return; |
| 6316 | |
| 6317 | /* someone else is in init, wait until next service event */ |
| 6318 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6319 | return; |
| 6320 | |
| 6321 | err = hw->phy.ops.identify_sfp(hw); |
| 6322 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6323 | goto sfp_out; |
| 6324 | |
| 6325 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6326 | /* If no cable is present, then we need to reset |
| 6327 | * the next time we find a good cable. */ |
| 6328 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6329 | } |
| 6330 | |
| 6331 | /* exit on error */ |
| 6332 | if (err) |
| 6333 | goto sfp_out; |
| 6334 | |
| 6335 | /* exit if reset not needed */ |
| 6336 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6337 | goto sfp_out; |
| 6338 | |
| 6339 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6340 | |
| 6341 | /* |
| 6342 | * A module may be identified correctly, but the EEPROM may not have |
| 6343 | * support for that module. setup_sfp() will fail in that case, so |
| 6344 | * we should not allow that module to load. |
| 6345 | */ |
| 6346 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6347 | err = hw->phy.ops.reset(hw); |
| 6348 | else |
| 6349 | err = hw->mac.ops.setup_sfp(hw); |
| 6350 | |
| 6351 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6352 | goto sfp_out; |
| 6353 | |
| 6354 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6355 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6356 | |
| 6357 | sfp_out: |
| 6358 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6359 | |
| 6360 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6361 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6362 | e_dev_err("failed to initialize because an unsupported " |
| 6363 | "SFP+ module type was detected.\n"); |
| 6364 | e_dev_err("Reload the driver after installing a " |
| 6365 | "supported module.\n"); |
| 6366 | unregister_netdev(adapter->netdev); |
| 6367 | } |
| 6368 | } |
| 6369 | |
| 6370 | /** |
| 6371 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
| 6372 | * @adapter - the ixgbe adapter structure |
| 6373 | **/ |
| 6374 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6375 | { |
| 6376 | struct ixgbe_hw *hw = &adapter->hw; |
| 6377 | u32 autoneg; |
| 6378 | bool negotiation; |
| 6379 | |
| 6380 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6381 | return; |
| 6382 | |
| 6383 | /* someone else is in init, wait until next service event */ |
| 6384 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6385 | return; |
| 6386 | |
| 6387 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6388 | |
| 6389 | autoneg = hw->phy.autoneg_advertised; |
| 6390 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 6391 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6392 | if (hw->mac.ops.setup_link) |
| 6393 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 6394 | |
| 6395 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6396 | adapter->link_check_timeout = jiffies; |
| 6397 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6398 | } |
| 6399 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6400 | #ifdef CONFIG_PCI_IOV |
| 6401 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6402 | { |
| 6403 | int vf; |
| 6404 | struct ixgbe_hw *hw = &adapter->hw; |
| 6405 | struct net_device *netdev = adapter->netdev; |
| 6406 | u32 gpc; |
| 6407 | u32 ciaa, ciad; |
| 6408 | |
| 6409 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6410 | if (gpc) /* If incrementing then no need for the check below */ |
| 6411 | return; |
| 6412 | /* |
| 6413 | * Check to see if a bad DMA write target from an errant or |
| 6414 | * malicious VF has caused a PCIe error. If so then we can |
| 6415 | * issue a VFLR to the offending VF(s) and then resume without |
| 6416 | * requesting a full slot reset. |
| 6417 | */ |
| 6418 | |
| 6419 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 6420 | ciaa = (vf << 16) | 0x80000000; |
| 6421 | /* 32 bit read so align, we really want status at offset 6 */ |
| 6422 | ciaa |= PCI_COMMAND; |
| 6423 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6424 | ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599); |
| 6425 | ciaa &= 0x7FFFFFFF; |
| 6426 | /* disable debug mode asap after reading data */ |
| 6427 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6428 | /* Get the upper 16 bits which will be the PCI status reg */ |
| 6429 | ciad >>= 16; |
| 6430 | if (ciad & PCI_STATUS_REC_MASTER_ABORT) { |
| 6431 | netdev_err(netdev, "VF %d Hung DMA\n", vf); |
| 6432 | /* Issue VFLR */ |
| 6433 | ciaa = (vf << 16) | 0x80000000; |
| 6434 | ciaa |= 0xA8; |
| 6435 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6436 | ciad = 0x00008000; /* VFLR */ |
| 6437 | IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad); |
| 6438 | ciaa &= 0x7FFFFFFF; |
| 6439 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6440 | } |
| 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6445 | /** |
| 6446 | * ixgbe_service_timer - Timer Call-back |
| 6447 | * @data: pointer to adapter cast into an unsigned long |
| 6448 | **/ |
| 6449 | static void ixgbe_service_timer(unsigned long data) |
| 6450 | { |
| 6451 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6452 | unsigned long next_event_offset; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6453 | bool ready = true; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6454 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6455 | #ifdef CONFIG_PCI_IOV |
| 6456 | ready = false; |
| 6457 | |
| 6458 | /* |
| 6459 | * don't bother with SR-IOV VF DMA hang check if there are |
| 6460 | * no VFs or the link is down |
| 6461 | */ |
| 6462 | if (!adapter->num_vfs || |
| 6463 | (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) { |
| 6464 | ready = true; |
| 6465 | goto normal_timer_service; |
| 6466 | } |
| 6467 | |
| 6468 | /* If we have VFs allocated then we must check for DMA hangs */ |
| 6469 | ixgbe_check_for_bad_vf(adapter); |
| 6470 | next_event_offset = HZ / 50; |
| 6471 | adapter->timer_event_accumulator++; |
| 6472 | |
| 6473 | if (adapter->timer_event_accumulator >= 100) { |
| 6474 | ready = true; |
| 6475 | adapter->timer_event_accumulator = 0; |
| 6476 | } |
| 6477 | |
| 6478 | goto schedule_event; |
| 6479 | |
| 6480 | normal_timer_service: |
| 6481 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6482 | /* poll faster when waiting for link */ |
| 6483 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6484 | next_event_offset = HZ / 10; |
| 6485 | else |
| 6486 | next_event_offset = HZ * 2; |
| 6487 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6488 | #ifdef CONFIG_PCI_IOV |
| 6489 | schedule_event: |
| 6490 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6491 | /* Reset the timer */ |
| 6492 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6493 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6494 | if (ready) |
| 6495 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6496 | } |
| 6497 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6498 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6499 | { |
| 6500 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6501 | return; |
| 6502 | |
| 6503 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6504 | |
| 6505 | /* If we're already down or resetting, just bail */ |
| 6506 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6507 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6508 | return; |
| 6509 | |
| 6510 | ixgbe_dump(adapter); |
| 6511 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6512 | adapter->tx_timeout_count++; |
| 6513 | |
| 6514 | ixgbe_reinit_locked(adapter); |
| 6515 | } |
| 6516 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6517 | /** |
| 6518 | * ixgbe_service_task - manages and runs subtasks |
| 6519 | * @work: pointer to work_struct containing our data |
| 6520 | **/ |
| 6521 | static void ixgbe_service_task(struct work_struct *work) |
| 6522 | { |
| 6523 | struct ixgbe_adapter *adapter = container_of(work, |
| 6524 | struct ixgbe_adapter, |
| 6525 | service_task); |
| 6526 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6527 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6528 | ixgbe_sfp_detection_subtask(adapter); |
| 6529 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6530 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6531 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6532 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6533 | ixgbe_check_hang_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6534 | |
| 6535 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6536 | } |
| 6537 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6538 | void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens, |
| 6539 | u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6540 | { |
| 6541 | struct ixgbe_adv_tx_context_desc *context_desc; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6542 | u16 i = tx_ring->next_to_use; |
| 6543 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6544 | context_desc = IXGBE_TX_CTXTDESC(tx_ring, i); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6545 | |
| 6546 | i++; |
| 6547 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 6548 | |
| 6549 | /* set bits to identify this as an advanced context descriptor */ |
| 6550 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 6551 | |
| 6552 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6553 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); |
| 6554 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 6555 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 6556 | } |
| 6557 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6558 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 6559 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6560 | u32 tx_flags, __be16 protocol, u8 *hdr_len) |
| 6561 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6562 | struct sk_buff *skb = first->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6563 | int err; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6564 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6565 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6566 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6567 | if (!skb_is_gso(skb)) |
| 6568 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6569 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6570 | if (skb_header_cloned(skb)) { |
| 6571 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 6572 | if (err) |
| 6573 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6576 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6577 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6578 | |
| 6579 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6580 | struct iphdr *iph = ip_hdr(skb); |
| 6581 | iph->tot_len = 0; |
| 6582 | iph->check = 0; |
| 6583 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6584 | iph->daddr, 0, |
| 6585 | IPPROTO_TCP, |
| 6586 | 0); |
| 6587 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6588 | } else if (skb_is_gso_v6(skb)) { |
| 6589 | ipv6_hdr(skb)->payload_len = 0; |
| 6590 | tcp_hdr(skb)->check = |
| 6591 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6592 | &ipv6_hdr(skb)->daddr, |
| 6593 | 0, IPPROTO_TCP, 0); |
| 6594 | } |
| 6595 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame^] | 6596 | /* compute header lengths */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6597 | l4len = tcp_hdrlen(skb); |
| 6598 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6599 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame^] | 6600 | /* update gso size and bytecount with header size */ |
| 6601 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 6602 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 6603 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6604 | /* mss_l4len_id: use 1 as index for TSO */ |
| 6605 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6606 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 6607 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 6608 | |
| 6609 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6610 | vlan_macip_lens = skb_network_header_len(skb); |
| 6611 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6612 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6613 | |
| 6614 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
| 6615 | mss_l4len_idx); |
| 6616 | |
| 6617 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6618 | } |
| 6619 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6620 | static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6621 | struct ixgbe_tx_buffer *first, |
| 6622 | u32 tx_flags, __be16 protocol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6623 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6624 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6625 | u32 vlan_macip_lens = 0; |
| 6626 | u32 mss_l4len_idx = 0; |
| 6627 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6628 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6629 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6630 | if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) && |
| 6631 | !(tx_flags & IXGBE_TX_FLAGS_TXSW)) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6632 | return false; |
| 6633 | } else { |
| 6634 | u8 l4_hdr = 0; |
| 6635 | switch (protocol) { |
| 6636 | case __constant_htons(ETH_P_IP): |
| 6637 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6638 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6639 | l4_hdr = ip_hdr(skb)->protocol; |
| 6640 | break; |
| 6641 | case __constant_htons(ETH_P_IPV6): |
| 6642 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6643 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6644 | break; |
| 6645 | default: |
| 6646 | if (unlikely(net_ratelimit())) { |
| 6647 | dev_warn(tx_ring->dev, |
| 6648 | "partial checksum but proto=%x!\n", |
| 6649 | skb->protocol); |
| 6650 | } |
| 6651 | break; |
| 6652 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6653 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6654 | switch (l4_hdr) { |
| 6655 | case IPPROTO_TCP: |
| 6656 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6657 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6658 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6659 | break; |
| 6660 | case IPPROTO_SCTP: |
| 6661 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6662 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6663 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6664 | break; |
| 6665 | case IPPROTO_UDP: |
| 6666 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6667 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6668 | break; |
| 6669 | default: |
| 6670 | if (unlikely(net_ratelimit())) { |
| 6671 | dev_warn(tx_ring->dev, |
| 6672 | "partial checksum but l4 proto=%x!\n", |
| 6673 | skb->protocol); |
| 6674 | } |
| 6675 | break; |
| 6676 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6677 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6678 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6679 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6680 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6681 | |
| 6682 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6683 | type_tucmd, mss_l4len_idx); |
| 6684 | |
| 6685 | return (skb->ip_summed == CHECKSUM_PARTIAL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6686 | } |
| 6687 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6688 | static __le32 ixgbe_tx_cmd_type(u32 tx_flags) |
| 6689 | { |
| 6690 | /* set type for advanced descriptor with frame checksum insertion */ |
| 6691 | __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA | |
| 6692 | IXGBE_ADVTXD_DCMD_IFCS | |
| 6693 | IXGBE_ADVTXD_DCMD_DEXT); |
| 6694 | |
| 6695 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6696 | if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6697 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE); |
| 6698 | |
| 6699 | /* set segmentation enable bits for TSO/FSO */ |
| 6700 | #ifdef IXGBE_FCOE |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6701 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6702 | #else |
| 6703 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6704 | #endif |
| 6705 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE); |
| 6706 | |
| 6707 | return cmd_type; |
| 6708 | } |
| 6709 | |
| 6710 | static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen) |
| 6711 | { |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6712 | __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6713 | |
| 6714 | /* enable L4 checksum for TSO and TX checksum offload */ |
| 6715 | if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6716 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM); |
| 6717 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6718 | /* enble IPv4 checksum for TSO */ |
| 6719 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6720 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6721 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6722 | /* use index 1 context for TSO/FSO/FCOE */ |
| 6723 | #ifdef IXGBE_FCOE |
| 6724 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE)) |
| 6725 | #else |
| 6726 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6727 | #endif |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6728 | olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 6729 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6730 | /* |
| 6731 | * Check Context must be set if Tx switch is enabled, which it |
| 6732 | * always is for case where virtual functions are running |
| 6733 | */ |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6734 | #ifdef IXGBE_FCOE |
| 6735 | if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE)) |
| 6736 | #else |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6737 | if (tx_flags & IXGBE_TX_FLAGS_TXSW) |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6738 | #endif |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6739 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC); |
| 6740 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6741 | return olinfo_status; |
| 6742 | } |
| 6743 | |
| 6744 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 6745 | IXGBE_TXD_CMD_RS) |
| 6746 | |
| 6747 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6748 | struct ixgbe_tx_buffer *first, |
| 6749 | u32 tx_flags, |
| 6750 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6751 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6752 | struct sk_buff *skb = first->skb; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6753 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6754 | struct ixgbe_tx_buffer *tx_buffer_info; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6755 | union ixgbe_adv_tx_desc *tx_desc; |
| 6756 | dma_addr_t dma; |
| 6757 | __le32 cmd_type, olinfo_status; |
| 6758 | struct skb_frag_struct *frag; |
| 6759 | unsigned int f = 0; |
| 6760 | unsigned int data_len = skb->data_len; |
| 6761 | unsigned int size = skb_headlen(skb); |
| 6762 | u32 offset = 0; |
| 6763 | u32 paylen = skb->len - hdr_len; |
| 6764 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6765 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6766 | #ifdef IXGBE_FCOE |
| 6767 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6768 | if (data_len >= sizeof(struct fcoe_crc_eof)) { |
| 6769 | data_len -= sizeof(struct fcoe_crc_eof); |
| 6770 | } else { |
| 6771 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 6772 | data_len = 0; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6773 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6774 | } |
| 6775 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6776 | #endif |
| 6777 | dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE); |
| 6778 | if (dma_mapping_error(dev, dma)) |
| 6779 | goto dma_error; |
| 6780 | |
| 6781 | cmd_type = ixgbe_tx_cmd_type(tx_flags); |
| 6782 | olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen); |
| 6783 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6784 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6785 | |
| 6786 | for (;;) { |
| 6787 | while (size > IXGBE_MAX_DATA_PER_TXD) { |
| 6788 | tx_desc->read.buffer_addr = cpu_to_le64(dma + offset); |
| 6789 | tx_desc->read.cmd_type_len = |
| 6790 | cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD); |
| 6791 | tx_desc->read.olinfo_status = olinfo_status; |
| 6792 | |
| 6793 | offset += IXGBE_MAX_DATA_PER_TXD; |
| 6794 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 6795 | |
| 6796 | tx_desc++; |
| 6797 | i++; |
| 6798 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6799 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6800 | i = 0; |
| 6801 | } |
| 6802 | } |
| 6803 | |
| 6804 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6805 | tx_buffer_info->length = offset + size; |
| 6806 | tx_buffer_info->tx_flags = tx_flags; |
| 6807 | tx_buffer_info->dma = dma; |
| 6808 | |
| 6809 | tx_desc->read.buffer_addr = cpu_to_le64(dma + offset); |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 6810 | if (unlikely(skb->no_fcs)) |
| 6811 | cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6812 | tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size); |
| 6813 | tx_desc->read.olinfo_status = olinfo_status; |
| 6814 | |
| 6815 | if (!data_len) |
| 6816 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6817 | |
| 6818 | frag = &skb_shinfo(skb)->frags[f]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6819 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6820 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6821 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6822 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6823 | #endif |
| 6824 | data_len -= size; |
| 6825 | f++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6826 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6827 | offset = 0; |
| 6828 | tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6829 | |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 6830 | dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6831 | if (dma_mapping_error(dev, dma)) |
| 6832 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6833 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6834 | tx_desc++; |
| 6835 | i++; |
| 6836 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6837 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6838 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6839 | } |
| 6840 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6841 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6842 | tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD); |
| 6843 | |
| 6844 | i++; |
| 6845 | if (i == tx_ring->count) |
| 6846 | i = 0; |
| 6847 | |
| 6848 | tx_ring->next_to_use = i; |
| 6849 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame^] | 6850 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 6851 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6852 | /* set the timestamp */ |
| 6853 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6854 | |
| 6855 | /* |
| 6856 | * Force memory writes to complete before letting h/w |
| 6857 | * know there are new descriptors to fetch. (Only |
| 6858 | * applicable for weak-ordered memory model archs, |
| 6859 | * such as IA-64). |
| 6860 | */ |
| 6861 | wmb(); |
| 6862 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6863 | /* set next_to_watch value indicating a packet is present */ |
| 6864 | first->next_to_watch = tx_desc; |
| 6865 | |
| 6866 | /* notify HW of packet */ |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6867 | writel(i, tx_ring->tail); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6868 | |
| 6869 | return; |
| 6870 | dma_error: |
| 6871 | dev_err(dev, "TX DMA map failed\n"); |
| 6872 | |
| 6873 | /* clear dma mappings for failed tx_buffer_info map */ |
| 6874 | for (;;) { |
| 6875 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6876 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6877 | if (tx_buffer_info == first) |
| 6878 | break; |
| 6879 | if (i == 0) |
| 6880 | i = tx_ring->count; |
| 6881 | i--; |
| 6882 | } |
| 6883 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6884 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6885 | } |
| 6886 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6887 | static void ixgbe_atr(struct ixgbe_ring *ring, |
| 6888 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6889 | u32 tx_flags, __be16 protocol) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6890 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6891 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6892 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6893 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6894 | union { |
| 6895 | unsigned char *network; |
| 6896 | struct iphdr *ipv4; |
| 6897 | struct ipv6hdr *ipv6; |
| 6898 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6899 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6900 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6901 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6902 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6903 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6904 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6905 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6906 | /* do nothing if sampling is disabled */ |
| 6907 | if (!ring->atr_sample_rate) |
| 6908 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6909 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6910 | ring->atr_count++; |
| 6911 | |
| 6912 | /* snag network header to get L4 type and address */ |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6913 | hdr.network = skb_network_header(first->skb); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6914 | |
| 6915 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 6916 | if ((protocol != __constant_htons(ETH_P_IPV6) || |
| 6917 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
| 6918 | (protocol != __constant_htons(ETH_P_IP) || |
| 6919 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6920 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6921 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6922 | th = tcp_hdr(first->skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6923 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6924 | /* skip this packet since it is invalid or the socket is closing */ |
| 6925 | if (!th || th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6926 | return; |
| 6927 | |
| 6928 | /* sample on all syn packets or once every atr sample count */ |
| 6929 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6930 | return; |
| 6931 | |
| 6932 | /* reset sample count */ |
| 6933 | ring->atr_count = 0; |
| 6934 | |
| 6935 | vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6936 | |
| 6937 | /* |
| 6938 | * src and dst are inverted, think how the receiver sees them |
| 6939 | * |
| 6940 | * The input is broken into two sections, a non-compressed section |
| 6941 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6942 | * is XORed together and stored in the compressed dword. |
| 6943 | */ |
| 6944 | input.formatted.vlan_id = vlan_id; |
| 6945 | |
| 6946 | /* |
| 6947 | * since src port and flex bytes occupy the same word XOR them together |
| 6948 | * and write the value to source port portion of compressed dword |
| 6949 | */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6950 | if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN)) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6951 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6952 | else |
| 6953 | common.port.src ^= th->dest ^ protocol; |
| 6954 | common.port.dst ^= th->source; |
| 6955 | |
| 6956 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6957 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6958 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6959 | } else { |
| 6960 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6961 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6962 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6963 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6964 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6965 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6966 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6967 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6968 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6969 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6970 | |
| 6971 | /* 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] | 6972 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6973 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6974 | } |
| 6975 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6976 | 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] | 6977 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6978 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6979 | /* Herbert's original patch had: |
| 6980 | * smp_mb__after_netif_stop_queue(); |
| 6981 | * but since that doesn't exist yet, just open code it. */ |
| 6982 | smp_mb(); |
| 6983 | |
| 6984 | /* We need to check again in a case another CPU has just |
| 6985 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6986 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6987 | return -EBUSY; |
| 6988 | |
| 6989 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6990 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6991 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6992 | return 0; |
| 6993 | } |
| 6994 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 6995 | 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] | 6996 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6997 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6998 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6999 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7000 | } |
| 7001 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7002 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 7003 | { |
| 7004 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 7005 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 7006 | smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 7007 | #ifdef IXGBE_FCOE |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 7008 | __be16 protocol = vlan_get_protocol(skb); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7009 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 7010 | if (((protocol == htons(ETH_P_FCOE)) || |
| 7011 | (protocol == htons(ETH_P_FIP))) && |
| 7012 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
| 7013 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 7014 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 7015 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 7016 | } |
| 7017 | #endif |
| 7018 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7019 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 7020 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 7021 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7022 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7023 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7024 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7025 | return skb_tx_hash(dev, skb); |
| 7026 | } |
| 7027 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7028 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7029 | struct ixgbe_adapter *adapter, |
| 7030 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7031 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7032 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7033 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7034 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7035 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 7036 | unsigned short f; |
| 7037 | #endif |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7038 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7039 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7040 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7041 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7042 | /* |
| 7043 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 7044 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7045 | * + 2 desc gap to keep tail from touching head, |
| 7046 | * + 1 desc for context descriptor, |
| 7047 | * otherwise try next time |
| 7048 | */ |
| 7049 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 7050 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 7051 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 7052 | #else |
| 7053 | count += skb_shinfo(skb)->nr_frags; |
| 7054 | #endif |
| 7055 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 7056 | tx_ring->tx_stats.tx_busy++; |
| 7057 | return NETDEV_TX_BUSY; |
| 7058 | } |
| 7059 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7060 | /* record the location of the first descriptor for this packet */ |
| 7061 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 7062 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame^] | 7063 | first->bytecount = skb->len; |
| 7064 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7065 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7066 | /* 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] | 7067 | if (vlan_tx_tag_present(skb)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7068 | tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 7069 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7070 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
| 7071 | } else if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 7072 | struct vlan_hdr *vhdr, _vhdr; |
| 7073 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 7074 | if (!vhdr) |
| 7075 | goto out_drop; |
| 7076 | |
| 7077 | protocol = vhdr->h_vlan_encapsulated_proto; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7078 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 7079 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7080 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7081 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7082 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7083 | #ifdef CONFIG_PCI_IOV |
| 7084 | /* |
| 7085 | * Use the l2switch_enable flag - would be false if the DMA |
| 7086 | * Tx switch had been disabled. |
| 7087 | */ |
| 7088 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7089 | tx_flags |= IXGBE_TX_FLAGS_TXSW; |
| 7090 | |
| 7091 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7092 | /* 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] | 7093 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 7094 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 7095 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7096 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7097 | tx_flags |= (skb->priority & 0x7) << |
| 7098 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7099 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 7100 | struct vlan_ethhdr *vhdr; |
| 7101 | if (skb_header_cloned(skb) && |
| 7102 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 7103 | goto out_drop; |
| 7104 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 7105 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 7106 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 7107 | } else { |
| 7108 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7109 | } |
| 7110 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7111 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7112 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7113 | /* setup tx offload for FCoE */ |
| 7114 | if ((protocol == __constant_htons(ETH_P_FCOE)) && |
| 7115 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7116 | tso = ixgbe_fso(tx_ring, first, tx_flags, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7117 | if (tso < 0) |
| 7118 | goto out_drop; |
| 7119 | else if (tso) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7120 | tx_flags |= IXGBE_TX_FLAGS_FSO | |
| 7121 | IXGBE_TX_FLAGS_FCOE; |
| 7122 | else |
| 7123 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7124 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7125 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7126 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7127 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7128 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7129 | /* setup IPv4/IPv6 offloads */ |
| 7130 | if (protocol == __constant_htons(ETH_P_IP)) |
| 7131 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7132 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7133 | tso = ixgbe_tso(tx_ring, first, tx_flags, protocol, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7134 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7135 | goto out_drop; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7136 | else if (tso) |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 7137 | tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7138 | else if (ixgbe_tx_csum(tx_ring, first, tx_flags, protocol)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7139 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7140 | |
| 7141 | /* add the ATR filter if ATR is on */ |
| 7142 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7143 | ixgbe_atr(tx_ring, first, tx_flags, protocol); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7144 | |
| 7145 | #ifdef IXGBE_FCOE |
| 7146 | xmit_fcoe: |
| 7147 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7148 | ixgbe_tx_map(tx_ring, first, tx_flags, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7149 | |
| 7150 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7151 | |
| 7152 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7153 | |
| 7154 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7155 | dev_kfree_skb_any(first->skb); |
| 7156 | first->skb = NULL; |
| 7157 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7158 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7159 | } |
| 7160 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7161 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7162 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7163 | { |
| 7164 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7165 | struct ixgbe_ring *tx_ring; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7166 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7167 | if (skb->len <= 0) { |
| 7168 | dev_kfree_skb_any(skb); |
| 7169 | return NETDEV_TX_OK; |
| 7170 | } |
| 7171 | |
| 7172 | /* |
| 7173 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 7174 | * in order to meet this minimum size requirement. |
| 7175 | */ |
| 7176 | if (skb->len < 17) { |
| 7177 | if (skb_padto(skb, 17)) |
| 7178 | return NETDEV_TX_OK; |
| 7179 | skb->len = 17; |
| 7180 | } |
| 7181 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7182 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
| 7183 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7184 | } |
| 7185 | |
| 7186 | /** |
| 7187 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7188 | * @netdev: network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7189 | * @p: pointer to an address structure |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7190 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7191 | * Returns 0 on success, negative on failure |
| 7192 | **/ |
| 7193 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7194 | { |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7195 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7196 | struct ixgbe_hw *hw = &adapter->hw; |
| 7197 | struct sockaddr *addr = p; |
| 7198 | |
| 7199 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7200 | return -EADDRNOTAVAIL; |
| 7201 | |
| 7202 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 7203 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
| 7204 | |
| 7205 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 7206 | IXGBE_RAH_AV); |
| 7207 | |
| 7208 | return 0; |
| 7209 | } |
| 7210 | |
| 7211 | static int |
| 7212 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7213 | { |
| 7214 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7215 | struct ixgbe_hw *hw = &adapter->hw; |
| 7216 | u16 value; |
| 7217 | int rc; |
| 7218 | |
| 7219 | if (prtad != hw->phy.mdio.prtad) |
| 7220 | return -EINVAL; |
| 7221 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7222 | if (!rc) |
| 7223 | rc = value; |
| 7224 | return rc; |
| 7225 | } |
| 7226 | |
| 7227 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7228 | u16 addr, u16 value) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7229 | { |
| 7230 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7231 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7232 | |
| 7233 | if (prtad != hw->phy.mdio.prtad) |
| 7234 | return -EINVAL; |
| 7235 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7236 | } |
| 7237 | |
| 7238 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7239 | { |
| 7240 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7241 | |
| 7242 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 7243 | } |
| 7244 | |
| 7245 | /** |
| 7246 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
| 7247 | * netdev->dev_addrs |
| 7248 | * @netdev: network interface device structure |
| 7249 | * |
| 7250 | * Returns non-zero on failure |
| 7251 | **/ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7252 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7253 | { |
| 7254 | int err = 0; |
| 7255 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7256 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7257 | |
| 7258 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7259 | rtnl_lock(); |
| 7260 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7261 | rtnl_unlock(); |
| 7262 | } |
| 7263 | return err; |
| 7264 | } |
| 7265 | |
| 7266 | /** |
| 7267 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
| 7268 | * netdev->dev_addrs |
| 7269 | * @netdev: network interface device structure |
| 7270 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7271 | * Returns non-zero on failure |
| 7272 | **/ |
| 7273 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 7274 | { |
| 7275 | int err = 0; |
| 7276 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7277 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7278 | |
| 7279 | if (is_valid_ether_addr(mac->san_addr)) { |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7280 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7281 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 7282 | rtnl_unlock(); |
| 7283 | } |
| 7284 | return err; |
| 7285 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7286 | |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7287 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7288 | /* |
| 7289 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7290 | * without having to re-enable interrupts. It's not called while |
| 7291 | * the interrupt routine is executing. |
| 7292 | */ |
| 7293 | static void ixgbe_netpoll(struct net_device *netdev) |
| 7294 | { |
| 7295 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7296 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7297 | |
| 7298 | /* if interface is down do nothing */ |
| 7299 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7300 | return; |
| 7301 | |
| 7302 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7303 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7304 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 7305 | for (i = 0; i < num_q_vectors; i++) { |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7306 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 7307 | ixgbe_msix_clean_rings(0, q_vector); |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7308 | } |
| 7309 | } else { |
| 7310 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 7311 | } |
| 7312 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
| 7313 | } |
| 7314 | #endif |
| 7315 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7316 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 7317 | struct rtnl_link_stats64 *stats) |
| 7318 | { |
| 7319 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7320 | int i; |
| 7321 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7322 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7323 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7324 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7325 | u64 bytes, packets; |
| 7326 | unsigned int start; |
| 7327 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7328 | if (ring) { |
| 7329 | do { |
| 7330 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7331 | packets = ring->stats.packets; |
| 7332 | bytes = ring->stats.bytes; |
| 7333 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7334 | stats->rx_packets += packets; |
| 7335 | stats->rx_bytes += bytes; |
| 7336 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7337 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7338 | |
| 7339 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7340 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7341 | u64 bytes, packets; |
| 7342 | unsigned int start; |
| 7343 | |
| 7344 | if (ring) { |
| 7345 | do { |
| 7346 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7347 | packets = ring->stats.packets; |
| 7348 | bytes = ring->stats.bytes; |
| 7349 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7350 | stats->tx_packets += packets; |
| 7351 | stats->tx_bytes += bytes; |
| 7352 | } |
| 7353 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7354 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7355 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7356 | stats->multicast = netdev->stats.multicast; |
| 7357 | stats->rx_errors = netdev->stats.rx_errors; |
| 7358 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7359 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7360 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7361 | return stats; |
| 7362 | } |
| 7363 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7364 | /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7365 | * #adapter: pointer to ixgbe_adapter |
| 7366 | * @tc: number of traffic classes currently enabled |
| 7367 | * |
| 7368 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7369 | * 802.1Q priority maps to a packet buffer that exists. |
| 7370 | */ |
| 7371 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7372 | { |
| 7373 | struct ixgbe_hw *hw = &adapter->hw; |
| 7374 | u32 reg, rsave; |
| 7375 | int i; |
| 7376 | |
| 7377 | /* 82598 have a static priority to TC mapping that can not |
| 7378 | * be changed so no validation is needed. |
| 7379 | */ |
| 7380 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7381 | return; |
| 7382 | |
| 7383 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7384 | rsave = reg; |
| 7385 | |
| 7386 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7387 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7388 | |
| 7389 | /* If up2tc is out of bounds default to zero */ |
| 7390 | if (up2tc > tc) |
| 7391 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7392 | } |
| 7393 | |
| 7394 | if (reg != rsave) |
| 7395 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7396 | |
| 7397 | return; |
| 7398 | } |
| 7399 | |
| 7400 | |
| 7401 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic |
| 7402 | * classes. |
| 7403 | * |
| 7404 | * @netdev: net device to configure |
| 7405 | * @tc: number of traffic classes to enable |
| 7406 | */ |
| 7407 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7408 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7409 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7410 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7411 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7412 | /* Multiple traffic classes requires multiple queues */ |
| 7413 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 7414 | e_err(drv, "Enable failed, needs MSI-X\n"); |
| 7415 | return -EINVAL; |
| 7416 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7417 | |
| 7418 | /* Hardware supports up to 8 traffic classes */ |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 7419 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs || |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7420 | (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS)) |
| 7421 | return -EINVAL; |
| 7422 | |
| 7423 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 7424 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7425 | * hardware is not flexible enough to do this dynamically. |
| 7426 | */ |
| 7427 | if (netif_running(dev)) |
| 7428 | ixgbe_close(dev); |
| 7429 | ixgbe_clear_interrupt_scheme(adapter); |
| 7430 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7431 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7432 | netdev_set_num_tc(dev, tc); |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7433 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; |
| 7434 | |
| 7435 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
| 7436 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7437 | |
| 7438 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 7439 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
| 7440 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7441 | netdev_reset_tc(dev); |
| 7442 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7443 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 7444 | |
| 7445 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 7446 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7447 | |
| 7448 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 7449 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 7450 | } |
| 7451 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7452 | ixgbe_init_interrupt_scheme(adapter); |
| 7453 | ixgbe_validate_rtr(adapter, tc); |
| 7454 | if (netif_running(dev)) |
| 7455 | ixgbe_open(dev); |
| 7456 | |
| 7457 | return 0; |
| 7458 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7459 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7460 | void ixgbe_do_reset(struct net_device *netdev) |
| 7461 | { |
| 7462 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7463 | |
| 7464 | if (netif_running(netdev)) |
| 7465 | ixgbe_reinit_locked(adapter); |
| 7466 | else |
| 7467 | ixgbe_reset(adapter); |
| 7468 | } |
| 7469 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7470 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
| 7471 | netdev_features_t data) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7472 | { |
| 7473 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7474 | |
| 7475 | #ifdef CONFIG_DCB |
| 7476 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 7477 | data &= ~NETIF_F_HW_VLAN_RX; |
| 7478 | #endif |
| 7479 | |
| 7480 | /* return error if RXHASH is being enabled when RSS is not supported */ |
| 7481 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 7482 | data &= ~NETIF_F_RXHASH; |
| 7483 | |
| 7484 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
| 7485 | if (!(data & NETIF_F_RXCSUM)) |
| 7486 | data &= ~NETIF_F_LRO; |
| 7487 | |
| 7488 | /* Turn off LRO if not RSC capable or invalid ITR settings */ |
| 7489 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) { |
| 7490 | data &= ~NETIF_F_LRO; |
| 7491 | } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
| 7492 | (adapter->rx_itr_setting != 1 && |
| 7493 | adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) { |
| 7494 | data &= ~NETIF_F_LRO; |
| 7495 | e_info(probe, "rx-usecs set too low, not enabling RSC\n"); |
| 7496 | } |
| 7497 | |
| 7498 | return data; |
| 7499 | } |
| 7500 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7501 | static int ixgbe_set_features(struct net_device *netdev, |
| 7502 | netdev_features_t data) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7503 | { |
| 7504 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7505 | netdev_features_t changed = netdev->features ^ data; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7506 | bool need_reset = false; |
| 7507 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7508 | /* Make sure RSC matches LRO, reset if change */ |
| 7509 | if (!!(data & NETIF_F_LRO) != |
| 7510 | !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 7511 | adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED; |
| 7512 | switch (adapter->hw.mac.type) { |
| 7513 | case ixgbe_mac_X540: |
| 7514 | case ixgbe_mac_82599EB: |
| 7515 | need_reset = true; |
| 7516 | break; |
| 7517 | default: |
| 7518 | break; |
| 7519 | } |
| 7520 | } |
| 7521 | |
| 7522 | /* |
| 7523 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 7524 | * the state changed, we need to reset. |
| 7525 | */ |
| 7526 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { |
| 7527 | /* turn off ATR, enable perfect filters and reset */ |
| 7528 | if (data & NETIF_F_NTUPLE) { |
| 7529 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7530 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7531 | need_reset = true; |
| 7532 | } |
| 7533 | } else if (!(data & NETIF_F_NTUPLE)) { |
| 7534 | /* turn off Flow Director, set ATR and reset */ |
| 7535 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7536 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 7537 | !(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 7538 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7539 | need_reset = true; |
| 7540 | } |
| 7541 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7542 | if (changed & NETIF_F_RXALL) |
| 7543 | need_reset = true; |
| 7544 | |
| 7545 | netdev->features = data; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7546 | if (need_reset) |
| 7547 | ixgbe_do_reset(netdev); |
| 7548 | |
| 7549 | return 0; |
| 7550 | |
| 7551 | } |
| 7552 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7553 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7554 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7555 | .ndo_stop = ixgbe_close, |
| 7556 | .ndo_start_xmit = ixgbe_xmit_frame, |
| 7557 | .ndo_select_queue = ixgbe_select_queue, |
| 7558 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7559 | .ndo_validate_addr = eth_validate_addr, |
| 7560 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7561 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7562 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7563 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7564 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7565 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7566 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7567 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7568 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 7569 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7570 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7571 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7572 | .ndo_setup_tc = ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7573 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7574 | .ndo_poll_controller = ixgbe_netpoll, |
| 7575 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7576 | #ifdef IXGBE_FCOE |
| 7577 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7578 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7579 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7580 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7581 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7582 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 7583 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7584 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7585 | .ndo_set_features = ixgbe_set_features, |
| 7586 | .ndo_fix_features = ixgbe_fix_features, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7587 | }; |
| 7588 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7589 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 7590 | const struct ixgbe_info *ii) |
| 7591 | { |
| 7592 | #ifdef CONFIG_PCI_IOV |
| 7593 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7594 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 7595 | if (hw->mac.type == ixgbe_mac_82598EB) |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7596 | return; |
| 7597 | |
| 7598 | /* The 82599 supports up to 64 VFs per physical function |
| 7599 | * but this implementation limits allocation to 63 so that |
| 7600 | * basic networking resources are still available to the |
| 7601 | * physical function |
| 7602 | */ |
| 7603 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 7604 | ixgbe_enable_sriov(adapter, ii); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7605 | #endif /* CONFIG_PCI_IOV */ |
| 7606 | } |
| 7607 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7608 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7609 | * ixgbe_probe - Device Initialization Routine |
| 7610 | * @pdev: PCI device information struct |
| 7611 | * @ent: entry in ixgbe_pci_tbl |
| 7612 | * |
| 7613 | * Returns 0 on success, negative on failure |
| 7614 | * |
| 7615 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7616 | * The OS initialization, configuring of the adapter private structure, |
| 7617 | * and a hardware reset occur. |
| 7618 | **/ |
| 7619 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7620 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7621 | { |
| 7622 | struct net_device *netdev; |
| 7623 | struct ixgbe_adapter *adapter = NULL; |
| 7624 | struct ixgbe_hw *hw; |
| 7625 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7626 | static int cards_found; |
| 7627 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7628 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7629 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7630 | #ifdef IXGBE_FCOE |
| 7631 | u16 device_caps; |
| 7632 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7633 | u32 eec; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7634 | u16 wol_cap; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7635 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7636 | /* Catch broken hardware that put the wrong VF device ID in |
| 7637 | * the PCIe SR-IOV capability. |
| 7638 | */ |
| 7639 | if (pdev->is_virtfn) { |
| 7640 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7641 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7642 | return -EINVAL; |
| 7643 | } |
| 7644 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7645 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7646 | if (err) |
| 7647 | return err; |
| 7648 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7649 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7650 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7651 | pci_using_dac = 1; |
| 7652 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7653 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7654 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7655 | err = dma_set_coherent_mask(&pdev->dev, |
| 7656 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7657 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7658 | dev_err(&pdev->dev, |
| 7659 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7660 | goto err_dma; |
| 7661 | } |
| 7662 | } |
| 7663 | pci_using_dac = 0; |
| 7664 | } |
| 7665 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7666 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7667 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7668 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7669 | dev_err(&pdev->dev, |
| 7670 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7671 | goto err_pci_reg; |
| 7672 | } |
| 7673 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7674 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7675 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7676 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7677 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7678 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7679 | #ifdef CONFIG_IXGBE_DCB |
| 7680 | indices *= MAX_TRAFFIC_CLASS; |
| 7681 | #endif |
| 7682 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7683 | if (ii->mac == ixgbe_mac_82598EB) |
| 7684 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7685 | else |
| 7686 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7687 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7688 | #ifdef IXGBE_FCOE |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7689 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7690 | IXGBE_MAX_FCOE_INDICES); |
| 7691 | #endif |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7692 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7693 | if (!netdev) { |
| 7694 | err = -ENOMEM; |
| 7695 | goto err_alloc_etherdev; |
| 7696 | } |
| 7697 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7698 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7699 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7700 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7701 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7702 | |
| 7703 | adapter->netdev = netdev; |
| 7704 | adapter->pdev = pdev; |
| 7705 | hw = &adapter->hw; |
| 7706 | hw->back = adapter; |
| 7707 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 7708 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7709 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7710 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7711 | if (!hw->hw_addr) { |
| 7712 | err = -EIO; |
| 7713 | goto err_ioremap; |
| 7714 | } |
| 7715 | |
| 7716 | for (i = 1; i <= 5; i++) { |
| 7717 | if (pci_resource_len(pdev, i) == 0) |
| 7718 | continue; |
| 7719 | } |
| 7720 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7721 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7722 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7723 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7724 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7725 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7726 | adapter->bd_number = cards_found; |
| 7727 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7728 | /* Setup hw api */ |
| 7729 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7730 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7731 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7732 | /* EEPROM */ |
| 7733 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7734 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7735 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7736 | if (!(eec & (1 << 8))) |
| 7737 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7738 | |
| 7739 | /* PHY */ |
| 7740 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7741 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7742 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7743 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7744 | hw->phy.mdio.mmds = 0; |
| 7745 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7746 | hw->phy.mdio.dev = netdev; |
| 7747 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7748 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7749 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7750 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7751 | |
| 7752 | /* setup the private structure */ |
| 7753 | err = ixgbe_sw_init(adapter); |
| 7754 | if (err) |
| 7755 | goto err_sw_init; |
| 7756 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7757 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7758 | switch (adapter->hw.mac.type) { |
| 7759 | case ixgbe_mac_82599EB: |
| 7760 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7761 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7762 | break; |
| 7763 | default: |
| 7764 | break; |
| 7765 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7766 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7767 | /* |
| 7768 | * If there is a fan on this device and it has failed log the |
| 7769 | * failure. |
| 7770 | */ |
| 7771 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7772 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7773 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7774 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7775 | } |
| 7776 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 7777 | if (allow_unsupported_sfp) |
| 7778 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 7779 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7780 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7781 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7782 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7783 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7784 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7785 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7786 | err = 0; |
| 7787 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7788 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7789 | "module type was detected.\n"); |
| 7790 | e_dev_err("Reload the driver after installing a supported " |
| 7791 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7792 | goto err_sw_init; |
| 7793 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7794 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7795 | goto err_sw_init; |
| 7796 | } |
| 7797 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7798 | ixgbe_probe_vf(adapter, ii); |
| 7799 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7800 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7801 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7802 | NETIF_F_IPV6_CSUM | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7803 | NETIF_F_HW_VLAN_TX | |
| 7804 | NETIF_F_HW_VLAN_RX | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7805 | NETIF_F_HW_VLAN_FILTER | |
| 7806 | NETIF_F_TSO | |
| 7807 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7808 | NETIF_F_RXHASH | |
| 7809 | NETIF_F_RXCSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7810 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7811 | netdev->hw_features = netdev->features; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7812 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7813 | switch (adapter->hw.mac.type) { |
| 7814 | case ixgbe_mac_82599EB: |
| 7815 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7816 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7817 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 7818 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7819 | break; |
| 7820 | default: |
| 7821 | break; |
| 7822 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7823 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7824 | netdev->hw_features |= NETIF_F_RXALL; |
| 7825 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7826 | netdev->vlan_features |= NETIF_F_TSO; |
| 7827 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7828 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7829 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7830 | netdev->vlan_features |= NETIF_F_SG; |
| 7831 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7832 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 7833 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7834 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7835 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7836 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 7837 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7838 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7839 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7840 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7841 | #endif |
| 7842 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7843 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7844 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7845 | if (hw->mac.ops.get_device_caps) { |
| 7846 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7847 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7848 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7849 | } |
| 7850 | } |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7851 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
| 7852 | netdev->vlan_features |= NETIF_F_FCOE_CRC; |
| 7853 | netdev->vlan_features |= NETIF_F_FSO; |
| 7854 | netdev->vlan_features |= NETIF_F_FCOE_MTU; |
| 7855 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7856 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7857 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7858 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7859 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7860 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7861 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7862 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 7863 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7864 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7865 | netdev->features |= NETIF_F_LRO; |
| 7866 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7867 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7868 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7869 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7870 | err = -EIO; |
| 7871 | goto err_eeprom; |
| 7872 | } |
| 7873 | |
| 7874 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7875 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7876 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7877 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7878 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7879 | err = -EIO; |
| 7880 | goto err_eeprom; |
| 7881 | } |
| 7882 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7883 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
| 7884 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7885 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7886 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7887 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7888 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7889 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7890 | if (err) |
| 7891 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7892 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7893 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
| 7894 | netdev->hw_features &= ~NETIF_F_RXHASH; |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7895 | netdev->features &= ~NETIF_F_RXHASH; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7896 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7897 | |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7898 | /* WOL not supported for all but the following */ |
| 7899 | adapter->wol = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7900 | switch (pdev->device) { |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7901 | case IXGBE_DEV_ID_82599_SFP: |
Don Skidmore | 0e22d04 | 2011-12-10 06:49:43 +0000 | [diff] [blame] | 7902 | /* Only these subdevice supports WOL */ |
| 7903 | switch (pdev->subsystem_device) { |
| 7904 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 7905 | /* only support first port */ |
| 7906 | if (hw->bus.func != 0) |
| 7907 | break; |
| 7908 | case IXGBE_SUBDEV_ID_82599_SFP: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7909 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0e22d04 | 2011-12-10 06:49:43 +0000 | [diff] [blame] | 7910 | break; |
| 7911 | } |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7912 | break; |
Alexander Duyck | 50d6c68 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 7913 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7914 | /* All except this subdevice support WOL */ |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7915 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7916 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7917 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7918 | case IXGBE_DEV_ID_82599_KX4: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7919 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7920 | break; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7921 | case IXGBE_DEV_ID_X540T: |
| 7922 | /* Check eeprom to see if it is enabled */ |
| 7923 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
| 7924 | wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 7925 | |
| 7926 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 7927 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 7928 | (hw->bus.func == 0))) |
| 7929 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7930 | break; |
| 7931 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7932 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7933 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 7934 | /* save off EEPROM version number */ |
| 7935 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 7936 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 7937 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7938 | /* pick up the PCI bus settings for reporting later */ |
| 7939 | hw->mac.ops.get_bus_info(hw); |
| 7940 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7941 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7942 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7943 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7944 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7945 | "Unknown"), |
| 7946 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7947 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7948 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7949 | "Unknown"), |
| 7950 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7951 | |
| 7952 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7953 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7954 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7955 | 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] | 7956 | 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] | 7957 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7958 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7959 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7960 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7961 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7962 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7963 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7964 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7965 | "not sufficient for optimal performance.\n"); |
| 7966 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7967 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7968 | } |
| 7969 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7970 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7971 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7972 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7973 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7974 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7975 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7976 | "Please be aware there may be issues associated " |
| 7977 | "with your hardware. If you are experiencing " |
| 7978 | "problems please contact your Intel or hardware " |
| 7979 | "representative who provided you with this " |
| 7980 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7981 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7982 | strcpy(netdev->name, "eth%d"); |
| 7983 | err = register_netdev(netdev); |
| 7984 | if (err) |
| 7985 | goto err_register; |
| 7986 | |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 7987 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 7988 | if (hw->mac.ops.disable_tx_laser && |
| 7989 | ((hw->phy.multispeed_fiber) || |
| 7990 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
| 7991 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 7992 | hw->mac.ops.disable_tx_laser(hw); |
| 7993 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 7994 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7995 | netif_carrier_off(netdev); |
| 7996 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7997 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 7998 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7999 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8000 | ixgbe_setup_dca(adapter); |
| 8001 | } |
| 8002 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8003 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8004 | 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] | 8005 | for (i = 0; i < adapter->num_vfs; i++) |
| 8006 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 8007 | } |
| 8008 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8009 | /* firmware requires driver version to be 0xFFFFFFFF |
| 8010 | * since os does not support feature |
| 8011 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8012 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8013 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 8014 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8015 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8016 | /* add san mac addr to netdev */ |
| 8017 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8018 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8019 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8020 | cards_found++; |
| 8021 | return 0; |
| 8022 | |
| 8023 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8024 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8025 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8026 | err_sw_init: |
| 8027 | err_eeprom: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8028 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 8029 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8030 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8031 | iounmap(hw->hw_addr); |
| 8032 | err_ioremap: |
| 8033 | free_netdev(netdev); |
| 8034 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8035 | pci_release_selected_regions(pdev, |
| 8036 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8037 | err_pci_reg: |
| 8038 | err_dma: |
| 8039 | pci_disable_device(pdev); |
| 8040 | return err; |
| 8041 | } |
| 8042 | |
| 8043 | /** |
| 8044 | * ixgbe_remove - Device Removal Routine |
| 8045 | * @pdev: PCI device information struct |
| 8046 | * |
| 8047 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 8048 | * that it should release a PCI device. The could be caused by a |
| 8049 | * Hot-Plug event, or because the driver is going to be removed from |
| 8050 | * memory. |
| 8051 | **/ |
| 8052 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 8053 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8054 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8055 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8056 | |
| 8057 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8058 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8059 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8060 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8061 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 8062 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 8063 | dca_remove_requester(&pdev->dev); |
| 8064 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 8065 | } |
| 8066 | |
| 8067 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8068 | #ifdef IXGBE_FCOE |
| 8069 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 8070 | ixgbe_cleanup_fcoe(adapter); |
| 8071 | |
| 8072 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8073 | |
| 8074 | /* remove the added san mac */ |
| 8075 | ixgbe_del_sanmac_netdev(netdev); |
| 8076 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 8077 | if (netdev->reg_state == NETREG_REGISTERED) |
| 8078 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8079 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 8080 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 8081 | if (!(ixgbe_check_vf_assignment(adapter))) |
| 8082 | ixgbe_disable_sriov(adapter); |
| 8083 | else |
| 8084 | e_dev_warn("Unloading driver while VFs are assigned " |
| 8085 | "- VFs will not be deallocated\n"); |
| 8086 | } |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8087 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8088 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8089 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8090 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8091 | |
| 8092 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8093 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8094 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8095 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8096 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8097 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8098 | free_netdev(netdev); |
| 8099 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 8100 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8101 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8102 | pci_disable_device(pdev); |
| 8103 | } |
| 8104 | |
| 8105 | /** |
| 8106 | * ixgbe_io_error_detected - called when PCI error is detected |
| 8107 | * @pdev: Pointer to PCI device |
| 8108 | * @state: The current pci connection state |
| 8109 | * |
| 8110 | * This function is called after a PCI bus error affecting |
| 8111 | * this device has been detected. |
| 8112 | */ |
| 8113 | 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] | 8114 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8115 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8116 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8117 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8118 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8119 | #ifdef CONFIG_PCI_IOV |
| 8120 | struct pci_dev *bdev, *vfdev; |
| 8121 | u32 dw0, dw1, dw2, dw3; |
| 8122 | int vf, pos; |
| 8123 | u16 req_id, pf_func; |
| 8124 | |
| 8125 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 8126 | adapter->num_vfs == 0) |
| 8127 | goto skip_bad_vf_detection; |
| 8128 | |
| 8129 | bdev = pdev->bus->self; |
| 8130 | while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT)) |
| 8131 | bdev = bdev->bus->self; |
| 8132 | |
| 8133 | if (!bdev) |
| 8134 | goto skip_bad_vf_detection; |
| 8135 | |
| 8136 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 8137 | if (!pos) |
| 8138 | goto skip_bad_vf_detection; |
| 8139 | |
| 8140 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0); |
| 8141 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1); |
| 8142 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2); |
| 8143 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3); |
| 8144 | |
| 8145 | req_id = dw1 >> 16; |
| 8146 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 8147 | if (!(req_id & 0x0080)) |
| 8148 | goto skip_bad_vf_detection; |
| 8149 | |
| 8150 | pf_func = req_id & 0x01; |
| 8151 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 8152 | unsigned int device_id; |
| 8153 | |
| 8154 | vf = (req_id & 0x7F) >> 1; |
| 8155 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 8156 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 8157 | "%8.8x\tdw3: %8.8x\n", |
| 8158 | dw0, dw1, dw2, dw3); |
| 8159 | switch (adapter->hw.mac.type) { |
| 8160 | case ixgbe_mac_82599EB: |
| 8161 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 8162 | break; |
| 8163 | case ixgbe_mac_X540: |
| 8164 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 8165 | break; |
| 8166 | default: |
| 8167 | device_id = 0; |
| 8168 | break; |
| 8169 | } |
| 8170 | |
| 8171 | /* Find the pci device of the offending VF */ |
| 8172 | vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL); |
| 8173 | while (vfdev) { |
| 8174 | if (vfdev->devfn == (req_id & 0xFF)) |
| 8175 | break; |
| 8176 | vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, |
| 8177 | device_id, vfdev); |
| 8178 | } |
| 8179 | /* |
| 8180 | * There's a slim chance the VF could have been hot plugged, |
| 8181 | * so if it is no longer present we don't need to issue the |
| 8182 | * VFLR. Just clean up the AER in that case. |
| 8183 | */ |
| 8184 | if (vfdev) { |
| 8185 | e_dev_err("Issuing VFLR to VF %d\n", vf); |
| 8186 | pci_write_config_dword(vfdev, 0xA8, 0x00008000); |
| 8187 | } |
| 8188 | |
| 8189 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8190 | } |
| 8191 | |
| 8192 | /* |
| 8193 | * Even though the error may have occurred on the other port |
| 8194 | * we still need to increment the vf error reference count for |
| 8195 | * both ports because the I/O resume function will be called |
| 8196 | * for both of them. |
| 8197 | */ |
| 8198 | adapter->vferr_refcount++; |
| 8199 | |
| 8200 | return PCI_ERS_RESULT_RECOVERED; |
| 8201 | |
| 8202 | skip_bad_vf_detection: |
| 8203 | #endif /* CONFIG_PCI_IOV */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8204 | netif_device_detach(netdev); |
| 8205 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 8206 | if (state == pci_channel_io_perm_failure) |
| 8207 | return PCI_ERS_RESULT_DISCONNECT; |
| 8208 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8209 | if (netif_running(netdev)) |
| 8210 | ixgbe_down(adapter); |
| 8211 | pci_disable_device(pdev); |
| 8212 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8213 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8214 | return PCI_ERS_RESULT_NEED_RESET; |
| 8215 | } |
| 8216 | |
| 8217 | /** |
| 8218 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 8219 | * @pdev: Pointer to PCI device |
| 8220 | * |
| 8221 | * Restart the card from scratch, as if from a cold-boot. |
| 8222 | */ |
| 8223 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 8224 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8225 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8226 | pci_ers_result_t result; |
| 8227 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8228 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8229 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8230 | 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] | 8231 | result = PCI_ERS_RESULT_DISCONNECT; |
| 8232 | } else { |
| 8233 | pci_set_master(pdev); |
| 8234 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 8235 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8236 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 8237 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8238 | |
| 8239 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 8240 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8241 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8242 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8243 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8244 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8245 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8246 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 8247 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8248 | /* non-fatal, continue */ |
| 8249 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8250 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8251 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8252 | } |
| 8253 | |
| 8254 | /** |
| 8255 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 8256 | * @pdev: Pointer to PCI device |
| 8257 | * |
| 8258 | * This callback is called when the error recovery driver tells us that |
| 8259 | * its OK to resume normal operation. |
| 8260 | */ |
| 8261 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 8262 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8263 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8264 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8265 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8266 | #ifdef CONFIG_PCI_IOV |
| 8267 | if (adapter->vferr_refcount) { |
| 8268 | e_info(drv, "Resuming after VF err\n"); |
| 8269 | adapter->vferr_refcount--; |
| 8270 | return; |
| 8271 | } |
| 8272 | |
| 8273 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 8274 | if (netif_running(netdev)) |
| 8275 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8276 | |
| 8277 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8278 | } |
| 8279 | |
| 8280 | static struct pci_error_handlers ixgbe_err_handler = { |
| 8281 | .error_detected = ixgbe_io_error_detected, |
| 8282 | .slot_reset = ixgbe_io_slot_reset, |
| 8283 | .resume = ixgbe_io_resume, |
| 8284 | }; |
| 8285 | |
| 8286 | static struct pci_driver ixgbe_driver = { |
| 8287 | .name = ixgbe_driver_name, |
| 8288 | .id_table = ixgbe_pci_tbl, |
| 8289 | .probe = ixgbe_probe, |
| 8290 | .remove = __devexit_p(ixgbe_remove), |
| 8291 | #ifdef CONFIG_PM |
| 8292 | .suspend = ixgbe_suspend, |
| 8293 | .resume = ixgbe_resume, |
| 8294 | #endif |
| 8295 | .shutdown = ixgbe_shutdown, |
| 8296 | .err_handler = &ixgbe_err_handler |
| 8297 | }; |
| 8298 | |
| 8299 | /** |
| 8300 | * ixgbe_init_module - Driver Registration Routine |
| 8301 | * |
| 8302 | * ixgbe_init_module is the first routine called when the driver is |
| 8303 | * loaded. All it does is register with the PCI subsystem. |
| 8304 | **/ |
| 8305 | static int __init ixgbe_init_module(void) |
| 8306 | { |
| 8307 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 8308 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8309 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8310 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8311 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8312 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8313 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8314 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8315 | ret = pci_register_driver(&ixgbe_driver); |
| 8316 | return ret; |
| 8317 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8318 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8319 | module_init(ixgbe_init_module); |
| 8320 | |
| 8321 | /** |
| 8322 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 8323 | * |
| 8324 | * ixgbe_exit_module is called just before the driver is removed |
| 8325 | * from memory. |
| 8326 | **/ |
| 8327 | static void __exit ixgbe_exit_module(void) |
| 8328 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8329 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8330 | dca_unregister_notify(&dca_notifier); |
| 8331 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8332 | pci_unregister_driver(&ixgbe_driver); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8333 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8334 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8335 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8336 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8337 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8338 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8339 | { |
| 8340 | int ret_val; |
| 8341 | |
| 8342 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8343 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8344 | |
| 8345 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 8346 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8347 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 8348 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8349 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8350 | module_exit(ixgbe_exit_module); |
| 8351 | |
| 8352 | /* ixgbe_main.c */ |