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 | { |
| 664 | return ring->tx_stats.completed; |
| 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 | |
| 763 | /* count the packet as being completed */ |
| 764 | tx_ring->tx_stats.completed++; |
| 765 | |
| 766 | /* clear next_to_watch to prevent false hangs */ |
| 767 | tx_buffer->next_to_watch = NULL; |
| 768 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 769 | do { |
| 770 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 771 | if (likely(tx_desc == eop_desc)) { |
| 772 | eop_desc = NULL; |
| 773 | dev_kfree_skb_any(tx_buffer->skb); |
| 774 | tx_buffer->skb = NULL; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 775 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 776 | total_bytes += tx_buffer->bytecount; |
| 777 | total_packets += tx_buffer->gso_segs; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 778 | } |
| 779 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 780 | tx_buffer++; |
| 781 | tx_desc++; |
| 782 | i++; |
| 783 | if (unlikely(i == tx_ring->count)) { |
| 784 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 785 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 786 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 787 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | } while (eop_desc); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 791 | } |
| 792 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 793 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 794 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 795 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 796 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 797 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 798 | q_vector->tx.total_bytes += total_bytes; |
| 799 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 800 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 801 | 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] | 802 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 803 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 804 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 805 | e_err(drv, "Detected Tx Unit Hang\n" |
| 806 | " Tx Queue <%d>\n" |
| 807 | " TDH, TDT <%x>, <%x>\n" |
| 808 | " next_to_use <%x>\n" |
| 809 | " next_to_clean <%x>\n" |
| 810 | "tx_buffer_info[next_to_clean]\n" |
| 811 | " time_stamp <%lx>\n" |
| 812 | " jiffies <%lx>\n", |
| 813 | tx_ring->queue_index, |
| 814 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 815 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 816 | tx_ring->next_to_use, i, |
| 817 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 818 | |
| 819 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 820 | |
| 821 | e_info(probe, |
| 822 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 823 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 824 | |
| 825 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 826 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 827 | |
| 828 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 829 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 830 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 831 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 832 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 833 | total_packets, total_bytes); |
| 834 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 835 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 836 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 837 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 838 | /* Make sure that anybody stopping the queue after this |
| 839 | * sees the new next_to_clean. |
| 840 | */ |
| 841 | smp_mb(); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 842 | if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) && |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 843 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 844 | netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 845 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 846 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 847 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 848 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 849 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 852 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 853 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 854 | struct ixgbe_ring *tx_ring, |
| 855 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 856 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 857 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 858 | u32 txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 859 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 860 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 861 | switch (hw->mac.type) { |
| 862 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 863 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 864 | break; |
| 865 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 866 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 867 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 868 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 869 | break; |
| 870 | default: |
| 871 | /* for unknown hardware do not write register */ |
| 872 | return; |
| 873 | } |
| 874 | |
| 875 | /* |
| 876 | * We can enable relaxed ordering for reads, but not writes when |
| 877 | * DCA is enabled. This is due to a known issue in some chipsets |
| 878 | * which will cause the DCA tag to be cleared. |
| 879 | */ |
| 880 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 881 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 882 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 883 | |
| 884 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 885 | } |
| 886 | |
| 887 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 888 | struct ixgbe_ring *rx_ring, |
| 889 | int cpu) |
| 890 | { |
| 891 | struct ixgbe_hw *hw = &adapter->hw; |
| 892 | u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
| 893 | u8 reg_idx = rx_ring->reg_idx; |
| 894 | |
| 895 | |
| 896 | switch (hw->mac.type) { |
| 897 | case ixgbe_mac_82599EB: |
| 898 | case ixgbe_mac_X540: |
| 899 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 900 | break; |
| 901 | default: |
| 902 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 903 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 904 | |
| 905 | /* |
| 906 | * We can enable relaxed ordering for reads, but not writes when |
| 907 | * DCA is enabled. This is due to a known issue in some chipsets |
| 908 | * which will cause the DCA tag to be cleared. |
| 909 | */ |
| 910 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
| 911 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
| 912 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 913 | |
| 914 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 918 | { |
| 919 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 920 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 921 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 922 | |
| 923 | if (q_vector->cpu == cpu) |
| 924 | goto out_no_update; |
| 925 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 926 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 927 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 928 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 929 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 930 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 931 | |
| 932 | q_vector->cpu = cpu; |
| 933 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 934 | put_cpu(); |
| 935 | } |
| 936 | |
| 937 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 938 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 939 | int num_q_vectors; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 940 | int i; |
| 941 | |
| 942 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 943 | return; |
| 944 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 945 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 946 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 947 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 948 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 949 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 950 | else |
| 951 | num_q_vectors = 1; |
| 952 | |
| 953 | for (i = 0; i < num_q_vectors; i++) { |
| 954 | adapter->q_vector[i]->cpu = -1; |
| 955 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
| 959 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 960 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 961 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 962 | unsigned long event = *(unsigned long *)data; |
| 963 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 964 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 965 | return 0; |
| 966 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 967 | switch (event) { |
| 968 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 969 | /* if we're already enabled, don't do it again */ |
| 970 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 971 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 972 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 973 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 974 | ixgbe_setup_dca(adapter); |
| 975 | break; |
| 976 | } |
| 977 | /* Fall Through since DCA is disabled. */ |
| 978 | case DCA_PROVIDER_REMOVE: |
| 979 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 980 | dca_remove_requester(dev); |
| 981 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 982 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 983 | } |
| 984 | break; |
| 985 | } |
| 986 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 987 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 988 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 989 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 990 | #endif /* CONFIG_IXGBE_DCA */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 991 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 992 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 993 | struct sk_buff *skb) |
| 994 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 995 | if (ring->netdev->features & NETIF_F_RXHASH) |
| 996 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 999 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1000 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1001 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
| 1002 | * @adapter: address of board private structure |
| 1003 | * @rx_desc: advanced rx descriptor |
| 1004 | * |
| 1005 | * Returns : true if it is FCoE pkt |
| 1006 | */ |
| 1007 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter, |
| 1008 | union ixgbe_adv_rx_desc *rx_desc) |
| 1009 | { |
| 1010 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1011 | |
| 1012 | return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 1013 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1014 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1015 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1016 | } |
| 1017 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1018 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1019 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1020 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1021 | * @ring: structure containing ring specific data |
| 1022 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1023 | * @skb: skb currently being received and modified |
| 1024 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1025 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1026 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1027 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1028 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1029 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1030 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1031 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1032 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1033 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1034 | |
| 1035 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1036 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1037 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1038 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1039 | return; |
| 1040 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1041 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1042 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1043 | return; |
| 1044 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1045 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1046 | __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] | 1047 | |
| 1048 | /* |
| 1049 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1050 | * checksum errors. |
| 1051 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1052 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1053 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1054 | return; |
| 1055 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1056 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1057 | return; |
| 1058 | } |
| 1059 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1060 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1061 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1064 | 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] | 1065 | { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1066 | rx_ring->next_to_use = val; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1067 | |
| 1068 | /* update next to alloc since we have filled the ring */ |
| 1069 | rx_ring->next_to_alloc = val; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1070 | /* |
| 1071 | * Force memory writes to complete before letting h/w |
| 1072 | * know there are new descriptors to fetch. (Only |
| 1073 | * applicable for weak-ordered memory model archs, |
| 1074 | * such as IA-64). |
| 1075 | */ |
| 1076 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1077 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1080 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1081 | struct ixgbe_rx_buffer *bi) |
| 1082 | { |
| 1083 | struct page *page = bi->page; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1084 | dma_addr_t dma = bi->dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1085 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1086 | /* since we are recycling buffers we should seldom need to alloc */ |
| 1087 | if (likely(dma)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1088 | return true; |
| 1089 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1090 | /* alloc new page for storage */ |
| 1091 | if (likely(!page)) { |
| 1092 | page = alloc_pages(GFP_ATOMIC | __GFP_COLD, |
| 1093 | ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1094 | if (unlikely(!page)) { |
| 1095 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1096 | return false; |
| 1097 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1098 | bi->page = page; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1101 | /* map page for use */ |
| 1102 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1103 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1104 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1105 | /* |
| 1106 | * if mapping failed free memory back to system since |
| 1107 | * there isn't much point in holding memory we can't use |
| 1108 | */ |
| 1109 | if (dma_mapping_error(rx_ring->dev, dma)) { |
| 1110 | put_page(page); |
| 1111 | bi->page = NULL; |
| 1112 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1113 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1114 | return false; |
| 1115 | } |
| 1116 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1117 | bi->dma = dma; |
| 1118 | bi->page_offset ^= ixgbe_rx_bufsz(rx_ring); |
| 1119 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1120 | return true; |
| 1121 | } |
| 1122 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1123 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1124 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1125 | * @rx_ring: ring to place buffers on |
| 1126 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1127 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1128 | 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] | 1129 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1130 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1131 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1132 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1133 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1134 | /* nothing to do */ |
| 1135 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1136 | return; |
| 1137 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1138 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1139 | bi = &rx_ring->rx_buffer_info[i]; |
| 1140 | i -= rx_ring->count; |
| 1141 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1142 | do { |
| 1143 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1144 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1145 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1146 | /* |
| 1147 | * Refresh the desc even if buffer_addrs didn't change |
| 1148 | * because each write-back erases this info. |
| 1149 | */ |
| 1150 | 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] | 1151 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1152 | rx_desc++; |
| 1153 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1154 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1155 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1156 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1157 | bi = rx_ring->rx_buffer_info; |
| 1158 | i -= rx_ring->count; |
| 1159 | } |
| 1160 | |
| 1161 | /* clear the hdr_addr for the next_to_use descriptor */ |
| 1162 | rx_desc->read.hdr_addr = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1163 | |
| 1164 | cleaned_count--; |
| 1165 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1166 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1167 | i += rx_ring->count; |
| 1168 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1169 | if (rx_ring->next_to_use != i) |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1170 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1173 | /** |
| 1174 | * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE |
| 1175 | * @data: pointer to the start of the headers |
| 1176 | * @max_len: total length of section to find headers in |
| 1177 | * |
| 1178 | * This function is meant to determine the length of headers that will |
| 1179 | * be recognized by hardware for LRO, GRO, and RSC offloads. The main |
| 1180 | * motivation of doing this is to only perform one pull for IPv4 TCP |
| 1181 | * packets so that we can do basic things like calculating the gso_size |
| 1182 | * based on the average data per packet. |
| 1183 | **/ |
| 1184 | static unsigned int ixgbe_get_headlen(unsigned char *data, |
| 1185 | unsigned int max_len) |
| 1186 | { |
| 1187 | union { |
| 1188 | unsigned char *network; |
| 1189 | /* l2 headers */ |
| 1190 | struct ethhdr *eth; |
| 1191 | struct vlan_hdr *vlan; |
| 1192 | /* l3 headers */ |
| 1193 | struct iphdr *ipv4; |
| 1194 | } hdr; |
| 1195 | __be16 protocol; |
| 1196 | u8 nexthdr = 0; /* default to not TCP */ |
| 1197 | u8 hlen; |
| 1198 | |
| 1199 | /* this should never happen, but better safe than sorry */ |
| 1200 | if (max_len < ETH_HLEN) |
| 1201 | return max_len; |
| 1202 | |
| 1203 | /* initialize network frame pointer */ |
| 1204 | hdr.network = data; |
| 1205 | |
| 1206 | /* set first protocol and move network header forward */ |
| 1207 | protocol = hdr.eth->h_proto; |
| 1208 | hdr.network += ETH_HLEN; |
| 1209 | |
| 1210 | /* handle any vlan tag if present */ |
| 1211 | if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 1212 | if ((hdr.network - data) > (max_len - VLAN_HLEN)) |
| 1213 | return max_len; |
| 1214 | |
| 1215 | protocol = hdr.vlan->h_vlan_encapsulated_proto; |
| 1216 | hdr.network += VLAN_HLEN; |
| 1217 | } |
| 1218 | |
| 1219 | /* handle L3 protocols */ |
| 1220 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 1221 | if ((hdr.network - data) > (max_len - sizeof(struct iphdr))) |
| 1222 | return max_len; |
| 1223 | |
| 1224 | /* access ihl as a u8 to avoid unaligned access on ia64 */ |
| 1225 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 1226 | |
| 1227 | /* verify hlen meets minimum size requirements */ |
| 1228 | if (hlen < sizeof(struct iphdr)) |
| 1229 | return hdr.network - data; |
| 1230 | |
| 1231 | /* record next protocol */ |
| 1232 | nexthdr = hdr.ipv4->protocol; |
| 1233 | hdr.network += hlen; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1234 | #ifdef IXGBE_FCOE |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1235 | } else if (protocol == __constant_htons(ETH_P_FCOE)) { |
| 1236 | if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN)) |
| 1237 | return max_len; |
| 1238 | hdr.network += FCOE_HEADER_LEN; |
| 1239 | #endif |
| 1240 | } else { |
| 1241 | return hdr.network - data; |
| 1242 | } |
| 1243 | |
| 1244 | /* finally sort out TCP */ |
| 1245 | if (nexthdr == IPPROTO_TCP) { |
| 1246 | if ((hdr.network - data) > (max_len - sizeof(struct tcphdr))) |
| 1247 | return max_len; |
| 1248 | |
| 1249 | /* access doff as a u8 to avoid unaligned access on ia64 */ |
| 1250 | hlen = (hdr.network[12] & 0xF0) >> 2; |
| 1251 | |
| 1252 | /* verify hlen meets minimum size requirements */ |
| 1253 | if (hlen < sizeof(struct tcphdr)) |
| 1254 | return hdr.network - data; |
| 1255 | |
| 1256 | hdr.network += hlen; |
| 1257 | } |
| 1258 | |
| 1259 | /* |
| 1260 | * If everything has gone correctly hdr.network should be the |
| 1261 | * data section of the packet and will be the end of the header. |
| 1262 | * If not then it probably represents the end of the last recognized |
| 1263 | * header. |
| 1264 | */ |
| 1265 | if ((hdr.network - data) < max_len) |
| 1266 | return hdr.network - data; |
| 1267 | else |
| 1268 | return max_len; |
| 1269 | } |
| 1270 | |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1271 | static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring, |
| 1272 | union ixgbe_adv_rx_desc *rx_desc, |
| 1273 | struct sk_buff *skb) |
| 1274 | { |
| 1275 | __le32 rsc_enabled; |
| 1276 | u32 rsc_cnt; |
| 1277 | |
| 1278 | if (!ring_is_rsc_enabled(rx_ring)) |
| 1279 | return; |
| 1280 | |
| 1281 | rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1282 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1283 | |
| 1284 | /* If this is an RSC frame rsc_cnt should be non-zero */ |
| 1285 | if (!rsc_enabled) |
| 1286 | return; |
| 1287 | |
| 1288 | rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1289 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1290 | |
| 1291 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1292 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1293 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1294 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1295 | struct sk_buff *skb) |
| 1296 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1297 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1298 | |
| 1299 | /* set gso_size to avoid messing up TCP MSS */ |
| 1300 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1301 | IXGBE_CB(skb)->append_cnt); |
| 1302 | } |
| 1303 | |
| 1304 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1305 | struct sk_buff *skb) |
| 1306 | { |
| 1307 | /* if append_cnt is 0 then frame is not RSC */ |
| 1308 | if (!IXGBE_CB(skb)->append_cnt) |
| 1309 | return; |
| 1310 | |
| 1311 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1312 | rx_ring->rx_stats.rsc_flush++; |
| 1313 | |
| 1314 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1315 | |
| 1316 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1317 | IXGBE_CB(skb)->append_cnt = 0; |
| 1318 | } |
| 1319 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1320 | /** |
| 1321 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1322 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1323 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1324 | * @skb: pointer to current skb being populated |
| 1325 | * |
| 1326 | * This function checks the ring, descriptor, and packet information in |
| 1327 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1328 | * other fields within the skb. |
| 1329 | **/ |
| 1330 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1331 | union ixgbe_adv_rx_desc *rx_desc, |
| 1332 | struct sk_buff *skb) |
| 1333 | { |
| 1334 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1335 | |
| 1336 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1337 | |
| 1338 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1339 | |
| 1340 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
| 1341 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
| 1342 | __vlan_hwaccel_put_tag(skb, vid); |
| 1343 | } |
| 1344 | |
| 1345 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1346 | |
| 1347 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
| 1348 | } |
| 1349 | |
| 1350 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1351 | struct sk_buff *skb) |
| 1352 | { |
| 1353 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1354 | |
| 1355 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1356 | napi_gro_receive(&q_vector->napi, skb); |
| 1357 | else |
| 1358 | netif_rx(skb); |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1361 | /** |
| 1362 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1363 | * @rx_ring: Rx ring being processed |
| 1364 | * @rx_desc: Rx descriptor for current buffer |
| 1365 | * @skb: Current socket buffer containing buffer in progress |
| 1366 | * |
| 1367 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1368 | * this function exits returning false, otherwise it will place the |
| 1369 | * sk_buff in the next buffer to be chained and return true indicating |
| 1370 | * that this is in fact a non-EOP buffer. |
| 1371 | **/ |
| 1372 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1373 | union ixgbe_adv_rx_desc *rx_desc, |
| 1374 | struct sk_buff *skb) |
| 1375 | { |
| 1376 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1377 | |
| 1378 | /* fetch, update, and store next to clean */ |
| 1379 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1380 | rx_ring->next_to_clean = ntc; |
| 1381 | |
| 1382 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1383 | |
| 1384 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1385 | return false; |
| 1386 | |
| 1387 | /* append_cnt indicates packet is RSC, if so fetch nextp */ |
| 1388 | if (IXGBE_CB(skb)->append_cnt) { |
| 1389 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1390 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1391 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1392 | } |
| 1393 | |
| 1394 | /* place skb in next buffer to be received */ |
| 1395 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1396 | rx_ring->rx_stats.non_eop_descs++; |
| 1397 | |
| 1398 | return true; |
| 1399 | } |
| 1400 | |
| 1401 | /** |
| 1402 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1403 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1404 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1405 | * @skb: pointer to current skb being fixed |
| 1406 | * |
| 1407 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1408 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1409 | * should be very rare. |
| 1410 | * |
| 1411 | * Also address the case where we are pulling data in on pages only |
| 1412 | * and as such no data is present in the skb header. |
| 1413 | * |
| 1414 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1415 | * it is large enough to qualify as a valid Ethernet frame. |
| 1416 | * |
| 1417 | * Returns true if an error was encountered and skb was freed. |
| 1418 | **/ |
| 1419 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1420 | union ixgbe_adv_rx_desc *rx_desc, |
| 1421 | struct sk_buff *skb) |
| 1422 | { |
| 1423 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1424 | struct net_device *netdev = rx_ring->netdev; |
| 1425 | unsigned char *va; |
| 1426 | unsigned int pull_len; |
| 1427 | |
| 1428 | /* if the page was released unmap it, else just sync our portion */ |
| 1429 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1430 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1431 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1432 | IXGBE_CB(skb)->page_released = false; |
| 1433 | } else { |
| 1434 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1435 | IXGBE_CB(skb)->dma, |
| 1436 | frag->page_offset, |
| 1437 | ixgbe_rx_bufsz(rx_ring), |
| 1438 | DMA_FROM_DEVICE); |
| 1439 | } |
| 1440 | IXGBE_CB(skb)->dma = 0; |
| 1441 | |
| 1442 | /* verify that the packet does not have any known errors */ |
| 1443 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1444 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1445 | !(netdev->features & NETIF_F_RXALL))) { |
| 1446 | dev_kfree_skb_any(skb); |
| 1447 | return true; |
| 1448 | } |
| 1449 | |
| 1450 | /* |
| 1451 | * it is valid to use page_address instead of kmap since we are |
| 1452 | * working with pages allocated out of the lomem pool per |
| 1453 | * alloc_page(GFP_ATOMIC) |
| 1454 | */ |
| 1455 | va = skb_frag_address(frag); |
| 1456 | |
| 1457 | /* |
| 1458 | * we need the header to contain the greater of either ETH_HLEN or |
| 1459 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1460 | */ |
| 1461 | pull_len = skb_frag_size(frag); |
| 1462 | if (pull_len > 256) |
| 1463 | pull_len = ixgbe_get_headlen(va, pull_len); |
| 1464 | |
| 1465 | /* align pull length to size of long to optimize memcpy performance */ |
| 1466 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1467 | |
| 1468 | /* update all of the pointers */ |
| 1469 | skb_frag_size_sub(frag, pull_len); |
| 1470 | frag->page_offset += pull_len; |
| 1471 | skb->data_len -= pull_len; |
| 1472 | skb->tail += pull_len; |
| 1473 | |
| 1474 | /* |
| 1475 | * if we sucked the frag empty then we should free it, |
| 1476 | * if there are other frags here something is screwed up in hardware |
| 1477 | */ |
| 1478 | if (skb_frag_size(frag) == 0) { |
| 1479 | BUG_ON(skb_shinfo(skb)->nr_frags != 1); |
| 1480 | skb_shinfo(skb)->nr_frags = 0; |
| 1481 | __skb_frag_unref(frag); |
| 1482 | skb->truesize -= ixgbe_rx_bufsz(rx_ring); |
| 1483 | } |
| 1484 | |
| 1485 | /* if skb_pad returns an error the skb was freed */ |
| 1486 | if (unlikely(skb->len < 60)) { |
| 1487 | int pad_len = 60 - skb->len; |
| 1488 | |
| 1489 | if (skb_pad(skb, pad_len)) |
| 1490 | return true; |
| 1491 | __skb_put(skb, pad_len); |
| 1492 | } |
| 1493 | |
| 1494 | return false; |
| 1495 | } |
| 1496 | |
| 1497 | /** |
| 1498 | * ixgbe_can_reuse_page - determine if we can reuse a page |
| 1499 | * @rx_buffer: pointer to rx_buffer containing the page we want to reuse |
| 1500 | * |
| 1501 | * Returns true if page can be reused in another Rx buffer |
| 1502 | **/ |
| 1503 | static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer) |
| 1504 | { |
| 1505 | struct page *page = rx_buffer->page; |
| 1506 | |
| 1507 | /* if we are only owner of page and it is local we can reuse it */ |
| 1508 | return likely(page_count(page) == 1) && |
| 1509 | likely(page_to_nid(page) == numa_node_id()); |
| 1510 | } |
| 1511 | |
| 1512 | /** |
| 1513 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1514 | * @rx_ring: rx descriptor ring to store buffers on |
| 1515 | * @old_buff: donor buffer to have page reused |
| 1516 | * |
| 1517 | * Syncronizes page for reuse by the adapter |
| 1518 | **/ |
| 1519 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1520 | struct ixgbe_rx_buffer *old_buff) |
| 1521 | { |
| 1522 | struct ixgbe_rx_buffer *new_buff; |
| 1523 | u16 nta = rx_ring->next_to_alloc; |
| 1524 | u16 bufsz = ixgbe_rx_bufsz(rx_ring); |
| 1525 | |
| 1526 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1527 | |
| 1528 | /* update, and store next to alloc */ |
| 1529 | nta++; |
| 1530 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1531 | |
| 1532 | /* transfer page from old buffer to new buffer */ |
| 1533 | new_buff->page = old_buff->page; |
| 1534 | new_buff->dma = old_buff->dma; |
| 1535 | |
| 1536 | /* flip page offset to other buffer and store to new_buff */ |
| 1537 | new_buff->page_offset = old_buff->page_offset ^ bufsz; |
| 1538 | |
| 1539 | /* sync the buffer for use by the device */ |
| 1540 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
| 1541 | new_buff->page_offset, bufsz, |
| 1542 | DMA_FROM_DEVICE); |
| 1543 | |
| 1544 | /* bump ref count on page before it is given to the stack */ |
| 1545 | get_page(new_buff->page); |
| 1546 | } |
| 1547 | |
| 1548 | /** |
| 1549 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1550 | * @rx_ring: rx descriptor ring to transact packets on |
| 1551 | * @rx_buffer: buffer containing page to add |
| 1552 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1553 | * @skb: sk_buff to place the data into |
| 1554 | * |
| 1555 | * This function is based on skb_add_rx_frag. I would have used that |
| 1556 | * function however it doesn't handle the truesize case correctly since we |
| 1557 | * are allocating more memory than might be used for a single receive. |
| 1558 | **/ |
| 1559 | static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
| 1560 | struct ixgbe_rx_buffer *rx_buffer, |
| 1561 | struct sk_buff *skb, int size) |
| 1562 | { |
| 1563 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
| 1564 | rx_buffer->page, rx_buffer->page_offset, |
| 1565 | size); |
| 1566 | skb->len += size; |
| 1567 | skb->data_len += size; |
| 1568 | skb->truesize += ixgbe_rx_bufsz(rx_ring); |
| 1569 | } |
| 1570 | |
| 1571 | /** |
| 1572 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 1573 | * @q_vector: structure containing interrupt and ring information |
| 1574 | * @rx_ring: rx descriptor ring to transact packets on |
| 1575 | * @budget: Total limit on number of packets to process |
| 1576 | * |
| 1577 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 1578 | * processing. The advantage to this is that on systems that have |
| 1579 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 1580 | * it by maintaining the mapping of the page to the syste. |
| 1581 | * |
| 1582 | * Returns true if all work is completed without reaching budget |
| 1583 | **/ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1584 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1585 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1586 | int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1587 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1588 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 1589 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1590 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1591 | int ddp_bytes = 0; |
| 1592 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1593 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1594 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1595 | do { |
| 1596 | struct ixgbe_rx_buffer *rx_buffer; |
| 1597 | union ixgbe_adv_rx_desc *rx_desc; |
| 1598 | struct sk_buff *skb; |
| 1599 | struct page *page; |
| 1600 | u16 ntc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1601 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1602 | /* return some buffers to hardware, one at a time is too slow */ |
| 1603 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 1604 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1605 | cleaned_count = 0; |
| 1606 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1607 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1608 | ntc = rx_ring->next_to_clean; |
| 1609 | rx_desc = IXGBE_RX_DESC(rx_ring, ntc); |
| 1610 | rx_buffer = &rx_ring->rx_buffer_info[ntc]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1611 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1612 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) |
| 1613 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1614 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1615 | /* |
| 1616 | * This memory barrier is needed to keep us from reading |
| 1617 | * any other fields out of the rx_desc until we know the |
| 1618 | * RXD_STAT_DD bit is set |
| 1619 | */ |
| 1620 | rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1621 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1622 | page = rx_buffer->page; |
| 1623 | prefetchw(page); |
| 1624 | |
| 1625 | skb = rx_buffer->skb; |
| 1626 | |
| 1627 | if (likely(!skb)) { |
| 1628 | void *page_addr = page_address(page) + |
| 1629 | rx_buffer->page_offset; |
| 1630 | |
| 1631 | /* prefetch first cache line of first page */ |
| 1632 | prefetch(page_addr); |
| 1633 | #if L1_CACHE_BYTES < 128 |
| 1634 | prefetch(page_addr + L1_CACHE_BYTES); |
| 1635 | #endif |
| 1636 | |
| 1637 | /* allocate a skb to store the frags */ |
| 1638 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
| 1639 | IXGBE_RX_HDR_SIZE); |
| 1640 | if (unlikely(!skb)) { |
| 1641 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 1642 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1643 | } |
| 1644 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1645 | /* |
| 1646 | * we will be copying header into skb->data in |
| 1647 | * pskb_may_pull so it is in our interest to prefetch |
| 1648 | * it now to avoid a possible cache miss |
| 1649 | */ |
| 1650 | prefetchw(skb->data); |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1651 | |
| 1652 | /* |
| 1653 | * Delay unmapping of the first packet. It carries the |
| 1654 | * header information, HW may still access the header |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1655 | * after the writeback. Only unmap it when EOP is |
| 1656 | * reached |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1657 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1658 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1659 | } else { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1660 | /* we are reusing so sync this buffer for CPU use */ |
| 1661 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1662 | rx_buffer->dma, |
| 1663 | rx_buffer->page_offset, |
| 1664 | ixgbe_rx_bufsz(rx_ring), |
| 1665 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1668 | /* pull page into skb */ |
| 1669 | ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, |
| 1670 | le16_to_cpu(rx_desc->wb.upper.length)); |
| 1671 | |
| 1672 | if (ixgbe_can_reuse_page(rx_buffer)) { |
| 1673 | /* hand second half of page back to the ring */ |
| 1674 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 1675 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 1676 | /* the page has been released from the ring */ |
| 1677 | IXGBE_CB(skb)->page_released = true; |
| 1678 | } else { |
| 1679 | /* we are not reusing the buffer so unmap it */ |
| 1680 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 1681 | ixgbe_rx_pg_size(rx_ring), |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1682 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1685 | /* clear contents of buffer_info */ |
| 1686 | rx_buffer->skb = NULL; |
| 1687 | rx_buffer->dma = 0; |
| 1688 | rx_buffer->page = NULL; |
| 1689 | |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1690 | ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb); |
| 1691 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1692 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1693 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1694 | /* place incomplete frames back on ring for completion */ |
| 1695 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 1696 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1697 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1698 | /* verify the packet layout is correct */ |
| 1699 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 1700 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1701 | |
| 1702 | /* probably a little skewed due to removing CRC */ |
| 1703 | total_rx_bytes += skb->len; |
| 1704 | total_rx_packets++; |
| 1705 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1706 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 1707 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 1708 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1709 | #ifdef IXGBE_FCOE |
| 1710 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1711 | if (ixgbe_rx_is_fcoe(adapter, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1712 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1713 | if (!ddp_bytes) { |
| 1714 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1715 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1716 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1717 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1718 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1719 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1720 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1721 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1722 | /* update budget accounting */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1723 | budget--; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1724 | } while (likely(budget)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1725 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1726 | #ifdef IXGBE_FCOE |
| 1727 | /* include DDPed FCoE data */ |
| 1728 | if (ddp_bytes > 0) { |
| 1729 | unsigned int mss; |
| 1730 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1731 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1732 | sizeof(struct fc_frame_header) - |
| 1733 | sizeof(struct fcoe_crc_eof); |
| 1734 | if (mss > 512) |
| 1735 | mss &= ~511; |
| 1736 | total_rx_bytes += ddp_bytes; |
| 1737 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1738 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1739 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1740 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1741 | u64_stats_update_begin(&rx_ring->syncp); |
| 1742 | rx_ring->stats.packets += total_rx_packets; |
| 1743 | rx_ring->stats.bytes += total_rx_bytes; |
| 1744 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1745 | q_vector->rx.total_packets += total_rx_packets; |
| 1746 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1747 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1748 | if (cleaned_count) |
| 1749 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1750 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1751 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1754 | /** |
| 1755 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1756 | * @adapter: board private structure |
| 1757 | * |
| 1758 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1759 | * interrupts. |
| 1760 | **/ |
| 1761 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1762 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1763 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1764 | int q_vectors, v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1765 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1766 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1767 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1768 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 1769 | /* Populate MSIX to EITR Select */ |
| 1770 | if (adapter->num_vfs > 32) { |
| 1771 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 1772 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 1773 | } |
| 1774 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1775 | /* |
| 1776 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1777 | * corresponding register. |
| 1778 | */ |
| 1779 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1780 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1781 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1782 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1783 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1784 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1785 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1786 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1787 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1788 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1789 | if (q_vector->tx.ring && !q_vector->rx.ring) { |
| 1790 | /* tx only vector */ |
| 1791 | if (adapter->tx_itr_setting == 1) |
| 1792 | q_vector->itr = IXGBE_10K_ITR; |
| 1793 | else |
| 1794 | q_vector->itr = adapter->tx_itr_setting; |
| 1795 | } else { |
| 1796 | /* rx or rx/tx vector */ |
| 1797 | if (adapter->rx_itr_setting == 1) |
| 1798 | q_vector->itr = IXGBE_20K_ITR; |
| 1799 | else |
| 1800 | q_vector->itr = adapter->rx_itr_setting; |
| 1801 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1802 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1803 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1806 | switch (adapter->hw.mac.type) { |
| 1807 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1808 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1809 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1810 | break; |
| 1811 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1812 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1813 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1814 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1815 | default: |
| 1816 | break; |
| 1817 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1818 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1819 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1820 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1821 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1822 | mask &= ~(IXGBE_EIMS_OTHER | |
| 1823 | IXGBE_EIMS_MAILBOX | |
| 1824 | IXGBE_EIMS_LSC); |
| 1825 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1826 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1829 | enum latency_range { |
| 1830 | lowest_latency = 0, |
| 1831 | low_latency = 1, |
| 1832 | bulk_latency = 2, |
| 1833 | latency_invalid = 255 |
| 1834 | }; |
| 1835 | |
| 1836 | /** |
| 1837 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1838 | * @q_vector: structure containing interrupt and ring information |
| 1839 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1840 | * |
| 1841 | * Stores a new ITR value based on packets and byte |
| 1842 | * counts during the last interrupt. The advantage of per interrupt |
| 1843 | * computation is faster updates and more accurate ITR for the current |
| 1844 | * traffic pattern. Constants in this function were computed |
| 1845 | * based on theoretical maximum wire speed and thresholds were set based |
| 1846 | * on testing data as well as attempting to minimize response time |
| 1847 | * while increasing bulk throughput. |
| 1848 | * this functionality is controlled by the InterruptThrottleRate module |
| 1849 | * parameter (see ixgbe_param.c) |
| 1850 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1851 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 1852 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1853 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1854 | int bytes = ring_container->total_bytes; |
| 1855 | int packets = ring_container->total_packets; |
| 1856 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1857 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1858 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1859 | |
| 1860 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1861 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1862 | |
| 1863 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1864 | * 0-10MB/s lowest (100000 ints/s) |
| 1865 | * 10-20MB/s low (20000 ints/s) |
| 1866 | * 20-1249MB/s bulk (8000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1867 | */ |
| 1868 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1869 | timepassed_us = q_vector->itr >> 2; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1870 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1871 | |
| 1872 | switch (itr_setting) { |
| 1873 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1874 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1875 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1876 | break; |
| 1877 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1878 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1879 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1880 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1881 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1882 | break; |
| 1883 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1884 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1885 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1886 | break; |
| 1887 | } |
| 1888 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1889 | /* clear work counters since we have the values we need */ |
| 1890 | ring_container->total_bytes = 0; |
| 1891 | ring_container->total_packets = 0; |
| 1892 | |
| 1893 | /* write updated itr to ring container */ |
| 1894 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1895 | } |
| 1896 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1897 | /** |
| 1898 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1899 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1900 | * |
| 1901 | * This function is made to be called by ethtool and by the driver |
| 1902 | * when it needs to update EITR registers at runtime. Hardware |
| 1903 | * specific quirks/differences are taken care of here. |
| 1904 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1905 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1906 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1907 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1908 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1909 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 1910 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1911 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1912 | switch (adapter->hw.mac.type) { |
| 1913 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1914 | /* must write high and low 16 bits to reset counter */ |
| 1915 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1916 | break; |
| 1917 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1918 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1919 | /* |
| 1920 | * set the WDIS bit to not clear the timer bits and cause an |
| 1921 | * immediate assertion of the interrupt |
| 1922 | */ |
| 1923 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1924 | break; |
| 1925 | default: |
| 1926 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1927 | } |
| 1928 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1929 | } |
| 1930 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1931 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1932 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1933 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1934 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1935 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1936 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 1937 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1938 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1939 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1940 | |
| 1941 | switch (current_itr) { |
| 1942 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1943 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1944 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1945 | break; |
| 1946 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1947 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1948 | break; |
| 1949 | case bulk_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1950 | new_itr = IXGBE_8K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1951 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1952 | default: |
| 1953 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1954 | } |
| 1955 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1956 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1957 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1958 | new_itr = (10 * new_itr * q_vector->itr) / |
| 1959 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1960 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1961 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 1962 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1963 | |
| 1964 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1965 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1966 | } |
| 1967 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1968 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 1969 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1970 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1971 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1972 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1973 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1974 | struct ixgbe_hw *hw = &adapter->hw; |
| 1975 | u32 eicr = adapter->interrupt_event; |
| 1976 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1977 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1978 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1979 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1980 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1981 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 1982 | return; |
| 1983 | |
| 1984 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1985 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1986 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1987 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 1988 | /* |
| 1989 | * Since the warning interrupt is for both ports |
| 1990 | * we don't have to check if: |
| 1991 | * - This interrupt wasn't for our port. |
| 1992 | * - We may have missed the interrupt so always have to |
| 1993 | * check if we got a LSC |
| 1994 | */ |
| 1995 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 1996 | !(eicr & IXGBE_EICR_LSC)) |
| 1997 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1998 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1999 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
| 2000 | u32 autoneg; |
| 2001 | bool link_up = false; |
| 2002 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2003 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2004 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2005 | if (link_up) |
| 2006 | return; |
| 2007 | } |
| 2008 | |
| 2009 | /* Check if this is not due to overtemp */ |
| 2010 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2011 | return; |
| 2012 | |
| 2013 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2014 | default: |
| 2015 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 2016 | return; |
| 2017 | break; |
| 2018 | } |
| 2019 | e_crit(drv, |
| 2020 | "Network adapter has been stopped because it has over heated. " |
| 2021 | "Restart the computer. If the problem persists, " |
| 2022 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2023 | |
| 2024 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2027 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2028 | { |
| 2029 | struct ixgbe_hw *hw = &adapter->hw; |
| 2030 | |
| 2031 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 2032 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2033 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2034 | /* write to clear the interrupt */ |
| 2035 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 2036 | } |
| 2037 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2038 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2039 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2040 | { |
| 2041 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2042 | return; |
| 2043 | |
| 2044 | switch (adapter->hw.mac.type) { |
| 2045 | case ixgbe_mac_82599EB: |
| 2046 | /* |
| 2047 | * Need to check link state so complete overtemp check |
| 2048 | * on service task |
| 2049 | */ |
| 2050 | if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) && |
| 2051 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2052 | adapter->interrupt_event = eicr; |
| 2053 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2054 | ixgbe_service_event_schedule(adapter); |
| 2055 | return; |
| 2056 | } |
| 2057 | return; |
| 2058 | case ixgbe_mac_X540: |
| 2059 | if (!(eicr & IXGBE_EICR_TS)) |
| 2060 | return; |
| 2061 | break; |
| 2062 | default: |
| 2063 | return; |
| 2064 | } |
| 2065 | |
| 2066 | e_crit(drv, |
| 2067 | "Network adapter has been stopped because it has over heated. " |
| 2068 | "Restart the computer. If the problem persists, " |
| 2069 | "power off the system and replace the adapter\n"); |
| 2070 | } |
| 2071 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2072 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2073 | { |
| 2074 | struct ixgbe_hw *hw = &adapter->hw; |
| 2075 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2076 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 2077 | /* Clear the interrupt */ |
| 2078 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2079 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2080 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 2081 | ixgbe_service_event_schedule(adapter); |
| 2082 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2083 | } |
| 2084 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2085 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 2086 | /* Clear the interrupt */ |
| 2087 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2088 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2089 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2090 | ixgbe_service_event_schedule(adapter); |
| 2091 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2092 | } |
| 2093 | } |
| 2094 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2095 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2096 | { |
| 2097 | struct ixgbe_hw *hw = &adapter->hw; |
| 2098 | |
| 2099 | adapter->lsc_int++; |
| 2100 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2101 | adapter->link_check_timeout = jiffies; |
| 2102 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2103 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2104 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2105 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2106 | } |
| 2107 | } |
| 2108 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2109 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2110 | u64 qmask) |
| 2111 | { |
| 2112 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2113 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2114 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2115 | switch (hw->mac.type) { |
| 2116 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2117 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2118 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2119 | break; |
| 2120 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2121 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2122 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2123 | if (mask) |
| 2124 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2125 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2126 | if (mask) |
| 2127 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2128 | break; |
| 2129 | default: |
| 2130 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2131 | } |
| 2132 | /* skip the flush */ |
| 2133 | } |
| 2134 | |
| 2135 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2136 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2137 | { |
| 2138 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2139 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2140 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2141 | switch (hw->mac.type) { |
| 2142 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2143 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2144 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2145 | break; |
| 2146 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2147 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2148 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2149 | if (mask) |
| 2150 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2151 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2152 | if (mask) |
| 2153 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2154 | break; |
| 2155 | default: |
| 2156 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2157 | } |
| 2158 | /* skip the flush */ |
| 2159 | } |
| 2160 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2161 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2162 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2163 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2164 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2165 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2166 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2167 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2168 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2169 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2170 | /* don't reenable LSC while waiting for link */ |
| 2171 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2172 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2173 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2174 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2175 | switch (adapter->hw.mac.type) { |
| 2176 | case ixgbe_mac_82599EB: |
| 2177 | mask |= IXGBE_EIMS_GPI_SDP0; |
| 2178 | break; |
| 2179 | case ixgbe_mac_X540: |
| 2180 | mask |= IXGBE_EIMS_TS; |
| 2181 | break; |
| 2182 | default: |
| 2183 | break; |
| 2184 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2185 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2186 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2187 | switch (adapter->hw.mac.type) { |
| 2188 | case ixgbe_mac_82599EB: |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2189 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2190 | mask |= IXGBE_EIMS_GPI_SDP2; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2191 | case ixgbe_mac_X540: |
| 2192 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2193 | mask |= IXGBE_EIMS_MAILBOX; |
| 2194 | break; |
| 2195 | default: |
| 2196 | break; |
| 2197 | } |
| 2198 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2199 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2200 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2201 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2202 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2203 | if (queues) |
| 2204 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2205 | if (flush) |
| 2206 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2209 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2210 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2211 | struct ixgbe_adapter *adapter = data; |
| 2212 | struct ixgbe_hw *hw = &adapter->hw; |
| 2213 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2214 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2215 | /* |
| 2216 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2217 | * of clear-by-read. Reading with EICS will return the |
| 2218 | * interrupt causes without clearing, which later be done |
| 2219 | * with the write to EICR. |
| 2220 | */ |
| 2221 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 2222 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2223 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2224 | if (eicr & IXGBE_EICR_LSC) |
| 2225 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2226 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2227 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2228 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2229 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2230 | switch (hw->mac.type) { |
| 2231 | case ixgbe_mac_82599EB: |
| 2232 | case ixgbe_mac_X540: |
| 2233 | if (eicr & IXGBE_EICR_ECC) |
| 2234 | e_info(link, "Received unrecoverable ECC Err, please " |
| 2235 | "reboot\n"); |
| 2236 | /* Handle Flow Director Full threshold interrupt */ |
| 2237 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2238 | int reinit_count = 0; |
| 2239 | int i; |
| 2240 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2241 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2242 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2243 | &ring->state)) |
| 2244 | reinit_count++; |
| 2245 | } |
| 2246 | if (reinit_count) { |
| 2247 | /* no more flow director interrupts until after init */ |
| 2248 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2249 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2250 | ixgbe_service_event_schedule(adapter); |
| 2251 | } |
| 2252 | } |
| 2253 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2254 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2255 | break; |
| 2256 | default: |
| 2257 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2260 | ixgbe_check_fan_failure(adapter, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2261 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2262 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2263 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2264 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2265 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2266 | return IRQ_HANDLED; |
| 2267 | } |
| 2268 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2269 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2270 | { |
| 2271 | struct ixgbe_q_vector *q_vector = data; |
| 2272 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2273 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2274 | |
| 2275 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 2276 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2277 | |
| 2278 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2281 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2282 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2283 | * @adapter: board private structure |
| 2284 | * |
| 2285 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2286 | * interrupts from the kernel. |
| 2287 | **/ |
| 2288 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2289 | { |
| 2290 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2291 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2292 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2293 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2294 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2295 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2296 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2297 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2298 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2299 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2300 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2301 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2302 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2303 | } else if (q_vector->rx.ring) { |
| 2304 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2305 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2306 | } else if (q_vector->tx.ring) { |
| 2307 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2308 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2309 | } else { |
| 2310 | /* skip this unused q_vector */ |
| 2311 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2312 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2313 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2314 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2315 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2316 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2317 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2318 | goto free_queue_irqs; |
| 2319 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2320 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2321 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2322 | /* assign the mask for this irq */ |
| 2323 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2324 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2325 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2326 | } |
| 2327 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2328 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2329 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2330 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2331 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2332 | goto free_queue_irqs; |
| 2333 | } |
| 2334 | |
| 2335 | return 0; |
| 2336 | |
| 2337 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2338 | while (vector) { |
| 2339 | vector--; |
| 2340 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2341 | NULL); |
| 2342 | free_irq(adapter->msix_entries[vector].vector, |
| 2343 | adapter->q_vector[vector]); |
| 2344 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2345 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2346 | pci_disable_msix(adapter->pdev); |
| 2347 | kfree(adapter->msix_entries); |
| 2348 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2349 | return err; |
| 2350 | } |
| 2351 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2352 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2353 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2354 | * @irq: interrupt number |
| 2355 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2356 | **/ |
| 2357 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2358 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2359 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2360 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2361 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2362 | u32 eicr; |
| 2363 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2364 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2365 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2366 | * before the read of EICR. |
| 2367 | */ |
| 2368 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2369 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2370 | /* 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] | 2371 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2372 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2373 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2374 | /* |
| 2375 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2376 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2377 | * have disabled interrupts due to EIAM |
| 2378 | * finish the workaround of silicon errata on 82598. Unmask |
| 2379 | * the interrupt that we masked before the EICR read. |
| 2380 | */ |
| 2381 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2382 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2383 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2384 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2385 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2386 | if (eicr & IXGBE_EICR_LSC) |
| 2387 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2388 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2389 | switch (hw->mac.type) { |
| 2390 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2391 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 2392 | /* Fall through */ |
| 2393 | case ixgbe_mac_X540: |
| 2394 | if (eicr & IXGBE_EICR_ECC) |
| 2395 | e_info(link, "Received unrecoverable ECC err, please " |
| 2396 | "reboot\n"); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2397 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2398 | break; |
| 2399 | default: |
| 2400 | break; |
| 2401 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2402 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2403 | ixgbe_check_fan_failure(adapter, eicr); |
| 2404 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 2405 | /* would disable interrupts here but EIAM disabled it */ |
| 2406 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2407 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2408 | /* |
| 2409 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2410 | * ixgbe_poll will re-enable the queue interrupts |
| 2411 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2412 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2413 | ixgbe_irq_enable(adapter, false, false); |
| 2414 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2415 | return IRQ_HANDLED; |
| 2416 | } |
| 2417 | |
| 2418 | /** |
| 2419 | * ixgbe_request_irq - initialize interrupts |
| 2420 | * @adapter: board private structure |
| 2421 | * |
| 2422 | * Attempts to configure interrupts using the best available |
| 2423 | * capabilities of the hardware and kernel. |
| 2424 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2425 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2426 | { |
| 2427 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2428 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2429 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2430 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2431 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2432 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2433 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2434 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2435 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2436 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2437 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2438 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2439 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2440 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2441 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2442 | return err; |
| 2443 | } |
| 2444 | |
| 2445 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2446 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2447 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2448 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2449 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2450 | q_vectors = adapter->num_msix_vectors; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2451 | i = q_vectors - 1; |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2452 | free_irq(adapter->msix_entries[i].vector, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2453 | i--; |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2454 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2455 | for (; i >= 0; i--) { |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2456 | /* free only the irqs that were actually requested */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2457 | if (!adapter->q_vector[i]->rx.ring && |
| 2458 | !adapter->q_vector[i]->tx.ring) |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2459 | continue; |
| 2460 | |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2461 | /* clear the affinity_mask in the IRQ descriptor */ |
| 2462 | irq_set_affinity_hint(adapter->msix_entries[i].vector, |
| 2463 | NULL); |
| 2464 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2465 | free_irq(adapter->msix_entries[i].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2466 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2467 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2468 | } else { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2469 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2474 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2475 | * @adapter: board private structure |
| 2476 | **/ |
| 2477 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2478 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2479 | switch (adapter->hw.mac.type) { |
| 2480 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2481 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2482 | break; |
| 2483 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2484 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2485 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2486 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2487 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2488 | break; |
| 2489 | default: |
| 2490 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2491 | } |
| 2492 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2493 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2494 | int i; |
| 2495 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 2496 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2497 | } else { |
| 2498 | synchronize_irq(adapter->pdev->irq); |
| 2499 | } |
| 2500 | } |
| 2501 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2502 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2503 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2504 | * |
| 2505 | **/ |
| 2506 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2507 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2508 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2509 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2510 | /* rx/tx vector */ |
| 2511 | if (adapter->rx_itr_setting == 1) |
| 2512 | q_vector->itr = IXGBE_20K_ITR; |
| 2513 | else |
| 2514 | q_vector->itr = adapter->rx_itr_setting; |
| 2515 | |
| 2516 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2517 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2518 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2519 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2520 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2521 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2524 | /** |
| 2525 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2526 | * @adapter: board private structure |
| 2527 | * @ring: structure containing ring specific data |
| 2528 | * |
| 2529 | * Configure the Tx descriptor ring after a reset. |
| 2530 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2531 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2532 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2533 | { |
| 2534 | struct ixgbe_hw *hw = &adapter->hw; |
| 2535 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2536 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2537 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2538 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2539 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2540 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2541 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2542 | IXGBE_WRITE_FLUSH(hw); |
| 2543 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2544 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2545 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2546 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2547 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2548 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2549 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2550 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2551 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2552 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2553 | /* |
| 2554 | * set WTHRESH to encourage burst writeback, it should not be set |
| 2555 | * higher than 1 when ITR is 0 as it could cause false TX hangs |
| 2556 | * |
| 2557 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 2558 | * to or less than the number of on chip descriptors, which is |
| 2559 | * currently 40. |
| 2560 | */ |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2561 | if (!ring->q_vector || (ring->q_vector->itr < 8)) |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2562 | txdctl |= (1 << 16); /* WTHRESH = 1 */ |
| 2563 | else |
| 2564 | txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 2565 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2566 | /* |
| 2567 | * Setting PTHRESH to 32 both improves performance |
| 2568 | * and avoids a TX hang with DFP enabled |
| 2569 | */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2570 | txdctl |= (1 << 8) | /* HTHRESH = 1 */ |
| 2571 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2572 | |
| 2573 | /* reinitialize flowdirector state */ |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2574 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2575 | adapter->atr_sample_rate) { |
| 2576 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2577 | ring->atr_count = 0; |
| 2578 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2579 | } else { |
| 2580 | ring->atr_sample_rate = 0; |
| 2581 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2582 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2583 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2584 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2585 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2586 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2587 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 2588 | netdev_tx_reset_queue(txring_txq(ring)); |
| 2589 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2590 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2591 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2592 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2593 | return; |
| 2594 | |
| 2595 | /* poll to verify queue is enabled */ |
| 2596 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2597 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2598 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2599 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2600 | if (!wait_loop) |
| 2601 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2604 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2605 | { |
| 2606 | struct ixgbe_hw *hw = &adapter->hw; |
| 2607 | u32 rttdcs; |
John Fastabend | 72a32f1 | 2011-04-26 07:25:58 +0000 | [diff] [blame] | 2608 | u32 reg; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2609 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2610 | |
| 2611 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2612 | return; |
| 2613 | |
| 2614 | /* disable the arbiter while setting MTQC */ |
| 2615 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2616 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2617 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2618 | |
| 2619 | /* set transmit pool layout */ |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2620 | switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2621 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2622 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2623 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2624 | break; |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2625 | default: |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2626 | if (!tcs) |
| 2627 | reg = IXGBE_MTQC_64Q_1PB; |
| 2628 | else if (tcs <= 4) |
| 2629 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2630 | else |
| 2631 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2632 | |
| 2633 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg); |
| 2634 | |
| 2635 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 2636 | if (tcs) { |
| 2637 | reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 2638 | reg |= IXGBE_SECTX_DCB; |
| 2639 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg); |
| 2640 | } |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2641 | break; |
| 2642 | } |
| 2643 | |
| 2644 | /* re-enable the arbiter */ |
| 2645 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2646 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2647 | } |
| 2648 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2649 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2650 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2651 | * @adapter: board private structure |
| 2652 | * |
| 2653 | * Configure the Tx unit of the MAC after a reset. |
| 2654 | **/ |
| 2655 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2656 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2657 | struct ixgbe_hw *hw = &adapter->hw; |
| 2658 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2659 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2660 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2661 | ixgbe_setup_mtqc(adapter); |
| 2662 | |
| 2663 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2664 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2665 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2666 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2667 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2668 | } |
| 2669 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2670 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2671 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2672 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2675 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2676 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2677 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2678 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2679 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2680 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2681 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2682 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2683 | switch (adapter->hw.mac.type) { |
| 2684 | case ixgbe_mac_82598EB: { |
| 2685 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
| 2686 | const int mask = feature[RING_F_RSS].mask; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2687 | reg_idx = reg_idx & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2688 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2689 | break; |
| 2690 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2691 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2692 | default: |
| 2693 | break; |
| 2694 | } |
| 2695 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2696 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2697 | |
| 2698 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2699 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2700 | if (adapter->num_vfs) |
| 2701 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2702 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2703 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2704 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2705 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2706 | #if PAGE_SIZE > IXGBE_MAX_RXBUFFER |
| 2707 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2708 | #else |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2709 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2710 | #endif |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2711 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2712 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2713 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2716 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2717 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2718 | struct ixgbe_hw *hw = &adapter->hw; |
| 2719 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2720 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2721 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2722 | u32 mrqc = 0, reta = 0; |
| 2723 | u32 rxcsum; |
| 2724 | int i, j; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2725 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2726 | int maxq = adapter->ring_feature[RING_F_RSS].indices; |
| 2727 | |
| 2728 | if (tcs) |
| 2729 | maxq = min(maxq, adapter->num_tx_queues / tcs); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2730 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2731 | /* Fill out hash function seeds */ |
| 2732 | for (i = 0; i < 10; i++) |
| 2733 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2734 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2735 | /* Fill out redirection table */ |
| 2736 | for (i = 0, j = 0; i < 128; i++, j++) { |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2737 | if (j == maxq) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2738 | j = 0; |
| 2739 | /* reta = 4-byte sliding window of |
| 2740 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2741 | reta = (reta << 8) | (j * 0x11); |
| 2742 | if ((i & 3) == 3) |
| 2743 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 2744 | } |
| 2745 | |
| 2746 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 2747 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2748 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2749 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 2750 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2751 | if (adapter->hw.mac.type == ixgbe_mac_82598EB && |
| 2752 | (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2753 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2754 | } else { |
| 2755 | int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2756 | | IXGBE_FLAG_SRIOV_ENABLED); |
| 2757 | |
| 2758 | switch (mask) { |
| 2759 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2760 | if (!tcs) |
| 2761 | mrqc = IXGBE_MRQC_RSSEN; |
| 2762 | else if (tcs <= 4) |
| 2763 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 2764 | else |
| 2765 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 2766 | break; |
| 2767 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2768 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2769 | break; |
| 2770 | default: |
| 2771 | break; |
| 2772 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2775 | /* Perform hash on these packet types */ |
| 2776 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2777 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2778 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2779 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2780 | |
| 2781 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2784 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2785 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2786 | * @adapter: address of board private structure |
| 2787 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2788 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 2789 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2790 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2791 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2792 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2793 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2794 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2795 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2796 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2797 | return; |
| 2798 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2799 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2800 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2801 | /* |
| 2802 | * we must limit the number of descriptors so that the |
| 2803 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 2804 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2805 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2806 | #if (PAGE_SIZE <= 8192) |
| 2807 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2808 | #elif (PAGE_SIZE <= 16384) |
| 2809 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2810 | #else |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2811 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2812 | #endif |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2813 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2814 | } |
| 2815 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2816 | /** |
| 2817 | * ixgbe_set_uta - Set unicast filter table address |
| 2818 | * @adapter: board private structure |
| 2819 | * |
| 2820 | * The unicast table address is a register array of 32-bit registers. |
| 2821 | * The table is meant to be used in a way similar to how the MTA is used |
| 2822 | * however due to certain limitations in the hardware it is necessary to |
| 2823 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 2824 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
| 2825 | **/ |
| 2826 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) |
| 2827 | { |
| 2828 | struct ixgbe_hw *hw = &adapter->hw; |
| 2829 | int i; |
| 2830 | |
| 2831 | /* The UTA table only exists on 82599 hardware and newer */ |
| 2832 | if (hw->mac.type < ixgbe_mac_82599EB) |
| 2833 | return; |
| 2834 | |
| 2835 | /* we only need to do this if VMDq is enabled */ |
| 2836 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2837 | return; |
| 2838 | |
| 2839 | for (i = 0; i < 128; i++) |
| 2840 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); |
| 2841 | } |
| 2842 | |
| 2843 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2844 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2845 | struct ixgbe_ring *ring) |
| 2846 | { |
| 2847 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2848 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2849 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2850 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2851 | |
| 2852 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2853 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2854 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2855 | return; |
| 2856 | |
| 2857 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2858 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2859 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2860 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2861 | |
| 2862 | if (!wait_loop) { |
| 2863 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 2864 | "the polling period\n", reg_idx); |
| 2865 | } |
| 2866 | } |
| 2867 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2868 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 2869 | struct ixgbe_ring *ring) |
| 2870 | { |
| 2871 | struct ixgbe_hw *hw = &adapter->hw; |
| 2872 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2873 | u32 rxdctl; |
| 2874 | u8 reg_idx = ring->reg_idx; |
| 2875 | |
| 2876 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2877 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 2878 | |
| 2879 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 2880 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2881 | |
| 2882 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2883 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2884 | return; |
| 2885 | |
| 2886 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 2887 | do { |
| 2888 | udelay(10); |
| 2889 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2890 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2891 | |
| 2892 | if (!wait_loop) { |
| 2893 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 2894 | "the polling period\n", reg_idx); |
| 2895 | } |
| 2896 | } |
| 2897 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2898 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 2899 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2900 | { |
| 2901 | struct ixgbe_hw *hw = &adapter->hw; |
| 2902 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2903 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2904 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2905 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2906 | /* disable queue to avoid issues while updating state */ |
| 2907 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2908 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2909 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2910 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 2911 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 2912 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 2913 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 2914 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 2915 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2916 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2917 | |
| 2918 | ixgbe_configure_srrctl(adapter, ring); |
| 2919 | ixgbe_configure_rscctl(adapter, ring); |
| 2920 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 2921 | /* If operating in IOV mode set RLPML for X540 */ |
| 2922 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 2923 | hw->mac.type == ixgbe_mac_X540) { |
| 2924 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 2925 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 2926 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 2927 | } |
| 2928 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2929 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2930 | /* |
| 2931 | * enable cache line friendly hardware writes: |
| 2932 | * PTHRESH=32 descriptors (half the internal cache), |
| 2933 | * this also removes ugly rx_no_buffer_count increment |
| 2934 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 2935 | * WTHRESH=8 burst writeback up to two cache lines |
| 2936 | */ |
| 2937 | rxdctl &= ~0x3FFFFF; |
| 2938 | rxdctl |= 0x080420; |
| 2939 | } |
| 2940 | |
| 2941 | /* enable receive descriptor ring */ |
| 2942 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 2943 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2944 | |
| 2945 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 2946 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2949 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 2950 | { |
| 2951 | struct ixgbe_hw *hw = &adapter->hw; |
| 2952 | int p; |
| 2953 | |
| 2954 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 2955 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2956 | IXGBE_PSRTYPE_UDPHDR | |
| 2957 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2958 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2959 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2960 | |
| 2961 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2962 | return; |
| 2963 | |
| 2964 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) |
| 2965 | psrtype |= (adapter->num_rx_queues_per_pool << 29); |
| 2966 | |
| 2967 | for (p = 0; p < adapter->num_rx_pools; p++) |
| 2968 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), |
| 2969 | psrtype); |
| 2970 | } |
| 2971 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2972 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 2973 | { |
| 2974 | struct ixgbe_hw *hw = &adapter->hw; |
| 2975 | u32 gcr_ext; |
| 2976 | u32 vt_reg_bits; |
| 2977 | u32 reg_offset, vf_shift; |
| 2978 | u32 vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 2979 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2980 | |
| 2981 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2982 | return; |
| 2983 | |
| 2984 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 2985 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; |
| 2986 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); |
| 2987 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 2988 | |
| 2989 | vf_shift = adapter->num_vfs % 32; |
Greg Rose | 4cd6923 | 2012-01-25 07:59:37 +0000 | [diff] [blame] | 2990 | reg_offset = (adapter->num_vfs >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2991 | |
| 2992 | /* Enable only the PF's pool for Tx/Rx */ |
| 2993 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 2994 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); |
| 2995 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 2996 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); |
| 2997 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 2998 | |
| 2999 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
| 3000 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 3001 | |
| 3002 | /* |
| 3003 | * Set up VF register offsets for selected VT Mode, |
| 3004 | * i.e. 32 or 64 VFs for SR-IOV |
| 3005 | */ |
| 3006 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3007 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; |
| 3008 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; |
| 3009 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3010 | |
| 3011 | /* enable Tx loopback for VF/PF communication */ |
| 3012 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3013 | /* Enable MAC Anti-Spoofing */ |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3014 | hw->mac.ops.set_mac_anti_spoofing(hw, |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3015 | (adapter->num_vfs != 0), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3016 | adapter->num_vfs); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3017 | /* For VFs that have spoof checking turned off */ |
| 3018 | for (i = 0; i < adapter->num_vfs; i++) { |
| 3019 | if (!adapter->vfinfo[i].spoofchk_enabled) |
| 3020 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false); |
| 3021 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3024 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3025 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3026 | struct ixgbe_hw *hw = &adapter->hw; |
| 3027 | struct net_device *netdev = adapter->netdev; |
| 3028 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3029 | struct ixgbe_ring *rx_ring; |
| 3030 | int i; |
| 3031 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3032 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3033 | #ifdef IXGBE_FCOE |
| 3034 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3035 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3036 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3037 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3038 | |
| 3039 | #endif /* IXGBE_FCOE */ |
| 3040 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3041 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3042 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3043 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3044 | |
| 3045 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
Alexander Duyck | 919e78a | 2011-08-26 09:52:38 +0000 | [diff] [blame] | 3048 | /* MHADD will allow an extra 4 bytes past for vlan tagged frames */ |
| 3049 | max_frame += VLAN_HLEN; |
| 3050 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3051 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3052 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3053 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3054 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3055 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3056 | /* |
| 3057 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3058 | * the Base and Length of the Rx Descriptor Ring |
| 3059 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3060 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3061 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3062 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3063 | set_ring_rsc_enabled(rx_ring); |
| 3064 | else |
| 3065 | clear_ring_rsc_enabled(rx_ring); |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3066 | #ifdef IXGBE_FCOE |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3067 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3068 | struct ixgbe_ring_feature *f; |
| 3069 | f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3070 | if ((i >= f->mask) && (i < f->mask + f->indices)) |
| 3071 | set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state); |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3072 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3073 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3074 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3075 | } |
| 3076 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3077 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3078 | { |
| 3079 | struct ixgbe_hw *hw = &adapter->hw; |
| 3080 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3081 | |
| 3082 | switch (hw->mac.type) { |
| 3083 | case ixgbe_mac_82598EB: |
| 3084 | /* |
| 3085 | * For VMDq support of different descriptor types or |
| 3086 | * buffer sizes through the use of multiple SRRCTL |
| 3087 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3088 | * |
| 3089 | * also, the manual doesn't mention it clearly but DCA hints |
| 3090 | * will only use queue 0's tags unless this bit is set. Side |
| 3091 | * effects of setting this bit are only that SRRCTL must be |
| 3092 | * fully programmed [0..15] |
| 3093 | */ |
| 3094 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3095 | break; |
| 3096 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3097 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3098 | /* Disable RSC for ACK packets */ |
| 3099 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3100 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3101 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3102 | /* hardware requires some bits to be set by default */ |
| 3103 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3104 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3105 | break; |
| 3106 | default: |
| 3107 | /* We should do nothing since we don't know this hardware */ |
| 3108 | return; |
| 3109 | } |
| 3110 | |
| 3111 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3112 | } |
| 3113 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3114 | /** |
| 3115 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3116 | * @adapter: board private structure |
| 3117 | * |
| 3118 | * Configure the Rx unit of the MAC after a reset. |
| 3119 | **/ |
| 3120 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3121 | { |
| 3122 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3123 | int i; |
| 3124 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3125 | |
| 3126 | /* disable receives while setting up the descriptors */ |
| 3127 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3128 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3129 | |
| 3130 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3131 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3132 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3133 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3134 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3135 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3136 | ixgbe_set_uta(adapter); |
| 3137 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3138 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3139 | ixgbe_set_rx_buffer_len(adapter); |
| 3140 | |
| 3141 | /* |
| 3142 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3143 | * the Base and Length of the Rx Descriptor Ring |
| 3144 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3145 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3146 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3147 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3148 | /* disable drop enable for 82598 parts */ |
| 3149 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3150 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3151 | |
| 3152 | /* enable all receives */ |
| 3153 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3154 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3155 | } |
| 3156 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3157 | 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] | 3158 | { |
| 3159 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3160 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3161 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3162 | |
| 3163 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3164 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3165 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3166 | |
| 3167 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3170 | 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] | 3171 | { |
| 3172 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3173 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3174 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3175 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3176 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3177 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3178 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3179 | |
| 3180 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3183 | /** |
| 3184 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3185 | * @adapter: driver data |
| 3186 | */ |
| 3187 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3188 | { |
| 3189 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3190 | u32 vlnctrl; |
| 3191 | |
| 3192 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3193 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3194 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3195 | } |
| 3196 | |
| 3197 | /** |
| 3198 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3199 | * @adapter: driver data |
| 3200 | */ |
| 3201 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3202 | { |
| 3203 | struct ixgbe_hw *hw = &adapter->hw; |
| 3204 | u32 vlnctrl; |
| 3205 | |
| 3206 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3207 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3208 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3209 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3210 | } |
| 3211 | |
| 3212 | /** |
| 3213 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3214 | * @adapter: driver data |
| 3215 | */ |
| 3216 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3217 | { |
| 3218 | struct ixgbe_hw *hw = &adapter->hw; |
| 3219 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3220 | int i, j; |
| 3221 | |
| 3222 | switch (hw->mac.type) { |
| 3223 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3224 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3225 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3226 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3227 | break; |
| 3228 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3229 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3230 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3231 | j = adapter->rx_ring[i]->reg_idx; |
| 3232 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3233 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3234 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3235 | } |
| 3236 | break; |
| 3237 | default: |
| 3238 | break; |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3243 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3244 | * @adapter: driver data |
| 3245 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3246 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3247 | { |
| 3248 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3249 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3250 | int i, j; |
| 3251 | |
| 3252 | switch (hw->mac.type) { |
| 3253 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3254 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3255 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3256 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3257 | break; |
| 3258 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3259 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3260 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3261 | j = adapter->rx_ring[i]->reg_idx; |
| 3262 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3263 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3264 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3265 | } |
| 3266 | break; |
| 3267 | default: |
| 3268 | break; |
| 3269 | } |
| 3270 | } |
| 3271 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3272 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3273 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3274 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3275 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3276 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3277 | |
| 3278 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3279 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3283 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3284 | * @netdev: network interface device structure |
| 3285 | * |
| 3286 | * Writes unicast address list to the RAR table. |
| 3287 | * Returns: -ENOMEM on failure/insufficient address space |
| 3288 | * 0 on no addresses written |
| 3289 | * X on writing X addresses to the RAR table |
| 3290 | **/ |
| 3291 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3292 | { |
| 3293 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3294 | struct ixgbe_hw *hw = &adapter->hw; |
| 3295 | unsigned int vfn = adapter->num_vfs; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3296 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3297 | int count = 0; |
| 3298 | |
| 3299 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3300 | if (netdev_uc_count(netdev) > rar_entries) |
| 3301 | return -ENOMEM; |
| 3302 | |
| 3303 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3304 | struct netdev_hw_addr *ha; |
| 3305 | /* return error if we do not support writing to RAR table */ |
| 3306 | if (!hw->mac.ops.set_rar) |
| 3307 | return -ENOMEM; |
| 3308 | |
| 3309 | netdev_for_each_uc_addr(ha, netdev) { |
| 3310 | if (!rar_entries) |
| 3311 | break; |
| 3312 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
| 3313 | vfn, IXGBE_RAH_AV); |
| 3314 | count++; |
| 3315 | } |
| 3316 | } |
| 3317 | /* write the addresses in reverse order to avoid write combining */ |
| 3318 | for (; rar_entries > 0 ; rar_entries--) |
| 3319 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3320 | |
| 3321 | return count; |
| 3322 | } |
| 3323 | |
| 3324 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3325 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3326 | * @netdev: network interface device structure |
| 3327 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3328 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3329 | * address list or the network interface flags are updated. This routine is |
| 3330 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3331 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3332 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3333 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3334 | { |
| 3335 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3336 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3337 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3338 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3339 | |
| 3340 | /* Check for Promiscuous and All Multicast modes */ |
| 3341 | |
| 3342 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3343 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3344 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3345 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3346 | fctrl |= IXGBE_FCTRL_BAM; |
| 3347 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3348 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3349 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3350 | /* clear the bits we are changing the status of */ |
| 3351 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3352 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3353 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3354 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3355 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3356 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3357 | /* don't hardware filter vlans in promisc mode */ |
| 3358 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3359 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3360 | if (netdev->flags & IFF_ALLMULTI) { |
| 3361 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3362 | vmolr |= IXGBE_VMOLR_MPE; |
| 3363 | } else { |
| 3364 | /* |
| 3365 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3366 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3367 | * that we can at least receive multicast traffic |
| 3368 | */ |
| 3369 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3370 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3371 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3372 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3373 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3374 | /* |
| 3375 | * Write addresses to available RAR registers, if there is not |
| 3376 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3377 | * unicast promiscuous mode |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3378 | */ |
| 3379 | count = ixgbe_write_uc_addr_list(netdev); |
| 3380 | if (count < 0) { |
| 3381 | fctrl |= IXGBE_FCTRL_UPE; |
| 3382 | vmolr |= IXGBE_VMOLR_ROPE; |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | if (adapter->num_vfs) { |
| 3387 | ixgbe_restore_vf_multicasts(adapter); |
| 3388 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & |
| 3389 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3390 | IXGBE_VMOLR_ROPE); |
| 3391 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3394 | /* This is useful for sniffing bad packets. */ |
| 3395 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3396 | /* UPE and MPE will be handled by normal PROMISC logic |
| 3397 | * in e1000e_set_rx_mode */ |
| 3398 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 3399 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 3400 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 3401 | |
| 3402 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 3403 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 3404 | } |
| 3405 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3406 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3407 | |
| 3408 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3409 | ixgbe_vlan_strip_enable(adapter); |
| 3410 | else |
| 3411 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3414 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3415 | { |
| 3416 | int q_idx; |
| 3417 | struct ixgbe_q_vector *q_vector; |
| 3418 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3419 | |
| 3420 | /* legacy and MSI only use one vector */ |
| 3421 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3422 | q_vectors = 1; |
| 3423 | |
| 3424 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3425 | q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3426 | napi_enable(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3427 | } |
| 3428 | } |
| 3429 | |
| 3430 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3431 | { |
| 3432 | int q_idx; |
| 3433 | struct ixgbe_q_vector *q_vector; |
| 3434 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3435 | |
| 3436 | /* legacy and MSI only use one vector */ |
| 3437 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3438 | q_vectors = 1; |
| 3439 | |
| 3440 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3441 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3442 | napi_disable(&q_vector->napi); |
| 3443 | } |
| 3444 | } |
| 3445 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3446 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3447 | /* |
| 3448 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3449 | * @adapter: ixgbe adapter struct |
| 3450 | * |
| 3451 | * This is called by the driver on open to configure the DCB hardware. |
| 3452 | * This is also called by the gennetlink interface when reconfiguring |
| 3453 | * the DCB state. |
| 3454 | */ |
| 3455 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3456 | { |
| 3457 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3458 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3459 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3460 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3461 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3462 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3463 | return; |
| 3464 | } |
| 3465 | |
| 3466 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3467 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3468 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3469 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3470 | /* Enable VLAN tag insert/strip */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3471 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3472 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3473 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3474 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3475 | #ifdef IXGBE_FCOE |
| 3476 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3477 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3478 | #endif |
| 3479 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3480 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3481 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3482 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3483 | DCB_TX_CONFIG); |
| 3484 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3485 | DCB_RX_CONFIG); |
| 3486 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3487 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 3488 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 3489 | adapter->ixgbe_ieee_ets, |
| 3490 | max_frame); |
| 3491 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 3492 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 3493 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3494 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3495 | |
| 3496 | /* Enable RSS Hash per TC */ |
| 3497 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3498 | int i; |
| 3499 | u32 reg = 0; |
| 3500 | |
| 3501 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 3502 | u8 msb = 0; |
| 3503 | u8 cnt = adapter->netdev->tc_to_txq[i].count; |
| 3504 | |
| 3505 | while (cnt >>= 1) |
| 3506 | msb++; |
| 3507 | |
| 3508 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); |
| 3509 | } |
| 3510 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); |
| 3511 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3512 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3513 | #endif |
| 3514 | |
| 3515 | /* Additional bittime to account for IXGBE framing */ |
| 3516 | #define IXGBE_ETH_FRAMING 20 |
| 3517 | |
| 3518 | /* |
| 3519 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 3520 | * |
| 3521 | * @adapter: board private structure to calculate for |
| 3522 | * @pb - packet buffer to calculate |
| 3523 | */ |
| 3524 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 3525 | { |
| 3526 | struct ixgbe_hw *hw = &adapter->hw; |
| 3527 | struct net_device *dev = adapter->netdev; |
| 3528 | int link, tc, kb, marker; |
| 3529 | u32 dv_id, rx_pba; |
| 3530 | |
| 3531 | /* Calculate max LAN frame size */ |
| 3532 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 3533 | |
| 3534 | #ifdef IXGBE_FCOE |
| 3535 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 3536 | if (dev->features & NETIF_F_FCOE_MTU) { |
| 3537 | int fcoe_pb = 0; |
| 3538 | |
| 3539 | #ifdef CONFIG_IXGBE_DCB |
| 3540 | fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3541 | |
| 3542 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3543 | if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 3544 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3545 | } |
| 3546 | #endif |
| 3547 | |
| 3548 | /* Calculate delay value for device */ |
| 3549 | switch (hw->mac.type) { |
| 3550 | case ixgbe_mac_X540: |
| 3551 | dv_id = IXGBE_DV_X540(link, tc); |
| 3552 | break; |
| 3553 | default: |
| 3554 | dv_id = IXGBE_DV(link, tc); |
| 3555 | break; |
| 3556 | } |
| 3557 | |
| 3558 | /* Loopback switch introduces additional latency */ |
| 3559 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3560 | dv_id += IXGBE_B2BT(tc); |
| 3561 | |
| 3562 | /* Delay value is calculated in bit times convert to KB */ |
| 3563 | kb = IXGBE_BT2KB(dv_id); |
| 3564 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 3565 | |
| 3566 | marker = rx_pba - kb; |
| 3567 | |
| 3568 | /* It is possible that the packet buffer is not large enough |
| 3569 | * to provide required headroom. In this case throw an error |
| 3570 | * to user and a do the best we can. |
| 3571 | */ |
| 3572 | if (marker < 0) { |
| 3573 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 3574 | "headroom to support flow control." |
| 3575 | "Decrease MTU or number of traffic classes\n", pb); |
| 3576 | marker = tc + 1; |
| 3577 | } |
| 3578 | |
| 3579 | return marker; |
| 3580 | } |
| 3581 | |
| 3582 | /* |
| 3583 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 3584 | * |
| 3585 | * @adapter: board private structure to calculate for |
| 3586 | * @pb - packet buffer to calculate |
| 3587 | */ |
| 3588 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter) |
| 3589 | { |
| 3590 | struct ixgbe_hw *hw = &adapter->hw; |
| 3591 | struct net_device *dev = adapter->netdev; |
| 3592 | int tc; |
| 3593 | u32 dv_id; |
| 3594 | |
| 3595 | /* Calculate max LAN frame size */ |
| 3596 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3597 | |
| 3598 | /* Calculate delay value for device */ |
| 3599 | switch (hw->mac.type) { |
| 3600 | case ixgbe_mac_X540: |
| 3601 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 3602 | break; |
| 3603 | default: |
| 3604 | dv_id = IXGBE_LOW_DV(tc); |
| 3605 | break; |
| 3606 | } |
| 3607 | |
| 3608 | /* Delay value is calculated in bit times convert to KB */ |
| 3609 | return IXGBE_BT2KB(dv_id); |
| 3610 | } |
| 3611 | |
| 3612 | /* |
| 3613 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 3614 | */ |
| 3615 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 3616 | { |
| 3617 | struct ixgbe_hw *hw = &adapter->hw; |
| 3618 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3619 | int i; |
| 3620 | |
| 3621 | if (!num_tc) |
| 3622 | num_tc = 1; |
| 3623 | |
| 3624 | hw->fc.low_water = ixgbe_lpbthresh(adapter); |
| 3625 | |
| 3626 | for (i = 0; i < num_tc; i++) { |
| 3627 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
| 3628 | |
| 3629 | /* Low water marks must not be larger than high water marks */ |
| 3630 | if (hw->fc.low_water > hw->fc.high_water[i]) |
| 3631 | hw->fc.low_water = 0; |
| 3632 | } |
| 3633 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3634 | |
| 3635 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3636 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3637 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3638 | int hdrm; |
| 3639 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3640 | |
| 3641 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3642 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3643 | hdrm = 32 << adapter->fdir_pballoc; |
| 3644 | else |
| 3645 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3646 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3647 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3648 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3649 | } |
| 3650 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3651 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 3652 | { |
| 3653 | struct ixgbe_hw *hw = &adapter->hw; |
| 3654 | struct hlist_node *node, *node2; |
| 3655 | struct ixgbe_fdir_filter *filter; |
| 3656 | |
| 3657 | spin_lock(&adapter->fdir_perfect_lock); |
| 3658 | |
| 3659 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 3660 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 3661 | |
| 3662 | hlist_for_each_entry_safe(filter, node, node2, |
| 3663 | &adapter->fdir_filter_list, fdir_node) { |
| 3664 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 3665 | &filter->filter, |
| 3666 | filter->sw_idx, |
| 3667 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 3668 | IXGBE_FDIR_DROP_QUEUE : |
| 3669 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | spin_unlock(&adapter->fdir_perfect_lock); |
| 3673 | } |
| 3674 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3675 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3676 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3677 | struct ixgbe_hw *hw = &adapter->hw; |
| 3678 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3679 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3680 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3681 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3682 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3683 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3684 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3685 | ixgbe_restore_vlan(adapter); |
| 3686 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3687 | #ifdef IXGBE_FCOE |
| 3688 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 3689 | ixgbe_configure_fcoe(adapter); |
| 3690 | |
| 3691 | #endif /* IXGBE_FCOE */ |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3692 | |
| 3693 | switch (hw->mac.type) { |
| 3694 | case ixgbe_mac_82599EB: |
| 3695 | case ixgbe_mac_X540: |
| 3696 | hw->mac.ops.disable_rx_buff(hw); |
| 3697 | break; |
| 3698 | default: |
| 3699 | break; |
| 3700 | } |
| 3701 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3702 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3703 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 3704 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3705 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3706 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 3707 | adapter->fdir_pballoc); |
| 3708 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3709 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3710 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3711 | switch (hw->mac.type) { |
| 3712 | case ixgbe_mac_82599EB: |
| 3713 | case ixgbe_mac_X540: |
| 3714 | hw->mac.ops.enable_rx_buff(hw); |
| 3715 | break; |
| 3716 | default: |
| 3717 | break; |
| 3718 | } |
| 3719 | |
Alexander Duyck | 933d41f | 2010-09-07 21:34:29 +0000 | [diff] [blame] | 3720 | ixgbe_configure_virtualization(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3721 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3722 | ixgbe_configure_tx(adapter); |
| 3723 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3724 | } |
| 3725 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3726 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3727 | { |
| 3728 | switch (hw->phy.type) { |
| 3729 | case ixgbe_phy_sfp_avago: |
| 3730 | case ixgbe_phy_sfp_ftl: |
| 3731 | case ixgbe_phy_sfp_intel: |
| 3732 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3733 | case ixgbe_phy_sfp_passive_tyco: |
| 3734 | case ixgbe_phy_sfp_passive_unknown: |
| 3735 | case ixgbe_phy_sfp_active_unknown: |
| 3736 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3737 | return true; |
Alexander Duyck | 8917b44 | 2011-07-21 00:40:51 +0000 | [diff] [blame] | 3738 | case ixgbe_phy_nl: |
| 3739 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3740 | return true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3741 | default: |
| 3742 | return false; |
| 3743 | } |
| 3744 | } |
| 3745 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3746 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3747 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3748 | * @adapter: pointer to private adapter struct |
| 3749 | **/ |
| 3750 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3751 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3752 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3753 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3754 | * is that an SFP was inserted/removed after the reset |
| 3755 | * but before SFP detection was enabled. As such the best |
| 3756 | * solution is to just start searching as soon as we start |
| 3757 | */ |
| 3758 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3759 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3760 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3761 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | /** |
| 3765 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3766 | * @hw: pointer to private hardware struct |
| 3767 | * |
| 3768 | * Returns 0 on success, negative on failure |
| 3769 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3770 | 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] | 3771 | { |
| 3772 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3773 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3774 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 3775 | |
| 3776 | if (hw->mac.ops.check_link) |
| 3777 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 3778 | |
| 3779 | if (ret) |
| 3780 | goto link_cfg_out; |
| 3781 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 3782 | autoneg = hw->phy.autoneg_advertised; |
| 3783 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3784 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3785 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3786 | if (ret) |
| 3787 | goto link_cfg_out; |
| 3788 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3789 | if (hw->mac.ops.setup_link) |
| 3790 | 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] | 3791 | link_cfg_out: |
| 3792 | return ret; |
| 3793 | } |
| 3794 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3795 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3796 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3797 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3798 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3799 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3800 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3801 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 3802 | IXGBE_GPIE_OCD; |
| 3803 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3804 | /* |
| 3805 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 3806 | * this saves a register write for every interrupt |
| 3807 | */ |
| 3808 | switch (hw->mac.type) { |
| 3809 | case ixgbe_mac_82598EB: |
| 3810 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 3811 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3812 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3813 | case ixgbe_mac_X540: |
| 3814 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3815 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 3816 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 3817 | break; |
| 3818 | } |
| 3819 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3820 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 3821 | * specifically only auto mask tx and rx interrupts */ |
| 3822 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3825 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 3826 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 3827 | |
| 3828 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3829 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 3830 | gpie |= IXGBE_GPIE_VTMODE_64; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 3833 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 3834 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 3835 | switch (adapter->hw.mac.type) { |
| 3836 | case ixgbe_mac_82599EB: |
| 3837 | gpie |= IXGBE_SDP0_GPIEN; |
| 3838 | break; |
| 3839 | case ixgbe_mac_X540: |
| 3840 | gpie |= IXGBE_EIMS_TS; |
| 3841 | break; |
| 3842 | default: |
| 3843 | break; |
| 3844 | } |
| 3845 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 3846 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3847 | /* Enable fan failure interrupt */ |
| 3848 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3849 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3850 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3851 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3852 | gpie |= IXGBE_SDP1_GPIEN; |
| 3853 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3854 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3855 | |
| 3856 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 3857 | } |
| 3858 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3859 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3860 | { |
| 3861 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3862 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3863 | u32 ctrl_ext; |
| 3864 | |
| 3865 | ixgbe_get_hw_control(adapter); |
| 3866 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3867 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3868 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3869 | ixgbe_configure_msix(adapter); |
| 3870 | else |
| 3871 | ixgbe_configure_msi_and_legacy(adapter); |
| 3872 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3873 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ |
| 3874 | if (hw->mac.ops.enable_tx_laser && |
| 3875 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 3876 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3877 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 3878 | hw->mac.ops.enable_tx_laser(hw); |
| 3879 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3880 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3881 | ixgbe_napi_enable_all(adapter); |
| 3882 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 3883 | if (ixgbe_is_sfp(hw)) { |
| 3884 | ixgbe_sfp_link_config(adapter); |
| 3885 | } else { |
| 3886 | err = ixgbe_non_sfp_link_config(hw); |
| 3887 | if (err) |
| 3888 | e_err(probe, "link_config FAILED %d\n", err); |
| 3889 | } |
| 3890 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3891 | /* clear any pending interrupts, may auto mask */ |
| 3892 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3893 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3894 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3895 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3896 | * If this adapter has a fan, check to see if we had a failure |
| 3897 | * before we enabled the interrupt. |
| 3898 | */ |
| 3899 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 3900 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 3901 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3902 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3905 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3906 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3907 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3908 | /* bring the link up in the watchdog, this could race with our first |
| 3909 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3910 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3911 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3912 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 3913 | |
| 3914 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 3915 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 3916 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 3917 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3920 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 3921 | { |
| 3922 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3923 | /* put off any impending NetWatchDogTimeout */ |
| 3924 | adapter->netdev->trans_start = jiffies; |
| 3925 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3926 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3927 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3928 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 3929 | /* |
| 3930 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 3931 | * back up to give the VFs time to respond to the reset. The |
| 3932 | * two second wait is based upon the watchdog timer cycle in |
| 3933 | * the VF driver. |
| 3934 | */ |
| 3935 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3936 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3937 | ixgbe_up(adapter); |
| 3938 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 3939 | } |
| 3940 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3941 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3942 | { |
| 3943 | /* hardware has been reset, we need to reload some things */ |
| 3944 | ixgbe_configure(adapter); |
| 3945 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3946 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 3950 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3951 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3952 | int err; |
| 3953 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3954 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 3955 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 3956 | usleep_range(1000, 2000); |
| 3957 | |
| 3958 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 3959 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 3960 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 3961 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 3962 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3963 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3964 | switch (err) { |
| 3965 | case 0: |
| 3966 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3967 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3968 | break; |
| 3969 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3970 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3971 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3972 | case IXGBE_ERR_EEPROM_VERSION: |
| 3973 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3974 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3975 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3976 | "your hardware. If you are experiencing problems " |
| 3977 | "please contact your Intel or hardware " |
| 3978 | "representative who provided you with this " |
| 3979 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3980 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3981 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3982 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3983 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3984 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3985 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 3986 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3987 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3988 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 3989 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3992 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3993 | * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers |
| 3994 | * @rx_ring: ring to setup |
| 3995 | * |
| 3996 | * On many IA platforms the L1 cache has a critical stride of 4K, this |
| 3997 | * results in each receive buffer starting in the same cache set. To help |
| 3998 | * reduce the pressure on this cache set we can interleave the offsets so |
| 3999 | * that only every other buffer will be in the same cache set. |
| 4000 | **/ |
| 4001 | static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring) |
| 4002 | { |
| 4003 | struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info; |
| 4004 | u16 i; |
| 4005 | |
| 4006 | for (i = 0; i < rx_ring->count; i += 2) { |
| 4007 | rx_buffer[0].page_offset = 0; |
| 4008 | rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring); |
| 4009 | rx_buffer = &rx_buffer[2]; |
| 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4014 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4015 | * @rx_ring: ring to free buffers from |
| 4016 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4017 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4018 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4019 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4020 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4021 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4022 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4023 | /* ring already cleared, nothing to do */ |
| 4024 | if (!rx_ring->rx_buffer_info) |
| 4025 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4026 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4027 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4028 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4029 | struct ixgbe_rx_buffer *rx_buffer; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4030 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4031 | rx_buffer = &rx_ring->rx_buffer_info[i]; |
| 4032 | if (rx_buffer->skb) { |
| 4033 | struct sk_buff *skb = rx_buffer->skb; |
| 4034 | if (IXGBE_CB(skb)->page_released) { |
| 4035 | dma_unmap_page(dev, |
| 4036 | IXGBE_CB(skb)->dma, |
| 4037 | ixgbe_rx_bufsz(rx_ring), |
| 4038 | DMA_FROM_DEVICE); |
| 4039 | IXGBE_CB(skb)->page_released = false; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 4040 | } |
| 4041 | dev_kfree_skb(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4042 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4043 | rx_buffer->skb = NULL; |
| 4044 | if (rx_buffer->dma) |
| 4045 | dma_unmap_page(dev, rx_buffer->dma, |
| 4046 | ixgbe_rx_pg_size(rx_ring), |
| 4047 | DMA_FROM_DEVICE); |
| 4048 | rx_buffer->dma = 0; |
| 4049 | if (rx_buffer->page) |
| 4050 | put_page(rx_buffer->page); |
| 4051 | rx_buffer->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4055 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4056 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4057 | ixgbe_init_rx_page_offset(rx_ring); |
| 4058 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4059 | /* Zero out the descriptor ring */ |
| 4060 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4061 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4062 | rx_ring->next_to_alloc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4063 | rx_ring->next_to_clean = 0; |
| 4064 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | /** |
| 4068 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4069 | * @tx_ring: ring to be cleaned |
| 4070 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4071 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4072 | { |
| 4073 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4074 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4075 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4076 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4077 | /* ring already cleared, nothing to do */ |
| 4078 | if (!tx_ring->tx_buffer_info) |
| 4079 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4080 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4081 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4082 | for (i = 0; i < tx_ring->count; i++) { |
| 4083 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4084 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4088 | memset(tx_ring->tx_buffer_info, 0, size); |
| 4089 | |
| 4090 | /* Zero out the descriptor ring */ |
| 4091 | memset(tx_ring->desc, 0, tx_ring->size); |
| 4092 | |
| 4093 | tx_ring->next_to_use = 0; |
| 4094 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4098 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4099 | * @adapter: board private structure |
| 4100 | **/ |
| 4101 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4102 | { |
| 4103 | int i; |
| 4104 | |
| 4105 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4106 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4107 | } |
| 4108 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4109 | /** |
| 4110 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4111 | * @adapter: board private structure |
| 4112 | **/ |
| 4113 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4114 | { |
| 4115 | int i; |
| 4116 | |
| 4117 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4118 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4119 | } |
| 4120 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4121 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4122 | { |
| 4123 | struct hlist_node *node, *node2; |
| 4124 | struct ixgbe_fdir_filter *filter; |
| 4125 | |
| 4126 | spin_lock(&adapter->fdir_perfect_lock); |
| 4127 | |
| 4128 | hlist_for_each_entry_safe(filter, node, node2, |
| 4129 | &adapter->fdir_filter_list, fdir_node) { |
| 4130 | hlist_del(&filter->fdir_node); |
| 4131 | kfree(filter); |
| 4132 | } |
| 4133 | adapter->fdir_filter_count = 0; |
| 4134 | |
| 4135 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4136 | } |
| 4137 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4138 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4139 | { |
| 4140 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4141 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4142 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4143 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4144 | |
| 4145 | /* signal that we are down to the interrupt handler */ |
| 4146 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4147 | |
| 4148 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4149 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4150 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4151 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4152 | /* disable all enabled rx queues */ |
| 4153 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4154 | /* this call also flushes the previous write */ |
| 4155 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4156 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4157 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4158 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4159 | netif_tx_stop_all_queues(netdev); |
| 4160 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4161 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4162 | netif_carrier_off(netdev); |
| 4163 | netif_tx_disable(netdev); |
| 4164 | |
| 4165 | ixgbe_irq_disable(adapter); |
| 4166 | |
| 4167 | ixgbe_napi_disable_all(adapter); |
| 4168 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4169 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4170 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4171 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4172 | |
| 4173 | del_timer_sync(&adapter->service_timer); |
| 4174 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4175 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4176 | /* Clear EITR Select mapping */ |
| 4177 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 4178 | |
| 4179 | /* Mark all the VFs as inactive */ |
| 4180 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4181 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4182 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4183 | /* 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] | 4184 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4185 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4186 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4187 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4188 | } |
| 4189 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4190 | /* disable transmits in the hardware now that interrupts are off */ |
| 4191 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4192 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4193 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4194 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4195 | |
| 4196 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4197 | switch (hw->mac.type) { |
| 4198 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4199 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4200 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4201 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4202 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4203 | break; |
| 4204 | default: |
| 4205 | break; |
| 4206 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4207 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4208 | if (!pci_channel_offline(adapter->pdev)) |
| 4209 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4210 | |
| 4211 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 4212 | if (hw->mac.ops.disable_tx_laser && |
| 4213 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 4214 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4215 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 4216 | hw->mac.ops.disable_tx_laser(hw); |
| 4217 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4218 | ixgbe_clean_all_tx_rings(adapter); |
| 4219 | ixgbe_clean_all_rx_rings(adapter); |
| 4220 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4221 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4222 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4223 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4224 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4225 | } |
| 4226 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4227 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4228 | * ixgbe_poll - NAPI Rx polling callback |
| 4229 | * @napi: structure for representing this polling device |
| 4230 | * @budget: how many packets driver is allowed to clean |
| 4231 | * |
| 4232 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4233 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4234 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4235 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4236 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4237 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4238 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4239 | struct ixgbe_ring *ring; |
| 4240 | int per_ring_budget; |
| 4241 | bool clean_complete = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4242 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4243 | #ifdef CONFIG_IXGBE_DCA |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 4244 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 4245 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4246 | #endif |
| 4247 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4248 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4249 | clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4250 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4251 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 4252 | * the budget to go below 1 because we'll exit polling */ |
| 4253 | if (q_vector->rx.count > 1) |
| 4254 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 4255 | else |
| 4256 | per_ring_budget = budget; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4257 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4258 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4259 | clean_complete &= ixgbe_clean_rx_irq(q_vector, ring, |
| 4260 | per_ring_budget); |
| 4261 | |
| 4262 | /* If all work not completed, return budget and keep polling */ |
| 4263 | if (!clean_complete) |
| 4264 | return budget; |
| 4265 | |
| 4266 | /* all work done, exit the polling mode */ |
| 4267 | napi_complete(napi); |
| 4268 | if (adapter->rx_itr_setting & 1) |
| 4269 | ixgbe_set_itr(q_vector); |
| 4270 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4271 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 4272 | |
| 4273 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | /** |
| 4277 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4278 | * @netdev: network interface device structure |
| 4279 | **/ |
| 4280 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4281 | { |
| 4282 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4283 | |
| 4284 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4285 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4286 | } |
| 4287 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4288 | /** |
| 4289 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 4290 | * @adapter: board private structure to initialize |
| 4291 | * |
| 4292 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 4293 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 4294 | * |
| 4295 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4296 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 4297 | { |
| 4298 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4299 | 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] | 4300 | |
| 4301 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4302 | f->mask = 0xF; |
| 4303 | adapter->num_rx_queues = f->indices; |
| 4304 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4305 | ret = true; |
| 4306 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4307 | ret = false; |
| 4308 | } |
| 4309 | |
| 4310 | return ret; |
| 4311 | } |
| 4312 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4313 | /** |
| 4314 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 4315 | * @adapter: board private structure to initialize |
| 4316 | * |
| 4317 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 4318 | * to the original CPU that initiated the Tx session. This runs in addition |
| 4319 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 4320 | * Rx load across CPUs using RSS. |
| 4321 | * |
| 4322 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4323 | 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] | 4324 | { |
| 4325 | bool ret = false; |
| 4326 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 4327 | |
| 4328 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 4329 | f_fdir->mask = 0; |
| 4330 | |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 4331 | /* |
| 4332 | * Use RSS in addition to Flow Director to ensure the best |
| 4333 | * distribution of flows across cores, even when an FDIR flow |
| 4334 | * isn't matched. |
| 4335 | */ |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4336 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4337 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4338 | adapter->num_tx_queues = f_fdir->indices; |
| 4339 | adapter->num_rx_queues = f_fdir->indices; |
| 4340 | ret = true; |
| 4341 | } else { |
| 4342 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4343 | } |
| 4344 | return ret; |
| 4345 | } |
| 4346 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4347 | #ifdef IXGBE_FCOE |
| 4348 | /** |
| 4349 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 4350 | * @adapter: board private structure to initialize |
| 4351 | * |
| 4352 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 4353 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 4354 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 4355 | * index of the first rx queue used by FCoE. |
| 4356 | * |
| 4357 | **/ |
| 4358 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 4359 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4360 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 4361 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4362 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4363 | return false; |
| 4364 | |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4365 | f->indices = min_t(int, num_online_cpus(), f->indices); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4366 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4367 | adapter->num_rx_queues = 1; |
| 4368 | adapter->num_tx_queues = 1; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4369 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4370 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 4371 | e_info(probe, "FCoE enabled with RSS\n"); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4372 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4373 | ixgbe_set_fdir_queues(adapter); |
| 4374 | else |
| 4375 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4376 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4377 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4378 | /* adding FCoE rx rings to the end */ |
| 4379 | f->mask = adapter->num_rx_queues; |
| 4380 | adapter->num_rx_queues += f->indices; |
| 4381 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4382 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4383 | return true; |
| 4384 | } |
| 4385 | #endif /* IXGBE_FCOE */ |
| 4386 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4387 | /* Artificial max queue cap per traffic class in DCB mode */ |
| 4388 | #define DCB_QUEUE_CAP 8 |
| 4389 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4390 | #ifdef CONFIG_IXGBE_DCB |
| 4391 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
| 4392 | { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4393 | int per_tc_q, q, i, offset = 0; |
| 4394 | struct net_device *dev = adapter->netdev; |
| 4395 | int tcs = netdev_get_num_tc(dev); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4396 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4397 | if (!tcs) |
| 4398 | return false; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4399 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4400 | /* Map queue offset and counts onto allocated tx queues */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4401 | per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP); |
| 4402 | q = min_t(int, num_online_cpus(), per_tc_q); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4403 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4404 | for (i = 0; i < tcs; i++) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4405 | netdev_set_tc_queue(dev, i, q, offset); |
| 4406 | offset += q; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4407 | } |
| 4408 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4409 | adapter->num_tx_queues = q * tcs; |
| 4410 | adapter->num_rx_queues = q * tcs; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4411 | |
| 4412 | #ifdef IXGBE_FCOE |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4413 | /* FCoE enabled queues require special configuration indexed |
| 4414 | * by feature specific indices and mask. Here we map FCoE |
| 4415 | * indices onto the DCB queue pairs allowing FCoE to own |
| 4416 | * configuration later. |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4417 | */ |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4418 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
John Fastabend | cdf485b | 2012-02-11 06:26:00 +0000 | [diff] [blame] | 4419 | u8 prio_tc[MAX_USER_PRIORITY] = {0}; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4420 | int tc; |
| 4421 | struct ixgbe_ring_feature *f = |
| 4422 | &adapter->ring_feature[RING_F_FCOE]; |
| 4423 | |
John Fastabend | cdf485b | 2012-02-11 06:26:00 +0000 | [diff] [blame] | 4424 | ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc); |
| 4425 | tc = prio_tc[adapter->fcoe.up]; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4426 | f->indices = dev->tc_to_txq[tc].count; |
| 4427 | f->mask = dev->tc_to_txq[tc].offset; |
| 4428 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4429 | #endif |
| 4430 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4431 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4432 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4433 | #endif |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4434 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4435 | /** |
| 4436 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 4437 | * @adapter: board private structure to initialize |
| 4438 | * |
| 4439 | * IOV doesn't actually use anything, so just NAK the |
| 4440 | * request for now and let the other queue routines |
| 4441 | * figure out what to do. |
| 4442 | */ |
| 4443 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 4444 | { |
| 4445 | return false; |
| 4446 | } |
| 4447 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4448 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4449 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4450 | * @adapter: board private structure to initialize |
| 4451 | * |
| 4452 | * This is the top level queue allocation routine. The order here is very |
| 4453 | * important, starting with the "most" number of features turned on at once, |
| 4454 | * and ending with the smallest set of features. This way large combinations |
| 4455 | * can be allocated if they're turned on, and smaller combinations are the |
| 4456 | * fallthrough conditions. |
| 4457 | * |
| 4458 | **/ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4459 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4460 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4461 | /* Start with base case */ |
| 4462 | adapter->num_rx_queues = 1; |
| 4463 | adapter->num_tx_queues = 1; |
| 4464 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 4465 | adapter->num_rx_queues_per_pool = 1; |
| 4466 | |
| 4467 | if (ixgbe_set_sriov_queues(adapter)) |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4468 | goto done; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4469 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4470 | #ifdef CONFIG_IXGBE_DCB |
| 4471 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4472 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4473 | |
| 4474 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4475 | #ifdef IXGBE_FCOE |
| 4476 | if (ixgbe_set_fcoe_queues(adapter)) |
| 4477 | goto done; |
| 4478 | |
| 4479 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4480 | if (ixgbe_set_fdir_queues(adapter)) |
| 4481 | goto done; |
| 4482 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4483 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4484 | goto done; |
| 4485 | |
| 4486 | /* fallback to base case */ |
| 4487 | adapter->num_rx_queues = 1; |
| 4488 | adapter->num_tx_queues = 1; |
| 4489 | |
| 4490 | done: |
Yi Zou | 9d837ea | 2012-01-07 08:39:50 +0000 | [diff] [blame] | 4491 | if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) || |
| 4492 | (adapter->netdev->reg_state == NETREG_UNREGISTERING)) |
| 4493 | return 0; |
| 4494 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4495 | /* Notify the stack of the (possibly) reduced queue counts. */ |
John Fastabend | f0796d5 | 2010-07-01 13:21:57 +0000 | [diff] [blame] | 4496 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4497 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 4498 | adapter->num_rx_queues); |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4499 | } |
| 4500 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4501 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4502 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4503 | { |
| 4504 | int err, vector_threshold; |
| 4505 | |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4506 | /* We'll want at least 2 (vector_threshold): |
| 4507 | * 1) TxQ[0] + RxQ[0] handler |
| 4508 | * 2) Other (Link Status Change, etc.) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4509 | */ |
| 4510 | vector_threshold = MIN_MSIX_COUNT; |
| 4511 | |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 4512 | /* |
| 4513 | * 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] | 4514 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 4515 | * Right now, we simply care about how many we'll get; we'll |
| 4516 | * set them up later while requesting irq's. |
| 4517 | */ |
| 4518 | while (vectors >= vector_threshold) { |
| 4519 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4520 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4521 | if (!err) /* Success in acquiring all requested vectors. */ |
| 4522 | break; |
| 4523 | else if (err < 0) |
| 4524 | vectors = 0; /* Nasty failure, quit now */ |
| 4525 | else /* err == number of vectors we should try again with */ |
| 4526 | vectors = err; |
| 4527 | } |
| 4528 | |
| 4529 | if (vectors < vector_threshold) { |
| 4530 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 4531 | * This just means we'll go with either a single MSI |
| 4532 | * vector or fall back to legacy interrupts. |
| 4533 | */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4534 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4535 | "Unable to allocate MSI-X interrupts\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4536 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4537 | kfree(adapter->msix_entries); |
| 4538 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4539 | } else { |
| 4540 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 4541 | /* |
| 4542 | * Adjust for only the vectors we'll use, which is minimum |
| 4543 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 4544 | * vectors we were allocated. |
| 4545 | */ |
| 4546 | adapter->num_msix_vectors = min(vectors, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4547 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4548 | } |
| 4549 | } |
| 4550 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4551 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4552 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4553 | * @adapter: board private structure to initialize |
| 4554 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4555 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 4556 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4557 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4558 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4559 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4560 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4561 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4562 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 4563 | return false; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4564 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4565 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4566 | adapter->rx_ring[i]->reg_idx = i; |
| 4567 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4568 | adapter->tx_ring[i]->reg_idx = i; |
| 4569 | |
| 4570 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4571 | } |
| 4572 | |
| 4573 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4574 | |
| 4575 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 4576 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, |
| 4577 | unsigned int *tx, unsigned int *rx) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4578 | { |
| 4579 | struct net_device *dev = adapter->netdev; |
| 4580 | struct ixgbe_hw *hw = &adapter->hw; |
| 4581 | u8 num_tcs = netdev_get_num_tc(dev); |
| 4582 | |
| 4583 | *tx = 0; |
| 4584 | *rx = 0; |
| 4585 | |
| 4586 | switch (hw->mac.type) { |
| 4587 | case ixgbe_mac_82598EB: |
John Fastabend | aba70d5 | 2011-04-26 07:26:14 +0000 | [diff] [blame] | 4588 | *tx = tc << 2; |
| 4589 | *rx = tc << 3; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4590 | break; |
| 4591 | case ixgbe_mac_82599EB: |
| 4592 | case ixgbe_mac_X540: |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4593 | if (num_tcs > 4) { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4594 | if (tc < 3) { |
| 4595 | *tx = tc << 5; |
| 4596 | *rx = tc << 4; |
| 4597 | } else if (tc < 5) { |
| 4598 | *tx = ((tc + 2) << 4); |
| 4599 | *rx = tc << 4; |
| 4600 | } else if (tc < num_tcs) { |
| 4601 | *tx = ((tc + 8) << 3); |
| 4602 | *rx = tc << 4; |
| 4603 | } |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4604 | } else { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4605 | *rx = tc << 5; |
| 4606 | switch (tc) { |
| 4607 | case 0: |
| 4608 | *tx = 0; |
| 4609 | break; |
| 4610 | case 1: |
| 4611 | *tx = 64; |
| 4612 | break; |
| 4613 | case 2: |
| 4614 | *tx = 96; |
| 4615 | break; |
| 4616 | case 3: |
| 4617 | *tx = 112; |
| 4618 | break; |
| 4619 | default: |
| 4620 | break; |
| 4621 | } |
| 4622 | } |
| 4623 | break; |
| 4624 | default: |
| 4625 | break; |
| 4626 | } |
| 4627 | } |
| 4628 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4629 | /** |
| 4630 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 4631 | * @adapter: board private structure to initialize |
| 4632 | * |
| 4633 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 4634 | * |
| 4635 | **/ |
| 4636 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 4637 | { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4638 | struct net_device *dev = adapter->netdev; |
| 4639 | int i, j, k; |
| 4640 | u8 num_tcs = netdev_get_num_tc(dev); |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4641 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4642 | if (!num_tcs) |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4643 | return false; |
| 4644 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4645 | for (i = 0, k = 0; i < num_tcs; i++) { |
| 4646 | unsigned int tx_s, rx_s; |
| 4647 | u16 count = dev->tc_to_txq[i].count; |
| 4648 | |
| 4649 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); |
| 4650 | for (j = 0; j < count; j++, k++) { |
| 4651 | adapter->tx_ring[k]->reg_idx = tx_s + j; |
| 4652 | adapter->rx_ring[k]->reg_idx = rx_s + j; |
| 4653 | adapter->tx_ring[k]->dcb_tc = i; |
| 4654 | adapter->rx_ring[k]->dcb_tc = i; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4655 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4656 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4657 | |
| 4658 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4659 | } |
| 4660 | #endif |
| 4661 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4662 | /** |
| 4663 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 4664 | * @adapter: board private structure to initialize |
| 4665 | * |
| 4666 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 4667 | * |
| 4668 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4669 | 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] | 4670 | { |
| 4671 | int i; |
| 4672 | bool ret = false; |
| 4673 | |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4674 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4675 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4676 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4677 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4678 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4679 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4680 | ret = true; |
| 4681 | } |
| 4682 | |
| 4683 | return ret; |
| 4684 | } |
| 4685 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4686 | #ifdef IXGBE_FCOE |
| 4687 | /** |
| 4688 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 4689 | * @adapter: board private structure to initialize |
| 4690 | * |
| 4691 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 4692 | * |
| 4693 | */ |
| 4694 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 4695 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4696 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4697 | int i; |
| 4698 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4699 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4700 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4701 | return false; |
| 4702 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4703 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4704 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4705 | ixgbe_cache_ring_fdir(adapter); |
| 4706 | else |
| 4707 | ixgbe_cache_ring_rss(adapter); |
| 4708 | |
| 4709 | fcoe_rx_i = f->mask; |
| 4710 | fcoe_tx_i = f->mask; |
| 4711 | } |
| 4712 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 4713 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 4714 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
| 4715 | } |
| 4716 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4717 | } |
| 4718 | |
| 4719 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4720 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4721 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 4722 | * @adapter: board private structure to initialize |
| 4723 | * |
| 4724 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 4725 | * no other mapping is used. |
| 4726 | * |
| 4727 | */ |
| 4728 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 4729 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4730 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 4731 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4732 | if (adapter->num_vfs) |
| 4733 | return true; |
| 4734 | else |
| 4735 | return false; |
| 4736 | } |
| 4737 | |
| 4738 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4739 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 4740 | * @adapter: board private structure to initialize |
| 4741 | * |
| 4742 | * Once we know the feature-set enabled for the device, we'll cache |
| 4743 | * the register offset the descriptor ring is assigned to. |
| 4744 | * |
| 4745 | * Note, the order the various feature calls is important. It must start with |
| 4746 | * the "most" features enabled at the same time, then trickle down to the |
| 4747 | * least amount of features turned on at once. |
| 4748 | **/ |
| 4749 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 4750 | { |
| 4751 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4752 | adapter->rx_ring[0]->reg_idx = 0; |
| 4753 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4754 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4755 | if (ixgbe_cache_ring_sriov(adapter)) |
| 4756 | return; |
| 4757 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4758 | #ifdef CONFIG_IXGBE_DCB |
| 4759 | if (ixgbe_cache_ring_dcb(adapter)) |
| 4760 | return; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4761 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4762 | |
| 4763 | #ifdef IXGBE_FCOE |
| 4764 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 4765 | return; |
| 4766 | #endif /* IXGBE_FCOE */ |
| 4767 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4768 | if (ixgbe_cache_ring_fdir(adapter)) |
| 4769 | return; |
| 4770 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4771 | if (ixgbe_cache_ring_rss(adapter)) |
| 4772 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4773 | } |
| 4774 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4775 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4776 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 4777 | * @adapter: board private structure to initialize |
| 4778 | * |
| 4779 | * Attempt to configure the interrupts using the best available |
| 4780 | * capabilities of the hardware and the kernel. |
| 4781 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 4782 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4783 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4784 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4785 | int err = 0; |
| 4786 | int vector, v_budget; |
| 4787 | |
| 4788 | /* |
| 4789 | * It's easy to be greedy for MSI-X vectors, but it really |
| 4790 | * doesn't do us much good if we have a lot more vectors |
| 4791 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 4792 | * (roughly) the same number of vectors as there are CPU's. |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4793 | * The default is to use pairs of vectors. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4794 | */ |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4795 | v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues); |
| 4796 | v_budget = min_t(int, v_budget, num_online_cpus()); |
| 4797 | v_budget += NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4798 | |
| 4799 | /* |
| 4800 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4801 | * hw.mac->max_msix_vectors vectors. With features |
| 4802 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 4803 | * descriptor queues supported by our device. Thus, we cap it off in |
| 4804 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4805 | */ |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4806 | v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4807 | |
| 4808 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 4809 | * mean we disable MSI-X capabilities of the adapter. */ |
| 4810 | adapter->msix_entries = kcalloc(v_budget, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4811 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4812 | if (adapter->msix_entries) { |
| 4813 | for (vector = 0; vector < v_budget; vector++) |
| 4814 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4815 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4816 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 4817 | |
| 4818 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4819 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4820 | } |
David S. Miller | 26d2784 | 2010-05-03 15:18:22 -0700 | [diff] [blame] | 4821 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4822 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 4823 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4824 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4825 | e_err(probe, |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4826 | "ATR is not supported while multiple " |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4827 | "queues are disabled. Disabling Flow Director\n"); |
| 4828 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4829 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4830 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4831 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4832 | ixgbe_disable_sriov(adapter); |
| 4833 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4834 | err = ixgbe_set_num_queues(adapter); |
| 4835 | if (err) |
| 4836 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4837 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4838 | err = pci_enable_msi(adapter->pdev); |
| 4839 | if (!err) { |
| 4840 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 4841 | } else { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4842 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4843 | "Unable to allocate MSI interrupt, " |
| 4844 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4845 | /* reset err */ |
| 4846 | err = 0; |
| 4847 | } |
| 4848 | |
| 4849 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4850 | return err; |
| 4851 | } |
| 4852 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4853 | static void ixgbe_add_ring(struct ixgbe_ring *ring, |
| 4854 | struct ixgbe_ring_container *head) |
| 4855 | { |
| 4856 | ring->next = head->ring; |
| 4857 | head->ring = ring; |
| 4858 | head->count++; |
| 4859 | } |
| 4860 | |
| 4861 | /** |
| 4862 | * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector |
| 4863 | * @adapter: board private structure to initialize |
| 4864 | * @v_idx: index of vector in adapter struct |
| 4865 | * |
| 4866 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 4867 | **/ |
| 4868 | static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx, |
| 4869 | int txr_count, int txr_idx, |
| 4870 | int rxr_count, int rxr_idx) |
| 4871 | { |
| 4872 | struct ixgbe_q_vector *q_vector; |
| 4873 | struct ixgbe_ring *ring; |
| 4874 | int node = -1; |
| 4875 | int cpu = -1; |
| 4876 | int ring_count, size; |
| 4877 | |
| 4878 | ring_count = txr_count + rxr_count; |
| 4879 | size = sizeof(struct ixgbe_q_vector) + |
| 4880 | (sizeof(struct ixgbe_ring) * ring_count); |
| 4881 | |
| 4882 | /* customize cpu for Flow Director mapping */ |
| 4883 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 4884 | if (cpu_online(v_idx)) { |
| 4885 | cpu = v_idx; |
| 4886 | node = cpu_to_node(cpu); |
| 4887 | } |
| 4888 | } |
| 4889 | |
| 4890 | /* allocate q_vector and rings */ |
| 4891 | q_vector = kzalloc_node(size, GFP_KERNEL, node); |
| 4892 | if (!q_vector) |
| 4893 | q_vector = kzalloc(size, GFP_KERNEL); |
| 4894 | if (!q_vector) |
| 4895 | return -ENOMEM; |
| 4896 | |
| 4897 | /* setup affinity mask and node */ |
| 4898 | if (cpu != -1) |
| 4899 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 4900 | else |
| 4901 | cpumask_copy(&q_vector->affinity_mask, cpu_online_mask); |
| 4902 | q_vector->numa_node = node; |
| 4903 | |
| 4904 | /* initialize NAPI */ |
| 4905 | netif_napi_add(adapter->netdev, &q_vector->napi, |
| 4906 | ixgbe_poll, 64); |
| 4907 | |
| 4908 | /* tie q_vector and adapter together */ |
| 4909 | adapter->q_vector[v_idx] = q_vector; |
| 4910 | q_vector->adapter = adapter; |
| 4911 | q_vector->v_idx = v_idx; |
| 4912 | |
| 4913 | /* initialize work limits */ |
| 4914 | q_vector->tx.work_limit = adapter->tx_work_limit; |
| 4915 | |
| 4916 | /* initialize pointer to rings */ |
| 4917 | ring = q_vector->ring; |
| 4918 | |
| 4919 | while (txr_count) { |
| 4920 | /* assign generic ring traits */ |
| 4921 | ring->dev = &adapter->pdev->dev; |
| 4922 | ring->netdev = adapter->netdev; |
| 4923 | |
| 4924 | /* configure backlink on ring */ |
| 4925 | ring->q_vector = q_vector; |
| 4926 | |
| 4927 | /* update q_vector Tx values */ |
| 4928 | ixgbe_add_ring(ring, &q_vector->tx); |
| 4929 | |
| 4930 | /* apply Tx specific ring traits */ |
| 4931 | ring->count = adapter->tx_ring_count; |
| 4932 | ring->queue_index = txr_idx; |
| 4933 | |
| 4934 | /* assign ring to adapter */ |
| 4935 | adapter->tx_ring[txr_idx] = ring; |
| 4936 | |
| 4937 | /* update count and index */ |
| 4938 | txr_count--; |
| 4939 | txr_idx++; |
| 4940 | |
| 4941 | /* push pointer to next ring */ |
| 4942 | ring++; |
| 4943 | } |
| 4944 | |
| 4945 | while (rxr_count) { |
| 4946 | /* assign generic ring traits */ |
| 4947 | ring->dev = &adapter->pdev->dev; |
| 4948 | ring->netdev = adapter->netdev; |
| 4949 | |
| 4950 | /* configure backlink on ring */ |
| 4951 | ring->q_vector = q_vector; |
| 4952 | |
| 4953 | /* update q_vector Rx values */ |
| 4954 | ixgbe_add_ring(ring, &q_vector->rx); |
| 4955 | |
| 4956 | /* |
| 4957 | * 82599 errata, UDP frames with a 0 checksum |
| 4958 | * can be marked as checksum errors. |
| 4959 | */ |
| 4960 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 4961 | set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state); |
| 4962 | |
| 4963 | /* apply Rx specific ring traits */ |
| 4964 | ring->count = adapter->rx_ring_count; |
| 4965 | ring->queue_index = rxr_idx; |
| 4966 | |
| 4967 | /* assign ring to adapter */ |
| 4968 | adapter->rx_ring[rxr_idx] = ring; |
| 4969 | |
| 4970 | /* update count and index */ |
| 4971 | rxr_count--; |
| 4972 | rxr_idx++; |
| 4973 | |
| 4974 | /* push pointer to next ring */ |
| 4975 | ring++; |
| 4976 | } |
| 4977 | |
| 4978 | return 0; |
| 4979 | } |
| 4980 | |
| 4981 | /** |
| 4982 | * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector |
| 4983 | * @adapter: board private structure to initialize |
| 4984 | * @v_idx: Index of vector to be freed |
| 4985 | * |
| 4986 | * This function frees the memory allocated to the q_vector. In addition if |
| 4987 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4988 | * to freeing the q_vector. |
| 4989 | **/ |
| 4990 | static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx) |
| 4991 | { |
| 4992 | struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 4993 | struct ixgbe_ring *ring; |
| 4994 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4995 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4996 | adapter->tx_ring[ring->queue_index] = NULL; |
| 4997 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4998 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4999 | adapter->rx_ring[ring->queue_index] = NULL; |
| 5000 | |
| 5001 | adapter->q_vector[v_idx] = NULL; |
| 5002 | netif_napi_del(&q_vector->napi); |
| 5003 | |
| 5004 | /* |
| 5005 | * ixgbe_get_stats64() might access the rings on this vector, |
| 5006 | * we must wait a grace period before freeing it. |
| 5007 | */ |
| 5008 | kfree_rcu(q_vector, rcu); |
| 5009 | } |
| 5010 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5011 | /** |
| 5012 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 5013 | * @adapter: board private structure to initialize |
| 5014 | * |
| 5015 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 5016 | * return -ENOMEM. |
| 5017 | **/ |
| 5018 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 5019 | { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5020 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5021 | int rxr_remaining = adapter->num_rx_queues; |
| 5022 | int txr_remaining = adapter->num_tx_queues; |
| 5023 | int rxr_idx = 0, txr_idx = 0, v_idx = 0; |
| 5024 | int err; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5025 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5026 | /* only one q_vector if MSI-X is disabled. */ |
| 5027 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 5028 | q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5029 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5030 | if (q_vectors >= (rxr_remaining + txr_remaining)) { |
| 5031 | for (; rxr_remaining; v_idx++, q_vectors--) { |
| 5032 | int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 5033 | err = ixgbe_alloc_q_vector(adapter, v_idx, |
| 5034 | 0, 0, rqpv, rxr_idx); |
| 5035 | |
| 5036 | if (err) |
| 5037 | goto err_out; |
| 5038 | |
| 5039 | /* update counts and index */ |
| 5040 | rxr_remaining -= rqpv; |
| 5041 | rxr_idx += rqpv; |
| 5042 | } |
| 5043 | } |
| 5044 | |
| 5045 | for (; q_vectors; v_idx++, q_vectors--) { |
| 5046 | int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 5047 | int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors); |
| 5048 | err = ixgbe_alloc_q_vector(adapter, v_idx, |
| 5049 | tqpv, txr_idx, |
| 5050 | rqpv, rxr_idx); |
| 5051 | |
| 5052 | if (err) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5053 | goto err_out; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 5054 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5055 | /* update counts and index */ |
| 5056 | rxr_remaining -= rqpv; |
| 5057 | rxr_idx += rqpv; |
| 5058 | txr_remaining -= tqpv; |
| 5059 | txr_idx += tqpv; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | return 0; |
| 5063 | |
| 5064 | err_out: |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 5065 | while (v_idx) { |
| 5066 | v_idx--; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5067 | ixgbe_free_q_vector(adapter, v_idx); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5068 | } |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5069 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5070 | return -ENOMEM; |
| 5071 | } |
| 5072 | |
| 5073 | /** |
| 5074 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 5075 | * @adapter: board private structure to initialize |
| 5076 | * |
| 5077 | * This function frees the memory allocated to the q_vectors. In addition if |
| 5078 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 5079 | * to freeing the q_vector. |
| 5080 | **/ |
| 5081 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 5082 | { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5083 | int v_idx, q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5084 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5085 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5086 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5087 | else |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5088 | q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5089 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5090 | for (v_idx = 0; v_idx < q_vectors; v_idx++) |
| 5091 | ixgbe_free_q_vector(adapter, v_idx); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5092 | } |
| 5093 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 5094 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5095 | { |
| 5096 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5097 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 5098 | pci_disable_msix(adapter->pdev); |
| 5099 | kfree(adapter->msix_entries); |
| 5100 | adapter->msix_entries = NULL; |
| 5101 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 5102 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 5103 | pci_disable_msi(adapter->pdev); |
| 5104 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | /** |
| 5108 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 5109 | * @adapter: board private structure to initialize |
| 5110 | * |
| 5111 | * We determine which interrupt scheme to use based on... |
| 5112 | * - Kernel support (MSI, MSI-X) |
| 5113 | * - which can be user-defined (via MODULE_PARAM) |
| 5114 | * - Hardware queue count (num_*_queues) |
| 5115 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 5116 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5117 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5118 | { |
| 5119 | int err; |
| 5120 | |
| 5121 | /* Number of supported queues */ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 5122 | err = ixgbe_set_num_queues(adapter); |
| 5123 | if (err) |
| 5124 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5125 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5126 | err = ixgbe_set_interrupt_capability(adapter); |
| 5127 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5128 | e_dev_err("Unable to setup interrupt capabilities\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5129 | goto err_set_interrupt; |
| 5130 | } |
| 5131 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5132 | err = ixgbe_alloc_q_vectors(adapter); |
| 5133 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5134 | e_dev_err("Unable to allocate memory for queue vectors\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5135 | goto err_alloc_q_vectors; |
| 5136 | } |
| 5137 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5138 | ixgbe_cache_ring_register(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5139 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5140 | 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] | 5141 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 5142 | adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5143 | |
| 5144 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5145 | |
| 5146 | return 0; |
| 5147 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5148 | err_alloc_q_vectors: |
| 5149 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5150 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5151 | return err; |
| 5152 | } |
| 5153 | |
| 5154 | /** |
| 5155 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 5156 | * @adapter: board private structure to clear interrupt scheme on |
| 5157 | * |
| 5158 | * We go through and clear interrupt specific resources and reset the structure |
| 5159 | * to pre-load conditions |
| 5160 | **/ |
| 5161 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 5162 | { |
Don Skidmore | b8eb3a1 | 2010-12-01 20:54:53 +0000 | [diff] [blame] | 5163 | adapter->num_tx_queues = 0; |
| 5164 | adapter->num_rx_queues = 0; |
| 5165 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5166 | ixgbe_free_q_vectors(adapter); |
| 5167 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5168 | } |
| 5169 | |
| 5170 | /** |
| 5171 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5172 | * @adapter: board private structure to initialize |
| 5173 | * |
| 5174 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5175 | * Fields are initialized based on PCI device information and |
| 5176 | * OS network device settings (MTU size). |
| 5177 | **/ |
| 5178 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 5179 | { |
| 5180 | struct ixgbe_hw *hw = &adapter->hw; |
| 5181 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5182 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5183 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5184 | int j; |
| 5185 | struct tc_configuration *tc; |
| 5186 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5187 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5188 | /* PCI config space info */ |
| 5189 | |
| 5190 | hw->vendor_id = pdev->vendor; |
| 5191 | hw->device_id = pdev->device; |
| 5192 | hw->revision_id = pdev->revision; |
| 5193 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5194 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5195 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5196 | /* Set capability flags */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 5197 | rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus()); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5198 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 5199 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5200 | switch (hw->mac.type) { |
| 5201 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5202 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5203 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5204 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5205 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5206 | case ixgbe_mac_X540: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 5207 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 5208 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5209 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5210 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5211 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5212 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5213 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 5214 | /* Flow Director hash filters enabled */ |
| 5215 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5216 | adapter->atr_sample_rate = 20; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5217 | adapter->ring_feature[RING_F_FDIR].indices = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5218 | IXGBE_MAX_FDIR_INDICES; |
Alexander Duyck | c04f6ca | 2011-05-11 07:18:36 +0000 | [diff] [blame] | 5219 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5220 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5221 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5222 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5223 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5224 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 5225 | /* Default traffic class to use for FCoE */ |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 5226 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5227 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5228 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5229 | break; |
| 5230 | default: |
| 5231 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5232 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5233 | |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5234 | /* n-tuple support exists, always init our spinlock */ |
| 5235 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5236 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5237 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5238 | switch (hw->mac.type) { |
| 5239 | case ixgbe_mac_X540: |
| 5240 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5241 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5242 | break; |
| 5243 | default: |
| 5244 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5245 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5246 | break; |
| 5247 | } |
| 5248 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5249 | /* Configure DCB traffic classes */ |
| 5250 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5251 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5252 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5253 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5254 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5255 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5256 | tc->dcb_pfc = pfc_disabled; |
| 5257 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5258 | |
| 5259 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5260 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5261 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5262 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5263 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5264 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5265 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5266 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5267 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5268 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5269 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 5270 | MAX_TRAFFIC_CLASS); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5271 | |
| 5272 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5273 | |
| 5274 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5275 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5276 | 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] | 5277 | #ifdef CONFIG_DCB |
| 5278 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 5279 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5280 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5281 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5282 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5283 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5284 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5285 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5286 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5287 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5288 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5289 | /* set default ring sizes */ |
| 5290 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5291 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5292 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5293 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5294 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5295 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5296 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5297 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5298 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5299 | return -EIO; |
| 5300 | } |
| 5301 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5302 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5303 | |
| 5304 | return 0; |
| 5305 | } |
| 5306 | |
| 5307 | /** |
| 5308 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5309 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5310 | * |
| 5311 | * Return 0 on success, negative on failure |
| 5312 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5313 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5314 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5315 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5316 | int orig_node = dev_to_node(dev); |
| 5317 | int numa_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5318 | int size; |
| 5319 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5320 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5321 | |
| 5322 | if (tx_ring->q_vector) |
| 5323 | numa_node = tx_ring->q_vector->numa_node; |
| 5324 | |
| 5325 | tx_ring->tx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5326 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5327 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5328 | if (!tx_ring->tx_buffer_info) |
| 5329 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5330 | |
| 5331 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5332 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5333 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5334 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5335 | set_dev_node(dev, numa_node); |
| 5336 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5337 | tx_ring->size, |
| 5338 | &tx_ring->dma, |
| 5339 | GFP_KERNEL); |
| 5340 | set_dev_node(dev, orig_node); |
| 5341 | if (!tx_ring->desc) |
| 5342 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5343 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5344 | if (!tx_ring->desc) |
| 5345 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5346 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5347 | tx_ring->next_to_use = 0; |
| 5348 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5349 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5350 | |
| 5351 | err: |
| 5352 | vfree(tx_ring->tx_buffer_info); |
| 5353 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5354 | 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] | 5355 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5359 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5360 | * @adapter: board private structure |
| 5361 | * |
| 5362 | * If this function returns with an error, then it's possible one or |
| 5363 | * more of the rings is populated (while the rest are not). It is the |
| 5364 | * callers duty to clean those orphaned rings. |
| 5365 | * |
| 5366 | * Return 0 on success, negative on failure |
| 5367 | **/ |
| 5368 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5369 | { |
| 5370 | int i, err = 0; |
| 5371 | |
| 5372 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5373 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5374 | if (!err) |
| 5375 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5376 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5377 | break; |
| 5378 | } |
| 5379 | |
| 5380 | return err; |
| 5381 | } |
| 5382 | |
| 5383 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5384 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5385 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5386 | * |
| 5387 | * Returns 0 on success, negative on failure |
| 5388 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5389 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5390 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5391 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5392 | int orig_node = dev_to_node(dev); |
| 5393 | int numa_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5394 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5395 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5396 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5397 | |
| 5398 | if (rx_ring->q_vector) |
| 5399 | numa_node = rx_ring->q_vector->numa_node; |
| 5400 | |
| 5401 | rx_ring->rx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5402 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5403 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5404 | if (!rx_ring->rx_buffer_info) |
| 5405 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5406 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5407 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5408 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5409 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5410 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5411 | set_dev_node(dev, numa_node); |
| 5412 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5413 | rx_ring->size, |
| 5414 | &rx_ring->dma, |
| 5415 | GFP_KERNEL); |
| 5416 | set_dev_node(dev, orig_node); |
| 5417 | if (!rx_ring->desc) |
| 5418 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5419 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5420 | if (!rx_ring->desc) |
| 5421 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5422 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5423 | rx_ring->next_to_clean = 0; |
| 5424 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5425 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 5426 | ixgbe_init_rx_page_offset(rx_ring); |
| 5427 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5428 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5429 | err: |
| 5430 | vfree(rx_ring->rx_buffer_info); |
| 5431 | rx_ring->rx_buffer_info = NULL; |
| 5432 | 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] | 5433 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5437 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5438 | * @adapter: board private structure |
| 5439 | * |
| 5440 | * If this function returns with an error, then it's possible one or |
| 5441 | * more of the rings is populated (while the rest are not). It is the |
| 5442 | * callers duty to clean those orphaned rings. |
| 5443 | * |
| 5444 | * Return 0 on success, negative on failure |
| 5445 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5446 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5447 | { |
| 5448 | int i, err = 0; |
| 5449 | |
| 5450 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5451 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5452 | if (!err) |
| 5453 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5454 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5455 | break; |
| 5456 | } |
| 5457 | |
| 5458 | return err; |
| 5459 | } |
| 5460 | |
| 5461 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5462 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5463 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5464 | * |
| 5465 | * Free all transmit software resources |
| 5466 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5467 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5468 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5469 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5470 | |
| 5471 | vfree(tx_ring->tx_buffer_info); |
| 5472 | tx_ring->tx_buffer_info = NULL; |
| 5473 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5474 | /* if not set, then don't free */ |
| 5475 | if (!tx_ring->desc) |
| 5476 | return; |
| 5477 | |
| 5478 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5479 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5480 | |
| 5481 | tx_ring->desc = NULL; |
| 5482 | } |
| 5483 | |
| 5484 | /** |
| 5485 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5486 | * @adapter: board private structure |
| 5487 | * |
| 5488 | * Free all transmit software resources |
| 5489 | **/ |
| 5490 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5491 | { |
| 5492 | int i; |
| 5493 | |
| 5494 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5495 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5496 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5500 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5501 | * @rx_ring: ring to clean the resources from |
| 5502 | * |
| 5503 | * Free all receive software resources |
| 5504 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5505 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5506 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5507 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5508 | |
| 5509 | vfree(rx_ring->rx_buffer_info); |
| 5510 | rx_ring->rx_buffer_info = NULL; |
| 5511 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5512 | /* if not set, then don't free */ |
| 5513 | if (!rx_ring->desc) |
| 5514 | return; |
| 5515 | |
| 5516 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5517 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5518 | |
| 5519 | rx_ring->desc = NULL; |
| 5520 | } |
| 5521 | |
| 5522 | /** |
| 5523 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5524 | * @adapter: board private structure |
| 5525 | * |
| 5526 | * Free all receive software resources |
| 5527 | **/ |
| 5528 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5529 | { |
| 5530 | int i; |
| 5531 | |
| 5532 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5533 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5534 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5538 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5539 | * @netdev: network interface device structure |
| 5540 | * @new_mtu: new value for maximum frame size |
| 5541 | * |
| 5542 | * Returns 0 on success, negative on failure |
| 5543 | **/ |
| 5544 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5545 | { |
| 5546 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5547 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5548 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5549 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5550 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5551 | return -EINVAL; |
| 5552 | |
| 5553 | /* |
| 5554 | * For 82599EB we cannot allow PF to change MTU greater than 1500 |
| 5555 | * in SR-IOV mode as it may cause buffer overruns in guest VFs that |
| 5556 | * don't allocate and chain buffers correctly. |
| 5557 | */ |
| 5558 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 5559 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
| 5560 | (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 5561 | return -EINVAL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5562 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5563 | 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] | 5564 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5565 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5566 | netdev->mtu = new_mtu; |
| 5567 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5568 | if (netif_running(netdev)) |
| 5569 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5570 | |
| 5571 | return 0; |
| 5572 | } |
| 5573 | |
| 5574 | /** |
| 5575 | * ixgbe_open - Called when a network interface is made active |
| 5576 | * @netdev: network interface device structure |
| 5577 | * |
| 5578 | * Returns 0 on success, negative value on failure |
| 5579 | * |
| 5580 | * The open entry point is called when a network interface is made |
| 5581 | * active by the system (IFF_UP). At this point all resources needed |
| 5582 | * for transmit and receive operations are allocated, the interrupt |
| 5583 | * handler is registered with the OS, the watchdog timer is started, |
| 5584 | * and the stack is notified that the interface is ready. |
| 5585 | **/ |
| 5586 | static int ixgbe_open(struct net_device *netdev) |
| 5587 | { |
| 5588 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5589 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5590 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5591 | /* disallow open during test */ |
| 5592 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5593 | return -EBUSY; |
| 5594 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5595 | netif_carrier_off(netdev); |
| 5596 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5597 | /* allocate transmit descriptors */ |
| 5598 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5599 | if (err) |
| 5600 | goto err_setup_tx; |
| 5601 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5602 | /* allocate receive descriptors */ |
| 5603 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5604 | if (err) |
| 5605 | goto err_setup_rx; |
| 5606 | |
| 5607 | ixgbe_configure(adapter); |
| 5608 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5609 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5610 | if (err) |
| 5611 | goto err_req_irq; |
| 5612 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5613 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5614 | |
| 5615 | return 0; |
| 5616 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5617 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5618 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5619 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5620 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5621 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5622 | ixgbe_reset(adapter); |
| 5623 | |
| 5624 | return err; |
| 5625 | } |
| 5626 | |
| 5627 | /** |
| 5628 | * ixgbe_close - Disables a network interface |
| 5629 | * @netdev: network interface device structure |
| 5630 | * |
| 5631 | * Returns 0, this is not allowed to fail |
| 5632 | * |
| 5633 | * The close entry point is called when an interface is de-activated |
| 5634 | * by the OS. The hardware is still under the drivers control, but |
| 5635 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5636 | * hardware, and all transmit and receive resources are freed. |
| 5637 | **/ |
| 5638 | static int ixgbe_close(struct net_device *netdev) |
| 5639 | { |
| 5640 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5641 | |
| 5642 | ixgbe_down(adapter); |
| 5643 | ixgbe_free_irq(adapter); |
| 5644 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5645 | ixgbe_fdir_filter_exit(adapter); |
| 5646 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5647 | ixgbe_free_all_tx_resources(adapter); |
| 5648 | ixgbe_free_all_rx_resources(adapter); |
| 5649 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5650 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5651 | |
| 5652 | return 0; |
| 5653 | } |
| 5654 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5655 | #ifdef CONFIG_PM |
| 5656 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5657 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5658 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5659 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5660 | u32 err; |
| 5661 | |
| 5662 | pci_set_power_state(pdev, PCI_D0); |
| 5663 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5664 | /* |
| 5665 | * pci_restore_state clears dev->state_saved so call |
| 5666 | * pci_save_state to restore it. |
| 5667 | */ |
| 5668 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5669 | |
| 5670 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5671 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5672 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5673 | return err; |
| 5674 | } |
| 5675 | pci_set_master(pdev); |
| 5676 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5677 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5678 | |
| 5679 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5680 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5681 | e_dev_err("Cannot initialize interrupts for device\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5682 | return err; |
| 5683 | } |
| 5684 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5685 | ixgbe_reset(adapter); |
| 5686 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5687 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5688 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5689 | if (netif_running(netdev)) { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5690 | err = ixgbe_open(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5691 | if (err) |
| 5692 | return err; |
| 5693 | } |
| 5694 | |
| 5695 | netif_device_attach(netdev); |
| 5696 | |
| 5697 | return 0; |
| 5698 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5699 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5700 | |
| 5701 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5702 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5703 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5704 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5705 | struct ixgbe_hw *hw = &adapter->hw; |
| 5706 | u32 ctrl, fctrl; |
| 5707 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5708 | #ifdef CONFIG_PM |
| 5709 | int retval = 0; |
| 5710 | #endif |
| 5711 | |
| 5712 | netif_device_detach(netdev); |
| 5713 | |
| 5714 | if (netif_running(netdev)) { |
| 5715 | ixgbe_down(adapter); |
| 5716 | ixgbe_free_irq(adapter); |
| 5717 | ixgbe_free_all_tx_resources(adapter); |
| 5718 | ixgbe_free_all_rx_resources(adapter); |
| 5719 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5720 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5721 | ixgbe_clear_interrupt_scheme(adapter); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 5722 | #ifdef CONFIG_DCB |
| 5723 | kfree(adapter->ixgbe_ieee_pfc); |
| 5724 | kfree(adapter->ixgbe_ieee_ets); |
| 5725 | #endif |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5726 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5727 | #ifdef CONFIG_PM |
| 5728 | retval = pci_save_state(pdev); |
| 5729 | if (retval) |
| 5730 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5731 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5732 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5733 | if (wufc) { |
| 5734 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5735 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5736 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5737 | if (wufc & IXGBE_WUFC_MC) { |
| 5738 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5739 | fctrl |= IXGBE_FCTRL_MPE; |
| 5740 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5741 | } |
| 5742 | |
| 5743 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5744 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5745 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5746 | |
| 5747 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5748 | } else { |
| 5749 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5750 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5751 | } |
| 5752 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5753 | switch (hw->mac.type) { |
| 5754 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5755 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5756 | break; |
| 5757 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5758 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5759 | pci_wake_from_d3(pdev, !!wufc); |
| 5760 | break; |
| 5761 | default: |
| 5762 | break; |
| 5763 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5764 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5765 | *enable_wake = !!wufc; |
| 5766 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5767 | ixgbe_release_hw_control(adapter); |
| 5768 | |
| 5769 | pci_disable_device(pdev); |
| 5770 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5771 | return 0; |
| 5772 | } |
| 5773 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5774 | #ifdef CONFIG_PM |
| 5775 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5776 | { |
| 5777 | int retval; |
| 5778 | bool wake; |
| 5779 | |
| 5780 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5781 | if (retval) |
| 5782 | return retval; |
| 5783 | |
| 5784 | if (wake) { |
| 5785 | pci_prepare_to_sleep(pdev); |
| 5786 | } else { |
| 5787 | pci_wake_from_d3(pdev, false); |
| 5788 | pci_set_power_state(pdev, PCI_D3hot); |
| 5789 | } |
| 5790 | |
| 5791 | return 0; |
| 5792 | } |
| 5793 | #endif /* CONFIG_PM */ |
| 5794 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5795 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5796 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5797 | bool wake; |
| 5798 | |
| 5799 | __ixgbe_shutdown(pdev, &wake); |
| 5800 | |
| 5801 | if (system_state == SYSTEM_POWER_OFF) { |
| 5802 | pci_wake_from_d3(pdev, wake); |
| 5803 | pci_set_power_state(pdev, PCI_D3hot); |
| 5804 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5808 | * ixgbe_update_stats - Update the board statistics counters. |
| 5809 | * @adapter: board private structure |
| 5810 | **/ |
| 5811 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5812 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5813 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5814 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5815 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5816 | u64 total_mpc = 0; |
| 5817 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5818 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5819 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5820 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5821 | #ifdef IXGBE_FCOE |
| 5822 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 5823 | unsigned int cpu; |
| 5824 | u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0; |
| 5825 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5826 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5827 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5828 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5829 | return; |
| 5830 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5831 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5832 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5833 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5834 | for (i = 0; i < 16; i++) |
| 5835 | adapter->hw_rx_no_dma_resources += |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5836 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5837 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5838 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5839 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5840 | } |
| 5841 | adapter->rsc_total_count = rsc_count; |
| 5842 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5843 | } |
| 5844 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5845 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5846 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5847 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5848 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5849 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5850 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5851 | bytes += rx_ring->stats.bytes; |
| 5852 | packets += rx_ring->stats.packets; |
| 5853 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5854 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5855 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5856 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5857 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5858 | netdev->stats.rx_bytes = bytes; |
| 5859 | netdev->stats.rx_packets = packets; |
| 5860 | |
| 5861 | bytes = 0; |
| 5862 | packets = 0; |
| 5863 | /* gather some stats to the adapter struct that are per queue */ |
| 5864 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5865 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5866 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5867 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5868 | bytes += tx_ring->stats.bytes; |
| 5869 | packets += tx_ring->stats.packets; |
| 5870 | } |
| 5871 | adapter->restart_queue = restart_queue; |
| 5872 | adapter->tx_busy = tx_busy; |
| 5873 | netdev->stats.tx_bytes = bytes; |
| 5874 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5875 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5876 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5877 | |
| 5878 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5879 | for (i = 0; i < 8; i++) { |
| 5880 | /* for packet buffers not used, the register should read 0 */ |
| 5881 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5882 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5883 | hwstats->mpc[i] += mpc; |
| 5884 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5885 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5886 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5887 | switch (hw->mac.type) { |
| 5888 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5889 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5890 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5891 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5892 | hwstats->pxonrxc[i] += |
| 5893 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5894 | break; |
| 5895 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5896 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5897 | hwstats->pxonrxc[i] += |
| 5898 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5899 | break; |
| 5900 | default: |
| 5901 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5902 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5903 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5904 | |
| 5905 | /*16 register reads */ |
| 5906 | for (i = 0; i < 16; i++) { |
| 5907 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5908 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5909 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
| 5910 | (hw->mac.type == ixgbe_mac_X540)) { |
| 5911 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 5912 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 5913 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 5914 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 5915 | } |
| 5916 | } |
| 5917 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5918 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5919 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5920 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5921 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5922 | ixgbe_update_xoff_received(adapter); |
| 5923 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5924 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5925 | switch (hw->mac.type) { |
| 5926 | case ixgbe_mac_82598EB: |
| 5927 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5928 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5929 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5930 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5931 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5932 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5933 | /* OS2BMC stats are X540 only*/ |
| 5934 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5935 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5936 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5937 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5938 | case ixgbe_mac_82599EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5939 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5940 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5941 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5942 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5943 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5944 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5945 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5946 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5947 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5948 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5949 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5950 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5951 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5952 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5953 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5954 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5955 | /* Add up per cpu counters for total ddp aloc fail */ |
| 5956 | if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) { |
| 5957 | for_each_possible_cpu(cpu) { |
| 5958 | fcoe_noddp_counts_sum += |
| 5959 | *per_cpu_ptr(fcoe->pcpu_noddp, cpu); |
| 5960 | fcoe_noddp_ext_buff_counts_sum += |
| 5961 | *per_cpu_ptr(fcoe-> |
| 5962 | pcpu_noddp_ext_buff, cpu); |
| 5963 | } |
| 5964 | } |
| 5965 | hwstats->fcoe_noddp = fcoe_noddp_counts_sum; |
| 5966 | hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum; |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5967 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5968 | break; |
| 5969 | default: |
| 5970 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5971 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5972 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5973 | hwstats->bprc += bprc; |
| 5974 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5975 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5976 | hwstats->mprc -= bprc; |
| 5977 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5978 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5979 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5980 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5981 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5982 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5983 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5984 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5985 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5986 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5987 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5988 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5989 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5990 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5991 | /* |
| 5992 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5993 | */ |
| 5994 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5995 | hwstats->gptc -= xon_off_tot; |
| 5996 | hwstats->mptc -= xon_off_tot; |
| 5997 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5998 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5999 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6000 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6001 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6002 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6003 | hwstats->ptc64 -= xon_off_tot; |
| 6004 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6005 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6006 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6007 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6008 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6009 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6010 | |
| 6011 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6012 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6013 | |
| 6014 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6015 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6016 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6017 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6018 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6019 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6023 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
| 6024 | * @adapter - pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6025 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6026 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6027 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6028 | struct ixgbe_hw *hw = &adapter->hw; |
| 6029 | int i; |
| 6030 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6031 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6032 | return; |
| 6033 | |
| 6034 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6035 | |
| 6036 | /* if interface is down do nothing */ |
| 6037 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6038 | return; |
| 6039 | |
| 6040 | /* do nothing if we are not using signature filters */ |
| 6041 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6042 | return; |
| 6043 | |
| 6044 | adapter->fdir_overflow++; |
| 6045 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6046 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6047 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6048 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6049 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6050 | /* re-enable flow director interrupts */ |
| 6051 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6052 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6053 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6054 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6055 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6056 | } |
| 6057 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6058 | /** |
| 6059 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
| 6060 | * @adapter - pointer to the device adapter structure |
| 6061 | * |
| 6062 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6063 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6064 | * 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] | 6065 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6066 | */ |
| 6067 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6068 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6069 | struct ixgbe_hw *hw = &adapter->hw; |
| 6070 | u64 eics = 0; |
| 6071 | int i; |
| 6072 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6073 | /* If we're down or resetting, just bail */ |
| 6074 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6075 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6076 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6077 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6078 | /* Force detection of hung controller */ |
| 6079 | if (netif_carrier_ok(adapter->netdev)) { |
| 6080 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6081 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6082 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6083 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6084 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6085 | /* |
| 6086 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6087 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6088 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6089 | */ |
| 6090 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6091 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6092 | } else { |
| 6093 | /* get one bit for every active tx/rx interrupt vector */ |
| 6094 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 6095 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6096 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6097 | eics |= ((u64)1 << i); |
| 6098 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6099 | } |
| 6100 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6101 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6102 | ixgbe_irq_rearm_queues(adapter, eics); |
| 6103 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6104 | } |
| 6105 | |
| 6106 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6107 | * ixgbe_watchdog_update_link - update the link status |
| 6108 | * @adapter - pointer to the device adapter structure |
| 6109 | * @link_speed - pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6110 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6111 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6112 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6113 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6114 | u32 link_speed = adapter->link_speed; |
| 6115 | bool link_up = adapter->link_up; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6116 | int i; |
| 6117 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6118 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6119 | return; |
| 6120 | |
| 6121 | if (hw->mac.ops.check_link) { |
| 6122 | 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] | 6123 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6124 | /* always assume link is up, if no check link function */ |
| 6125 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6126 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6127 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6128 | if (link_up) { |
| 6129 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 6130 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 6131 | hw->mac.ops.fc_enable(hw, i); |
| 6132 | } else { |
| 6133 | hw->mac.ops.fc_enable(hw, 0); |
| 6134 | } |
| 6135 | } |
| 6136 | |
| 6137 | if (link_up || |
| 6138 | time_after(jiffies, (adapter->link_check_timeout + |
| 6139 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6140 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6141 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6142 | IXGBE_WRITE_FLUSH(hw); |
| 6143 | } |
| 6144 | |
| 6145 | adapter->link_up = link_up; |
| 6146 | adapter->link_speed = link_speed; |
| 6147 | } |
| 6148 | |
| 6149 | /** |
| 6150 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6151 | * print link up message |
| 6152 | * @adapter - pointer to the device adapter structure |
| 6153 | **/ |
| 6154 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6155 | { |
| 6156 | struct net_device *netdev = adapter->netdev; |
| 6157 | struct ixgbe_hw *hw = &adapter->hw; |
| 6158 | u32 link_speed = adapter->link_speed; |
| 6159 | bool flow_rx, flow_tx; |
| 6160 | |
| 6161 | /* only continue if link was previously down */ |
| 6162 | if (netif_carrier_ok(netdev)) |
| 6163 | return; |
| 6164 | |
| 6165 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6166 | |
| 6167 | switch (hw->mac.type) { |
| 6168 | case ixgbe_mac_82598EB: { |
| 6169 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6170 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6171 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6172 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6173 | } |
| 6174 | break; |
| 6175 | case ixgbe_mac_X540: |
| 6176 | case ixgbe_mac_82599EB: { |
| 6177 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6178 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6179 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6180 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6181 | } |
| 6182 | break; |
| 6183 | default: |
| 6184 | flow_tx = false; |
| 6185 | flow_rx = false; |
| 6186 | break; |
| 6187 | } |
| 6188 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 6189 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 6190 | "10 Gbps" : |
| 6191 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 6192 | "1 Gbps" : |
| 6193 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6194 | "100 Mbps" : |
| 6195 | "unknown speed"))), |
| 6196 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6197 | (flow_rx ? "RX" : |
| 6198 | (flow_tx ? "TX" : "None")))); |
| 6199 | |
| 6200 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6201 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | /** |
| 6205 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6206 | * print link down message |
| 6207 | * @adapter - pointer to the adapter structure |
| 6208 | **/ |
| 6209 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) |
| 6210 | { |
| 6211 | struct net_device *netdev = adapter->netdev; |
| 6212 | struct ixgbe_hw *hw = &adapter->hw; |
| 6213 | |
| 6214 | adapter->link_up = false; |
| 6215 | adapter->link_speed = 0; |
| 6216 | |
| 6217 | /* only continue if link was up previously */ |
| 6218 | if (!netif_carrier_ok(netdev)) |
| 6219 | return; |
| 6220 | |
| 6221 | /* poll for SFP+ cable when link is down */ |
| 6222 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6223 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6224 | |
| 6225 | e_info(drv, "NIC Link is Down\n"); |
| 6226 | netif_carrier_off(netdev); |
| 6227 | } |
| 6228 | |
| 6229 | /** |
| 6230 | * ixgbe_watchdog_flush_tx - flush queues on link down |
| 6231 | * @adapter - pointer to the device adapter structure |
| 6232 | **/ |
| 6233 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6234 | { |
| 6235 | int i; |
| 6236 | int some_tx_pending = 0; |
| 6237 | |
| 6238 | if (!netif_carrier_ok(adapter->netdev)) { |
| 6239 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6240 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6241 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 6242 | some_tx_pending = 1; |
| 6243 | break; |
| 6244 | } |
| 6245 | } |
| 6246 | |
| 6247 | if (some_tx_pending) { |
| 6248 | /* We've lost link, so the controller stops DMA, |
| 6249 | * but we've got queued Tx work that's never going |
| 6250 | * to get done, so reset controller to flush Tx. |
| 6251 | * (Do the reset outside of interrupt context). |
| 6252 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6253 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6254 | } |
| 6255 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6258 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6259 | { |
| 6260 | u32 ssvpc; |
| 6261 | |
| 6262 | /* Do not perform spoof check for 82598 */ |
| 6263 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6264 | return; |
| 6265 | |
| 6266 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6267 | |
| 6268 | /* |
| 6269 | * ssvpc register is cleared on read, if zero then no |
| 6270 | * spoofed packets in the last interval. |
| 6271 | */ |
| 6272 | if (!ssvpc) |
| 6273 | return; |
| 6274 | |
| 6275 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); |
| 6276 | } |
| 6277 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6278 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6279 | * ixgbe_watchdog_subtask - check and bring link up |
| 6280 | * @adapter - pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6281 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6282 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6283 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6284 | /* if interface is down do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6285 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6286 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6287 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6288 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6289 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6290 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6291 | if (adapter->link_up) |
| 6292 | ixgbe_watchdog_link_is_up(adapter); |
| 6293 | else |
| 6294 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6295 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6296 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6297 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6298 | |
| 6299 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6300 | } |
| 6301 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6302 | /** |
| 6303 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
| 6304 | * @adapter - the ixgbe adapter structure |
| 6305 | **/ |
| 6306 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6307 | { |
| 6308 | struct ixgbe_hw *hw = &adapter->hw; |
| 6309 | s32 err; |
| 6310 | |
| 6311 | /* not searching for SFP so there is nothing to do here */ |
| 6312 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6313 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6314 | return; |
| 6315 | |
| 6316 | /* someone else is in init, wait until next service event */ |
| 6317 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6318 | return; |
| 6319 | |
| 6320 | err = hw->phy.ops.identify_sfp(hw); |
| 6321 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6322 | goto sfp_out; |
| 6323 | |
| 6324 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6325 | /* If no cable is present, then we need to reset |
| 6326 | * the next time we find a good cable. */ |
| 6327 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6328 | } |
| 6329 | |
| 6330 | /* exit on error */ |
| 6331 | if (err) |
| 6332 | goto sfp_out; |
| 6333 | |
| 6334 | /* exit if reset not needed */ |
| 6335 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6336 | goto sfp_out; |
| 6337 | |
| 6338 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6339 | |
| 6340 | /* |
| 6341 | * A module may be identified correctly, but the EEPROM may not have |
| 6342 | * support for that module. setup_sfp() will fail in that case, so |
| 6343 | * we should not allow that module to load. |
| 6344 | */ |
| 6345 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6346 | err = hw->phy.ops.reset(hw); |
| 6347 | else |
| 6348 | err = hw->mac.ops.setup_sfp(hw); |
| 6349 | |
| 6350 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6351 | goto sfp_out; |
| 6352 | |
| 6353 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6354 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6355 | |
| 6356 | sfp_out: |
| 6357 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6358 | |
| 6359 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6360 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6361 | e_dev_err("failed to initialize because an unsupported " |
| 6362 | "SFP+ module type was detected.\n"); |
| 6363 | e_dev_err("Reload the driver after installing a " |
| 6364 | "supported module.\n"); |
| 6365 | unregister_netdev(adapter->netdev); |
| 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | /** |
| 6370 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
| 6371 | * @adapter - the ixgbe adapter structure |
| 6372 | **/ |
| 6373 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6374 | { |
| 6375 | struct ixgbe_hw *hw = &adapter->hw; |
| 6376 | u32 autoneg; |
| 6377 | bool negotiation; |
| 6378 | |
| 6379 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6380 | return; |
| 6381 | |
| 6382 | /* someone else is in init, wait until next service event */ |
| 6383 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6384 | return; |
| 6385 | |
| 6386 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6387 | |
| 6388 | autoneg = hw->phy.autoneg_advertised; |
| 6389 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 6390 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6391 | if (hw->mac.ops.setup_link) |
| 6392 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 6393 | |
| 6394 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6395 | adapter->link_check_timeout = jiffies; |
| 6396 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6397 | } |
| 6398 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6399 | #ifdef CONFIG_PCI_IOV |
| 6400 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6401 | { |
| 6402 | int vf; |
| 6403 | struct ixgbe_hw *hw = &adapter->hw; |
| 6404 | struct net_device *netdev = adapter->netdev; |
| 6405 | u32 gpc; |
| 6406 | u32 ciaa, ciad; |
| 6407 | |
| 6408 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6409 | if (gpc) /* If incrementing then no need for the check below */ |
| 6410 | return; |
| 6411 | /* |
| 6412 | * Check to see if a bad DMA write target from an errant or |
| 6413 | * malicious VF has caused a PCIe error. If so then we can |
| 6414 | * issue a VFLR to the offending VF(s) and then resume without |
| 6415 | * requesting a full slot reset. |
| 6416 | */ |
| 6417 | |
| 6418 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 6419 | ciaa = (vf << 16) | 0x80000000; |
| 6420 | /* 32 bit read so align, we really want status at offset 6 */ |
| 6421 | ciaa |= PCI_COMMAND; |
| 6422 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6423 | ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599); |
| 6424 | ciaa &= 0x7FFFFFFF; |
| 6425 | /* disable debug mode asap after reading data */ |
| 6426 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6427 | /* Get the upper 16 bits which will be the PCI status reg */ |
| 6428 | ciad >>= 16; |
| 6429 | if (ciad & PCI_STATUS_REC_MASTER_ABORT) { |
| 6430 | netdev_err(netdev, "VF %d Hung DMA\n", vf); |
| 6431 | /* Issue VFLR */ |
| 6432 | ciaa = (vf << 16) | 0x80000000; |
| 6433 | ciaa |= 0xA8; |
| 6434 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6435 | ciad = 0x00008000; /* VFLR */ |
| 6436 | IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad); |
| 6437 | ciaa &= 0x7FFFFFFF; |
| 6438 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6439 | } |
| 6440 | } |
| 6441 | } |
| 6442 | |
| 6443 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6444 | /** |
| 6445 | * ixgbe_service_timer - Timer Call-back |
| 6446 | * @data: pointer to adapter cast into an unsigned long |
| 6447 | **/ |
| 6448 | static void ixgbe_service_timer(unsigned long data) |
| 6449 | { |
| 6450 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6451 | unsigned long next_event_offset; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6452 | bool ready = true; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6453 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6454 | #ifdef CONFIG_PCI_IOV |
| 6455 | ready = false; |
| 6456 | |
| 6457 | /* |
| 6458 | * don't bother with SR-IOV VF DMA hang check if there are |
| 6459 | * no VFs or the link is down |
| 6460 | */ |
| 6461 | if (!adapter->num_vfs || |
| 6462 | (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) { |
| 6463 | ready = true; |
| 6464 | goto normal_timer_service; |
| 6465 | } |
| 6466 | |
| 6467 | /* If we have VFs allocated then we must check for DMA hangs */ |
| 6468 | ixgbe_check_for_bad_vf(adapter); |
| 6469 | next_event_offset = HZ / 50; |
| 6470 | adapter->timer_event_accumulator++; |
| 6471 | |
| 6472 | if (adapter->timer_event_accumulator >= 100) { |
| 6473 | ready = true; |
| 6474 | adapter->timer_event_accumulator = 0; |
| 6475 | } |
| 6476 | |
| 6477 | goto schedule_event; |
| 6478 | |
| 6479 | normal_timer_service: |
| 6480 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6481 | /* poll faster when waiting for link */ |
| 6482 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6483 | next_event_offset = HZ / 10; |
| 6484 | else |
| 6485 | next_event_offset = HZ * 2; |
| 6486 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6487 | #ifdef CONFIG_PCI_IOV |
| 6488 | schedule_event: |
| 6489 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6490 | /* Reset the timer */ |
| 6491 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6492 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6493 | if (ready) |
| 6494 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6495 | } |
| 6496 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6497 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6498 | { |
| 6499 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6500 | return; |
| 6501 | |
| 6502 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6503 | |
| 6504 | /* If we're already down or resetting, just bail */ |
| 6505 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6506 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6507 | return; |
| 6508 | |
| 6509 | ixgbe_dump(adapter); |
| 6510 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6511 | adapter->tx_timeout_count++; |
| 6512 | |
| 6513 | ixgbe_reinit_locked(adapter); |
| 6514 | } |
| 6515 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6516 | /** |
| 6517 | * ixgbe_service_task - manages and runs subtasks |
| 6518 | * @work: pointer to work_struct containing our data |
| 6519 | **/ |
| 6520 | static void ixgbe_service_task(struct work_struct *work) |
| 6521 | { |
| 6522 | struct ixgbe_adapter *adapter = container_of(work, |
| 6523 | struct ixgbe_adapter, |
| 6524 | service_task); |
| 6525 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6526 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6527 | ixgbe_sfp_detection_subtask(adapter); |
| 6528 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6529 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6530 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6531 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6532 | ixgbe_check_hang_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6533 | |
| 6534 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6535 | } |
| 6536 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6537 | void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens, |
| 6538 | u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6539 | { |
| 6540 | struct ixgbe_adv_tx_context_desc *context_desc; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6541 | u16 i = tx_ring->next_to_use; |
| 6542 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6543 | context_desc = IXGBE_TX_CTXTDESC(tx_ring, i); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6544 | |
| 6545 | i++; |
| 6546 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 6547 | |
| 6548 | /* set bits to identify this as an advanced context descriptor */ |
| 6549 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 6550 | |
| 6551 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6552 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); |
| 6553 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 6554 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 6555 | } |
| 6556 | |
| 6557 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 6558 | u32 tx_flags, __be16 protocol, u8 *hdr_len) |
| 6559 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6560 | int err; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6561 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6562 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6563 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6564 | if (!skb_is_gso(skb)) |
| 6565 | return 0; |
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_header_cloned(skb)) { |
| 6568 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 6569 | if (err) |
| 6570 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6571 | } |
| 6572 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6573 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6574 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6575 | |
| 6576 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6577 | struct iphdr *iph = ip_hdr(skb); |
| 6578 | iph->tot_len = 0; |
| 6579 | iph->check = 0; |
| 6580 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6581 | iph->daddr, 0, |
| 6582 | IPPROTO_TCP, |
| 6583 | 0); |
| 6584 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6585 | } else if (skb_is_gso_v6(skb)) { |
| 6586 | ipv6_hdr(skb)->payload_len = 0; |
| 6587 | tcp_hdr(skb)->check = |
| 6588 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6589 | &ipv6_hdr(skb)->daddr, |
| 6590 | 0, IPPROTO_TCP, 0); |
| 6591 | } |
| 6592 | |
| 6593 | l4len = tcp_hdrlen(skb); |
| 6594 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6595 | |
| 6596 | /* mss_l4len_id: use 1 as index for TSO */ |
| 6597 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6598 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 6599 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 6600 | |
| 6601 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6602 | vlan_macip_lens = skb_network_header_len(skb); |
| 6603 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6604 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6605 | |
| 6606 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
| 6607 | mss_l4len_idx); |
| 6608 | |
| 6609 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6610 | } |
| 6611 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6612 | static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6613 | struct sk_buff *skb, u32 tx_flags, |
| 6614 | __be16 protocol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6615 | { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6616 | u32 vlan_macip_lens = 0; |
| 6617 | u32 mss_l4len_idx = 0; |
| 6618 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6619 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6620 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6621 | if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) && |
| 6622 | !(tx_flags & IXGBE_TX_FLAGS_TXSW)) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6623 | return false; |
| 6624 | } else { |
| 6625 | u8 l4_hdr = 0; |
| 6626 | switch (protocol) { |
| 6627 | case __constant_htons(ETH_P_IP): |
| 6628 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6629 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6630 | l4_hdr = ip_hdr(skb)->protocol; |
| 6631 | break; |
| 6632 | case __constant_htons(ETH_P_IPV6): |
| 6633 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6634 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6635 | break; |
| 6636 | default: |
| 6637 | if (unlikely(net_ratelimit())) { |
| 6638 | dev_warn(tx_ring->dev, |
| 6639 | "partial checksum but proto=%x!\n", |
| 6640 | skb->protocol); |
| 6641 | } |
| 6642 | break; |
| 6643 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6644 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6645 | switch (l4_hdr) { |
| 6646 | case IPPROTO_TCP: |
| 6647 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6648 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6649 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6650 | break; |
| 6651 | case IPPROTO_SCTP: |
| 6652 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6653 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6654 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6655 | break; |
| 6656 | case IPPROTO_UDP: |
| 6657 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6658 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6659 | break; |
| 6660 | default: |
| 6661 | if (unlikely(net_ratelimit())) { |
| 6662 | dev_warn(tx_ring->dev, |
| 6663 | "partial checksum but l4 proto=%x!\n", |
| 6664 | skb->protocol); |
| 6665 | } |
| 6666 | break; |
| 6667 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6668 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6669 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6670 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6671 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6672 | |
| 6673 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6674 | type_tucmd, mss_l4len_idx); |
| 6675 | |
| 6676 | return (skb->ip_summed == CHECKSUM_PARTIAL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6677 | } |
| 6678 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6679 | static __le32 ixgbe_tx_cmd_type(u32 tx_flags) |
| 6680 | { |
| 6681 | /* set type for advanced descriptor with frame checksum insertion */ |
| 6682 | __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA | |
| 6683 | IXGBE_ADVTXD_DCMD_IFCS | |
| 6684 | IXGBE_ADVTXD_DCMD_DEXT); |
| 6685 | |
| 6686 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6687 | if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6688 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE); |
| 6689 | |
| 6690 | /* set segmentation enable bits for TSO/FSO */ |
| 6691 | #ifdef IXGBE_FCOE |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame^] | 6692 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6693 | #else |
| 6694 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6695 | #endif |
| 6696 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE); |
| 6697 | |
| 6698 | return cmd_type; |
| 6699 | } |
| 6700 | |
| 6701 | static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen) |
| 6702 | { |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame^] | 6703 | __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6704 | |
| 6705 | /* enable L4 checksum for TSO and TX checksum offload */ |
| 6706 | if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6707 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM); |
| 6708 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame^] | 6709 | /* enble IPv4 checksum for TSO */ |
| 6710 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6711 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6712 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame^] | 6713 | /* use index 1 context for TSO/FSO/FCOE */ |
| 6714 | #ifdef IXGBE_FCOE |
| 6715 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE)) |
| 6716 | #else |
| 6717 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6718 | #endif |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame^] | 6719 | olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 6720 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6721 | /* |
| 6722 | * Check Context must be set if Tx switch is enabled, which it |
| 6723 | * always is for case where virtual functions are running |
| 6724 | */ |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame^] | 6725 | #ifdef IXGBE_FCOE |
| 6726 | if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE)) |
| 6727 | #else |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6728 | if (tx_flags & IXGBE_TX_FLAGS_TXSW) |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame^] | 6729 | #endif |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6730 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC); |
| 6731 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6732 | return olinfo_status; |
| 6733 | } |
| 6734 | |
| 6735 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 6736 | IXGBE_TXD_CMD_RS) |
| 6737 | |
| 6738 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
| 6739 | struct sk_buff *skb, |
| 6740 | struct ixgbe_tx_buffer *first, |
| 6741 | u32 tx_flags, |
| 6742 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6743 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6744 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6745 | struct ixgbe_tx_buffer *tx_buffer_info; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6746 | union ixgbe_adv_tx_desc *tx_desc; |
| 6747 | dma_addr_t dma; |
| 6748 | __le32 cmd_type, olinfo_status; |
| 6749 | struct skb_frag_struct *frag; |
| 6750 | unsigned int f = 0; |
| 6751 | unsigned int data_len = skb->data_len; |
| 6752 | unsigned int size = skb_headlen(skb); |
| 6753 | u32 offset = 0; |
| 6754 | u32 paylen = skb->len - hdr_len; |
| 6755 | u16 i = tx_ring->next_to_use; |
| 6756 | u16 gso_segs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6757 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6758 | #ifdef IXGBE_FCOE |
| 6759 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6760 | if (data_len >= sizeof(struct fcoe_crc_eof)) { |
| 6761 | data_len -= sizeof(struct fcoe_crc_eof); |
| 6762 | } else { |
| 6763 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 6764 | data_len = 0; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6765 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6768 | #endif |
| 6769 | dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE); |
| 6770 | if (dma_mapping_error(dev, dma)) |
| 6771 | goto dma_error; |
| 6772 | |
| 6773 | cmd_type = ixgbe_tx_cmd_type(tx_flags); |
| 6774 | olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen); |
| 6775 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6776 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6777 | |
| 6778 | for (;;) { |
| 6779 | while (size > IXGBE_MAX_DATA_PER_TXD) { |
| 6780 | tx_desc->read.buffer_addr = cpu_to_le64(dma + offset); |
| 6781 | tx_desc->read.cmd_type_len = |
| 6782 | cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD); |
| 6783 | tx_desc->read.olinfo_status = olinfo_status; |
| 6784 | |
| 6785 | offset += IXGBE_MAX_DATA_PER_TXD; |
| 6786 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 6787 | |
| 6788 | tx_desc++; |
| 6789 | i++; |
| 6790 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6791 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6792 | i = 0; |
| 6793 | } |
| 6794 | } |
| 6795 | |
| 6796 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6797 | tx_buffer_info->length = offset + size; |
| 6798 | tx_buffer_info->tx_flags = tx_flags; |
| 6799 | tx_buffer_info->dma = dma; |
| 6800 | |
| 6801 | tx_desc->read.buffer_addr = cpu_to_le64(dma + offset); |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 6802 | if (unlikely(skb->no_fcs)) |
| 6803 | cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6804 | tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size); |
| 6805 | tx_desc->read.olinfo_status = olinfo_status; |
| 6806 | |
| 6807 | if (!data_len) |
| 6808 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6809 | |
| 6810 | frag = &skb_shinfo(skb)->frags[f]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6811 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6812 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6813 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6814 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6815 | #endif |
| 6816 | data_len -= size; |
| 6817 | f++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6818 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6819 | offset = 0; |
| 6820 | tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6821 | |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 6822 | dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6823 | if (dma_mapping_error(dev, dma)) |
| 6824 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6825 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6826 | tx_desc++; |
| 6827 | i++; |
| 6828 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6829 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6830 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6831 | } |
| 6832 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6833 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6834 | tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD); |
| 6835 | |
| 6836 | i++; |
| 6837 | if (i == tx_ring->count) |
| 6838 | i = 0; |
| 6839 | |
| 6840 | tx_ring->next_to_use = i; |
| 6841 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6842 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6843 | gso_segs = skb_shinfo(skb)->gso_segs; |
| 6844 | #ifdef IXGBE_FCOE |
| 6845 | /* adjust for FCoE Sequence Offload */ |
| 6846 | else if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6847 | gso_segs = DIV_ROUND_UP(skb->len - hdr_len, |
| 6848 | skb_shinfo(skb)->gso_size); |
| 6849 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6850 | else |
| 6851 | gso_segs = 1; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6852 | |
| 6853 | /* multiply data chunks by size of headers */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6854 | tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len); |
| 6855 | tx_buffer_info->gso_segs = gso_segs; |
| 6856 | tx_buffer_info->skb = skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6857 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 6858 | netdev_tx_sent_queue(txring_txq(tx_ring), tx_buffer_info->bytecount); |
| 6859 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6860 | /* set the timestamp */ |
| 6861 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6862 | |
| 6863 | /* |
| 6864 | * Force memory writes to complete before letting h/w |
| 6865 | * know there are new descriptors to fetch. (Only |
| 6866 | * applicable for weak-ordered memory model archs, |
| 6867 | * such as IA-64). |
| 6868 | */ |
| 6869 | wmb(); |
| 6870 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6871 | /* set next_to_watch value indicating a packet is present */ |
| 6872 | first->next_to_watch = tx_desc; |
| 6873 | |
| 6874 | /* notify HW of packet */ |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6875 | writel(i, tx_ring->tail); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6876 | |
| 6877 | return; |
| 6878 | dma_error: |
| 6879 | dev_err(dev, "TX DMA map failed\n"); |
| 6880 | |
| 6881 | /* clear dma mappings for failed tx_buffer_info map */ |
| 6882 | for (;;) { |
| 6883 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6884 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info); |
| 6885 | if (tx_buffer_info == first) |
| 6886 | break; |
| 6887 | if (i == 0) |
| 6888 | i = tx_ring->count; |
| 6889 | i--; |
| 6890 | } |
| 6891 | |
| 6892 | dev_kfree_skb_any(skb); |
| 6893 | |
| 6894 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6895 | } |
| 6896 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6897 | static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb, |
| 6898 | u32 tx_flags, __be16 protocol) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6899 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6900 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6901 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6902 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6903 | union { |
| 6904 | unsigned char *network; |
| 6905 | struct iphdr *ipv4; |
| 6906 | struct ipv6hdr *ipv6; |
| 6907 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6908 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6909 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6910 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6911 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6912 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6913 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6914 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6915 | /* do nothing if sampling is disabled */ |
| 6916 | if (!ring->atr_sample_rate) |
| 6917 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6918 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6919 | ring->atr_count++; |
| 6920 | |
| 6921 | /* snag network header to get L4 type and address */ |
| 6922 | hdr.network = skb_network_header(skb); |
| 6923 | |
| 6924 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 6925 | if ((protocol != __constant_htons(ETH_P_IPV6) || |
| 6926 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
| 6927 | (protocol != __constant_htons(ETH_P_IP) || |
| 6928 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6929 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6930 | |
| 6931 | th = tcp_hdr(skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6932 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6933 | /* skip this packet since it is invalid or the socket is closing */ |
| 6934 | if (!th || th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6935 | return; |
| 6936 | |
| 6937 | /* sample on all syn packets or once every atr sample count */ |
| 6938 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6939 | return; |
| 6940 | |
| 6941 | /* reset sample count */ |
| 6942 | ring->atr_count = 0; |
| 6943 | |
| 6944 | vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6945 | |
| 6946 | /* |
| 6947 | * src and dst are inverted, think how the receiver sees them |
| 6948 | * |
| 6949 | * The input is broken into two sections, a non-compressed section |
| 6950 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6951 | * is XORed together and stored in the compressed dword. |
| 6952 | */ |
| 6953 | input.formatted.vlan_id = vlan_id; |
| 6954 | |
| 6955 | /* |
| 6956 | * since src port and flex bytes occupy the same word XOR them together |
| 6957 | * and write the value to source port portion of compressed dword |
| 6958 | */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6959 | 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] | 6960 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6961 | else |
| 6962 | common.port.src ^= th->dest ^ protocol; |
| 6963 | common.port.dst ^= th->source; |
| 6964 | |
| 6965 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6966 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6967 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6968 | } else { |
| 6969 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6970 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6971 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6972 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6973 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6974 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6975 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6976 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6977 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6978 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6979 | |
| 6980 | /* 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] | 6981 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6982 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6983 | } |
| 6984 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6985 | 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] | 6986 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6987 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6988 | /* Herbert's original patch had: |
| 6989 | * smp_mb__after_netif_stop_queue(); |
| 6990 | * but since that doesn't exist yet, just open code it. */ |
| 6991 | smp_mb(); |
| 6992 | |
| 6993 | /* We need to check again in a case another CPU has just |
| 6994 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6995 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6996 | return -EBUSY; |
| 6997 | |
| 6998 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6999 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 7000 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7001 | return 0; |
| 7002 | } |
| 7003 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 7004 | 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] | 7005 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 7006 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7007 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7008 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7009 | } |
| 7010 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7011 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 7012 | { |
| 7013 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 7014 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 7015 | smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 7016 | #ifdef IXGBE_FCOE |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 7017 | __be16 protocol = vlan_get_protocol(skb); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7018 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 7019 | if (((protocol == htons(ETH_P_FCOE)) || |
| 7020 | (protocol == htons(ETH_P_FIP))) && |
| 7021 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
| 7022 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 7023 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 7024 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 7025 | } |
| 7026 | #endif |
| 7027 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7028 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 7029 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 7030 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7031 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7032 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7033 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7034 | return skb_tx_hash(dev, skb); |
| 7035 | } |
| 7036 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7037 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7038 | struct ixgbe_adapter *adapter, |
| 7039 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7040 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7041 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7042 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7043 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7044 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 7045 | unsigned short f; |
| 7046 | #endif |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7047 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7048 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7049 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7050 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7051 | /* |
| 7052 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 7053 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7054 | * + 2 desc gap to keep tail from touching head, |
| 7055 | * + 1 desc for context descriptor, |
| 7056 | * otherwise try next time |
| 7057 | */ |
| 7058 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 7059 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 7060 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 7061 | #else |
| 7062 | count += skb_shinfo(skb)->nr_frags; |
| 7063 | #endif |
| 7064 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 7065 | tx_ring->tx_stats.tx_busy++; |
| 7066 | return NETDEV_TX_BUSY; |
| 7067 | } |
| 7068 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7069 | /* 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] | 7070 | if (vlan_tx_tag_present(skb)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7071 | tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 7072 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7073 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
| 7074 | } else if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 7075 | struct vlan_hdr *vhdr, _vhdr; |
| 7076 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 7077 | if (!vhdr) |
| 7078 | goto out_drop; |
| 7079 | |
| 7080 | protocol = vhdr->h_vlan_encapsulated_proto; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7081 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 7082 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7083 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7084 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7085 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7086 | #ifdef CONFIG_PCI_IOV |
| 7087 | /* |
| 7088 | * Use the l2switch_enable flag - would be false if the DMA |
| 7089 | * Tx switch had been disabled. |
| 7090 | */ |
| 7091 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7092 | tx_flags |= IXGBE_TX_FLAGS_TXSW; |
| 7093 | |
| 7094 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7095 | /* 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] | 7096 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 7097 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 7098 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7099 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7100 | tx_flags |= (skb->priority & 0x7) << |
| 7101 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7102 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 7103 | struct vlan_ethhdr *vhdr; |
| 7104 | if (skb_header_cloned(skb) && |
| 7105 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 7106 | goto out_drop; |
| 7107 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 7108 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 7109 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 7110 | } else { |
| 7111 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7112 | } |
| 7113 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7114 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7115 | /* record the location of the first descriptor for this packet */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7116 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7117 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7118 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7119 | /* setup tx offload for FCoE */ |
| 7120 | if ((protocol == __constant_htons(ETH_P_FCOE)) && |
| 7121 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7122 | tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len); |
| 7123 | if (tso < 0) |
| 7124 | goto out_drop; |
| 7125 | else if (tso) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7126 | tx_flags |= IXGBE_TX_FLAGS_FSO | |
| 7127 | IXGBE_TX_FLAGS_FCOE; |
| 7128 | else |
| 7129 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7130 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7131 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7132 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7133 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7134 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7135 | /* setup IPv4/IPv6 offloads */ |
| 7136 | if (protocol == __constant_htons(ETH_P_IP)) |
| 7137 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7138 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7139 | tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len); |
| 7140 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7141 | goto out_drop; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7142 | else if (tso) |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame^] | 7143 | tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7144 | else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol)) |
| 7145 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7146 | |
| 7147 | /* add the ATR filter if ATR is on */ |
| 7148 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
| 7149 | ixgbe_atr(tx_ring, skb, tx_flags, protocol); |
| 7150 | |
| 7151 | #ifdef IXGBE_FCOE |
| 7152 | xmit_fcoe: |
| 7153 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7154 | ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len); |
| 7155 | |
| 7156 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7157 | |
| 7158 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7159 | |
| 7160 | out_drop: |
| 7161 | dev_kfree_skb_any(skb); |
| 7162 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7163 | } |
| 7164 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7165 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7166 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7167 | { |
| 7168 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7169 | struct ixgbe_ring *tx_ring; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7170 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7171 | if (skb->len <= 0) { |
| 7172 | dev_kfree_skb_any(skb); |
| 7173 | return NETDEV_TX_OK; |
| 7174 | } |
| 7175 | |
| 7176 | /* |
| 7177 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 7178 | * in order to meet this minimum size requirement. |
| 7179 | */ |
| 7180 | if (skb->len < 17) { |
| 7181 | if (skb_padto(skb, 17)) |
| 7182 | return NETDEV_TX_OK; |
| 7183 | skb->len = 17; |
| 7184 | } |
| 7185 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7186 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
| 7187 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7188 | } |
| 7189 | |
| 7190 | /** |
| 7191 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7192 | * @netdev: network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7193 | * @p: pointer to an address structure |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7194 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7195 | * Returns 0 on success, negative on failure |
| 7196 | **/ |
| 7197 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7198 | { |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7199 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7200 | struct ixgbe_hw *hw = &adapter->hw; |
| 7201 | struct sockaddr *addr = p; |
| 7202 | |
| 7203 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7204 | return -EADDRNOTAVAIL; |
| 7205 | |
| 7206 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 7207 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
| 7208 | |
| 7209 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 7210 | IXGBE_RAH_AV); |
| 7211 | |
| 7212 | return 0; |
| 7213 | } |
| 7214 | |
| 7215 | static int |
| 7216 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7217 | { |
| 7218 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7219 | struct ixgbe_hw *hw = &adapter->hw; |
| 7220 | u16 value; |
| 7221 | int rc; |
| 7222 | |
| 7223 | if (prtad != hw->phy.mdio.prtad) |
| 7224 | return -EINVAL; |
| 7225 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7226 | if (!rc) |
| 7227 | rc = value; |
| 7228 | return rc; |
| 7229 | } |
| 7230 | |
| 7231 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7232 | u16 addr, u16 value) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7233 | { |
| 7234 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7235 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7236 | |
| 7237 | if (prtad != hw->phy.mdio.prtad) |
| 7238 | return -EINVAL; |
| 7239 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7240 | } |
| 7241 | |
| 7242 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7243 | { |
| 7244 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7245 | |
| 7246 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 7247 | } |
| 7248 | |
| 7249 | /** |
| 7250 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
| 7251 | * netdev->dev_addrs |
| 7252 | * @netdev: network interface device structure |
| 7253 | * |
| 7254 | * Returns non-zero on failure |
| 7255 | **/ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7256 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7257 | { |
| 7258 | int err = 0; |
| 7259 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7260 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7261 | |
| 7262 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7263 | rtnl_lock(); |
| 7264 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7265 | rtnl_unlock(); |
| 7266 | } |
| 7267 | return err; |
| 7268 | } |
| 7269 | |
| 7270 | /** |
| 7271 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
| 7272 | * netdev->dev_addrs |
| 7273 | * @netdev: network interface device structure |
| 7274 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7275 | * Returns non-zero on failure |
| 7276 | **/ |
| 7277 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 7278 | { |
| 7279 | int err = 0; |
| 7280 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7281 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7282 | |
| 7283 | if (is_valid_ether_addr(mac->san_addr)) { |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7284 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7285 | 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] | 7286 | rtnl_unlock(); |
| 7287 | } |
| 7288 | return err; |
| 7289 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7290 | |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7291 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7292 | /* |
| 7293 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7294 | * without having to re-enable interrupts. It's not called while |
| 7295 | * the interrupt routine is executing. |
| 7296 | */ |
| 7297 | static void ixgbe_netpoll(struct net_device *netdev) |
| 7298 | { |
| 7299 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7300 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7301 | |
| 7302 | /* if interface is down do nothing */ |
| 7303 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7304 | return; |
| 7305 | |
| 7306 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7307 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7308 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 7309 | for (i = 0; i < num_q_vectors; i++) { |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7310 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 7311 | ixgbe_msix_clean_rings(0, q_vector); |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7312 | } |
| 7313 | } else { |
| 7314 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 7315 | } |
| 7316 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
| 7317 | } |
| 7318 | #endif |
| 7319 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7320 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 7321 | struct rtnl_link_stats64 *stats) |
| 7322 | { |
| 7323 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7324 | int i; |
| 7325 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7326 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7327 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7328 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7329 | u64 bytes, packets; |
| 7330 | unsigned int start; |
| 7331 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7332 | if (ring) { |
| 7333 | do { |
| 7334 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7335 | packets = ring->stats.packets; |
| 7336 | bytes = ring->stats.bytes; |
| 7337 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7338 | stats->rx_packets += packets; |
| 7339 | stats->rx_bytes += bytes; |
| 7340 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7341 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7342 | |
| 7343 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7344 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7345 | u64 bytes, packets; |
| 7346 | unsigned int start; |
| 7347 | |
| 7348 | if (ring) { |
| 7349 | do { |
| 7350 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7351 | packets = ring->stats.packets; |
| 7352 | bytes = ring->stats.bytes; |
| 7353 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7354 | stats->tx_packets += packets; |
| 7355 | stats->tx_bytes += bytes; |
| 7356 | } |
| 7357 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7358 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7359 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7360 | stats->multicast = netdev->stats.multicast; |
| 7361 | stats->rx_errors = netdev->stats.rx_errors; |
| 7362 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7363 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7364 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7365 | return stats; |
| 7366 | } |
| 7367 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7368 | /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7369 | * #adapter: pointer to ixgbe_adapter |
| 7370 | * @tc: number of traffic classes currently enabled |
| 7371 | * |
| 7372 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7373 | * 802.1Q priority maps to a packet buffer that exists. |
| 7374 | */ |
| 7375 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7376 | { |
| 7377 | struct ixgbe_hw *hw = &adapter->hw; |
| 7378 | u32 reg, rsave; |
| 7379 | int i; |
| 7380 | |
| 7381 | /* 82598 have a static priority to TC mapping that can not |
| 7382 | * be changed so no validation is needed. |
| 7383 | */ |
| 7384 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7385 | return; |
| 7386 | |
| 7387 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7388 | rsave = reg; |
| 7389 | |
| 7390 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7391 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7392 | |
| 7393 | /* If up2tc is out of bounds default to zero */ |
| 7394 | if (up2tc > tc) |
| 7395 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7396 | } |
| 7397 | |
| 7398 | if (reg != rsave) |
| 7399 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7400 | |
| 7401 | return; |
| 7402 | } |
| 7403 | |
| 7404 | |
| 7405 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic |
| 7406 | * classes. |
| 7407 | * |
| 7408 | * @netdev: net device to configure |
| 7409 | * @tc: number of traffic classes to enable |
| 7410 | */ |
| 7411 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7412 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7413 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7414 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7415 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7416 | /* Multiple traffic classes requires multiple queues */ |
| 7417 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 7418 | e_err(drv, "Enable failed, needs MSI-X\n"); |
| 7419 | return -EINVAL; |
| 7420 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7421 | |
| 7422 | /* Hardware supports up to 8 traffic classes */ |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 7423 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs || |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7424 | (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS)) |
| 7425 | return -EINVAL; |
| 7426 | |
| 7427 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 7428 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7429 | * hardware is not flexible enough to do this dynamically. |
| 7430 | */ |
| 7431 | if (netif_running(dev)) |
| 7432 | ixgbe_close(dev); |
| 7433 | ixgbe_clear_interrupt_scheme(adapter); |
| 7434 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7435 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7436 | netdev_set_num_tc(dev, tc); |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7437 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; |
| 7438 | |
| 7439 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
| 7440 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7441 | |
| 7442 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 7443 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
| 7444 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7445 | netdev_reset_tc(dev); |
| 7446 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7447 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 7448 | |
| 7449 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 7450 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7451 | |
| 7452 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 7453 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 7454 | } |
| 7455 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7456 | ixgbe_init_interrupt_scheme(adapter); |
| 7457 | ixgbe_validate_rtr(adapter, tc); |
| 7458 | if (netif_running(dev)) |
| 7459 | ixgbe_open(dev); |
| 7460 | |
| 7461 | return 0; |
| 7462 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7463 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7464 | void ixgbe_do_reset(struct net_device *netdev) |
| 7465 | { |
| 7466 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7467 | |
| 7468 | if (netif_running(netdev)) |
| 7469 | ixgbe_reinit_locked(adapter); |
| 7470 | else |
| 7471 | ixgbe_reset(adapter); |
| 7472 | } |
| 7473 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7474 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
| 7475 | netdev_features_t data) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7476 | { |
| 7477 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7478 | |
| 7479 | #ifdef CONFIG_DCB |
| 7480 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 7481 | data &= ~NETIF_F_HW_VLAN_RX; |
| 7482 | #endif |
| 7483 | |
| 7484 | /* return error if RXHASH is being enabled when RSS is not supported */ |
| 7485 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 7486 | data &= ~NETIF_F_RXHASH; |
| 7487 | |
| 7488 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
| 7489 | if (!(data & NETIF_F_RXCSUM)) |
| 7490 | data &= ~NETIF_F_LRO; |
| 7491 | |
| 7492 | /* Turn off LRO if not RSC capable or invalid ITR settings */ |
| 7493 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) { |
| 7494 | data &= ~NETIF_F_LRO; |
| 7495 | } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
| 7496 | (adapter->rx_itr_setting != 1 && |
| 7497 | adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) { |
| 7498 | data &= ~NETIF_F_LRO; |
| 7499 | e_info(probe, "rx-usecs set too low, not enabling RSC\n"); |
| 7500 | } |
| 7501 | |
| 7502 | return data; |
| 7503 | } |
| 7504 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7505 | static int ixgbe_set_features(struct net_device *netdev, |
| 7506 | netdev_features_t data) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7507 | { |
| 7508 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7509 | netdev_features_t changed = netdev->features ^ data; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7510 | bool need_reset = false; |
| 7511 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7512 | /* Make sure RSC matches LRO, reset if change */ |
| 7513 | if (!!(data & NETIF_F_LRO) != |
| 7514 | !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 7515 | adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED; |
| 7516 | switch (adapter->hw.mac.type) { |
| 7517 | case ixgbe_mac_X540: |
| 7518 | case ixgbe_mac_82599EB: |
| 7519 | need_reset = true; |
| 7520 | break; |
| 7521 | default: |
| 7522 | break; |
| 7523 | } |
| 7524 | } |
| 7525 | |
| 7526 | /* |
| 7527 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 7528 | * the state changed, we need to reset. |
| 7529 | */ |
| 7530 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { |
| 7531 | /* turn off ATR, enable perfect filters and reset */ |
| 7532 | if (data & NETIF_F_NTUPLE) { |
| 7533 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7534 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7535 | need_reset = true; |
| 7536 | } |
| 7537 | } else if (!(data & NETIF_F_NTUPLE)) { |
| 7538 | /* turn off Flow Director, set ATR and reset */ |
| 7539 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7540 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 7541 | !(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 7542 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7543 | need_reset = true; |
| 7544 | } |
| 7545 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7546 | if (changed & NETIF_F_RXALL) |
| 7547 | need_reset = true; |
| 7548 | |
| 7549 | netdev->features = data; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7550 | if (need_reset) |
| 7551 | ixgbe_do_reset(netdev); |
| 7552 | |
| 7553 | return 0; |
| 7554 | |
| 7555 | } |
| 7556 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7557 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7558 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7559 | .ndo_stop = ixgbe_close, |
| 7560 | .ndo_start_xmit = ixgbe_xmit_frame, |
| 7561 | .ndo_select_queue = ixgbe_select_queue, |
| 7562 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7563 | .ndo_validate_addr = eth_validate_addr, |
| 7564 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7565 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7566 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7567 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7568 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7569 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7570 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7571 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7572 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 7573 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7574 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7575 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7576 | .ndo_setup_tc = ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7577 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7578 | .ndo_poll_controller = ixgbe_netpoll, |
| 7579 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7580 | #ifdef IXGBE_FCOE |
| 7581 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7582 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7583 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7584 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7585 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7586 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 7587 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7588 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7589 | .ndo_set_features = ixgbe_set_features, |
| 7590 | .ndo_fix_features = ixgbe_fix_features, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7591 | }; |
| 7592 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7593 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 7594 | const struct ixgbe_info *ii) |
| 7595 | { |
| 7596 | #ifdef CONFIG_PCI_IOV |
| 7597 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7598 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 7599 | if (hw->mac.type == ixgbe_mac_82598EB) |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7600 | return; |
| 7601 | |
| 7602 | /* The 82599 supports up to 64 VFs per physical function |
| 7603 | * but this implementation limits allocation to 63 so that |
| 7604 | * basic networking resources are still available to the |
| 7605 | * physical function |
| 7606 | */ |
| 7607 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 7608 | ixgbe_enable_sriov(adapter, ii); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7609 | #endif /* CONFIG_PCI_IOV */ |
| 7610 | } |
| 7611 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7612 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7613 | * ixgbe_probe - Device Initialization Routine |
| 7614 | * @pdev: PCI device information struct |
| 7615 | * @ent: entry in ixgbe_pci_tbl |
| 7616 | * |
| 7617 | * Returns 0 on success, negative on failure |
| 7618 | * |
| 7619 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7620 | * The OS initialization, configuring of the adapter private structure, |
| 7621 | * and a hardware reset occur. |
| 7622 | **/ |
| 7623 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7624 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7625 | { |
| 7626 | struct net_device *netdev; |
| 7627 | struct ixgbe_adapter *adapter = NULL; |
| 7628 | struct ixgbe_hw *hw; |
| 7629 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7630 | static int cards_found; |
| 7631 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7632 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7633 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7634 | #ifdef IXGBE_FCOE |
| 7635 | u16 device_caps; |
| 7636 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7637 | u32 eec; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7638 | u16 wol_cap; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7639 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7640 | /* Catch broken hardware that put the wrong VF device ID in |
| 7641 | * the PCIe SR-IOV capability. |
| 7642 | */ |
| 7643 | if (pdev->is_virtfn) { |
| 7644 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7645 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7646 | return -EINVAL; |
| 7647 | } |
| 7648 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7649 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7650 | if (err) |
| 7651 | return err; |
| 7652 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7653 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7654 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7655 | pci_using_dac = 1; |
| 7656 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7657 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7658 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7659 | err = dma_set_coherent_mask(&pdev->dev, |
| 7660 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7661 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7662 | dev_err(&pdev->dev, |
| 7663 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7664 | goto err_dma; |
| 7665 | } |
| 7666 | } |
| 7667 | pci_using_dac = 0; |
| 7668 | } |
| 7669 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7670 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7671 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7672 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7673 | dev_err(&pdev->dev, |
| 7674 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7675 | goto err_pci_reg; |
| 7676 | } |
| 7677 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7678 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7679 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7680 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7681 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7682 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7683 | #ifdef CONFIG_IXGBE_DCB |
| 7684 | indices *= MAX_TRAFFIC_CLASS; |
| 7685 | #endif |
| 7686 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7687 | if (ii->mac == ixgbe_mac_82598EB) |
| 7688 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7689 | else |
| 7690 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7691 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7692 | #ifdef IXGBE_FCOE |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7693 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7694 | IXGBE_MAX_FCOE_INDICES); |
| 7695 | #endif |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7696 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7697 | if (!netdev) { |
| 7698 | err = -ENOMEM; |
| 7699 | goto err_alloc_etherdev; |
| 7700 | } |
| 7701 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7702 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7703 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7704 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7705 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7706 | |
| 7707 | adapter->netdev = netdev; |
| 7708 | adapter->pdev = pdev; |
| 7709 | hw = &adapter->hw; |
| 7710 | hw->back = adapter; |
| 7711 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 7712 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7713 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7714 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7715 | if (!hw->hw_addr) { |
| 7716 | err = -EIO; |
| 7717 | goto err_ioremap; |
| 7718 | } |
| 7719 | |
| 7720 | for (i = 1; i <= 5; i++) { |
| 7721 | if (pci_resource_len(pdev, i) == 0) |
| 7722 | continue; |
| 7723 | } |
| 7724 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7725 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7726 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7727 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7728 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7729 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7730 | adapter->bd_number = cards_found; |
| 7731 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7732 | /* Setup hw api */ |
| 7733 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7734 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7735 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7736 | /* EEPROM */ |
| 7737 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7738 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7739 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7740 | if (!(eec & (1 << 8))) |
| 7741 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7742 | |
| 7743 | /* PHY */ |
| 7744 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7745 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7746 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7747 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7748 | hw->phy.mdio.mmds = 0; |
| 7749 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7750 | hw->phy.mdio.dev = netdev; |
| 7751 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7752 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7753 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7754 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7755 | |
| 7756 | /* setup the private structure */ |
| 7757 | err = ixgbe_sw_init(adapter); |
| 7758 | if (err) |
| 7759 | goto err_sw_init; |
| 7760 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7761 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7762 | switch (adapter->hw.mac.type) { |
| 7763 | case ixgbe_mac_82599EB: |
| 7764 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7765 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7766 | break; |
| 7767 | default: |
| 7768 | break; |
| 7769 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7770 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7771 | /* |
| 7772 | * If there is a fan on this device and it has failed log the |
| 7773 | * failure. |
| 7774 | */ |
| 7775 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7776 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7777 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7778 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7779 | } |
| 7780 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 7781 | if (allow_unsupported_sfp) |
| 7782 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 7783 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7784 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7785 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7786 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7787 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7788 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7789 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7790 | err = 0; |
| 7791 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7792 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7793 | "module type was detected.\n"); |
| 7794 | e_dev_err("Reload the driver after installing a supported " |
| 7795 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7796 | goto err_sw_init; |
| 7797 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7798 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7799 | goto err_sw_init; |
| 7800 | } |
| 7801 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7802 | ixgbe_probe_vf(adapter, ii); |
| 7803 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7804 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7805 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7806 | NETIF_F_IPV6_CSUM | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7807 | NETIF_F_HW_VLAN_TX | |
| 7808 | NETIF_F_HW_VLAN_RX | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7809 | NETIF_F_HW_VLAN_FILTER | |
| 7810 | NETIF_F_TSO | |
| 7811 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7812 | NETIF_F_RXHASH | |
| 7813 | NETIF_F_RXCSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7814 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7815 | netdev->hw_features = netdev->features; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7816 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7817 | switch (adapter->hw.mac.type) { |
| 7818 | case ixgbe_mac_82599EB: |
| 7819 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7820 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7821 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 7822 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7823 | break; |
| 7824 | default: |
| 7825 | break; |
| 7826 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7827 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7828 | netdev->hw_features |= NETIF_F_RXALL; |
| 7829 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7830 | netdev->vlan_features |= NETIF_F_TSO; |
| 7831 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7832 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7833 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7834 | netdev->vlan_features |= NETIF_F_SG; |
| 7835 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7836 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 7837 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7838 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7839 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7840 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 7841 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7842 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7843 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7844 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7845 | #endif |
| 7846 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7847 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7848 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7849 | if (hw->mac.ops.get_device_caps) { |
| 7850 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7851 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7852 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7853 | } |
| 7854 | } |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7855 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
| 7856 | netdev->vlan_features |= NETIF_F_FCOE_CRC; |
| 7857 | netdev->vlan_features |= NETIF_F_FSO; |
| 7858 | netdev->vlan_features |= NETIF_F_FCOE_MTU; |
| 7859 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7860 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7861 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7862 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7863 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7864 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7865 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7866 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 7867 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7868 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7869 | netdev->features |= NETIF_F_LRO; |
| 7870 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7871 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7872 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7873 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7874 | err = -EIO; |
| 7875 | goto err_eeprom; |
| 7876 | } |
| 7877 | |
| 7878 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7879 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7880 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7881 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7882 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7883 | err = -EIO; |
| 7884 | goto err_eeprom; |
| 7885 | } |
| 7886 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7887 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
| 7888 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7889 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7890 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7891 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7892 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7893 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7894 | if (err) |
| 7895 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7896 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7897 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
| 7898 | netdev->hw_features &= ~NETIF_F_RXHASH; |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7899 | netdev->features &= ~NETIF_F_RXHASH; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7900 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7901 | |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7902 | /* WOL not supported for all but the following */ |
| 7903 | adapter->wol = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7904 | switch (pdev->device) { |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7905 | case IXGBE_DEV_ID_82599_SFP: |
Don Skidmore | 0e22d04 | 2011-12-10 06:49:43 +0000 | [diff] [blame] | 7906 | /* Only these subdevice supports WOL */ |
| 7907 | switch (pdev->subsystem_device) { |
| 7908 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 7909 | /* only support first port */ |
| 7910 | if (hw->bus.func != 0) |
| 7911 | break; |
| 7912 | case IXGBE_SUBDEV_ID_82599_SFP: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7913 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0e22d04 | 2011-12-10 06:49:43 +0000 | [diff] [blame] | 7914 | break; |
| 7915 | } |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7916 | break; |
Alexander Duyck | 50d6c68 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 7917 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7918 | /* All except this subdevice support WOL */ |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7919 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7920 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7921 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7922 | case IXGBE_DEV_ID_82599_KX4: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7923 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7924 | break; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7925 | case IXGBE_DEV_ID_X540T: |
| 7926 | /* Check eeprom to see if it is enabled */ |
| 7927 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
| 7928 | wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 7929 | |
| 7930 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 7931 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 7932 | (hw->bus.func == 0))) |
| 7933 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7934 | break; |
| 7935 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7936 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7937 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 7938 | /* save off EEPROM version number */ |
| 7939 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 7940 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 7941 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7942 | /* pick up the PCI bus settings for reporting later */ |
| 7943 | hw->mac.ops.get_bus_info(hw); |
| 7944 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7945 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7946 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7947 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7948 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7949 | "Unknown"), |
| 7950 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7951 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7952 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7953 | "Unknown"), |
| 7954 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7955 | |
| 7956 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7957 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7958 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7959 | 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] | 7960 | 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] | 7961 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7962 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7963 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7964 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7965 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7966 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7967 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7968 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7969 | "not sufficient for optimal performance.\n"); |
| 7970 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7971 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7972 | } |
| 7973 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7974 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7975 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7976 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7977 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7978 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7979 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7980 | "Please be aware there may be issues associated " |
| 7981 | "with your hardware. If you are experiencing " |
| 7982 | "problems please contact your Intel or hardware " |
| 7983 | "representative who provided you with this " |
| 7984 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7985 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7986 | strcpy(netdev->name, "eth%d"); |
| 7987 | err = register_netdev(netdev); |
| 7988 | if (err) |
| 7989 | goto err_register; |
| 7990 | |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 7991 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 7992 | if (hw->mac.ops.disable_tx_laser && |
| 7993 | ((hw->phy.multispeed_fiber) || |
| 7994 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
| 7995 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 7996 | hw->mac.ops.disable_tx_laser(hw); |
| 7997 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 7998 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7999 | netif_carrier_off(netdev); |
| 8000 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8001 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 8002 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8003 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8004 | ixgbe_setup_dca(adapter); |
| 8005 | } |
| 8006 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8007 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8008 | 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] | 8009 | for (i = 0; i < adapter->num_vfs; i++) |
| 8010 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 8011 | } |
| 8012 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8013 | /* firmware requires driver version to be 0xFFFFFFFF |
| 8014 | * since os does not support feature |
| 8015 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8016 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8017 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 8018 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8019 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8020 | /* add san mac addr to netdev */ |
| 8021 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8022 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8023 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8024 | cards_found++; |
| 8025 | return 0; |
| 8026 | |
| 8027 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8028 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8029 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8030 | err_sw_init: |
| 8031 | err_eeprom: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8032 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 8033 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8034 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8035 | iounmap(hw->hw_addr); |
| 8036 | err_ioremap: |
| 8037 | free_netdev(netdev); |
| 8038 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8039 | pci_release_selected_regions(pdev, |
| 8040 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8041 | err_pci_reg: |
| 8042 | err_dma: |
| 8043 | pci_disable_device(pdev); |
| 8044 | return err; |
| 8045 | } |
| 8046 | |
| 8047 | /** |
| 8048 | * ixgbe_remove - Device Removal Routine |
| 8049 | * @pdev: PCI device information struct |
| 8050 | * |
| 8051 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 8052 | * that it should release a PCI device. The could be caused by a |
| 8053 | * Hot-Plug event, or because the driver is going to be removed from |
| 8054 | * memory. |
| 8055 | **/ |
| 8056 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 8057 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8058 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8059 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8060 | |
| 8061 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8062 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8063 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8064 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8065 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 8066 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 8067 | dca_remove_requester(&pdev->dev); |
| 8068 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 8069 | } |
| 8070 | |
| 8071 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8072 | #ifdef IXGBE_FCOE |
| 8073 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 8074 | ixgbe_cleanup_fcoe(adapter); |
| 8075 | |
| 8076 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8077 | |
| 8078 | /* remove the added san mac */ |
| 8079 | ixgbe_del_sanmac_netdev(netdev); |
| 8080 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 8081 | if (netdev->reg_state == NETREG_REGISTERED) |
| 8082 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8083 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 8084 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 8085 | if (!(ixgbe_check_vf_assignment(adapter))) |
| 8086 | ixgbe_disable_sriov(adapter); |
| 8087 | else |
| 8088 | e_dev_warn("Unloading driver while VFs are assigned " |
| 8089 | "- VFs will not be deallocated\n"); |
| 8090 | } |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8091 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8092 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8093 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8094 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8095 | |
| 8096 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8097 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8098 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8099 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8100 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8101 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8102 | free_netdev(netdev); |
| 8103 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 8104 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8105 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8106 | pci_disable_device(pdev); |
| 8107 | } |
| 8108 | |
| 8109 | /** |
| 8110 | * ixgbe_io_error_detected - called when PCI error is detected |
| 8111 | * @pdev: Pointer to PCI device |
| 8112 | * @state: The current pci connection state |
| 8113 | * |
| 8114 | * This function is called after a PCI bus error affecting |
| 8115 | * this device has been detected. |
| 8116 | */ |
| 8117 | 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] | 8118 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8119 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8120 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8121 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8122 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8123 | #ifdef CONFIG_PCI_IOV |
| 8124 | struct pci_dev *bdev, *vfdev; |
| 8125 | u32 dw0, dw1, dw2, dw3; |
| 8126 | int vf, pos; |
| 8127 | u16 req_id, pf_func; |
| 8128 | |
| 8129 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 8130 | adapter->num_vfs == 0) |
| 8131 | goto skip_bad_vf_detection; |
| 8132 | |
| 8133 | bdev = pdev->bus->self; |
| 8134 | while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT)) |
| 8135 | bdev = bdev->bus->self; |
| 8136 | |
| 8137 | if (!bdev) |
| 8138 | goto skip_bad_vf_detection; |
| 8139 | |
| 8140 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 8141 | if (!pos) |
| 8142 | goto skip_bad_vf_detection; |
| 8143 | |
| 8144 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0); |
| 8145 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1); |
| 8146 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2); |
| 8147 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3); |
| 8148 | |
| 8149 | req_id = dw1 >> 16; |
| 8150 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 8151 | if (!(req_id & 0x0080)) |
| 8152 | goto skip_bad_vf_detection; |
| 8153 | |
| 8154 | pf_func = req_id & 0x01; |
| 8155 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 8156 | unsigned int device_id; |
| 8157 | |
| 8158 | vf = (req_id & 0x7F) >> 1; |
| 8159 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 8160 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 8161 | "%8.8x\tdw3: %8.8x\n", |
| 8162 | dw0, dw1, dw2, dw3); |
| 8163 | switch (adapter->hw.mac.type) { |
| 8164 | case ixgbe_mac_82599EB: |
| 8165 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 8166 | break; |
| 8167 | case ixgbe_mac_X540: |
| 8168 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 8169 | break; |
| 8170 | default: |
| 8171 | device_id = 0; |
| 8172 | break; |
| 8173 | } |
| 8174 | |
| 8175 | /* Find the pci device of the offending VF */ |
| 8176 | vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL); |
| 8177 | while (vfdev) { |
| 8178 | if (vfdev->devfn == (req_id & 0xFF)) |
| 8179 | break; |
| 8180 | vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, |
| 8181 | device_id, vfdev); |
| 8182 | } |
| 8183 | /* |
| 8184 | * There's a slim chance the VF could have been hot plugged, |
| 8185 | * so if it is no longer present we don't need to issue the |
| 8186 | * VFLR. Just clean up the AER in that case. |
| 8187 | */ |
| 8188 | if (vfdev) { |
| 8189 | e_dev_err("Issuing VFLR to VF %d\n", vf); |
| 8190 | pci_write_config_dword(vfdev, 0xA8, 0x00008000); |
| 8191 | } |
| 8192 | |
| 8193 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8194 | } |
| 8195 | |
| 8196 | /* |
| 8197 | * Even though the error may have occurred on the other port |
| 8198 | * we still need to increment the vf error reference count for |
| 8199 | * both ports because the I/O resume function will be called |
| 8200 | * for both of them. |
| 8201 | */ |
| 8202 | adapter->vferr_refcount++; |
| 8203 | |
| 8204 | return PCI_ERS_RESULT_RECOVERED; |
| 8205 | |
| 8206 | skip_bad_vf_detection: |
| 8207 | #endif /* CONFIG_PCI_IOV */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8208 | netif_device_detach(netdev); |
| 8209 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 8210 | if (state == pci_channel_io_perm_failure) |
| 8211 | return PCI_ERS_RESULT_DISCONNECT; |
| 8212 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8213 | if (netif_running(netdev)) |
| 8214 | ixgbe_down(adapter); |
| 8215 | pci_disable_device(pdev); |
| 8216 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8217 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8218 | return PCI_ERS_RESULT_NEED_RESET; |
| 8219 | } |
| 8220 | |
| 8221 | /** |
| 8222 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 8223 | * @pdev: Pointer to PCI device |
| 8224 | * |
| 8225 | * Restart the card from scratch, as if from a cold-boot. |
| 8226 | */ |
| 8227 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 8228 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8229 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8230 | pci_ers_result_t result; |
| 8231 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8232 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8233 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8234 | 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] | 8235 | result = PCI_ERS_RESULT_DISCONNECT; |
| 8236 | } else { |
| 8237 | pci_set_master(pdev); |
| 8238 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 8239 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8240 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 8241 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8242 | |
| 8243 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 8244 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8245 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8246 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8247 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8248 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8249 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8250 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 8251 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8252 | /* non-fatal, continue */ |
| 8253 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8254 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8255 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8256 | } |
| 8257 | |
| 8258 | /** |
| 8259 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 8260 | * @pdev: Pointer to PCI device |
| 8261 | * |
| 8262 | * This callback is called when the error recovery driver tells us that |
| 8263 | * its OK to resume normal operation. |
| 8264 | */ |
| 8265 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 8266 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8267 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8268 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8269 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8270 | #ifdef CONFIG_PCI_IOV |
| 8271 | if (adapter->vferr_refcount) { |
| 8272 | e_info(drv, "Resuming after VF err\n"); |
| 8273 | adapter->vferr_refcount--; |
| 8274 | return; |
| 8275 | } |
| 8276 | |
| 8277 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 8278 | if (netif_running(netdev)) |
| 8279 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8280 | |
| 8281 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | static struct pci_error_handlers ixgbe_err_handler = { |
| 8285 | .error_detected = ixgbe_io_error_detected, |
| 8286 | .slot_reset = ixgbe_io_slot_reset, |
| 8287 | .resume = ixgbe_io_resume, |
| 8288 | }; |
| 8289 | |
| 8290 | static struct pci_driver ixgbe_driver = { |
| 8291 | .name = ixgbe_driver_name, |
| 8292 | .id_table = ixgbe_pci_tbl, |
| 8293 | .probe = ixgbe_probe, |
| 8294 | .remove = __devexit_p(ixgbe_remove), |
| 8295 | #ifdef CONFIG_PM |
| 8296 | .suspend = ixgbe_suspend, |
| 8297 | .resume = ixgbe_resume, |
| 8298 | #endif |
| 8299 | .shutdown = ixgbe_shutdown, |
| 8300 | .err_handler = &ixgbe_err_handler |
| 8301 | }; |
| 8302 | |
| 8303 | /** |
| 8304 | * ixgbe_init_module - Driver Registration Routine |
| 8305 | * |
| 8306 | * ixgbe_init_module is the first routine called when the driver is |
| 8307 | * loaded. All it does is register with the PCI subsystem. |
| 8308 | **/ |
| 8309 | static int __init ixgbe_init_module(void) |
| 8310 | { |
| 8311 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 8312 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8313 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8314 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8315 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8316 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8317 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8318 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8319 | ret = pci_register_driver(&ixgbe_driver); |
| 8320 | return ret; |
| 8321 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8322 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8323 | module_init(ixgbe_init_module); |
| 8324 | |
| 8325 | /** |
| 8326 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 8327 | * |
| 8328 | * ixgbe_exit_module is called just before the driver is removed |
| 8329 | * from memory. |
| 8330 | **/ |
| 8331 | static void __exit ixgbe_exit_module(void) |
| 8332 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8333 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8334 | dca_unregister_notify(&dca_notifier); |
| 8335 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8336 | pci_unregister_driver(&ixgbe_driver); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8337 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8338 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8339 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8340 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8341 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8342 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8343 | { |
| 8344 | int ret_val; |
| 8345 | |
| 8346 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8347 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8348 | |
| 8349 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 8350 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8351 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 8352 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8353 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8354 | module_exit(ixgbe_exit_module); |
| 8355 | |
| 8356 | /* ixgbe_main.c */ |