Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | 9497182 | 2012-01-06 03:24:16 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2012 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 35 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 36 | #include <linux/ip.h> |
| 37 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 38 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 39 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 40 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 42 | #include <net/checksum.h> |
| 43 | #include <net/ip6_checksum.h> |
| 44 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 45 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 46 | #include <linux/if_vlan.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 47 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 48 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | |
| 50 | #include "ixgbe.h" |
| 51 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 52 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 53 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 54 | |
| 55 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 56 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 57 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 58 | char ixgbe_default_device_descr[] = |
| 59 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 60 | #define MAJ 3 |
Don Skidmore | 19d478b | 2011-10-07 03:53:51 +0000 | [diff] [blame] | 61 | #define MIN 6 |
| 62 | #define BUILD 7 |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 63 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 64 | __stringify(BUILD) "-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 65 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 66 | static const char ixgbe_copyright[] = |
Don Skidmore | 9497182 | 2012-01-06 03:24:16 +0000 | [diff] [blame] | 67 | "Copyright (c) 1999-2012 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 68 | |
| 69 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 70 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 71 | [board_82599] = &ixgbe_82599_info, |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 72 | [board_X540] = &ixgbe_X540_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 76 | * |
| 77 | * Wildcard entries (PCI_ANY_ID) should come last |
| 78 | * Last entry must be all 0s |
| 79 | * |
| 80 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 81 | * Class, Class Mask, private data (not used) } |
| 82 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 83 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 84 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 86 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 112 | /* required last entry */ |
| 113 | {0, } |
| 114 | }; |
| 115 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 116 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 117 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 118 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 119 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 120 | static struct notifier_block dca_notifier = { |
| 121 | .notifier_call = ixgbe_notify_dca, |
| 122 | .next = NULL, |
| 123 | .priority = 0 |
| 124 | }; |
| 125 | #endif |
| 126 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 127 | #ifdef CONFIG_PCI_IOV |
| 128 | static unsigned int max_vfs; |
| 129 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 130 | MODULE_PARM_DESC(max_vfs, |
| 131 | "Maximum number of virtual functions to allocate per physical function"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 132 | #endif /* CONFIG_PCI_IOV */ |
| 133 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 134 | static unsigned int allow_unsupported_sfp; |
| 135 | module_param(allow_unsupported_sfp, uint, 0); |
| 136 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 137 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 138 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 139 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 140 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 141 | MODULE_LICENSE("GPL"); |
| 142 | MODULE_VERSION(DRV_VERSION); |
| 143 | |
| 144 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 145 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 146 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 147 | { |
| 148 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
| 149 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
| 150 | schedule_work(&adapter->service_task); |
| 151 | } |
| 152 | |
| 153 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 154 | { |
| 155 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 156 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 157 | /* flush memory to make sure state is correct before next watchdog */ |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 158 | smp_mb__before_clear_bit(); |
| 159 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 160 | } |
| 161 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 162 | struct ixgbe_reg_info { |
| 163 | u32 ofs; |
| 164 | char *name; |
| 165 | }; |
| 166 | |
| 167 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 168 | |
| 169 | /* General Registers */ |
| 170 | {IXGBE_CTRL, "CTRL"}, |
| 171 | {IXGBE_STATUS, "STATUS"}, |
| 172 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 173 | |
| 174 | /* Interrupt Registers */ |
| 175 | {IXGBE_EICR, "EICR"}, |
| 176 | |
| 177 | /* RX Registers */ |
| 178 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 179 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 180 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 181 | {IXGBE_RDH(0), "RDH"}, |
| 182 | {IXGBE_RDT(0), "RDT"}, |
| 183 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 184 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 185 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 186 | |
| 187 | /* TX Registers */ |
| 188 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 189 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 190 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 191 | {IXGBE_TDH(0), "TDH"}, |
| 192 | {IXGBE_TDT(0), "TDT"}, |
| 193 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 194 | |
| 195 | /* List Terminator */ |
| 196 | {} |
| 197 | }; |
| 198 | |
| 199 | |
| 200 | /* |
| 201 | * ixgbe_regdump - register printout routine |
| 202 | */ |
| 203 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 204 | { |
| 205 | int i = 0, j = 0; |
| 206 | char rname[16]; |
| 207 | u32 regs[64]; |
| 208 | |
| 209 | switch (reginfo->ofs) { |
| 210 | case IXGBE_SRRCTL(0): |
| 211 | for (i = 0; i < 64; i++) |
| 212 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 213 | break; |
| 214 | case IXGBE_DCA_RXCTRL(0): |
| 215 | for (i = 0; i < 64; i++) |
| 216 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 217 | break; |
| 218 | case IXGBE_RDLEN(0): |
| 219 | for (i = 0; i < 64; i++) |
| 220 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 221 | break; |
| 222 | case IXGBE_RDH(0): |
| 223 | for (i = 0; i < 64; i++) |
| 224 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 225 | break; |
| 226 | case IXGBE_RDT(0): |
| 227 | for (i = 0; i < 64; i++) |
| 228 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 229 | break; |
| 230 | case IXGBE_RXDCTL(0): |
| 231 | for (i = 0; i < 64; i++) |
| 232 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 233 | break; |
| 234 | case IXGBE_RDBAL(0): |
| 235 | for (i = 0; i < 64; i++) |
| 236 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 237 | break; |
| 238 | case IXGBE_RDBAH(0): |
| 239 | for (i = 0; i < 64; i++) |
| 240 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 241 | break; |
| 242 | case IXGBE_TDBAL(0): |
| 243 | for (i = 0; i < 64; i++) |
| 244 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 245 | break; |
| 246 | case IXGBE_TDBAH(0): |
| 247 | for (i = 0; i < 64; i++) |
| 248 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 249 | break; |
| 250 | case IXGBE_TDLEN(0): |
| 251 | for (i = 0; i < 64; i++) |
| 252 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 253 | break; |
| 254 | case IXGBE_TDH(0): |
| 255 | for (i = 0; i < 64; i++) |
| 256 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 257 | break; |
| 258 | case IXGBE_TDT(0): |
| 259 | for (i = 0; i < 64; i++) |
| 260 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 261 | break; |
| 262 | case IXGBE_TXDCTL(0): |
| 263 | for (i = 0; i < 64; i++) |
| 264 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 265 | break; |
| 266 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 267 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 268 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | for (i = 0; i < 8; i++) { |
| 273 | snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 274 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 275 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 276 | pr_cont(" %08x", regs[i*8+j]); |
| 277 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 284 | */ |
| 285 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 286 | { |
| 287 | struct net_device *netdev = adapter->netdev; |
| 288 | struct ixgbe_hw *hw = &adapter->hw; |
| 289 | struct ixgbe_reg_info *reginfo; |
| 290 | int n = 0; |
| 291 | struct ixgbe_ring *tx_ring; |
| 292 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 293 | union ixgbe_adv_tx_desc *tx_desc; |
| 294 | struct my_u0 { u64 a; u64 b; } *u0; |
| 295 | struct ixgbe_ring *rx_ring; |
| 296 | union ixgbe_adv_rx_desc *rx_desc; |
| 297 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 298 | u32 staterr; |
| 299 | int i = 0; |
| 300 | |
| 301 | if (!netif_msg_hw(adapter)) |
| 302 | return; |
| 303 | |
| 304 | /* Print netdevice Info */ |
| 305 | if (netdev) { |
| 306 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 307 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 308 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 309 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 310 | netdev->name, |
| 311 | netdev->state, |
| 312 | netdev->trans_start, |
| 313 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /* Print Registers */ |
| 317 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 318 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 319 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 320 | reginfo->name; reginfo++) { |
| 321 | ixgbe_regdump(hw, reginfo); |
| 322 | } |
| 323 | |
| 324 | /* Print TX Ring Summary */ |
| 325 | if (!netdev || !netif_running(netdev)) |
| 326 | goto exit; |
| 327 | |
| 328 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 329 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 330 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 331 | tx_ring = adapter->tx_ring[n]; |
| 332 | tx_buffer_info = |
| 333 | &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 334 | pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 335 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 336 | (u64)tx_buffer_info->dma, |
| 337 | tx_buffer_info->length, |
| 338 | tx_buffer_info->next_to_watch, |
| 339 | (u64)tx_buffer_info->time_stamp); |
| 340 | } |
| 341 | |
| 342 | /* Print TX Rings */ |
| 343 | if (!netif_msg_tx_done(adapter)) |
| 344 | goto rx_ring_summary; |
| 345 | |
| 346 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 347 | |
| 348 | /* Transmit Descriptor Formats |
| 349 | * |
| 350 | * Advanced Transmit Descriptor |
| 351 | * +--------------------------------------------------------------+ |
| 352 | * 0 | Buffer Address [63:0] | |
| 353 | * +--------------------------------------------------------------+ |
| 354 | * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
| 355 | * +--------------------------------------------------------------+ |
| 356 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 |
| 357 | */ |
| 358 | |
| 359 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 360 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 361 | pr_info("------------------------------------\n"); |
| 362 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 363 | pr_info("------------------------------------\n"); |
| 364 | pr_info("T [desc] [address 63:0 ] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 365 | "[PlPOIdStDDt Ln] [bi->dma ] " |
| 366 | "leng ntw timestamp bi->skb\n"); |
| 367 | |
| 368 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 369 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 370 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 371 | u0 = (struct my_u0 *)tx_desc; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 372 | pr_info("T [0x%03X] %016llX %016llX %016llX" |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 373 | " %04X %p %016llX %p", i, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 374 | le64_to_cpu(u0->a), |
| 375 | le64_to_cpu(u0->b), |
| 376 | (u64)tx_buffer_info->dma, |
| 377 | tx_buffer_info->length, |
| 378 | tx_buffer_info->next_to_watch, |
| 379 | (u64)tx_buffer_info->time_stamp, |
| 380 | tx_buffer_info->skb); |
| 381 | if (i == tx_ring->next_to_use && |
| 382 | i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 383 | pr_cont(" NTC/U\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 384 | else if (i == tx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 385 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 386 | else if (i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 387 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 388 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 389 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 390 | |
| 391 | if (netif_msg_pktdata(adapter) && |
| 392 | tx_buffer_info->dma != 0) |
| 393 | print_hex_dump(KERN_INFO, "", |
| 394 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 395 | phys_to_virt(tx_buffer_info->dma), |
| 396 | tx_buffer_info->length, true); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | /* Print RX Rings Summary */ |
| 401 | rx_ring_summary: |
| 402 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 403 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 404 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 405 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 406 | pr_info("%5d %5X %5X\n", |
| 407 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* Print RX Rings */ |
| 411 | if (!netif_msg_rx_status(adapter)) |
| 412 | goto exit; |
| 413 | |
| 414 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 415 | |
| 416 | /* Advanced Receive Descriptor (Read) Format |
| 417 | * 63 1 0 |
| 418 | * +-----------------------------------------------------+ |
| 419 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 420 | * +----------------------------------------------+------+ |
| 421 | * 8 | Header Buffer Address [63:1] | DD | |
| 422 | * +-----------------------------------------------------+ |
| 423 | * |
| 424 | * |
| 425 | * Advanced Receive Descriptor (Write-Back) Format |
| 426 | * |
| 427 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 428 | * +------------------------------------------------------+ |
| 429 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | |
| 430 | * | Checksum Ident | | | | Type | Type | |
| 431 | * +------------------------------------------------------+ |
| 432 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 433 | * +------------------------------------------------------+ |
| 434 | * 63 48 47 32 31 20 19 0 |
| 435 | */ |
| 436 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 437 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 438 | pr_info("------------------------------------\n"); |
| 439 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 440 | pr_info("------------------------------------\n"); |
| 441 | pr_info("R [desc] [ PktBuf A0] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 442 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " |
| 443 | "<-- Adv Rx Read format\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 444 | pr_info("RWB[desc] [PcsmIpSHl PtRs] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 445 | "[vl er S cks ln] ---------------- [bi->skb] " |
| 446 | "<-- Adv Rx Write-Back format\n"); |
| 447 | |
| 448 | for (i = 0; i < rx_ring->count; i++) { |
| 449 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 450 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 451 | u0 = (struct my_u0 *)rx_desc; |
| 452 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 453 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 454 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 455 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 456 | "%016llX ---------------- %p", i, |
| 457 | le64_to_cpu(u0->a), |
| 458 | le64_to_cpu(u0->b), |
| 459 | rx_buffer_info->skb); |
| 460 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 461 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 462 | "%016llX %016llX %p", i, |
| 463 | le64_to_cpu(u0->a), |
| 464 | le64_to_cpu(u0->b), |
| 465 | (u64)rx_buffer_info->dma, |
| 466 | rx_buffer_info->skb); |
| 467 | |
| 468 | if (netif_msg_pktdata(adapter)) { |
| 469 | print_hex_dump(KERN_INFO, "", |
| 470 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 471 | phys_to_virt(rx_buffer_info->dma), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 472 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
| 476 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 477 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 478 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 479 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 480 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 481 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 482 | |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | exit: |
| 487 | return; |
| 488 | } |
| 489 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 490 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 491 | { |
| 492 | u32 ctrl_ext; |
| 493 | |
| 494 | /* Let firmware take over control of h/w */ |
| 495 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 496 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 497 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 501 | { |
| 502 | u32 ctrl_ext; |
| 503 | |
| 504 | /* Let firmware know the driver has taken over */ |
| 505 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 506 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 507 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 508 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 509 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 510 | /* |
| 511 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 512 | * @adapter: pointer to adapter struct |
| 513 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 514 | * @queue: queue to map the corresponding interrupt to |
| 515 | * @msix_vector: the vector to map to the corresponding queue |
| 516 | * |
| 517 | */ |
| 518 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 519 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 520 | { |
| 521 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 522 | struct ixgbe_hw *hw = &adapter->hw; |
| 523 | switch (hw->mac.type) { |
| 524 | case ixgbe_mac_82598EB: |
| 525 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 526 | if (direction == -1) |
| 527 | direction = 0; |
| 528 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 529 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 530 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 531 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 532 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 533 | break; |
| 534 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 535 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 536 | if (direction == -1) { |
| 537 | /* other causes */ |
| 538 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 539 | index = ((queue & 1) * 8); |
| 540 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 541 | ivar &= ~(0xFF << index); |
| 542 | ivar |= (msix_vector << index); |
| 543 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 544 | break; |
| 545 | } else { |
| 546 | /* tx or rx causes */ |
| 547 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 548 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 549 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 550 | ivar &= ~(0xFF << index); |
| 551 | ivar |= (msix_vector << index); |
| 552 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 553 | break; |
| 554 | } |
| 555 | default: |
| 556 | break; |
| 557 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 560 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 561 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 562 | { |
| 563 | u32 mask; |
| 564 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 565 | switch (adapter->hw.mac.type) { |
| 566 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 567 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 568 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 569 | break; |
| 570 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 571 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 572 | mask = (qmask & 0xFFFFFFFF); |
| 573 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 574 | mask = (qmask >> 32); |
| 575 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 576 | break; |
| 577 | default: |
| 578 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 582 | static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring, |
| 583 | struct ixgbe_tx_buffer *tx_buffer) |
| 584 | { |
| 585 | if (tx_buffer->dma) { |
| 586 | if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE) |
| 587 | dma_unmap_page(ring->dev, |
| 588 | tx_buffer->dma, |
| 589 | tx_buffer->length, |
| 590 | DMA_TO_DEVICE); |
| 591 | else |
| 592 | dma_unmap_single(ring->dev, |
| 593 | tx_buffer->dma, |
| 594 | tx_buffer->length, |
| 595 | DMA_TO_DEVICE); |
| 596 | } |
| 597 | tx_buffer->dma = 0; |
| 598 | } |
| 599 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 600 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring, |
| 601 | struct ixgbe_tx_buffer *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 602 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 603 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info); |
| 604 | if (tx_buffer_info->skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 605 | dev_kfree_skb_any(tx_buffer_info->skb); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 606 | tx_buffer_info->skb = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 607 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 608 | } |
| 609 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 610 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 611 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 612 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 613 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 614 | u32 data = 0; |
| 615 | u32 xoff[8] = {0}; |
| 616 | int i; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 617 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 618 | if ((hw->fc.current_mode == ixgbe_fc_full) || |
| 619 | (hw->fc.current_mode == ixgbe_fc_rx_pause)) { |
| 620 | switch (hw->mac.type) { |
| 621 | case ixgbe_mac_82598EB: |
| 622 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 623 | break; |
| 624 | default: |
| 625 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 626 | } |
| 627 | hwstats->lxoffrxc += data; |
| 628 | |
| 629 | /* refill credits (no tx hang) if we received xoff */ |
| 630 | if (!data) |
| 631 | return; |
| 632 | |
| 633 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 634 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 635 | &adapter->tx_ring[i]->state); |
| 636 | return; |
| 637 | } else if (!(adapter->dcb_cfg.pfc_mode_enable)) |
| 638 | return; |
| 639 | |
| 640 | /* update stats for each tc, only valid with PFC enabled */ |
| 641 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
| 642 | switch (hw->mac.type) { |
| 643 | case ixgbe_mac_82598EB: |
| 644 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 645 | break; |
| 646 | default: |
| 647 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 648 | } |
| 649 | hwstats->pxoffrxc[i] += xoff[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 650 | } |
| 651 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 652 | /* disarm tx queues that have received xoff frames */ |
| 653 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 654 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | fb5475f | 2011-04-26 07:26:36 +0000 | [diff] [blame] | 655 | u8 tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 656 | |
| 657 | if (xoff[tc]) |
| 658 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 663 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame^] | 664 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 668 | { |
| 669 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); |
| 670 | struct ixgbe_hw *hw = &adapter->hw; |
| 671 | |
| 672 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 673 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
| 674 | |
| 675 | if (head != tail) |
| 676 | return (head < tail) ? |
| 677 | tail - head : (tail + ring->count - head); |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 683 | { |
| 684 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 685 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 686 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 687 | bool ret = false; |
| 688 | |
| 689 | clear_check_for_tx_hang(tx_ring); |
| 690 | |
| 691 | /* |
| 692 | * Check for a hung queue, but be thorough. This verifies |
| 693 | * that a transmit has been completed since the previous |
| 694 | * check AND there is at least one packet pending. The |
| 695 | * ARMED bit is set to indicate a potential hang. The |
| 696 | * bit is cleared if a pause frame is received to remove |
| 697 | * false hang detection due to PFC or 802.3x frames. By |
| 698 | * requiring this to fail twice we avoid races with |
| 699 | * pfc clearing the ARMED bit and conditions where we |
| 700 | * run the check_tx_hang logic with a transmit completion |
| 701 | * pending but without time to complete it yet. |
| 702 | */ |
| 703 | if ((tx_done_old == tx_done) && tx_pending) { |
| 704 | /* make sure it is true for two checks in a row */ |
| 705 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 706 | &tx_ring->state); |
| 707 | } else { |
| 708 | /* update completed stats and continue */ |
| 709 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 710 | /* reset the countdown */ |
| 711 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 712 | } |
| 713 | |
| 714 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 717 | /** |
| 718 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 719 | * @adapter: driver private struct |
| 720 | **/ |
| 721 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 722 | { |
| 723 | |
| 724 | /* Do the reset outside of interrupt context */ |
| 725 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 726 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 727 | ixgbe_service_event_schedule(adapter); |
| 728 | } |
| 729 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 730 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 731 | /** |
| 732 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 733 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 734 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 735 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 736 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 737 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 738 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 739 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 740 | struct ixgbe_tx_buffer *tx_buffer; |
| 741 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 742 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 743 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 744 | u16 i = tx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 745 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 746 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 747 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 748 | |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 749 | for (; budget; budget--) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 750 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 751 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 752 | /* if next_to_watch is not set then there is no work pending */ |
| 753 | if (!eop_desc) |
| 754 | break; |
| 755 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 756 | /* prevent any other reads prior to eop_desc */ |
| 757 | rmb(); |
| 758 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 759 | /* if DD is not set pending work has not been completed */ |
| 760 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 761 | break; |
| 762 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 763 | /* clear next_to_watch to prevent false hangs */ |
| 764 | tx_buffer->next_to_watch = NULL; |
| 765 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 766 | do { |
| 767 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 768 | if (likely(tx_desc == eop_desc)) { |
| 769 | eop_desc = NULL; |
| 770 | dev_kfree_skb_any(tx_buffer->skb); |
| 771 | tx_buffer->skb = NULL; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 772 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 773 | total_bytes += tx_buffer->bytecount; |
| 774 | total_packets += tx_buffer->gso_segs; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 775 | } |
| 776 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 777 | tx_buffer++; |
| 778 | tx_desc++; |
| 779 | i++; |
| 780 | if (unlikely(i == tx_ring->count)) { |
| 781 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 782 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 783 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 784 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | } while (eop_desc); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 788 | } |
| 789 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 790 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 791 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 792 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 793 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 794 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 795 | q_vector->tx.total_bytes += total_bytes; |
| 796 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 797 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 798 | 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] | 799 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 800 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 801 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 802 | e_err(drv, "Detected Tx Unit Hang\n" |
| 803 | " Tx Queue <%d>\n" |
| 804 | " TDH, TDT <%x>, <%x>\n" |
| 805 | " next_to_use <%x>\n" |
| 806 | " next_to_clean <%x>\n" |
| 807 | "tx_buffer_info[next_to_clean]\n" |
| 808 | " time_stamp <%lx>\n" |
| 809 | " jiffies <%lx>\n", |
| 810 | tx_ring->queue_index, |
| 811 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 812 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 813 | tx_ring->next_to_use, i, |
| 814 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 815 | |
| 816 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 817 | |
| 818 | e_info(probe, |
| 819 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 820 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 821 | |
| 822 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 823 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 824 | |
| 825 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 826 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 827 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 828 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 829 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 830 | total_packets, total_bytes); |
| 831 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 832 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 833 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 834 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 835 | /* Make sure that anybody stopping the queue after this |
| 836 | * sees the new next_to_clean. |
| 837 | */ |
| 838 | smp_mb(); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 839 | if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) && |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 840 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 841 | netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 842 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 843 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 844 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 845 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 846 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 849 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 850 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 851 | struct ixgbe_ring *tx_ring, |
| 852 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 853 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 854 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 855 | u32 txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 856 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 857 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 858 | switch (hw->mac.type) { |
| 859 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 860 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 861 | break; |
| 862 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 863 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 864 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 865 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 866 | break; |
| 867 | default: |
| 868 | /* for unknown hardware do not write register */ |
| 869 | return; |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * We can enable relaxed ordering for reads, but not writes when |
| 874 | * DCA is enabled. This is due to a known issue in some chipsets |
| 875 | * which will cause the DCA tag to be cleared. |
| 876 | */ |
| 877 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 878 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 879 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 880 | |
| 881 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 882 | } |
| 883 | |
| 884 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 885 | struct ixgbe_ring *rx_ring, |
| 886 | int cpu) |
| 887 | { |
| 888 | struct ixgbe_hw *hw = &adapter->hw; |
| 889 | u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
| 890 | u8 reg_idx = rx_ring->reg_idx; |
| 891 | |
| 892 | |
| 893 | switch (hw->mac.type) { |
| 894 | case ixgbe_mac_82599EB: |
| 895 | case ixgbe_mac_X540: |
| 896 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 897 | break; |
| 898 | default: |
| 899 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 900 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 901 | |
| 902 | /* |
| 903 | * We can enable relaxed ordering for reads, but not writes when |
| 904 | * DCA is enabled. This is due to a known issue in some chipsets |
| 905 | * which will cause the DCA tag to be cleared. |
| 906 | */ |
| 907 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
| 908 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
| 909 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 910 | |
| 911 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 915 | { |
| 916 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 917 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 918 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 919 | |
| 920 | if (q_vector->cpu == cpu) |
| 921 | goto out_no_update; |
| 922 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 923 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 924 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 925 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 926 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 927 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 928 | |
| 929 | q_vector->cpu = cpu; |
| 930 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 931 | put_cpu(); |
| 932 | } |
| 933 | |
| 934 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 935 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 936 | int num_q_vectors; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 937 | int i; |
| 938 | |
| 939 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 940 | return; |
| 941 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 942 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 943 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 944 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 945 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 946 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 947 | else |
| 948 | num_q_vectors = 1; |
| 949 | |
| 950 | for (i = 0; i < num_q_vectors; i++) { |
| 951 | adapter->q_vector[i]->cpu = -1; |
| 952 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 957 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 958 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 959 | unsigned long event = *(unsigned long *)data; |
| 960 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 961 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 962 | return 0; |
| 963 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 964 | switch (event) { |
| 965 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 966 | /* if we're already enabled, don't do it again */ |
| 967 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 968 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 969 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 970 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 971 | ixgbe_setup_dca(adapter); |
| 972 | break; |
| 973 | } |
| 974 | /* Fall Through since DCA is disabled. */ |
| 975 | case DCA_PROVIDER_REMOVE: |
| 976 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 977 | dca_remove_requester(dev); |
| 978 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 979 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 980 | } |
| 981 | break; |
| 982 | } |
| 983 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 984 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 985 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 986 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 987 | #endif /* CONFIG_IXGBE_DCA */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 988 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 989 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 990 | struct sk_buff *skb) |
| 991 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 992 | if (ring->netdev->features & NETIF_F_RXHASH) |
| 993 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 996 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 997 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 998 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
| 999 | * @adapter: address of board private structure |
| 1000 | * @rx_desc: advanced rx descriptor |
| 1001 | * |
| 1002 | * Returns : true if it is FCoE pkt |
| 1003 | */ |
| 1004 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter, |
| 1005 | union ixgbe_adv_rx_desc *rx_desc) |
| 1006 | { |
| 1007 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1008 | |
| 1009 | return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 1010 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1011 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1012 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1013 | } |
| 1014 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1015 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1016 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1017 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1018 | * @ring: structure containing ring specific data |
| 1019 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1020 | * @skb: skb currently being received and modified |
| 1021 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1022 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1023 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1024 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1025 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1026 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1027 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1028 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1029 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1030 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1031 | |
| 1032 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1033 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1034 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1035 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1036 | return; |
| 1037 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1038 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1039 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1040 | return; |
| 1041 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1042 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1043 | __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] | 1044 | |
| 1045 | /* |
| 1046 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1047 | * checksum errors. |
| 1048 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1049 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1050 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1051 | return; |
| 1052 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1053 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1054 | return; |
| 1055 | } |
| 1056 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1057 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1058 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1061 | 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] | 1062 | { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1063 | rx_ring->next_to_use = val; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1064 | |
| 1065 | /* update next to alloc since we have filled the ring */ |
| 1066 | rx_ring->next_to_alloc = val; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1067 | /* |
| 1068 | * Force memory writes to complete before letting h/w |
| 1069 | * know there are new descriptors to fetch. (Only |
| 1070 | * applicable for weak-ordered memory model archs, |
| 1071 | * such as IA-64). |
| 1072 | */ |
| 1073 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1074 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1077 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1078 | struct ixgbe_rx_buffer *bi) |
| 1079 | { |
| 1080 | struct page *page = bi->page; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1081 | dma_addr_t dma = bi->dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1082 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1083 | /* since we are recycling buffers we should seldom need to alloc */ |
| 1084 | if (likely(dma)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1085 | return true; |
| 1086 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1087 | /* alloc new page for storage */ |
| 1088 | if (likely(!page)) { |
| 1089 | page = alloc_pages(GFP_ATOMIC | __GFP_COLD, |
| 1090 | ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1091 | if (unlikely(!page)) { |
| 1092 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1093 | return false; |
| 1094 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1095 | bi->page = page; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1098 | /* map page for use */ |
| 1099 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1100 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1101 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1102 | /* |
| 1103 | * if mapping failed free memory back to system since |
| 1104 | * there isn't much point in holding memory we can't use |
| 1105 | */ |
| 1106 | if (dma_mapping_error(rx_ring->dev, dma)) { |
| 1107 | put_page(page); |
| 1108 | bi->page = NULL; |
| 1109 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1110 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1111 | return false; |
| 1112 | } |
| 1113 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1114 | bi->dma = dma; |
| 1115 | bi->page_offset ^= ixgbe_rx_bufsz(rx_ring); |
| 1116 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1117 | return true; |
| 1118 | } |
| 1119 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1120 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1121 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1122 | * @rx_ring: ring to place buffers on |
| 1123 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1124 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1125 | 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] | 1126 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1127 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1128 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1129 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1130 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1131 | /* nothing to do */ |
| 1132 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1133 | return; |
| 1134 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1135 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1136 | bi = &rx_ring->rx_buffer_info[i]; |
| 1137 | i -= rx_ring->count; |
| 1138 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1139 | do { |
| 1140 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1141 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1142 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1143 | /* |
| 1144 | * Refresh the desc even if buffer_addrs didn't change |
| 1145 | * because each write-back erases this info. |
| 1146 | */ |
| 1147 | 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] | 1148 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1149 | rx_desc++; |
| 1150 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1151 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1152 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1153 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1154 | bi = rx_ring->rx_buffer_info; |
| 1155 | i -= rx_ring->count; |
| 1156 | } |
| 1157 | |
| 1158 | /* clear the hdr_addr for the next_to_use descriptor */ |
| 1159 | rx_desc->read.hdr_addr = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1160 | |
| 1161 | cleaned_count--; |
| 1162 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1163 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1164 | i += rx_ring->count; |
| 1165 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1166 | if (rx_ring->next_to_use != i) |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1167 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1170 | /** |
| 1171 | * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE |
| 1172 | * @data: pointer to the start of the headers |
| 1173 | * @max_len: total length of section to find headers in |
| 1174 | * |
| 1175 | * This function is meant to determine the length of headers that will |
| 1176 | * be recognized by hardware for LRO, GRO, and RSC offloads. The main |
| 1177 | * motivation of doing this is to only perform one pull for IPv4 TCP |
| 1178 | * packets so that we can do basic things like calculating the gso_size |
| 1179 | * based on the average data per packet. |
| 1180 | **/ |
| 1181 | static unsigned int ixgbe_get_headlen(unsigned char *data, |
| 1182 | unsigned int max_len) |
| 1183 | { |
| 1184 | union { |
| 1185 | unsigned char *network; |
| 1186 | /* l2 headers */ |
| 1187 | struct ethhdr *eth; |
| 1188 | struct vlan_hdr *vlan; |
| 1189 | /* l3 headers */ |
| 1190 | struct iphdr *ipv4; |
| 1191 | } hdr; |
| 1192 | __be16 protocol; |
| 1193 | u8 nexthdr = 0; /* default to not TCP */ |
| 1194 | u8 hlen; |
| 1195 | |
| 1196 | /* this should never happen, but better safe than sorry */ |
| 1197 | if (max_len < ETH_HLEN) |
| 1198 | return max_len; |
| 1199 | |
| 1200 | /* initialize network frame pointer */ |
| 1201 | hdr.network = data; |
| 1202 | |
| 1203 | /* set first protocol and move network header forward */ |
| 1204 | protocol = hdr.eth->h_proto; |
| 1205 | hdr.network += ETH_HLEN; |
| 1206 | |
| 1207 | /* handle any vlan tag if present */ |
| 1208 | if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 1209 | if ((hdr.network - data) > (max_len - VLAN_HLEN)) |
| 1210 | return max_len; |
| 1211 | |
| 1212 | protocol = hdr.vlan->h_vlan_encapsulated_proto; |
| 1213 | hdr.network += VLAN_HLEN; |
| 1214 | } |
| 1215 | |
| 1216 | /* handle L3 protocols */ |
| 1217 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 1218 | if ((hdr.network - data) > (max_len - sizeof(struct iphdr))) |
| 1219 | return max_len; |
| 1220 | |
| 1221 | /* access ihl as a u8 to avoid unaligned access on ia64 */ |
| 1222 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 1223 | |
| 1224 | /* verify hlen meets minimum size requirements */ |
| 1225 | if (hlen < sizeof(struct iphdr)) |
| 1226 | return hdr.network - data; |
| 1227 | |
| 1228 | /* record next protocol */ |
| 1229 | nexthdr = hdr.ipv4->protocol; |
| 1230 | hdr.network += hlen; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1231 | #ifdef IXGBE_FCOE |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1232 | } else if (protocol == __constant_htons(ETH_P_FCOE)) { |
| 1233 | if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN)) |
| 1234 | return max_len; |
| 1235 | hdr.network += FCOE_HEADER_LEN; |
| 1236 | #endif |
| 1237 | } else { |
| 1238 | return hdr.network - data; |
| 1239 | } |
| 1240 | |
| 1241 | /* finally sort out TCP */ |
| 1242 | if (nexthdr == IPPROTO_TCP) { |
| 1243 | if ((hdr.network - data) > (max_len - sizeof(struct tcphdr))) |
| 1244 | return max_len; |
| 1245 | |
| 1246 | /* access doff as a u8 to avoid unaligned access on ia64 */ |
| 1247 | hlen = (hdr.network[12] & 0xF0) >> 2; |
| 1248 | |
| 1249 | /* verify hlen meets minimum size requirements */ |
| 1250 | if (hlen < sizeof(struct tcphdr)) |
| 1251 | return hdr.network - data; |
| 1252 | |
| 1253 | hdr.network += hlen; |
| 1254 | } |
| 1255 | |
| 1256 | /* |
| 1257 | * If everything has gone correctly hdr.network should be the |
| 1258 | * data section of the packet and will be the end of the header. |
| 1259 | * If not then it probably represents the end of the last recognized |
| 1260 | * header. |
| 1261 | */ |
| 1262 | if ((hdr.network - data) < max_len) |
| 1263 | return hdr.network - data; |
| 1264 | else |
| 1265 | return max_len; |
| 1266 | } |
| 1267 | |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1268 | static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring, |
| 1269 | union ixgbe_adv_rx_desc *rx_desc, |
| 1270 | struct sk_buff *skb) |
| 1271 | { |
| 1272 | __le32 rsc_enabled; |
| 1273 | u32 rsc_cnt; |
| 1274 | |
| 1275 | if (!ring_is_rsc_enabled(rx_ring)) |
| 1276 | return; |
| 1277 | |
| 1278 | rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1279 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1280 | |
| 1281 | /* If this is an RSC frame rsc_cnt should be non-zero */ |
| 1282 | if (!rsc_enabled) |
| 1283 | return; |
| 1284 | |
| 1285 | rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1286 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1287 | |
| 1288 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1289 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1290 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1291 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1292 | struct sk_buff *skb) |
| 1293 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1294 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1295 | |
| 1296 | /* set gso_size to avoid messing up TCP MSS */ |
| 1297 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1298 | IXGBE_CB(skb)->append_cnt); |
| 1299 | } |
| 1300 | |
| 1301 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1302 | struct sk_buff *skb) |
| 1303 | { |
| 1304 | /* if append_cnt is 0 then frame is not RSC */ |
| 1305 | if (!IXGBE_CB(skb)->append_cnt) |
| 1306 | return; |
| 1307 | |
| 1308 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1309 | rx_ring->rx_stats.rsc_flush++; |
| 1310 | |
| 1311 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1312 | |
| 1313 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1314 | IXGBE_CB(skb)->append_cnt = 0; |
| 1315 | } |
| 1316 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1317 | /** |
| 1318 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1319 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1320 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1321 | * @skb: pointer to current skb being populated |
| 1322 | * |
| 1323 | * This function checks the ring, descriptor, and packet information in |
| 1324 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1325 | * other fields within the skb. |
| 1326 | **/ |
| 1327 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1328 | union ixgbe_adv_rx_desc *rx_desc, |
| 1329 | struct sk_buff *skb) |
| 1330 | { |
| 1331 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1332 | |
| 1333 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1334 | |
| 1335 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1336 | |
| 1337 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
| 1338 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
| 1339 | __vlan_hwaccel_put_tag(skb, vid); |
| 1340 | } |
| 1341 | |
| 1342 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1343 | |
| 1344 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
| 1345 | } |
| 1346 | |
| 1347 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1348 | struct sk_buff *skb) |
| 1349 | { |
| 1350 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1351 | |
| 1352 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1353 | napi_gro_receive(&q_vector->napi, skb); |
| 1354 | else |
| 1355 | netif_rx(skb); |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1358 | /** |
| 1359 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1360 | * @rx_ring: Rx ring being processed |
| 1361 | * @rx_desc: Rx descriptor for current buffer |
| 1362 | * @skb: Current socket buffer containing buffer in progress |
| 1363 | * |
| 1364 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1365 | * this function exits returning false, otherwise it will place the |
| 1366 | * sk_buff in the next buffer to be chained and return true indicating |
| 1367 | * that this is in fact a non-EOP buffer. |
| 1368 | **/ |
| 1369 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1370 | union ixgbe_adv_rx_desc *rx_desc, |
| 1371 | struct sk_buff *skb) |
| 1372 | { |
| 1373 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1374 | |
| 1375 | /* fetch, update, and store next to clean */ |
| 1376 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1377 | rx_ring->next_to_clean = ntc; |
| 1378 | |
| 1379 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1380 | |
| 1381 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1382 | return false; |
| 1383 | |
| 1384 | /* append_cnt indicates packet is RSC, if so fetch nextp */ |
| 1385 | if (IXGBE_CB(skb)->append_cnt) { |
| 1386 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1387 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1388 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1389 | } |
| 1390 | |
| 1391 | /* place skb in next buffer to be received */ |
| 1392 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1393 | rx_ring->rx_stats.non_eop_descs++; |
| 1394 | |
| 1395 | return true; |
| 1396 | } |
| 1397 | |
| 1398 | /** |
| 1399 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1400 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1401 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1402 | * @skb: pointer to current skb being fixed |
| 1403 | * |
| 1404 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1405 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1406 | * should be very rare. |
| 1407 | * |
| 1408 | * Also address the case where we are pulling data in on pages only |
| 1409 | * and as such no data is present in the skb header. |
| 1410 | * |
| 1411 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1412 | * it is large enough to qualify as a valid Ethernet frame. |
| 1413 | * |
| 1414 | * Returns true if an error was encountered and skb was freed. |
| 1415 | **/ |
| 1416 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1417 | union ixgbe_adv_rx_desc *rx_desc, |
| 1418 | struct sk_buff *skb) |
| 1419 | { |
| 1420 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1421 | struct net_device *netdev = rx_ring->netdev; |
| 1422 | unsigned char *va; |
| 1423 | unsigned int pull_len; |
| 1424 | |
| 1425 | /* if the page was released unmap it, else just sync our portion */ |
| 1426 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1427 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1428 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1429 | IXGBE_CB(skb)->page_released = false; |
| 1430 | } else { |
| 1431 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1432 | IXGBE_CB(skb)->dma, |
| 1433 | frag->page_offset, |
| 1434 | ixgbe_rx_bufsz(rx_ring), |
| 1435 | DMA_FROM_DEVICE); |
| 1436 | } |
| 1437 | IXGBE_CB(skb)->dma = 0; |
| 1438 | |
| 1439 | /* verify that the packet does not have any known errors */ |
| 1440 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1441 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1442 | !(netdev->features & NETIF_F_RXALL))) { |
| 1443 | dev_kfree_skb_any(skb); |
| 1444 | return true; |
| 1445 | } |
| 1446 | |
| 1447 | /* |
| 1448 | * it is valid to use page_address instead of kmap since we are |
| 1449 | * working with pages allocated out of the lomem pool per |
| 1450 | * alloc_page(GFP_ATOMIC) |
| 1451 | */ |
| 1452 | va = skb_frag_address(frag); |
| 1453 | |
| 1454 | /* |
| 1455 | * we need the header to contain the greater of either ETH_HLEN or |
| 1456 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1457 | */ |
| 1458 | pull_len = skb_frag_size(frag); |
| 1459 | if (pull_len > 256) |
| 1460 | pull_len = ixgbe_get_headlen(va, pull_len); |
| 1461 | |
| 1462 | /* align pull length to size of long to optimize memcpy performance */ |
| 1463 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1464 | |
| 1465 | /* update all of the pointers */ |
| 1466 | skb_frag_size_sub(frag, pull_len); |
| 1467 | frag->page_offset += pull_len; |
| 1468 | skb->data_len -= pull_len; |
| 1469 | skb->tail += pull_len; |
| 1470 | |
| 1471 | /* |
| 1472 | * if we sucked the frag empty then we should free it, |
| 1473 | * if there are other frags here something is screwed up in hardware |
| 1474 | */ |
| 1475 | if (skb_frag_size(frag) == 0) { |
| 1476 | BUG_ON(skb_shinfo(skb)->nr_frags != 1); |
| 1477 | skb_shinfo(skb)->nr_frags = 0; |
| 1478 | __skb_frag_unref(frag); |
| 1479 | skb->truesize -= ixgbe_rx_bufsz(rx_ring); |
| 1480 | } |
| 1481 | |
| 1482 | /* if skb_pad returns an error the skb was freed */ |
| 1483 | if (unlikely(skb->len < 60)) { |
| 1484 | int pad_len = 60 - skb->len; |
| 1485 | |
| 1486 | if (skb_pad(skb, pad_len)) |
| 1487 | return true; |
| 1488 | __skb_put(skb, pad_len); |
| 1489 | } |
| 1490 | |
| 1491 | return false; |
| 1492 | } |
| 1493 | |
| 1494 | /** |
| 1495 | * ixgbe_can_reuse_page - determine if we can reuse a page |
| 1496 | * @rx_buffer: pointer to rx_buffer containing the page we want to reuse |
| 1497 | * |
| 1498 | * Returns true if page can be reused in another Rx buffer |
| 1499 | **/ |
| 1500 | static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer) |
| 1501 | { |
| 1502 | struct page *page = rx_buffer->page; |
| 1503 | |
| 1504 | /* if we are only owner of page and it is local we can reuse it */ |
| 1505 | return likely(page_count(page) == 1) && |
| 1506 | likely(page_to_nid(page) == numa_node_id()); |
| 1507 | } |
| 1508 | |
| 1509 | /** |
| 1510 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1511 | * @rx_ring: rx descriptor ring to store buffers on |
| 1512 | * @old_buff: donor buffer to have page reused |
| 1513 | * |
| 1514 | * Syncronizes page for reuse by the adapter |
| 1515 | **/ |
| 1516 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1517 | struct ixgbe_rx_buffer *old_buff) |
| 1518 | { |
| 1519 | struct ixgbe_rx_buffer *new_buff; |
| 1520 | u16 nta = rx_ring->next_to_alloc; |
| 1521 | u16 bufsz = ixgbe_rx_bufsz(rx_ring); |
| 1522 | |
| 1523 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1524 | |
| 1525 | /* update, and store next to alloc */ |
| 1526 | nta++; |
| 1527 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1528 | |
| 1529 | /* transfer page from old buffer to new buffer */ |
| 1530 | new_buff->page = old_buff->page; |
| 1531 | new_buff->dma = old_buff->dma; |
| 1532 | |
| 1533 | /* flip page offset to other buffer and store to new_buff */ |
| 1534 | new_buff->page_offset = old_buff->page_offset ^ bufsz; |
| 1535 | |
| 1536 | /* sync the buffer for use by the device */ |
| 1537 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
| 1538 | new_buff->page_offset, bufsz, |
| 1539 | DMA_FROM_DEVICE); |
| 1540 | |
| 1541 | /* bump ref count on page before it is given to the stack */ |
| 1542 | get_page(new_buff->page); |
| 1543 | } |
| 1544 | |
| 1545 | /** |
| 1546 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1547 | * @rx_ring: rx descriptor ring to transact packets on |
| 1548 | * @rx_buffer: buffer containing page to add |
| 1549 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1550 | * @skb: sk_buff to place the data into |
| 1551 | * |
| 1552 | * This function is based on skb_add_rx_frag. I would have used that |
| 1553 | * function however it doesn't handle the truesize case correctly since we |
| 1554 | * are allocating more memory than might be used for a single receive. |
| 1555 | **/ |
| 1556 | static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
| 1557 | struct ixgbe_rx_buffer *rx_buffer, |
| 1558 | struct sk_buff *skb, int size) |
| 1559 | { |
| 1560 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
| 1561 | rx_buffer->page, rx_buffer->page_offset, |
| 1562 | size); |
| 1563 | skb->len += size; |
| 1564 | skb->data_len += size; |
| 1565 | skb->truesize += ixgbe_rx_bufsz(rx_ring); |
| 1566 | } |
| 1567 | |
| 1568 | /** |
| 1569 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 1570 | * @q_vector: structure containing interrupt and ring information |
| 1571 | * @rx_ring: rx descriptor ring to transact packets on |
| 1572 | * @budget: Total limit on number of packets to process |
| 1573 | * |
| 1574 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 1575 | * processing. The advantage to this is that on systems that have |
| 1576 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 1577 | * it by maintaining the mapping of the page to the syste. |
| 1578 | * |
| 1579 | * Returns true if all work is completed without reaching budget |
| 1580 | **/ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1581 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1582 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1583 | int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1584 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1585 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 1586 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1587 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1588 | int ddp_bytes = 0; |
| 1589 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1590 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1591 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1592 | do { |
| 1593 | struct ixgbe_rx_buffer *rx_buffer; |
| 1594 | union ixgbe_adv_rx_desc *rx_desc; |
| 1595 | struct sk_buff *skb; |
| 1596 | struct page *page; |
| 1597 | u16 ntc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1598 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1599 | /* return some buffers to hardware, one at a time is too slow */ |
| 1600 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 1601 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1602 | cleaned_count = 0; |
| 1603 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1604 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1605 | ntc = rx_ring->next_to_clean; |
| 1606 | rx_desc = IXGBE_RX_DESC(rx_ring, ntc); |
| 1607 | rx_buffer = &rx_ring->rx_buffer_info[ntc]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1608 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1609 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) |
| 1610 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1611 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1612 | /* |
| 1613 | * This memory barrier is needed to keep us from reading |
| 1614 | * any other fields out of the rx_desc until we know the |
| 1615 | * RXD_STAT_DD bit is set |
| 1616 | */ |
| 1617 | rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1618 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1619 | page = rx_buffer->page; |
| 1620 | prefetchw(page); |
| 1621 | |
| 1622 | skb = rx_buffer->skb; |
| 1623 | |
| 1624 | if (likely(!skb)) { |
| 1625 | void *page_addr = page_address(page) + |
| 1626 | rx_buffer->page_offset; |
| 1627 | |
| 1628 | /* prefetch first cache line of first page */ |
| 1629 | prefetch(page_addr); |
| 1630 | #if L1_CACHE_BYTES < 128 |
| 1631 | prefetch(page_addr + L1_CACHE_BYTES); |
| 1632 | #endif |
| 1633 | |
| 1634 | /* allocate a skb to store the frags */ |
| 1635 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
| 1636 | IXGBE_RX_HDR_SIZE); |
| 1637 | if (unlikely(!skb)) { |
| 1638 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 1639 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1640 | } |
| 1641 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1642 | /* |
| 1643 | * we will be copying header into skb->data in |
| 1644 | * pskb_may_pull so it is in our interest to prefetch |
| 1645 | * it now to avoid a possible cache miss |
| 1646 | */ |
| 1647 | prefetchw(skb->data); |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1648 | |
| 1649 | /* |
| 1650 | * Delay unmapping of the first packet. It carries the |
| 1651 | * header information, HW may still access the header |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1652 | * after the writeback. Only unmap it when EOP is |
| 1653 | * reached |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1654 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1655 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1656 | } else { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1657 | /* we are reusing so sync this buffer for CPU use */ |
| 1658 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1659 | rx_buffer->dma, |
| 1660 | rx_buffer->page_offset, |
| 1661 | ixgbe_rx_bufsz(rx_ring), |
| 1662 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1665 | /* pull page into skb */ |
| 1666 | ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, |
| 1667 | le16_to_cpu(rx_desc->wb.upper.length)); |
| 1668 | |
| 1669 | if (ixgbe_can_reuse_page(rx_buffer)) { |
| 1670 | /* hand second half of page back to the ring */ |
| 1671 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 1672 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 1673 | /* the page has been released from the ring */ |
| 1674 | IXGBE_CB(skb)->page_released = true; |
| 1675 | } else { |
| 1676 | /* we are not reusing the buffer so unmap it */ |
| 1677 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 1678 | ixgbe_rx_pg_size(rx_ring), |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1679 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1682 | /* clear contents of buffer_info */ |
| 1683 | rx_buffer->skb = NULL; |
| 1684 | rx_buffer->dma = 0; |
| 1685 | rx_buffer->page = NULL; |
| 1686 | |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1687 | ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb); |
| 1688 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1689 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1690 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1691 | /* place incomplete frames back on ring for completion */ |
| 1692 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 1693 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1694 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1695 | /* verify the packet layout is correct */ |
| 1696 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 1697 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1698 | |
| 1699 | /* probably a little skewed due to removing CRC */ |
| 1700 | total_rx_bytes += skb->len; |
| 1701 | total_rx_packets++; |
| 1702 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1703 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 1704 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 1705 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1706 | #ifdef IXGBE_FCOE |
| 1707 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1708 | if (ixgbe_rx_is_fcoe(adapter, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1709 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1710 | if (!ddp_bytes) { |
| 1711 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1712 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1713 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1714 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1715 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1716 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1717 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1718 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1719 | /* update budget accounting */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1720 | budget--; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1721 | } while (likely(budget)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1722 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1723 | #ifdef IXGBE_FCOE |
| 1724 | /* include DDPed FCoE data */ |
| 1725 | if (ddp_bytes > 0) { |
| 1726 | unsigned int mss; |
| 1727 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1728 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1729 | sizeof(struct fc_frame_header) - |
| 1730 | sizeof(struct fcoe_crc_eof); |
| 1731 | if (mss > 512) |
| 1732 | mss &= ~511; |
| 1733 | total_rx_bytes += ddp_bytes; |
| 1734 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1735 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1736 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1737 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1738 | u64_stats_update_begin(&rx_ring->syncp); |
| 1739 | rx_ring->stats.packets += total_rx_packets; |
| 1740 | rx_ring->stats.bytes += total_rx_bytes; |
| 1741 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1742 | q_vector->rx.total_packets += total_rx_packets; |
| 1743 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1744 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1745 | if (cleaned_count) |
| 1746 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1747 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1748 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1751 | /** |
| 1752 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1753 | * @adapter: board private structure |
| 1754 | * |
| 1755 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1756 | * interrupts. |
| 1757 | **/ |
| 1758 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1759 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1760 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1761 | int q_vectors, v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1762 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1763 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1764 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1765 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 1766 | /* Populate MSIX to EITR Select */ |
| 1767 | if (adapter->num_vfs > 32) { |
| 1768 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 1769 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 1770 | } |
| 1771 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1772 | /* |
| 1773 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1774 | * corresponding register. |
| 1775 | */ |
| 1776 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1777 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1778 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1779 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1780 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1781 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, 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->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1784 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1785 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1786 | if (q_vector->tx.ring && !q_vector->rx.ring) { |
| 1787 | /* tx only vector */ |
| 1788 | if (adapter->tx_itr_setting == 1) |
| 1789 | q_vector->itr = IXGBE_10K_ITR; |
| 1790 | else |
| 1791 | q_vector->itr = adapter->tx_itr_setting; |
| 1792 | } else { |
| 1793 | /* rx or rx/tx vector */ |
| 1794 | if (adapter->rx_itr_setting == 1) |
| 1795 | q_vector->itr = IXGBE_20K_ITR; |
| 1796 | else |
| 1797 | q_vector->itr = adapter->rx_itr_setting; |
| 1798 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1799 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1800 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1803 | switch (adapter->hw.mac.type) { |
| 1804 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1805 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1806 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1807 | break; |
| 1808 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1809 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1810 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1811 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1812 | default: |
| 1813 | break; |
| 1814 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1815 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1816 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1817 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1818 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1819 | mask &= ~(IXGBE_EIMS_OTHER | |
| 1820 | IXGBE_EIMS_MAILBOX | |
| 1821 | IXGBE_EIMS_LSC); |
| 1822 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1823 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1826 | enum latency_range { |
| 1827 | lowest_latency = 0, |
| 1828 | low_latency = 1, |
| 1829 | bulk_latency = 2, |
| 1830 | latency_invalid = 255 |
| 1831 | }; |
| 1832 | |
| 1833 | /** |
| 1834 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1835 | * @q_vector: structure containing interrupt and ring information |
| 1836 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1837 | * |
| 1838 | * Stores a new ITR value based on packets and byte |
| 1839 | * counts during the last interrupt. The advantage of per interrupt |
| 1840 | * computation is faster updates and more accurate ITR for the current |
| 1841 | * traffic pattern. Constants in this function were computed |
| 1842 | * based on theoretical maximum wire speed and thresholds were set based |
| 1843 | * on testing data as well as attempting to minimize response time |
| 1844 | * while increasing bulk throughput. |
| 1845 | * this functionality is controlled by the InterruptThrottleRate module |
| 1846 | * parameter (see ixgbe_param.c) |
| 1847 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1848 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 1849 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1850 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1851 | int bytes = ring_container->total_bytes; |
| 1852 | int packets = ring_container->total_packets; |
| 1853 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1854 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1855 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1856 | |
| 1857 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1858 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1859 | |
| 1860 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1861 | * 0-10MB/s lowest (100000 ints/s) |
| 1862 | * 10-20MB/s low (20000 ints/s) |
| 1863 | * 20-1249MB/s bulk (8000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1864 | */ |
| 1865 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1866 | timepassed_us = q_vector->itr >> 2; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1867 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1868 | |
| 1869 | switch (itr_setting) { |
| 1870 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1871 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1872 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1873 | break; |
| 1874 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1875 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1876 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1877 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1878 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1879 | break; |
| 1880 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1881 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1882 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1883 | break; |
| 1884 | } |
| 1885 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1886 | /* clear work counters since we have the values we need */ |
| 1887 | ring_container->total_bytes = 0; |
| 1888 | ring_container->total_packets = 0; |
| 1889 | |
| 1890 | /* write updated itr to ring container */ |
| 1891 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1892 | } |
| 1893 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1894 | /** |
| 1895 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1896 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1897 | * |
| 1898 | * This function is made to be called by ethtool and by the driver |
| 1899 | * when it needs to update EITR registers at runtime. Hardware |
| 1900 | * specific quirks/differences are taken care of here. |
| 1901 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1902 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1903 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1904 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1905 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1906 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 1907 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1908 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1909 | switch (adapter->hw.mac.type) { |
| 1910 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1911 | /* must write high and low 16 bits to reset counter */ |
| 1912 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1913 | break; |
| 1914 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1915 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1916 | /* |
| 1917 | * set the WDIS bit to not clear the timer bits and cause an |
| 1918 | * immediate assertion of the interrupt |
| 1919 | */ |
| 1920 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1921 | break; |
| 1922 | default: |
| 1923 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1924 | } |
| 1925 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1926 | } |
| 1927 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1928 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1929 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1930 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1931 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1932 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1933 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 1934 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1935 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1936 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1937 | |
| 1938 | switch (current_itr) { |
| 1939 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1940 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1941 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1942 | break; |
| 1943 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1944 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1945 | break; |
| 1946 | case bulk_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1947 | new_itr = IXGBE_8K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1948 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1949 | default: |
| 1950 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1951 | } |
| 1952 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1953 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1954 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1955 | new_itr = (10 * new_itr * q_vector->itr) / |
| 1956 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1957 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1958 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 1959 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1960 | |
| 1961 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1962 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1963 | } |
| 1964 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1965 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 1966 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1967 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1968 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1969 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1970 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1971 | struct ixgbe_hw *hw = &adapter->hw; |
| 1972 | u32 eicr = adapter->interrupt_event; |
| 1973 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1974 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1975 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1976 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1977 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1978 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 1979 | return; |
| 1980 | |
| 1981 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1982 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1983 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1984 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 1985 | /* |
| 1986 | * Since the warning interrupt is for both ports |
| 1987 | * we don't have to check if: |
| 1988 | * - This interrupt wasn't for our port. |
| 1989 | * - We may have missed the interrupt so always have to |
| 1990 | * check if we got a LSC |
| 1991 | */ |
| 1992 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 1993 | !(eicr & IXGBE_EICR_LSC)) |
| 1994 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1995 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1996 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
| 1997 | u32 autoneg; |
| 1998 | bool link_up = false; |
| 1999 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2000 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2001 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2002 | if (link_up) |
| 2003 | return; |
| 2004 | } |
| 2005 | |
| 2006 | /* Check if this is not due to overtemp */ |
| 2007 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2008 | return; |
| 2009 | |
| 2010 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2011 | default: |
| 2012 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 2013 | return; |
| 2014 | break; |
| 2015 | } |
| 2016 | e_crit(drv, |
| 2017 | "Network adapter has been stopped because it has over heated. " |
| 2018 | "Restart the computer. If the problem persists, " |
| 2019 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2020 | |
| 2021 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2024 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2025 | { |
| 2026 | struct ixgbe_hw *hw = &adapter->hw; |
| 2027 | |
| 2028 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 2029 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2030 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2031 | /* write to clear the interrupt */ |
| 2032 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 2033 | } |
| 2034 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2035 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2036 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2037 | { |
| 2038 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2039 | return; |
| 2040 | |
| 2041 | switch (adapter->hw.mac.type) { |
| 2042 | case ixgbe_mac_82599EB: |
| 2043 | /* |
| 2044 | * Need to check link state so complete overtemp check |
| 2045 | * on service task |
| 2046 | */ |
| 2047 | if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) && |
| 2048 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2049 | adapter->interrupt_event = eicr; |
| 2050 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2051 | ixgbe_service_event_schedule(adapter); |
| 2052 | return; |
| 2053 | } |
| 2054 | return; |
| 2055 | case ixgbe_mac_X540: |
| 2056 | if (!(eicr & IXGBE_EICR_TS)) |
| 2057 | return; |
| 2058 | break; |
| 2059 | default: |
| 2060 | return; |
| 2061 | } |
| 2062 | |
| 2063 | e_crit(drv, |
| 2064 | "Network adapter has been stopped because it has over heated. " |
| 2065 | "Restart the computer. If the problem persists, " |
| 2066 | "power off the system and replace the adapter\n"); |
| 2067 | } |
| 2068 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2069 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2070 | { |
| 2071 | struct ixgbe_hw *hw = &adapter->hw; |
| 2072 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2073 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 2074 | /* Clear the interrupt */ |
| 2075 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2076 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2077 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 2078 | ixgbe_service_event_schedule(adapter); |
| 2079 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2080 | } |
| 2081 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2082 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 2083 | /* Clear the interrupt */ |
| 2084 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2085 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2086 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2087 | ixgbe_service_event_schedule(adapter); |
| 2088 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2092 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2093 | { |
| 2094 | struct ixgbe_hw *hw = &adapter->hw; |
| 2095 | |
| 2096 | adapter->lsc_int++; |
| 2097 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2098 | adapter->link_check_timeout = jiffies; |
| 2099 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2100 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2101 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2102 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2103 | } |
| 2104 | } |
| 2105 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2106 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2107 | u64 qmask) |
| 2108 | { |
| 2109 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2110 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2111 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2112 | switch (hw->mac.type) { |
| 2113 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2114 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2115 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2116 | break; |
| 2117 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2118 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2119 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2120 | if (mask) |
| 2121 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2122 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2123 | if (mask) |
| 2124 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2125 | break; |
| 2126 | default: |
| 2127 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2128 | } |
| 2129 | /* skip the flush */ |
| 2130 | } |
| 2131 | |
| 2132 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2133 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2134 | { |
| 2135 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2136 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2137 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2138 | switch (hw->mac.type) { |
| 2139 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2140 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2141 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2142 | break; |
| 2143 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2144 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2145 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2146 | if (mask) |
| 2147 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2148 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2149 | if (mask) |
| 2150 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2151 | break; |
| 2152 | default: |
| 2153 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2154 | } |
| 2155 | /* skip the flush */ |
| 2156 | } |
| 2157 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2158 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2159 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2160 | * @adapter: board private structure |
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 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2163 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2164 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2165 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2166 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2167 | /* don't reenable LSC while waiting for link */ |
| 2168 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2169 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2170 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2171 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2172 | switch (adapter->hw.mac.type) { |
| 2173 | case ixgbe_mac_82599EB: |
| 2174 | mask |= IXGBE_EIMS_GPI_SDP0; |
| 2175 | break; |
| 2176 | case ixgbe_mac_X540: |
| 2177 | mask |= IXGBE_EIMS_TS; |
| 2178 | break; |
| 2179 | default: |
| 2180 | break; |
| 2181 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2182 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2183 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2184 | switch (adapter->hw.mac.type) { |
| 2185 | case ixgbe_mac_82599EB: |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2186 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2187 | mask |= IXGBE_EIMS_GPI_SDP2; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2188 | case ixgbe_mac_X540: |
| 2189 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2190 | mask |= IXGBE_EIMS_MAILBOX; |
| 2191 | break; |
| 2192 | default: |
| 2193 | break; |
| 2194 | } |
| 2195 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2196 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2197 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2198 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2199 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2200 | if (queues) |
| 2201 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2202 | if (flush) |
| 2203 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2206 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2207 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2208 | struct ixgbe_adapter *adapter = data; |
| 2209 | struct ixgbe_hw *hw = &adapter->hw; |
| 2210 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2211 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2212 | /* |
| 2213 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2214 | * of clear-by-read. Reading with EICS will return the |
| 2215 | * interrupt causes without clearing, which later be done |
| 2216 | * with the write to EICR. |
| 2217 | */ |
| 2218 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 2219 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2220 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2221 | if (eicr & IXGBE_EICR_LSC) |
| 2222 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2223 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2224 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2225 | ixgbe_msg_task(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 | switch (hw->mac.type) { |
| 2228 | case ixgbe_mac_82599EB: |
| 2229 | case ixgbe_mac_X540: |
| 2230 | if (eicr & IXGBE_EICR_ECC) |
| 2231 | e_info(link, "Received unrecoverable ECC Err, please " |
| 2232 | "reboot\n"); |
| 2233 | /* Handle Flow Director Full threshold interrupt */ |
| 2234 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2235 | int reinit_count = 0; |
| 2236 | int i; |
| 2237 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2238 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2239 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2240 | &ring->state)) |
| 2241 | reinit_count++; |
| 2242 | } |
| 2243 | if (reinit_count) { |
| 2244 | /* no more flow director interrupts until after init */ |
| 2245 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2246 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2247 | ixgbe_service_event_schedule(adapter); |
| 2248 | } |
| 2249 | } |
| 2250 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2251 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2252 | break; |
| 2253 | default: |
| 2254 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2257 | ixgbe_check_fan_failure(adapter, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2258 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2259 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2260 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2261 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2262 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2263 | return IRQ_HANDLED; |
| 2264 | } |
| 2265 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2266 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2267 | { |
| 2268 | struct ixgbe_q_vector *q_vector = data; |
| 2269 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2270 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2271 | |
| 2272 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 2273 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2274 | |
| 2275 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2278 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2279 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2280 | * @adapter: board private structure |
| 2281 | * |
| 2282 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2283 | * interrupts from the kernel. |
| 2284 | **/ |
| 2285 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2286 | { |
| 2287 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2288 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2289 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2290 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2291 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2292 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2293 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2294 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2295 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2296 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2297 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2298 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2299 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2300 | } else if (q_vector->rx.ring) { |
| 2301 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2302 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2303 | } else if (q_vector->tx.ring) { |
| 2304 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2305 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2306 | } else { |
| 2307 | /* skip this unused q_vector */ |
| 2308 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2309 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2310 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2311 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2312 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2313 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2314 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2315 | goto free_queue_irqs; |
| 2316 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2317 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2318 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2319 | /* assign the mask for this irq */ |
| 2320 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2321 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2322 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2323 | } |
| 2324 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2325 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2326 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2327 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2328 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2329 | goto free_queue_irqs; |
| 2330 | } |
| 2331 | |
| 2332 | return 0; |
| 2333 | |
| 2334 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2335 | while (vector) { |
| 2336 | vector--; |
| 2337 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2338 | NULL); |
| 2339 | free_irq(adapter->msix_entries[vector].vector, |
| 2340 | adapter->q_vector[vector]); |
| 2341 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2342 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2343 | pci_disable_msix(adapter->pdev); |
| 2344 | kfree(adapter->msix_entries); |
| 2345 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2346 | return err; |
| 2347 | } |
| 2348 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2349 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2350 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2351 | * @irq: interrupt number |
| 2352 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2353 | **/ |
| 2354 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2355 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2356 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2357 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2358 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2359 | u32 eicr; |
| 2360 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2361 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2362 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2363 | * before the read of EICR. |
| 2364 | */ |
| 2365 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2366 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2367 | /* 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] | 2368 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2369 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2370 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2371 | /* |
| 2372 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2373 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2374 | * have disabled interrupts due to EIAM |
| 2375 | * finish the workaround of silicon errata on 82598. Unmask |
| 2376 | * the interrupt that we masked before the EICR read. |
| 2377 | */ |
| 2378 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2379 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2380 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2381 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2382 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2383 | if (eicr & IXGBE_EICR_LSC) |
| 2384 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2385 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2386 | switch (hw->mac.type) { |
| 2387 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2388 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 2389 | /* Fall through */ |
| 2390 | case ixgbe_mac_X540: |
| 2391 | if (eicr & IXGBE_EICR_ECC) |
| 2392 | e_info(link, "Received unrecoverable ECC err, please " |
| 2393 | "reboot\n"); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2394 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2395 | break; |
| 2396 | default: |
| 2397 | break; |
| 2398 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2399 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2400 | ixgbe_check_fan_failure(adapter, eicr); |
| 2401 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 2402 | /* would disable interrupts here but EIAM disabled it */ |
| 2403 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2404 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2405 | /* |
| 2406 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2407 | * ixgbe_poll will re-enable the queue interrupts |
| 2408 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2409 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2410 | ixgbe_irq_enable(adapter, false, false); |
| 2411 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2412 | return IRQ_HANDLED; |
| 2413 | } |
| 2414 | |
| 2415 | /** |
| 2416 | * ixgbe_request_irq - initialize interrupts |
| 2417 | * @adapter: board private structure |
| 2418 | * |
| 2419 | * Attempts to configure interrupts using the best available |
| 2420 | * capabilities of the hardware and kernel. |
| 2421 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2422 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2423 | { |
| 2424 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2425 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2426 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2427 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2428 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2429 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2430 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2431 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2432 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2433 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2434 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2435 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2436 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2437 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2438 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2439 | return err; |
| 2440 | } |
| 2441 | |
| 2442 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2443 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2444 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2445 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2446 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2447 | q_vectors = adapter->num_msix_vectors; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2448 | i = q_vectors - 1; |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2449 | free_irq(adapter->msix_entries[i].vector, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2450 | i--; |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2451 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2452 | for (; i >= 0; i--) { |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2453 | /* free only the irqs that were actually requested */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2454 | if (!adapter->q_vector[i]->rx.ring && |
| 2455 | !adapter->q_vector[i]->tx.ring) |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2456 | continue; |
| 2457 | |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2458 | /* clear the affinity_mask in the IRQ descriptor */ |
| 2459 | irq_set_affinity_hint(adapter->msix_entries[i].vector, |
| 2460 | NULL); |
| 2461 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2462 | free_irq(adapter->msix_entries[i].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2463 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2464 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2465 | } else { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2466 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2471 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2472 | * @adapter: board private structure |
| 2473 | **/ |
| 2474 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2475 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2476 | switch (adapter->hw.mac.type) { |
| 2477 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2478 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2479 | break; |
| 2480 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2481 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2482 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2483 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2484 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2485 | break; |
| 2486 | default: |
| 2487 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2488 | } |
| 2489 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2490 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2491 | int i; |
| 2492 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 2493 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2494 | } else { |
| 2495 | synchronize_irq(adapter->pdev->irq); |
| 2496 | } |
| 2497 | } |
| 2498 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2499 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2500 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2501 | * |
| 2502 | **/ |
| 2503 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2504 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2505 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2506 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2507 | /* rx/tx vector */ |
| 2508 | if (adapter->rx_itr_setting == 1) |
| 2509 | q_vector->itr = IXGBE_20K_ITR; |
| 2510 | else |
| 2511 | q_vector->itr = adapter->rx_itr_setting; |
| 2512 | |
| 2513 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2514 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2515 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2516 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2517 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2518 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2521 | /** |
| 2522 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2523 | * @adapter: board private structure |
| 2524 | * @ring: structure containing ring specific data |
| 2525 | * |
| 2526 | * Configure the Tx descriptor ring after a reset. |
| 2527 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2528 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2529 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2530 | { |
| 2531 | struct ixgbe_hw *hw = &adapter->hw; |
| 2532 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2533 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2534 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2535 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2536 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2537 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2538 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2539 | IXGBE_WRITE_FLUSH(hw); |
| 2540 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2541 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2542 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2543 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2544 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2545 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2546 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2547 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2548 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2549 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2550 | /* |
| 2551 | * set WTHRESH to encourage burst writeback, it should not be set |
| 2552 | * higher than 1 when ITR is 0 as it could cause false TX hangs |
| 2553 | * |
| 2554 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 2555 | * to or less than the number of on chip descriptors, which is |
| 2556 | * currently 40. |
| 2557 | */ |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2558 | if (!ring->q_vector || (ring->q_vector->itr < 8)) |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2559 | txdctl |= (1 << 16); /* WTHRESH = 1 */ |
| 2560 | else |
| 2561 | txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 2562 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2563 | /* |
| 2564 | * Setting PTHRESH to 32 both improves performance |
| 2565 | * and avoids a TX hang with DFP enabled |
| 2566 | */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2567 | txdctl |= (1 << 8) | /* HTHRESH = 1 */ |
| 2568 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2569 | |
| 2570 | /* reinitialize flowdirector state */ |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2571 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2572 | adapter->atr_sample_rate) { |
| 2573 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2574 | ring->atr_count = 0; |
| 2575 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2576 | } else { |
| 2577 | ring->atr_sample_rate = 0; |
| 2578 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2579 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2580 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2581 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2582 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2583 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2584 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 2585 | netdev_tx_reset_queue(txring_txq(ring)); |
| 2586 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2587 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2588 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2589 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2590 | return; |
| 2591 | |
| 2592 | /* poll to verify queue is enabled */ |
| 2593 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2594 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2595 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2596 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2597 | if (!wait_loop) |
| 2598 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2601 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2602 | { |
| 2603 | struct ixgbe_hw *hw = &adapter->hw; |
| 2604 | u32 rttdcs; |
John Fastabend | 72a32f1 | 2011-04-26 07:25:58 +0000 | [diff] [blame] | 2605 | u32 reg; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2606 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2607 | |
| 2608 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2609 | return; |
| 2610 | |
| 2611 | /* disable the arbiter while setting MTQC */ |
| 2612 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2613 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2614 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2615 | |
| 2616 | /* set transmit pool layout */ |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2617 | switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2618 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2619 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2620 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2621 | break; |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2622 | default: |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2623 | if (!tcs) |
| 2624 | reg = IXGBE_MTQC_64Q_1PB; |
| 2625 | else if (tcs <= 4) |
| 2626 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2627 | else |
| 2628 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2629 | |
| 2630 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg); |
| 2631 | |
| 2632 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 2633 | if (tcs) { |
| 2634 | reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 2635 | reg |= IXGBE_SECTX_DCB; |
| 2636 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg); |
| 2637 | } |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2638 | break; |
| 2639 | } |
| 2640 | |
| 2641 | /* re-enable the arbiter */ |
| 2642 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2643 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2644 | } |
| 2645 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2646 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2647 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2648 | * @adapter: board private structure |
| 2649 | * |
| 2650 | * Configure the Tx unit of the MAC after a reset. |
| 2651 | **/ |
| 2652 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2653 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2654 | struct ixgbe_hw *hw = &adapter->hw; |
| 2655 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2656 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2657 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2658 | ixgbe_setup_mtqc(adapter); |
| 2659 | |
| 2660 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2661 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2662 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2663 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2664 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2665 | } |
| 2666 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2667 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2668 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2669 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2672 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2673 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2674 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2675 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2676 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2677 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2678 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2679 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2680 | switch (adapter->hw.mac.type) { |
| 2681 | case ixgbe_mac_82598EB: { |
| 2682 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
| 2683 | const int mask = feature[RING_F_RSS].mask; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2684 | reg_idx = reg_idx & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2685 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2686 | break; |
| 2687 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2688 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2689 | default: |
| 2690 | break; |
| 2691 | } |
| 2692 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2693 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2694 | |
| 2695 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2696 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2697 | if (adapter->num_vfs) |
| 2698 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2699 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2700 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2701 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2702 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2703 | #if PAGE_SIZE > IXGBE_MAX_RXBUFFER |
| 2704 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2705 | #else |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2706 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2707 | #endif |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2708 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2709 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2710 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2711 | } |
| 2712 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2713 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2714 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2715 | struct ixgbe_hw *hw = &adapter->hw; |
| 2716 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2717 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2718 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2719 | u32 mrqc = 0, reta = 0; |
| 2720 | u32 rxcsum; |
| 2721 | int i, j; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2722 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2723 | int maxq = adapter->ring_feature[RING_F_RSS].indices; |
| 2724 | |
| 2725 | if (tcs) |
| 2726 | maxq = min(maxq, adapter->num_tx_queues / tcs); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2727 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2728 | /* Fill out hash function seeds */ |
| 2729 | for (i = 0; i < 10; i++) |
| 2730 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2731 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2732 | /* Fill out redirection table */ |
| 2733 | for (i = 0, j = 0; i < 128; i++, j++) { |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2734 | if (j == maxq) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2735 | j = 0; |
| 2736 | /* reta = 4-byte sliding window of |
| 2737 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2738 | reta = (reta << 8) | (j * 0x11); |
| 2739 | if ((i & 3) == 3) |
| 2740 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 2741 | } |
| 2742 | |
| 2743 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 2744 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2745 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2746 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 2747 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2748 | if (adapter->hw.mac.type == ixgbe_mac_82598EB && |
| 2749 | (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2750 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2751 | } else { |
| 2752 | int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2753 | | IXGBE_FLAG_SRIOV_ENABLED); |
| 2754 | |
| 2755 | switch (mask) { |
| 2756 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2757 | if (!tcs) |
| 2758 | mrqc = IXGBE_MRQC_RSSEN; |
| 2759 | else if (tcs <= 4) |
| 2760 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 2761 | else |
| 2762 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 2763 | break; |
| 2764 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2765 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2766 | break; |
| 2767 | default: |
| 2768 | break; |
| 2769 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2772 | /* Perform hash on these packet types */ |
| 2773 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2774 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2775 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2776 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2777 | |
| 2778 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2781 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2782 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2783 | * @adapter: address of board private structure |
| 2784 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2785 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 2786 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2787 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2788 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2789 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2790 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2791 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2792 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2793 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2794 | return; |
| 2795 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2796 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2797 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2798 | /* |
| 2799 | * we must limit the number of descriptors so that the |
| 2800 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 2801 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2802 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2803 | #if (PAGE_SIZE <= 8192) |
| 2804 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2805 | #elif (PAGE_SIZE <= 16384) |
| 2806 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2807 | #else |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2808 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2809 | #endif |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2810 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2813 | /** |
| 2814 | * ixgbe_set_uta - Set unicast filter table address |
| 2815 | * @adapter: board private structure |
| 2816 | * |
| 2817 | * The unicast table address is a register array of 32-bit registers. |
| 2818 | * The table is meant to be used in a way similar to how the MTA is used |
| 2819 | * however due to certain limitations in the hardware it is necessary to |
| 2820 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 2821 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
| 2822 | **/ |
| 2823 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) |
| 2824 | { |
| 2825 | struct ixgbe_hw *hw = &adapter->hw; |
| 2826 | int i; |
| 2827 | |
| 2828 | /* The UTA table only exists on 82599 hardware and newer */ |
| 2829 | if (hw->mac.type < ixgbe_mac_82599EB) |
| 2830 | return; |
| 2831 | |
| 2832 | /* we only need to do this if VMDq is enabled */ |
| 2833 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2834 | return; |
| 2835 | |
| 2836 | for (i = 0; i < 128; i++) |
| 2837 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); |
| 2838 | } |
| 2839 | |
| 2840 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2841 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2842 | struct ixgbe_ring *ring) |
| 2843 | { |
| 2844 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2845 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2846 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2847 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2848 | |
| 2849 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2850 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2851 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2852 | return; |
| 2853 | |
| 2854 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2855 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2856 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2857 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2858 | |
| 2859 | if (!wait_loop) { |
| 2860 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 2861 | "the polling period\n", reg_idx); |
| 2862 | } |
| 2863 | } |
| 2864 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2865 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 2866 | struct ixgbe_ring *ring) |
| 2867 | { |
| 2868 | struct ixgbe_hw *hw = &adapter->hw; |
| 2869 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2870 | u32 rxdctl; |
| 2871 | u8 reg_idx = ring->reg_idx; |
| 2872 | |
| 2873 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2874 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 2875 | |
| 2876 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 2877 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2878 | |
| 2879 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2880 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2881 | return; |
| 2882 | |
| 2883 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 2884 | do { |
| 2885 | udelay(10); |
| 2886 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2887 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2888 | |
| 2889 | if (!wait_loop) { |
| 2890 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 2891 | "the polling period\n", reg_idx); |
| 2892 | } |
| 2893 | } |
| 2894 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2895 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 2896 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2897 | { |
| 2898 | struct ixgbe_hw *hw = &adapter->hw; |
| 2899 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2900 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2901 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2902 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2903 | /* disable queue to avoid issues while updating state */ |
| 2904 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2905 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2906 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2907 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 2908 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 2909 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 2910 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 2911 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 2912 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2913 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2914 | |
| 2915 | ixgbe_configure_srrctl(adapter, ring); |
| 2916 | ixgbe_configure_rscctl(adapter, ring); |
| 2917 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 2918 | /* If operating in IOV mode set RLPML for X540 */ |
| 2919 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 2920 | hw->mac.type == ixgbe_mac_X540) { |
| 2921 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 2922 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 2923 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 2924 | } |
| 2925 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2926 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2927 | /* |
| 2928 | * enable cache line friendly hardware writes: |
| 2929 | * PTHRESH=32 descriptors (half the internal cache), |
| 2930 | * this also removes ugly rx_no_buffer_count increment |
| 2931 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 2932 | * WTHRESH=8 burst writeback up to two cache lines |
| 2933 | */ |
| 2934 | rxdctl &= ~0x3FFFFF; |
| 2935 | rxdctl |= 0x080420; |
| 2936 | } |
| 2937 | |
| 2938 | /* enable receive descriptor ring */ |
| 2939 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 2940 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2941 | |
| 2942 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 2943 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2944 | } |
| 2945 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2946 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 2947 | { |
| 2948 | struct ixgbe_hw *hw = &adapter->hw; |
| 2949 | int p; |
| 2950 | |
| 2951 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 2952 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2953 | IXGBE_PSRTYPE_UDPHDR | |
| 2954 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2955 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2956 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2957 | |
| 2958 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2959 | return; |
| 2960 | |
| 2961 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) |
| 2962 | psrtype |= (adapter->num_rx_queues_per_pool << 29); |
| 2963 | |
| 2964 | for (p = 0; p < adapter->num_rx_pools; p++) |
| 2965 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), |
| 2966 | psrtype); |
| 2967 | } |
| 2968 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2969 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 2970 | { |
| 2971 | struct ixgbe_hw *hw = &adapter->hw; |
| 2972 | u32 gcr_ext; |
| 2973 | u32 vt_reg_bits; |
| 2974 | u32 reg_offset, vf_shift; |
| 2975 | u32 vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 2976 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2977 | |
| 2978 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2979 | return; |
| 2980 | |
| 2981 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 2982 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; |
| 2983 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); |
| 2984 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 2985 | |
| 2986 | vf_shift = adapter->num_vfs % 32; |
Greg Rose | 4cd6923 | 2012-01-25 07:59:37 +0000 | [diff] [blame] | 2987 | reg_offset = (adapter->num_vfs >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 2988 | |
| 2989 | /* Enable only the PF's pool for Tx/Rx */ |
| 2990 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 2991 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); |
| 2992 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 2993 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); |
| 2994 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 2995 | |
| 2996 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
| 2997 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 2998 | |
| 2999 | /* |
| 3000 | * Set up VF register offsets for selected VT Mode, |
| 3001 | * i.e. 32 or 64 VFs for SR-IOV |
| 3002 | */ |
| 3003 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3004 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; |
| 3005 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; |
| 3006 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3007 | |
| 3008 | /* enable Tx loopback for VF/PF communication */ |
| 3009 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3010 | /* Enable MAC Anti-Spoofing */ |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3011 | hw->mac.ops.set_mac_anti_spoofing(hw, |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3012 | (adapter->num_vfs != 0), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3013 | adapter->num_vfs); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3014 | /* For VFs that have spoof checking turned off */ |
| 3015 | for (i = 0; i < adapter->num_vfs; i++) { |
| 3016 | if (!adapter->vfinfo[i].spoofchk_enabled) |
| 3017 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false); |
| 3018 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3021 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3022 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3023 | struct ixgbe_hw *hw = &adapter->hw; |
| 3024 | struct net_device *netdev = adapter->netdev; |
| 3025 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3026 | struct ixgbe_ring *rx_ring; |
| 3027 | int i; |
| 3028 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3029 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3030 | #ifdef IXGBE_FCOE |
| 3031 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3032 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3033 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3034 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3035 | |
| 3036 | #endif /* IXGBE_FCOE */ |
| 3037 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3038 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3039 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3040 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3041 | |
| 3042 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
Alexander Duyck | 919e78a | 2011-08-26 09:52:38 +0000 | [diff] [blame] | 3045 | /* MHADD will allow an extra 4 bytes past for vlan tagged frames */ |
| 3046 | max_frame += VLAN_HLEN; |
| 3047 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3048 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3049 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3050 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3051 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3052 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3053 | /* |
| 3054 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3055 | * the Base and Length of the Rx Descriptor Ring |
| 3056 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3057 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3058 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3059 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3060 | set_ring_rsc_enabled(rx_ring); |
| 3061 | else |
| 3062 | clear_ring_rsc_enabled(rx_ring); |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3063 | #ifdef IXGBE_FCOE |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3064 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3065 | struct ixgbe_ring_feature *f; |
| 3066 | f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3067 | if ((i >= f->mask) && (i < f->mask + f->indices)) |
| 3068 | set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state); |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3069 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3070 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3071 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3072 | } |
| 3073 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3074 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3075 | { |
| 3076 | struct ixgbe_hw *hw = &adapter->hw; |
| 3077 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3078 | |
| 3079 | switch (hw->mac.type) { |
| 3080 | case ixgbe_mac_82598EB: |
| 3081 | /* |
| 3082 | * For VMDq support of different descriptor types or |
| 3083 | * buffer sizes through the use of multiple SRRCTL |
| 3084 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3085 | * |
| 3086 | * also, the manual doesn't mention it clearly but DCA hints |
| 3087 | * will only use queue 0's tags unless this bit is set. Side |
| 3088 | * effects of setting this bit are only that SRRCTL must be |
| 3089 | * fully programmed [0..15] |
| 3090 | */ |
| 3091 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3092 | break; |
| 3093 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3094 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3095 | /* Disable RSC for ACK packets */ |
| 3096 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3097 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3098 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3099 | /* hardware requires some bits to be set by default */ |
| 3100 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3101 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3102 | break; |
| 3103 | default: |
| 3104 | /* We should do nothing since we don't know this hardware */ |
| 3105 | return; |
| 3106 | } |
| 3107 | |
| 3108 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3109 | } |
| 3110 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3111 | /** |
| 3112 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3113 | * @adapter: board private structure |
| 3114 | * |
| 3115 | * Configure the Rx unit of the MAC after a reset. |
| 3116 | **/ |
| 3117 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3118 | { |
| 3119 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3120 | int i; |
| 3121 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3122 | |
| 3123 | /* disable receives while setting up the descriptors */ |
| 3124 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3125 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3126 | |
| 3127 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3128 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3129 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3130 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3131 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3132 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3133 | ixgbe_set_uta(adapter); |
| 3134 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3135 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3136 | ixgbe_set_rx_buffer_len(adapter); |
| 3137 | |
| 3138 | /* |
| 3139 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3140 | * the Base and Length of the Rx Descriptor Ring |
| 3141 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3142 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3143 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3144 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3145 | /* disable drop enable for 82598 parts */ |
| 3146 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3147 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3148 | |
| 3149 | /* enable all receives */ |
| 3150 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3151 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3154 | 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] | 3155 | { |
| 3156 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3157 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3158 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3159 | |
| 3160 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3161 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3162 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3163 | |
| 3164 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3167 | 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] | 3168 | { |
| 3169 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3170 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3171 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3172 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3173 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3174 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3175 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3176 | |
| 3177 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3180 | /** |
| 3181 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3182 | * @adapter: driver data |
| 3183 | */ |
| 3184 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3185 | { |
| 3186 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3187 | u32 vlnctrl; |
| 3188 | |
| 3189 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3190 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3191 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3192 | } |
| 3193 | |
| 3194 | /** |
| 3195 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3196 | * @adapter: driver data |
| 3197 | */ |
| 3198 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3199 | { |
| 3200 | struct ixgbe_hw *hw = &adapter->hw; |
| 3201 | u32 vlnctrl; |
| 3202 | |
| 3203 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3204 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3205 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3206 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3207 | } |
| 3208 | |
| 3209 | /** |
| 3210 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3211 | * @adapter: driver data |
| 3212 | */ |
| 3213 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3214 | { |
| 3215 | struct ixgbe_hw *hw = &adapter->hw; |
| 3216 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3217 | int i, j; |
| 3218 | |
| 3219 | switch (hw->mac.type) { |
| 3220 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3221 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3222 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3223 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3224 | break; |
| 3225 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3226 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3227 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3228 | j = adapter->rx_ring[i]->reg_idx; |
| 3229 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3230 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3231 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3232 | } |
| 3233 | break; |
| 3234 | default: |
| 3235 | break; |
| 3236 | } |
| 3237 | } |
| 3238 | |
| 3239 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3240 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3241 | * @adapter: driver data |
| 3242 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3243 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3244 | { |
| 3245 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3246 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3247 | int i, j; |
| 3248 | |
| 3249 | switch (hw->mac.type) { |
| 3250 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3251 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3252 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3253 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3254 | break; |
| 3255 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3256 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3257 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3258 | j = adapter->rx_ring[i]->reg_idx; |
| 3259 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3260 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3261 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3262 | } |
| 3263 | break; |
| 3264 | default: |
| 3265 | break; |
| 3266 | } |
| 3267 | } |
| 3268 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3269 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3270 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3271 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3272 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3273 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3274 | |
| 3275 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3276 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3280 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3281 | * @netdev: network interface device structure |
| 3282 | * |
| 3283 | * Writes unicast address list to the RAR table. |
| 3284 | * Returns: -ENOMEM on failure/insufficient address space |
| 3285 | * 0 on no addresses written |
| 3286 | * X on writing X addresses to the RAR table |
| 3287 | **/ |
| 3288 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3289 | { |
| 3290 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3291 | struct ixgbe_hw *hw = &adapter->hw; |
| 3292 | unsigned int vfn = adapter->num_vfs; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3293 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3294 | int count = 0; |
| 3295 | |
| 3296 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3297 | if (netdev_uc_count(netdev) > rar_entries) |
| 3298 | return -ENOMEM; |
| 3299 | |
| 3300 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3301 | struct netdev_hw_addr *ha; |
| 3302 | /* return error if we do not support writing to RAR table */ |
| 3303 | if (!hw->mac.ops.set_rar) |
| 3304 | return -ENOMEM; |
| 3305 | |
| 3306 | netdev_for_each_uc_addr(ha, netdev) { |
| 3307 | if (!rar_entries) |
| 3308 | break; |
| 3309 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
| 3310 | vfn, IXGBE_RAH_AV); |
| 3311 | count++; |
| 3312 | } |
| 3313 | } |
| 3314 | /* write the addresses in reverse order to avoid write combining */ |
| 3315 | for (; rar_entries > 0 ; rar_entries--) |
| 3316 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3317 | |
| 3318 | return count; |
| 3319 | } |
| 3320 | |
| 3321 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3322 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3323 | * @netdev: network interface device structure |
| 3324 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3325 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3326 | * address list or the network interface flags are updated. This routine is |
| 3327 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3328 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3329 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3330 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3331 | { |
| 3332 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3333 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3334 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3335 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3336 | |
| 3337 | /* Check for Promiscuous and All Multicast modes */ |
| 3338 | |
| 3339 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3340 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3341 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3342 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3343 | fctrl |= IXGBE_FCTRL_BAM; |
| 3344 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3345 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3346 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3347 | /* clear the bits we are changing the status of */ |
| 3348 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3349 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3350 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3351 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3352 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3353 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3354 | /* don't hardware filter vlans in promisc mode */ |
| 3355 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3356 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3357 | if (netdev->flags & IFF_ALLMULTI) { |
| 3358 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3359 | vmolr |= IXGBE_VMOLR_MPE; |
| 3360 | } else { |
| 3361 | /* |
| 3362 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3363 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3364 | * that we can at least receive multicast traffic |
| 3365 | */ |
| 3366 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3367 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3368 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3369 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3370 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3371 | /* |
| 3372 | * Write addresses to available RAR registers, if there is not |
| 3373 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3374 | * unicast promiscuous mode |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3375 | */ |
| 3376 | count = ixgbe_write_uc_addr_list(netdev); |
| 3377 | if (count < 0) { |
| 3378 | fctrl |= IXGBE_FCTRL_UPE; |
| 3379 | vmolr |= IXGBE_VMOLR_ROPE; |
| 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | if (adapter->num_vfs) { |
| 3384 | ixgbe_restore_vf_multicasts(adapter); |
| 3385 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & |
| 3386 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3387 | IXGBE_VMOLR_ROPE); |
| 3388 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3391 | /* This is useful for sniffing bad packets. */ |
| 3392 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3393 | /* UPE and MPE will be handled by normal PROMISC logic |
| 3394 | * in e1000e_set_rx_mode */ |
| 3395 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 3396 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 3397 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 3398 | |
| 3399 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 3400 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 3401 | } |
| 3402 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3403 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3404 | |
| 3405 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3406 | ixgbe_vlan_strip_enable(adapter); |
| 3407 | else |
| 3408 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3409 | } |
| 3410 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3411 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3412 | { |
| 3413 | int q_idx; |
| 3414 | struct ixgbe_q_vector *q_vector; |
| 3415 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3416 | |
| 3417 | /* legacy and MSI only use one vector */ |
| 3418 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3419 | q_vectors = 1; |
| 3420 | |
| 3421 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3422 | q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3423 | napi_enable(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3428 | { |
| 3429 | int q_idx; |
| 3430 | struct ixgbe_q_vector *q_vector; |
| 3431 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3432 | |
| 3433 | /* legacy and MSI only use one vector */ |
| 3434 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3435 | q_vectors = 1; |
| 3436 | |
| 3437 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3438 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3439 | napi_disable(&q_vector->napi); |
| 3440 | } |
| 3441 | } |
| 3442 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3443 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3444 | /* |
| 3445 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3446 | * @adapter: ixgbe adapter struct |
| 3447 | * |
| 3448 | * This is called by the driver on open to configure the DCB hardware. |
| 3449 | * This is also called by the gennetlink interface when reconfiguring |
| 3450 | * the DCB state. |
| 3451 | */ |
| 3452 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3453 | { |
| 3454 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3455 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3456 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3457 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3458 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3459 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3460 | return; |
| 3461 | } |
| 3462 | |
| 3463 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3464 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3465 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3466 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3467 | /* Enable VLAN tag insert/strip */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3468 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3469 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3470 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3471 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3472 | #ifdef IXGBE_FCOE |
| 3473 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3474 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3475 | #endif |
| 3476 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3477 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3478 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3479 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3480 | DCB_TX_CONFIG); |
| 3481 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3482 | DCB_RX_CONFIG); |
| 3483 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3484 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 3485 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 3486 | adapter->ixgbe_ieee_ets, |
| 3487 | max_frame); |
| 3488 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 3489 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 3490 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3491 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3492 | |
| 3493 | /* Enable RSS Hash per TC */ |
| 3494 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3495 | int i; |
| 3496 | u32 reg = 0; |
| 3497 | |
| 3498 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 3499 | u8 msb = 0; |
| 3500 | u8 cnt = adapter->netdev->tc_to_txq[i].count; |
| 3501 | |
| 3502 | while (cnt >>= 1) |
| 3503 | msb++; |
| 3504 | |
| 3505 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); |
| 3506 | } |
| 3507 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); |
| 3508 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3509 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3510 | #endif |
| 3511 | |
| 3512 | /* Additional bittime to account for IXGBE framing */ |
| 3513 | #define IXGBE_ETH_FRAMING 20 |
| 3514 | |
| 3515 | /* |
| 3516 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 3517 | * |
| 3518 | * @adapter: board private structure to calculate for |
| 3519 | * @pb - packet buffer to calculate |
| 3520 | */ |
| 3521 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 3522 | { |
| 3523 | struct ixgbe_hw *hw = &adapter->hw; |
| 3524 | struct net_device *dev = adapter->netdev; |
| 3525 | int link, tc, kb, marker; |
| 3526 | u32 dv_id, rx_pba; |
| 3527 | |
| 3528 | /* Calculate max LAN frame size */ |
| 3529 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 3530 | |
| 3531 | #ifdef IXGBE_FCOE |
| 3532 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 3533 | if (dev->features & NETIF_F_FCOE_MTU) { |
| 3534 | int fcoe_pb = 0; |
| 3535 | |
| 3536 | #ifdef CONFIG_IXGBE_DCB |
| 3537 | fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3538 | |
| 3539 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3540 | if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 3541 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3542 | } |
| 3543 | #endif |
| 3544 | |
| 3545 | /* Calculate delay value for device */ |
| 3546 | switch (hw->mac.type) { |
| 3547 | case ixgbe_mac_X540: |
| 3548 | dv_id = IXGBE_DV_X540(link, tc); |
| 3549 | break; |
| 3550 | default: |
| 3551 | dv_id = IXGBE_DV(link, tc); |
| 3552 | break; |
| 3553 | } |
| 3554 | |
| 3555 | /* Loopback switch introduces additional latency */ |
| 3556 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3557 | dv_id += IXGBE_B2BT(tc); |
| 3558 | |
| 3559 | /* Delay value is calculated in bit times convert to KB */ |
| 3560 | kb = IXGBE_BT2KB(dv_id); |
| 3561 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 3562 | |
| 3563 | marker = rx_pba - kb; |
| 3564 | |
| 3565 | /* It is possible that the packet buffer is not large enough |
| 3566 | * to provide required headroom. In this case throw an error |
| 3567 | * to user and a do the best we can. |
| 3568 | */ |
| 3569 | if (marker < 0) { |
| 3570 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 3571 | "headroom to support flow control." |
| 3572 | "Decrease MTU or number of traffic classes\n", pb); |
| 3573 | marker = tc + 1; |
| 3574 | } |
| 3575 | |
| 3576 | return marker; |
| 3577 | } |
| 3578 | |
| 3579 | /* |
| 3580 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 3581 | * |
| 3582 | * @adapter: board private structure to calculate for |
| 3583 | * @pb - packet buffer to calculate |
| 3584 | */ |
| 3585 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter) |
| 3586 | { |
| 3587 | struct ixgbe_hw *hw = &adapter->hw; |
| 3588 | struct net_device *dev = adapter->netdev; |
| 3589 | int tc; |
| 3590 | u32 dv_id; |
| 3591 | |
| 3592 | /* Calculate max LAN frame size */ |
| 3593 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3594 | |
| 3595 | /* Calculate delay value for device */ |
| 3596 | switch (hw->mac.type) { |
| 3597 | case ixgbe_mac_X540: |
| 3598 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 3599 | break; |
| 3600 | default: |
| 3601 | dv_id = IXGBE_LOW_DV(tc); |
| 3602 | break; |
| 3603 | } |
| 3604 | |
| 3605 | /* Delay value is calculated in bit times convert to KB */ |
| 3606 | return IXGBE_BT2KB(dv_id); |
| 3607 | } |
| 3608 | |
| 3609 | /* |
| 3610 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 3611 | */ |
| 3612 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 3613 | { |
| 3614 | struct ixgbe_hw *hw = &adapter->hw; |
| 3615 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3616 | int i; |
| 3617 | |
| 3618 | if (!num_tc) |
| 3619 | num_tc = 1; |
| 3620 | |
| 3621 | hw->fc.low_water = ixgbe_lpbthresh(adapter); |
| 3622 | |
| 3623 | for (i = 0; i < num_tc; i++) { |
| 3624 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
| 3625 | |
| 3626 | /* Low water marks must not be larger than high water marks */ |
| 3627 | if (hw->fc.low_water > hw->fc.high_water[i]) |
| 3628 | hw->fc.low_water = 0; |
| 3629 | } |
| 3630 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3631 | |
| 3632 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3633 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3634 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3635 | int hdrm; |
| 3636 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3637 | |
| 3638 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3639 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3640 | hdrm = 32 << adapter->fdir_pballoc; |
| 3641 | else |
| 3642 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3643 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3644 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3645 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3646 | } |
| 3647 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3648 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 3649 | { |
| 3650 | struct ixgbe_hw *hw = &adapter->hw; |
| 3651 | struct hlist_node *node, *node2; |
| 3652 | struct ixgbe_fdir_filter *filter; |
| 3653 | |
| 3654 | spin_lock(&adapter->fdir_perfect_lock); |
| 3655 | |
| 3656 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 3657 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 3658 | |
| 3659 | hlist_for_each_entry_safe(filter, node, node2, |
| 3660 | &adapter->fdir_filter_list, fdir_node) { |
| 3661 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 3662 | &filter->filter, |
| 3663 | filter->sw_idx, |
| 3664 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 3665 | IXGBE_FDIR_DROP_QUEUE : |
| 3666 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | spin_unlock(&adapter->fdir_perfect_lock); |
| 3670 | } |
| 3671 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3672 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3673 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3674 | struct ixgbe_hw *hw = &adapter->hw; |
| 3675 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3676 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3677 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3678 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3679 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3680 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3681 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3682 | ixgbe_restore_vlan(adapter); |
| 3683 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3684 | #ifdef IXGBE_FCOE |
| 3685 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 3686 | ixgbe_configure_fcoe(adapter); |
| 3687 | |
| 3688 | #endif /* IXGBE_FCOE */ |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3689 | |
| 3690 | switch (hw->mac.type) { |
| 3691 | case ixgbe_mac_82599EB: |
| 3692 | case ixgbe_mac_X540: |
| 3693 | hw->mac.ops.disable_rx_buff(hw); |
| 3694 | break; |
| 3695 | default: |
| 3696 | break; |
| 3697 | } |
| 3698 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3699 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3700 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 3701 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3702 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3703 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 3704 | adapter->fdir_pballoc); |
| 3705 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3706 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3707 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3708 | switch (hw->mac.type) { |
| 3709 | case ixgbe_mac_82599EB: |
| 3710 | case ixgbe_mac_X540: |
| 3711 | hw->mac.ops.enable_rx_buff(hw); |
| 3712 | break; |
| 3713 | default: |
| 3714 | break; |
| 3715 | } |
| 3716 | |
Alexander Duyck | 933d41f | 2010-09-07 21:34:29 +0000 | [diff] [blame] | 3717 | ixgbe_configure_virtualization(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3718 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3719 | ixgbe_configure_tx(adapter); |
| 3720 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3721 | } |
| 3722 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3723 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3724 | { |
| 3725 | switch (hw->phy.type) { |
| 3726 | case ixgbe_phy_sfp_avago: |
| 3727 | case ixgbe_phy_sfp_ftl: |
| 3728 | case ixgbe_phy_sfp_intel: |
| 3729 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3730 | case ixgbe_phy_sfp_passive_tyco: |
| 3731 | case ixgbe_phy_sfp_passive_unknown: |
| 3732 | case ixgbe_phy_sfp_active_unknown: |
| 3733 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3734 | return true; |
Alexander Duyck | 8917b44 | 2011-07-21 00:40:51 +0000 | [diff] [blame] | 3735 | case ixgbe_phy_nl: |
| 3736 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3737 | return true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3738 | default: |
| 3739 | return false; |
| 3740 | } |
| 3741 | } |
| 3742 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3743 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3744 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3745 | * @adapter: pointer to private adapter struct |
| 3746 | **/ |
| 3747 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3748 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3749 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3750 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3751 | * is that an SFP was inserted/removed after the reset |
| 3752 | * but before SFP detection was enabled. As such the best |
| 3753 | * solution is to just start searching as soon as we start |
| 3754 | */ |
| 3755 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3756 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3757 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3758 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | /** |
| 3762 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3763 | * @hw: pointer to private hardware struct |
| 3764 | * |
| 3765 | * Returns 0 on success, negative on failure |
| 3766 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3767 | 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] | 3768 | { |
| 3769 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3770 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3771 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 3772 | |
| 3773 | if (hw->mac.ops.check_link) |
| 3774 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 3775 | |
| 3776 | if (ret) |
| 3777 | goto link_cfg_out; |
| 3778 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 3779 | autoneg = hw->phy.autoneg_advertised; |
| 3780 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3781 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3782 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3783 | if (ret) |
| 3784 | goto link_cfg_out; |
| 3785 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3786 | if (hw->mac.ops.setup_link) |
| 3787 | 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] | 3788 | link_cfg_out: |
| 3789 | return ret; |
| 3790 | } |
| 3791 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3792 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3793 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3794 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3795 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3796 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3797 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3798 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 3799 | IXGBE_GPIE_OCD; |
| 3800 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3801 | /* |
| 3802 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 3803 | * this saves a register write for every interrupt |
| 3804 | */ |
| 3805 | switch (hw->mac.type) { |
| 3806 | case ixgbe_mac_82598EB: |
| 3807 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 3808 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3809 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3810 | case ixgbe_mac_X540: |
| 3811 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3812 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 3813 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 3814 | break; |
| 3815 | } |
| 3816 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3817 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 3818 | * specifically only auto mask tx and rx interrupts */ |
| 3819 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3822 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 3823 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 3824 | |
| 3825 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3826 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 3827 | gpie |= IXGBE_GPIE_VTMODE_64; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 3830 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 3831 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 3832 | switch (adapter->hw.mac.type) { |
| 3833 | case ixgbe_mac_82599EB: |
| 3834 | gpie |= IXGBE_SDP0_GPIEN; |
| 3835 | break; |
| 3836 | case ixgbe_mac_X540: |
| 3837 | gpie |= IXGBE_EIMS_TS; |
| 3838 | break; |
| 3839 | default: |
| 3840 | break; |
| 3841 | } |
| 3842 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 3843 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3844 | /* Enable fan failure interrupt */ |
| 3845 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3846 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3847 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3848 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3849 | gpie |= IXGBE_SDP1_GPIEN; |
| 3850 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3851 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3852 | |
| 3853 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 3854 | } |
| 3855 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3856 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3857 | { |
| 3858 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3859 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3860 | u32 ctrl_ext; |
| 3861 | |
| 3862 | ixgbe_get_hw_control(adapter); |
| 3863 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3864 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3865 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3866 | ixgbe_configure_msix(adapter); |
| 3867 | else |
| 3868 | ixgbe_configure_msi_and_legacy(adapter); |
| 3869 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3870 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ |
| 3871 | if (hw->mac.ops.enable_tx_laser && |
| 3872 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 3873 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3874 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 3875 | hw->mac.ops.enable_tx_laser(hw); |
| 3876 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3877 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3878 | ixgbe_napi_enable_all(adapter); |
| 3879 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 3880 | if (ixgbe_is_sfp(hw)) { |
| 3881 | ixgbe_sfp_link_config(adapter); |
| 3882 | } else { |
| 3883 | err = ixgbe_non_sfp_link_config(hw); |
| 3884 | if (err) |
| 3885 | e_err(probe, "link_config FAILED %d\n", err); |
| 3886 | } |
| 3887 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3888 | /* clear any pending interrupts, may auto mask */ |
| 3889 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3890 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3891 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3892 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3893 | * If this adapter has a fan, check to see if we had a failure |
| 3894 | * before we enabled the interrupt. |
| 3895 | */ |
| 3896 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 3897 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 3898 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3899 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3900 | } |
| 3901 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3902 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3903 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3904 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3905 | /* bring the link up in the watchdog, this could race with our first |
| 3906 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3907 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3908 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3909 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 3910 | |
| 3911 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 3912 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 3913 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 3914 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3917 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 3918 | { |
| 3919 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3920 | /* put off any impending NetWatchDogTimeout */ |
| 3921 | adapter->netdev->trans_start = jiffies; |
| 3922 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3923 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3924 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3925 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 3926 | /* |
| 3927 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 3928 | * back up to give the VFs time to respond to the reset. The |
| 3929 | * two second wait is based upon the watchdog timer cycle in |
| 3930 | * the VF driver. |
| 3931 | */ |
| 3932 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3933 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3934 | ixgbe_up(adapter); |
| 3935 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 3936 | } |
| 3937 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3938 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3939 | { |
| 3940 | /* hardware has been reset, we need to reload some things */ |
| 3941 | ixgbe_configure(adapter); |
| 3942 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3943 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 3947 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3948 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3949 | int err; |
| 3950 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3951 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 3952 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 3953 | usleep_range(1000, 2000); |
| 3954 | |
| 3955 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 3956 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 3957 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 3958 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 3959 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3960 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3961 | switch (err) { |
| 3962 | case 0: |
| 3963 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3964 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3965 | break; |
| 3966 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3967 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3968 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3969 | case IXGBE_ERR_EEPROM_VERSION: |
| 3970 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3971 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3972 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3973 | "your hardware. If you are experiencing problems " |
| 3974 | "please contact your Intel or hardware " |
| 3975 | "representative who provided you with this " |
| 3976 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3977 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3978 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3979 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3980 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3981 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3982 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 3983 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3984 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3985 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 3986 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3987 | } |
| 3988 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3989 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3990 | * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers |
| 3991 | * @rx_ring: ring to setup |
| 3992 | * |
| 3993 | * On many IA platforms the L1 cache has a critical stride of 4K, this |
| 3994 | * results in each receive buffer starting in the same cache set. To help |
| 3995 | * reduce the pressure on this cache set we can interleave the offsets so |
| 3996 | * that only every other buffer will be in the same cache set. |
| 3997 | **/ |
| 3998 | static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring) |
| 3999 | { |
| 4000 | struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info; |
| 4001 | u16 i; |
| 4002 | |
| 4003 | for (i = 0; i < rx_ring->count; i += 2) { |
| 4004 | rx_buffer[0].page_offset = 0; |
| 4005 | rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring); |
| 4006 | rx_buffer = &rx_buffer[2]; |
| 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4011 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4012 | * @rx_ring: ring to free buffers from |
| 4013 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4014 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4015 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4016 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4017 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4018 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4019 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4020 | /* ring already cleared, nothing to do */ |
| 4021 | if (!rx_ring->rx_buffer_info) |
| 4022 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4023 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4024 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4025 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4026 | struct ixgbe_rx_buffer *rx_buffer; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4027 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4028 | rx_buffer = &rx_ring->rx_buffer_info[i]; |
| 4029 | if (rx_buffer->skb) { |
| 4030 | struct sk_buff *skb = rx_buffer->skb; |
| 4031 | if (IXGBE_CB(skb)->page_released) { |
| 4032 | dma_unmap_page(dev, |
| 4033 | IXGBE_CB(skb)->dma, |
| 4034 | ixgbe_rx_bufsz(rx_ring), |
| 4035 | DMA_FROM_DEVICE); |
| 4036 | IXGBE_CB(skb)->page_released = false; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 4037 | } |
| 4038 | dev_kfree_skb(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4039 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4040 | rx_buffer->skb = NULL; |
| 4041 | if (rx_buffer->dma) |
| 4042 | dma_unmap_page(dev, rx_buffer->dma, |
| 4043 | ixgbe_rx_pg_size(rx_ring), |
| 4044 | DMA_FROM_DEVICE); |
| 4045 | rx_buffer->dma = 0; |
| 4046 | if (rx_buffer->page) |
| 4047 | put_page(rx_buffer->page); |
| 4048 | rx_buffer->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4052 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4053 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4054 | ixgbe_init_rx_page_offset(rx_ring); |
| 4055 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4056 | /* Zero out the descriptor ring */ |
| 4057 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4058 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4059 | rx_ring->next_to_alloc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4060 | rx_ring->next_to_clean = 0; |
| 4061 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | /** |
| 4065 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4066 | * @tx_ring: ring to be cleaned |
| 4067 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4068 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4069 | { |
| 4070 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4071 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4072 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4073 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4074 | /* ring already cleared, nothing to do */ |
| 4075 | if (!tx_ring->tx_buffer_info) |
| 4076 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4077 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4078 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4079 | for (i = 0; i < tx_ring->count; i++) { |
| 4080 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4081 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4085 | memset(tx_ring->tx_buffer_info, 0, size); |
| 4086 | |
| 4087 | /* Zero out the descriptor ring */ |
| 4088 | memset(tx_ring->desc, 0, tx_ring->size); |
| 4089 | |
| 4090 | tx_ring->next_to_use = 0; |
| 4091 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4095 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4096 | * @adapter: board private structure |
| 4097 | **/ |
| 4098 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4099 | { |
| 4100 | int i; |
| 4101 | |
| 4102 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4103 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4104 | } |
| 4105 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4106 | /** |
| 4107 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4108 | * @adapter: board private structure |
| 4109 | **/ |
| 4110 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4111 | { |
| 4112 | int i; |
| 4113 | |
| 4114 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4115 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4116 | } |
| 4117 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4118 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4119 | { |
| 4120 | struct hlist_node *node, *node2; |
| 4121 | struct ixgbe_fdir_filter *filter; |
| 4122 | |
| 4123 | spin_lock(&adapter->fdir_perfect_lock); |
| 4124 | |
| 4125 | hlist_for_each_entry_safe(filter, node, node2, |
| 4126 | &adapter->fdir_filter_list, fdir_node) { |
| 4127 | hlist_del(&filter->fdir_node); |
| 4128 | kfree(filter); |
| 4129 | } |
| 4130 | adapter->fdir_filter_count = 0; |
| 4131 | |
| 4132 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4133 | } |
| 4134 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4135 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4136 | { |
| 4137 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4138 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4139 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4140 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4141 | |
| 4142 | /* signal that we are down to the interrupt handler */ |
| 4143 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4144 | |
| 4145 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4146 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4147 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4148 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4149 | /* disable all enabled rx queues */ |
| 4150 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4151 | /* this call also flushes the previous write */ |
| 4152 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4153 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4154 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4155 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4156 | netif_tx_stop_all_queues(netdev); |
| 4157 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4158 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4159 | netif_carrier_off(netdev); |
| 4160 | netif_tx_disable(netdev); |
| 4161 | |
| 4162 | ixgbe_irq_disable(adapter); |
| 4163 | |
| 4164 | ixgbe_napi_disable_all(adapter); |
| 4165 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4166 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4167 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4168 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4169 | |
| 4170 | del_timer_sync(&adapter->service_timer); |
| 4171 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4172 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4173 | /* Clear EITR Select mapping */ |
| 4174 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 4175 | |
| 4176 | /* Mark all the VFs as inactive */ |
| 4177 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4178 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4179 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4180 | /* 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] | 4181 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4182 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4183 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4184 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4185 | } |
| 4186 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4187 | /* disable transmits in the hardware now that interrupts are off */ |
| 4188 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4189 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4190 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4191 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4192 | |
| 4193 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4194 | switch (hw->mac.type) { |
| 4195 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4196 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4197 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4198 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4199 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4200 | break; |
| 4201 | default: |
| 4202 | break; |
| 4203 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4204 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4205 | if (!pci_channel_offline(adapter->pdev)) |
| 4206 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4207 | |
| 4208 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 4209 | if (hw->mac.ops.disable_tx_laser && |
| 4210 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 4211 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4212 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 4213 | hw->mac.ops.disable_tx_laser(hw); |
| 4214 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4215 | ixgbe_clean_all_tx_rings(adapter); |
| 4216 | ixgbe_clean_all_rx_rings(adapter); |
| 4217 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4218 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4219 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4220 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4221 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4222 | } |
| 4223 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4224 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4225 | * ixgbe_poll - NAPI Rx polling callback |
| 4226 | * @napi: structure for representing this polling device |
| 4227 | * @budget: how many packets driver is allowed to clean |
| 4228 | * |
| 4229 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4230 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4231 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4232 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4233 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4234 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4235 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4236 | struct ixgbe_ring *ring; |
| 4237 | int per_ring_budget; |
| 4238 | bool clean_complete = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4239 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4240 | #ifdef CONFIG_IXGBE_DCA |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 4241 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 4242 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4243 | #endif |
| 4244 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4245 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4246 | clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4247 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4248 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 4249 | * the budget to go below 1 because we'll exit polling */ |
| 4250 | if (q_vector->rx.count > 1) |
| 4251 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 4252 | else |
| 4253 | per_ring_budget = budget; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4254 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4255 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 4256 | clean_complete &= ixgbe_clean_rx_irq(q_vector, ring, |
| 4257 | per_ring_budget); |
| 4258 | |
| 4259 | /* If all work not completed, return budget and keep polling */ |
| 4260 | if (!clean_complete) |
| 4261 | return budget; |
| 4262 | |
| 4263 | /* all work done, exit the polling mode */ |
| 4264 | napi_complete(napi); |
| 4265 | if (adapter->rx_itr_setting & 1) |
| 4266 | ixgbe_set_itr(q_vector); |
| 4267 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4268 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 4269 | |
| 4270 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | /** |
| 4274 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4275 | * @netdev: network interface device structure |
| 4276 | **/ |
| 4277 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4278 | { |
| 4279 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4280 | |
| 4281 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4282 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4283 | } |
| 4284 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4285 | /** |
| 4286 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 4287 | * @adapter: board private structure to initialize |
| 4288 | * |
| 4289 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 4290 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 4291 | * |
| 4292 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4293 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 4294 | { |
| 4295 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4296 | 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] | 4297 | |
| 4298 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4299 | f->mask = 0xF; |
| 4300 | adapter->num_rx_queues = f->indices; |
| 4301 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4302 | ret = true; |
| 4303 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4304 | ret = false; |
| 4305 | } |
| 4306 | |
| 4307 | return ret; |
| 4308 | } |
| 4309 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4310 | /** |
| 4311 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 4312 | * @adapter: board private structure to initialize |
| 4313 | * |
| 4314 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 4315 | * to the original CPU that initiated the Tx session. This runs in addition |
| 4316 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 4317 | * Rx load across CPUs using RSS. |
| 4318 | * |
| 4319 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4320 | 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] | 4321 | { |
| 4322 | bool ret = false; |
| 4323 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 4324 | |
| 4325 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 4326 | f_fdir->mask = 0; |
| 4327 | |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 4328 | /* |
| 4329 | * Use RSS in addition to Flow Director to ensure the best |
| 4330 | * distribution of flows across cores, even when an FDIR flow |
| 4331 | * isn't matched. |
| 4332 | */ |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4333 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4334 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4335 | adapter->num_tx_queues = f_fdir->indices; |
| 4336 | adapter->num_rx_queues = f_fdir->indices; |
| 4337 | ret = true; |
| 4338 | } else { |
| 4339 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4340 | } |
| 4341 | return ret; |
| 4342 | } |
| 4343 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4344 | #ifdef IXGBE_FCOE |
| 4345 | /** |
| 4346 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 4347 | * @adapter: board private structure to initialize |
| 4348 | * |
| 4349 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 4350 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 4351 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 4352 | * index of the first rx queue used by FCoE. |
| 4353 | * |
| 4354 | **/ |
| 4355 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 4356 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4357 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 4358 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4359 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4360 | return false; |
| 4361 | |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4362 | f->indices = min_t(int, num_online_cpus(), f->indices); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4363 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4364 | adapter->num_rx_queues = 1; |
| 4365 | adapter->num_tx_queues = 1; |
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 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 4368 | e_info(probe, "FCoE enabled with RSS\n"); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4369 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4370 | ixgbe_set_fdir_queues(adapter); |
| 4371 | else |
| 4372 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4373 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4374 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4375 | /* adding FCoE rx rings to the end */ |
| 4376 | f->mask = adapter->num_rx_queues; |
| 4377 | adapter->num_rx_queues += f->indices; |
| 4378 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4379 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4380 | return true; |
| 4381 | } |
| 4382 | #endif /* IXGBE_FCOE */ |
| 4383 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4384 | /* Artificial max queue cap per traffic class in DCB mode */ |
| 4385 | #define DCB_QUEUE_CAP 8 |
| 4386 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4387 | #ifdef CONFIG_IXGBE_DCB |
| 4388 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
| 4389 | { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4390 | int per_tc_q, q, i, offset = 0; |
| 4391 | struct net_device *dev = adapter->netdev; |
| 4392 | int tcs = netdev_get_num_tc(dev); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4393 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4394 | if (!tcs) |
| 4395 | return false; |
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 | /* Map queue offset and counts onto allocated tx queues */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4398 | per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP); |
| 4399 | q = min_t(int, num_online_cpus(), per_tc_q); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4400 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4401 | for (i = 0; i < tcs; i++) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4402 | netdev_set_tc_queue(dev, i, q, offset); |
| 4403 | offset += q; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4406 | adapter->num_tx_queues = q * tcs; |
| 4407 | adapter->num_rx_queues = q * tcs; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4408 | |
| 4409 | #ifdef IXGBE_FCOE |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4410 | /* FCoE enabled queues require special configuration indexed |
| 4411 | * by feature specific indices and mask. Here we map FCoE |
| 4412 | * indices onto the DCB queue pairs allowing FCoE to own |
| 4413 | * configuration later. |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4414 | */ |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4415 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
John Fastabend | cdf485b | 2012-02-11 06:26:00 +0000 | [diff] [blame] | 4416 | u8 prio_tc[MAX_USER_PRIORITY] = {0}; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4417 | int tc; |
| 4418 | struct ixgbe_ring_feature *f = |
| 4419 | &adapter->ring_feature[RING_F_FCOE]; |
| 4420 | |
John Fastabend | cdf485b | 2012-02-11 06:26:00 +0000 | [diff] [blame] | 4421 | ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc); |
| 4422 | tc = prio_tc[adapter->fcoe.up]; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4423 | f->indices = dev->tc_to_txq[tc].count; |
| 4424 | f->mask = dev->tc_to_txq[tc].offset; |
| 4425 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4426 | #endif |
| 4427 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4428 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4429 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4430 | #endif |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4431 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4432 | /** |
| 4433 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 4434 | * @adapter: board private structure to initialize |
| 4435 | * |
| 4436 | * IOV doesn't actually use anything, so just NAK the |
| 4437 | * request for now and let the other queue routines |
| 4438 | * figure out what to do. |
| 4439 | */ |
| 4440 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 4441 | { |
| 4442 | return false; |
| 4443 | } |
| 4444 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4445 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4446 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4447 | * @adapter: board private structure to initialize |
| 4448 | * |
| 4449 | * This is the top level queue allocation routine. The order here is very |
| 4450 | * important, starting with the "most" number of features turned on at once, |
| 4451 | * and ending with the smallest set of features. This way large combinations |
| 4452 | * can be allocated if they're turned on, and smaller combinations are the |
| 4453 | * fallthrough conditions. |
| 4454 | * |
| 4455 | **/ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4456 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4457 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4458 | /* Start with base case */ |
| 4459 | adapter->num_rx_queues = 1; |
| 4460 | adapter->num_tx_queues = 1; |
| 4461 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 4462 | adapter->num_rx_queues_per_pool = 1; |
| 4463 | |
| 4464 | if (ixgbe_set_sriov_queues(adapter)) |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4465 | goto done; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4466 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4467 | #ifdef CONFIG_IXGBE_DCB |
| 4468 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4469 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4470 | |
| 4471 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4472 | #ifdef IXGBE_FCOE |
| 4473 | if (ixgbe_set_fcoe_queues(adapter)) |
| 4474 | goto done; |
| 4475 | |
| 4476 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4477 | if (ixgbe_set_fdir_queues(adapter)) |
| 4478 | goto done; |
| 4479 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4480 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4481 | goto done; |
| 4482 | |
| 4483 | /* fallback to base case */ |
| 4484 | adapter->num_rx_queues = 1; |
| 4485 | adapter->num_tx_queues = 1; |
| 4486 | |
| 4487 | done: |
Yi Zou | 9d837ea | 2012-01-07 08:39:50 +0000 | [diff] [blame] | 4488 | if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) || |
| 4489 | (adapter->netdev->reg_state == NETREG_UNREGISTERING)) |
| 4490 | return 0; |
| 4491 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4492 | /* Notify the stack of the (possibly) reduced queue counts. */ |
John Fastabend | f0796d5 | 2010-07-01 13:21:57 +0000 | [diff] [blame] | 4493 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4494 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 4495 | adapter->num_rx_queues); |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4498 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4499 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4500 | { |
| 4501 | int err, vector_threshold; |
| 4502 | |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4503 | /* We'll want at least 2 (vector_threshold): |
| 4504 | * 1) TxQ[0] + RxQ[0] handler |
| 4505 | * 2) Other (Link Status Change, etc.) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4506 | */ |
| 4507 | vector_threshold = MIN_MSIX_COUNT; |
| 4508 | |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 4509 | /* |
| 4510 | * 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] | 4511 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 4512 | * Right now, we simply care about how many we'll get; we'll |
| 4513 | * set them up later while requesting irq's. |
| 4514 | */ |
| 4515 | while (vectors >= vector_threshold) { |
| 4516 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4517 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4518 | if (!err) /* Success in acquiring all requested vectors. */ |
| 4519 | break; |
| 4520 | else if (err < 0) |
| 4521 | vectors = 0; /* Nasty failure, quit now */ |
| 4522 | else /* err == number of vectors we should try again with */ |
| 4523 | vectors = err; |
| 4524 | } |
| 4525 | |
| 4526 | if (vectors < vector_threshold) { |
| 4527 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 4528 | * This just means we'll go with either a single MSI |
| 4529 | * vector or fall back to legacy interrupts. |
| 4530 | */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4531 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4532 | "Unable to allocate MSI-X interrupts\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4533 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4534 | kfree(adapter->msix_entries); |
| 4535 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4536 | } else { |
| 4537 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 4538 | /* |
| 4539 | * Adjust for only the vectors we'll use, which is minimum |
| 4540 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 4541 | * vectors we were allocated. |
| 4542 | */ |
| 4543 | adapter->num_msix_vectors = min(vectors, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4544 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4545 | } |
| 4546 | } |
| 4547 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4548 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4549 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4550 | * @adapter: board private structure to initialize |
| 4551 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4552 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 4553 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4554 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4555 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4556 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4557 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4558 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4559 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 4560 | return false; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4561 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4562 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4563 | adapter->rx_ring[i]->reg_idx = i; |
| 4564 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4565 | adapter->tx_ring[i]->reg_idx = i; |
| 4566 | |
| 4567 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4568 | } |
| 4569 | |
| 4570 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4571 | |
| 4572 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 4573 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, |
| 4574 | unsigned int *tx, unsigned int *rx) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4575 | { |
| 4576 | struct net_device *dev = adapter->netdev; |
| 4577 | struct ixgbe_hw *hw = &adapter->hw; |
| 4578 | u8 num_tcs = netdev_get_num_tc(dev); |
| 4579 | |
| 4580 | *tx = 0; |
| 4581 | *rx = 0; |
| 4582 | |
| 4583 | switch (hw->mac.type) { |
| 4584 | case ixgbe_mac_82598EB: |
John Fastabend | aba70d5 | 2011-04-26 07:26:14 +0000 | [diff] [blame] | 4585 | *tx = tc << 2; |
| 4586 | *rx = tc << 3; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4587 | break; |
| 4588 | case ixgbe_mac_82599EB: |
| 4589 | case ixgbe_mac_X540: |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4590 | if (num_tcs > 4) { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4591 | if (tc < 3) { |
| 4592 | *tx = tc << 5; |
| 4593 | *rx = tc << 4; |
| 4594 | } else if (tc < 5) { |
| 4595 | *tx = ((tc + 2) << 4); |
| 4596 | *rx = tc << 4; |
| 4597 | } else if (tc < num_tcs) { |
| 4598 | *tx = ((tc + 8) << 3); |
| 4599 | *rx = tc << 4; |
| 4600 | } |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4601 | } else { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4602 | *rx = tc << 5; |
| 4603 | switch (tc) { |
| 4604 | case 0: |
| 4605 | *tx = 0; |
| 4606 | break; |
| 4607 | case 1: |
| 4608 | *tx = 64; |
| 4609 | break; |
| 4610 | case 2: |
| 4611 | *tx = 96; |
| 4612 | break; |
| 4613 | case 3: |
| 4614 | *tx = 112; |
| 4615 | break; |
| 4616 | default: |
| 4617 | break; |
| 4618 | } |
| 4619 | } |
| 4620 | break; |
| 4621 | default: |
| 4622 | break; |
| 4623 | } |
| 4624 | } |
| 4625 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4626 | /** |
| 4627 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 4628 | * @adapter: board private structure to initialize |
| 4629 | * |
| 4630 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 4631 | * |
| 4632 | **/ |
| 4633 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 4634 | { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4635 | struct net_device *dev = adapter->netdev; |
| 4636 | int i, j, k; |
| 4637 | u8 num_tcs = netdev_get_num_tc(dev); |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4638 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4639 | if (!num_tcs) |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4640 | return false; |
| 4641 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4642 | for (i = 0, k = 0; i < num_tcs; i++) { |
| 4643 | unsigned int tx_s, rx_s; |
| 4644 | u16 count = dev->tc_to_txq[i].count; |
| 4645 | |
| 4646 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); |
| 4647 | for (j = 0; j < count; j++, k++) { |
| 4648 | adapter->tx_ring[k]->reg_idx = tx_s + j; |
| 4649 | adapter->rx_ring[k]->reg_idx = rx_s + j; |
| 4650 | adapter->tx_ring[k]->dcb_tc = i; |
| 4651 | adapter->rx_ring[k]->dcb_tc = i; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4652 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4653 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4654 | |
| 4655 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4656 | } |
| 4657 | #endif |
| 4658 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4659 | /** |
| 4660 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 4661 | * @adapter: board private structure to initialize |
| 4662 | * |
| 4663 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 4664 | * |
| 4665 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4666 | 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] | 4667 | { |
| 4668 | int i; |
| 4669 | bool ret = false; |
| 4670 | |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4671 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4672 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4673 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4674 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4675 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4676 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4677 | ret = true; |
| 4678 | } |
| 4679 | |
| 4680 | return ret; |
| 4681 | } |
| 4682 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4683 | #ifdef IXGBE_FCOE |
| 4684 | /** |
| 4685 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 4686 | * @adapter: board private structure to initialize |
| 4687 | * |
| 4688 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 4689 | * |
| 4690 | */ |
| 4691 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 4692 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4693 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4694 | int i; |
| 4695 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4696 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4697 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4698 | return false; |
| 4699 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4700 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4701 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4702 | ixgbe_cache_ring_fdir(adapter); |
| 4703 | else |
| 4704 | ixgbe_cache_ring_rss(adapter); |
| 4705 | |
| 4706 | fcoe_rx_i = f->mask; |
| 4707 | fcoe_tx_i = f->mask; |
| 4708 | } |
| 4709 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 4710 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 4711 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
| 4712 | } |
| 4713 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4717 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4718 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 4719 | * @adapter: board private structure to initialize |
| 4720 | * |
| 4721 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 4722 | * no other mapping is used. |
| 4723 | * |
| 4724 | */ |
| 4725 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 4726 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4727 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 4728 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4729 | if (adapter->num_vfs) |
| 4730 | return true; |
| 4731 | else |
| 4732 | return false; |
| 4733 | } |
| 4734 | |
| 4735 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4736 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 4737 | * @adapter: board private structure to initialize |
| 4738 | * |
| 4739 | * Once we know the feature-set enabled for the device, we'll cache |
| 4740 | * the register offset the descriptor ring is assigned to. |
| 4741 | * |
| 4742 | * Note, the order the various feature calls is important. It must start with |
| 4743 | * the "most" features enabled at the same time, then trickle down to the |
| 4744 | * least amount of features turned on at once. |
| 4745 | **/ |
| 4746 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 4747 | { |
| 4748 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4749 | adapter->rx_ring[0]->reg_idx = 0; |
| 4750 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4751 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4752 | if (ixgbe_cache_ring_sriov(adapter)) |
| 4753 | return; |
| 4754 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4755 | #ifdef CONFIG_IXGBE_DCB |
| 4756 | if (ixgbe_cache_ring_dcb(adapter)) |
| 4757 | return; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4758 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4759 | |
| 4760 | #ifdef IXGBE_FCOE |
| 4761 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 4762 | return; |
| 4763 | #endif /* IXGBE_FCOE */ |
| 4764 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4765 | if (ixgbe_cache_ring_fdir(adapter)) |
| 4766 | return; |
| 4767 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4768 | if (ixgbe_cache_ring_rss(adapter)) |
| 4769 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4770 | } |
| 4771 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4772 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4773 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 4774 | * @adapter: board private structure to initialize |
| 4775 | * |
| 4776 | * Attempt to configure the interrupts using the best available |
| 4777 | * capabilities of the hardware and the kernel. |
| 4778 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 4779 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4780 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4781 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4782 | int err = 0; |
| 4783 | int vector, v_budget; |
| 4784 | |
| 4785 | /* |
| 4786 | * It's easy to be greedy for MSI-X vectors, but it really |
| 4787 | * doesn't do us much good if we have a lot more vectors |
| 4788 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 4789 | * (roughly) the same number of vectors as there are CPU's. |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4790 | * The default is to use pairs of vectors. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4791 | */ |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4792 | v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues); |
| 4793 | v_budget = min_t(int, v_budget, num_online_cpus()); |
| 4794 | v_budget += NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4795 | |
| 4796 | /* |
| 4797 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4798 | * hw.mac->max_msix_vectors vectors. With features |
| 4799 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 4800 | * descriptor queues supported by our device. Thus, we cap it off in |
| 4801 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4802 | */ |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4803 | v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4804 | |
| 4805 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 4806 | * mean we disable MSI-X capabilities of the adapter. */ |
| 4807 | adapter->msix_entries = kcalloc(v_budget, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4808 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4809 | if (adapter->msix_entries) { |
| 4810 | for (vector = 0; vector < v_budget; vector++) |
| 4811 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4812 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4813 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 4814 | |
| 4815 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4816 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4817 | } |
David S. Miller | 26d2784 | 2010-05-03 15:18:22 -0700 | [diff] [blame] | 4818 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4819 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 4820 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4821 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4822 | e_err(probe, |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4823 | "ATR is not supported while multiple " |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4824 | "queues are disabled. Disabling Flow Director\n"); |
| 4825 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4826 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4827 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4828 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4829 | ixgbe_disable_sriov(adapter); |
| 4830 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4831 | err = ixgbe_set_num_queues(adapter); |
| 4832 | if (err) |
| 4833 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4834 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4835 | err = pci_enable_msi(adapter->pdev); |
| 4836 | if (!err) { |
| 4837 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 4838 | } else { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4839 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4840 | "Unable to allocate MSI interrupt, " |
| 4841 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4842 | /* reset err */ |
| 4843 | err = 0; |
| 4844 | } |
| 4845 | |
| 4846 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4847 | return err; |
| 4848 | } |
| 4849 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4850 | static void ixgbe_add_ring(struct ixgbe_ring *ring, |
| 4851 | struct ixgbe_ring_container *head) |
| 4852 | { |
| 4853 | ring->next = head->ring; |
| 4854 | head->ring = ring; |
| 4855 | head->count++; |
| 4856 | } |
| 4857 | |
| 4858 | /** |
| 4859 | * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector |
| 4860 | * @adapter: board private structure to initialize |
| 4861 | * @v_idx: index of vector in adapter struct |
| 4862 | * |
| 4863 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 4864 | **/ |
| 4865 | static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx, |
| 4866 | int txr_count, int txr_idx, |
| 4867 | int rxr_count, int rxr_idx) |
| 4868 | { |
| 4869 | struct ixgbe_q_vector *q_vector; |
| 4870 | struct ixgbe_ring *ring; |
| 4871 | int node = -1; |
| 4872 | int cpu = -1; |
| 4873 | int ring_count, size; |
| 4874 | |
| 4875 | ring_count = txr_count + rxr_count; |
| 4876 | size = sizeof(struct ixgbe_q_vector) + |
| 4877 | (sizeof(struct ixgbe_ring) * ring_count); |
| 4878 | |
| 4879 | /* customize cpu for Flow Director mapping */ |
| 4880 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 4881 | if (cpu_online(v_idx)) { |
| 4882 | cpu = v_idx; |
| 4883 | node = cpu_to_node(cpu); |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | /* allocate q_vector and rings */ |
| 4888 | q_vector = kzalloc_node(size, GFP_KERNEL, node); |
| 4889 | if (!q_vector) |
| 4890 | q_vector = kzalloc(size, GFP_KERNEL); |
| 4891 | if (!q_vector) |
| 4892 | return -ENOMEM; |
| 4893 | |
| 4894 | /* setup affinity mask and node */ |
| 4895 | if (cpu != -1) |
| 4896 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 4897 | else |
| 4898 | cpumask_copy(&q_vector->affinity_mask, cpu_online_mask); |
| 4899 | q_vector->numa_node = node; |
| 4900 | |
| 4901 | /* initialize NAPI */ |
| 4902 | netif_napi_add(adapter->netdev, &q_vector->napi, |
| 4903 | ixgbe_poll, 64); |
| 4904 | |
| 4905 | /* tie q_vector and adapter together */ |
| 4906 | adapter->q_vector[v_idx] = q_vector; |
| 4907 | q_vector->adapter = adapter; |
| 4908 | q_vector->v_idx = v_idx; |
| 4909 | |
| 4910 | /* initialize work limits */ |
| 4911 | q_vector->tx.work_limit = adapter->tx_work_limit; |
| 4912 | |
| 4913 | /* initialize pointer to rings */ |
| 4914 | ring = q_vector->ring; |
| 4915 | |
| 4916 | while (txr_count) { |
| 4917 | /* assign generic ring traits */ |
| 4918 | ring->dev = &adapter->pdev->dev; |
| 4919 | ring->netdev = adapter->netdev; |
| 4920 | |
| 4921 | /* configure backlink on ring */ |
| 4922 | ring->q_vector = q_vector; |
| 4923 | |
| 4924 | /* update q_vector Tx values */ |
| 4925 | ixgbe_add_ring(ring, &q_vector->tx); |
| 4926 | |
| 4927 | /* apply Tx specific ring traits */ |
| 4928 | ring->count = adapter->tx_ring_count; |
| 4929 | ring->queue_index = txr_idx; |
| 4930 | |
| 4931 | /* assign ring to adapter */ |
| 4932 | adapter->tx_ring[txr_idx] = ring; |
| 4933 | |
| 4934 | /* update count and index */ |
| 4935 | txr_count--; |
| 4936 | txr_idx++; |
| 4937 | |
| 4938 | /* push pointer to next ring */ |
| 4939 | ring++; |
| 4940 | } |
| 4941 | |
| 4942 | while (rxr_count) { |
| 4943 | /* assign generic ring traits */ |
| 4944 | ring->dev = &adapter->pdev->dev; |
| 4945 | ring->netdev = adapter->netdev; |
| 4946 | |
| 4947 | /* configure backlink on ring */ |
| 4948 | ring->q_vector = q_vector; |
| 4949 | |
| 4950 | /* update q_vector Rx values */ |
| 4951 | ixgbe_add_ring(ring, &q_vector->rx); |
| 4952 | |
| 4953 | /* |
| 4954 | * 82599 errata, UDP frames with a 0 checksum |
| 4955 | * can be marked as checksum errors. |
| 4956 | */ |
| 4957 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 4958 | set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state); |
| 4959 | |
| 4960 | /* apply Rx specific ring traits */ |
| 4961 | ring->count = adapter->rx_ring_count; |
| 4962 | ring->queue_index = rxr_idx; |
| 4963 | |
| 4964 | /* assign ring to adapter */ |
| 4965 | adapter->rx_ring[rxr_idx] = ring; |
| 4966 | |
| 4967 | /* update count and index */ |
| 4968 | rxr_count--; |
| 4969 | rxr_idx++; |
| 4970 | |
| 4971 | /* push pointer to next ring */ |
| 4972 | ring++; |
| 4973 | } |
| 4974 | |
| 4975 | return 0; |
| 4976 | } |
| 4977 | |
| 4978 | /** |
| 4979 | * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector |
| 4980 | * @adapter: board private structure to initialize |
| 4981 | * @v_idx: Index of vector to be freed |
| 4982 | * |
| 4983 | * This function frees the memory allocated to the q_vector. In addition if |
| 4984 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4985 | * to freeing the q_vector. |
| 4986 | **/ |
| 4987 | static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx) |
| 4988 | { |
| 4989 | struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 4990 | struct ixgbe_ring *ring; |
| 4991 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4992 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4993 | adapter->tx_ring[ring->queue_index] = NULL; |
| 4994 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 4995 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4996 | adapter->rx_ring[ring->queue_index] = NULL; |
| 4997 | |
| 4998 | adapter->q_vector[v_idx] = NULL; |
| 4999 | netif_napi_del(&q_vector->napi); |
| 5000 | |
| 5001 | /* |
| 5002 | * ixgbe_get_stats64() might access the rings on this vector, |
| 5003 | * we must wait a grace period before freeing it. |
| 5004 | */ |
| 5005 | kfree_rcu(q_vector, rcu); |
| 5006 | } |
| 5007 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5008 | /** |
| 5009 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 5010 | * @adapter: board private structure to initialize |
| 5011 | * |
| 5012 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 5013 | * return -ENOMEM. |
| 5014 | **/ |
| 5015 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 5016 | { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5017 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5018 | int rxr_remaining = adapter->num_rx_queues; |
| 5019 | int txr_remaining = adapter->num_tx_queues; |
| 5020 | int rxr_idx = 0, txr_idx = 0, v_idx = 0; |
| 5021 | int err; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5022 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5023 | /* only one q_vector if MSI-X is disabled. */ |
| 5024 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 5025 | q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5026 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5027 | if (q_vectors >= (rxr_remaining + txr_remaining)) { |
| 5028 | for (; rxr_remaining; v_idx++, q_vectors--) { |
| 5029 | int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 5030 | err = ixgbe_alloc_q_vector(adapter, v_idx, |
| 5031 | 0, 0, rqpv, rxr_idx); |
| 5032 | |
| 5033 | if (err) |
| 5034 | goto err_out; |
| 5035 | |
| 5036 | /* update counts and index */ |
| 5037 | rxr_remaining -= rqpv; |
| 5038 | rxr_idx += rqpv; |
| 5039 | } |
| 5040 | } |
| 5041 | |
| 5042 | for (; q_vectors; v_idx++, q_vectors--) { |
| 5043 | int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 5044 | int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors); |
| 5045 | err = ixgbe_alloc_q_vector(adapter, v_idx, |
| 5046 | tqpv, txr_idx, |
| 5047 | rqpv, rxr_idx); |
| 5048 | |
| 5049 | if (err) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5050 | goto err_out; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 5051 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5052 | /* update counts and index */ |
| 5053 | rxr_remaining -= rqpv; |
| 5054 | rxr_idx += rqpv; |
| 5055 | txr_remaining -= tqpv; |
| 5056 | txr_idx += tqpv; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | return 0; |
| 5060 | |
| 5061 | err_out: |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 5062 | while (v_idx) { |
| 5063 | v_idx--; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5064 | ixgbe_free_q_vector(adapter, v_idx); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5065 | } |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5066 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5067 | return -ENOMEM; |
| 5068 | } |
| 5069 | |
| 5070 | /** |
| 5071 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 5072 | * @adapter: board private structure to initialize |
| 5073 | * |
| 5074 | * This function frees the memory allocated to the q_vectors. In addition if |
| 5075 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 5076 | * to freeing the q_vector. |
| 5077 | **/ |
| 5078 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 5079 | { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5080 | int v_idx, q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5081 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5082 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5083 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5084 | else |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5085 | q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5086 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5087 | for (v_idx = 0; v_idx < q_vectors; v_idx++) |
| 5088 | ixgbe_free_q_vector(adapter, v_idx); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 5091 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5092 | { |
| 5093 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5094 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 5095 | pci_disable_msix(adapter->pdev); |
| 5096 | kfree(adapter->msix_entries); |
| 5097 | adapter->msix_entries = NULL; |
| 5098 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 5099 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 5100 | pci_disable_msi(adapter->pdev); |
| 5101 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | /** |
| 5105 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 5106 | * @adapter: board private structure to initialize |
| 5107 | * |
| 5108 | * We determine which interrupt scheme to use based on... |
| 5109 | * - Kernel support (MSI, MSI-X) |
| 5110 | * - which can be user-defined (via MODULE_PARAM) |
| 5111 | * - Hardware queue count (num_*_queues) |
| 5112 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 5113 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5114 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5115 | { |
| 5116 | int err; |
| 5117 | |
| 5118 | /* Number of supported queues */ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 5119 | err = ixgbe_set_num_queues(adapter); |
| 5120 | if (err) |
| 5121 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5122 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5123 | err = ixgbe_set_interrupt_capability(adapter); |
| 5124 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5125 | e_dev_err("Unable to setup interrupt capabilities\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5126 | goto err_set_interrupt; |
| 5127 | } |
| 5128 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5129 | err = ixgbe_alloc_q_vectors(adapter); |
| 5130 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5131 | e_dev_err("Unable to allocate memory for queue vectors\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5132 | goto err_alloc_q_vectors; |
| 5133 | } |
| 5134 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5135 | ixgbe_cache_ring_register(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5136 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5137 | 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] | 5138 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 5139 | adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5140 | |
| 5141 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5142 | |
| 5143 | return 0; |
| 5144 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5145 | err_alloc_q_vectors: |
| 5146 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5147 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5148 | return err; |
| 5149 | } |
| 5150 | |
| 5151 | /** |
| 5152 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 5153 | * @adapter: board private structure to clear interrupt scheme on |
| 5154 | * |
| 5155 | * We go through and clear interrupt specific resources and reset the structure |
| 5156 | * to pre-load conditions |
| 5157 | **/ |
| 5158 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 5159 | { |
Don Skidmore | b8eb3a1 | 2010-12-01 20:54:53 +0000 | [diff] [blame] | 5160 | adapter->num_tx_queues = 0; |
| 5161 | adapter->num_rx_queues = 0; |
| 5162 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5163 | ixgbe_free_q_vectors(adapter); |
| 5164 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | /** |
| 5168 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5169 | * @adapter: board private structure to initialize |
| 5170 | * |
| 5171 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5172 | * Fields are initialized based on PCI device information and |
| 5173 | * OS network device settings (MTU size). |
| 5174 | **/ |
| 5175 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 5176 | { |
| 5177 | struct ixgbe_hw *hw = &adapter->hw; |
| 5178 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5179 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5180 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5181 | int j; |
| 5182 | struct tc_configuration *tc; |
| 5183 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5184 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5185 | /* PCI config space info */ |
| 5186 | |
| 5187 | hw->vendor_id = pdev->vendor; |
| 5188 | hw->device_id = pdev->device; |
| 5189 | hw->revision_id = pdev->revision; |
| 5190 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5191 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5192 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5193 | /* Set capability flags */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 5194 | rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus()); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5195 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 5196 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5197 | switch (hw->mac.type) { |
| 5198 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5199 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5200 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5201 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5202 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5203 | case ixgbe_mac_X540: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 5204 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 5205 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5206 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5207 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5208 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5209 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5210 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 5211 | /* Flow Director hash filters enabled */ |
| 5212 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5213 | adapter->atr_sample_rate = 20; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5214 | adapter->ring_feature[RING_F_FDIR].indices = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5215 | IXGBE_MAX_FDIR_INDICES; |
Alexander Duyck | c04f6ca | 2011-05-11 07:18:36 +0000 | [diff] [blame] | 5216 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5217 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5218 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5219 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5220 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5221 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 5222 | /* Default traffic class to use for FCoE */ |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 5223 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5224 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5225 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5226 | break; |
| 5227 | default: |
| 5228 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5229 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5230 | |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5231 | /* n-tuple support exists, always init our spinlock */ |
| 5232 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5233 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5234 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5235 | switch (hw->mac.type) { |
| 5236 | case ixgbe_mac_X540: |
| 5237 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5238 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5239 | break; |
| 5240 | default: |
| 5241 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5242 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5243 | break; |
| 5244 | } |
| 5245 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5246 | /* Configure DCB traffic classes */ |
| 5247 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5248 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5249 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5250 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5251 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5252 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5253 | tc->dcb_pfc = pfc_disabled; |
| 5254 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5255 | |
| 5256 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5257 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5258 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5259 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5260 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5261 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5262 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5263 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5264 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5265 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5266 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 5267 | MAX_TRAFFIC_CLASS); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5268 | |
| 5269 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5270 | |
| 5271 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5272 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5273 | 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] | 5274 | #ifdef CONFIG_DCB |
| 5275 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 5276 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5277 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5278 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5279 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5280 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5281 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5282 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5283 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5284 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5285 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5286 | /* set default ring sizes */ |
| 5287 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5288 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5289 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5290 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5291 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5292 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5293 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5294 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5295 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5296 | return -EIO; |
| 5297 | } |
| 5298 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5299 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5300 | |
| 5301 | return 0; |
| 5302 | } |
| 5303 | |
| 5304 | /** |
| 5305 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5306 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5307 | * |
| 5308 | * Return 0 on success, negative on failure |
| 5309 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5310 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5311 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5312 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5313 | int orig_node = dev_to_node(dev); |
| 5314 | int numa_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5315 | int size; |
| 5316 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5317 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5318 | |
| 5319 | if (tx_ring->q_vector) |
| 5320 | numa_node = tx_ring->q_vector->numa_node; |
| 5321 | |
| 5322 | tx_ring->tx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5323 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5324 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5325 | if (!tx_ring->tx_buffer_info) |
| 5326 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5327 | |
| 5328 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5329 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5330 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5331 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5332 | set_dev_node(dev, numa_node); |
| 5333 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5334 | tx_ring->size, |
| 5335 | &tx_ring->dma, |
| 5336 | GFP_KERNEL); |
| 5337 | set_dev_node(dev, orig_node); |
| 5338 | if (!tx_ring->desc) |
| 5339 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5340 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5341 | if (!tx_ring->desc) |
| 5342 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5343 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5344 | tx_ring->next_to_use = 0; |
| 5345 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5346 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5347 | |
| 5348 | err: |
| 5349 | vfree(tx_ring->tx_buffer_info); |
| 5350 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5351 | 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] | 5352 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5353 | } |
| 5354 | |
| 5355 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5356 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5357 | * @adapter: board private structure |
| 5358 | * |
| 5359 | * If this function returns with an error, then it's possible one or |
| 5360 | * more of the rings is populated (while the rest are not). It is the |
| 5361 | * callers duty to clean those orphaned rings. |
| 5362 | * |
| 5363 | * Return 0 on success, negative on failure |
| 5364 | **/ |
| 5365 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5366 | { |
| 5367 | int i, err = 0; |
| 5368 | |
| 5369 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5370 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5371 | if (!err) |
| 5372 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5373 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5374 | break; |
| 5375 | } |
| 5376 | |
| 5377 | return err; |
| 5378 | } |
| 5379 | |
| 5380 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5381 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5382 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5383 | * |
| 5384 | * Returns 0 on success, negative on failure |
| 5385 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5386 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5387 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5388 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5389 | int orig_node = dev_to_node(dev); |
| 5390 | int numa_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5391 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5392 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5393 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5394 | |
| 5395 | if (rx_ring->q_vector) |
| 5396 | numa_node = rx_ring->q_vector->numa_node; |
| 5397 | |
| 5398 | rx_ring->rx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5399 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5400 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5401 | if (!rx_ring->rx_buffer_info) |
| 5402 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5403 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5404 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5405 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5406 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5407 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5408 | set_dev_node(dev, numa_node); |
| 5409 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5410 | rx_ring->size, |
| 5411 | &rx_ring->dma, |
| 5412 | GFP_KERNEL); |
| 5413 | set_dev_node(dev, orig_node); |
| 5414 | if (!rx_ring->desc) |
| 5415 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5416 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5417 | if (!rx_ring->desc) |
| 5418 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5419 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5420 | rx_ring->next_to_clean = 0; |
| 5421 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5422 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 5423 | ixgbe_init_rx_page_offset(rx_ring); |
| 5424 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5425 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5426 | err: |
| 5427 | vfree(rx_ring->rx_buffer_info); |
| 5428 | rx_ring->rx_buffer_info = NULL; |
| 5429 | 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] | 5430 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5434 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5435 | * @adapter: board private structure |
| 5436 | * |
| 5437 | * If this function returns with an error, then it's possible one or |
| 5438 | * more of the rings is populated (while the rest are not). It is the |
| 5439 | * callers duty to clean those orphaned rings. |
| 5440 | * |
| 5441 | * Return 0 on success, negative on failure |
| 5442 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5443 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5444 | { |
| 5445 | int i, err = 0; |
| 5446 | |
| 5447 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5448 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5449 | if (!err) |
| 5450 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5451 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5452 | break; |
| 5453 | } |
| 5454 | |
| 5455 | return err; |
| 5456 | } |
| 5457 | |
| 5458 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5459 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5460 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5461 | * |
| 5462 | * Free all transmit software resources |
| 5463 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5464 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5465 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5466 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5467 | |
| 5468 | vfree(tx_ring->tx_buffer_info); |
| 5469 | tx_ring->tx_buffer_info = NULL; |
| 5470 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5471 | /* if not set, then don't free */ |
| 5472 | if (!tx_ring->desc) |
| 5473 | return; |
| 5474 | |
| 5475 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5476 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5477 | |
| 5478 | tx_ring->desc = NULL; |
| 5479 | } |
| 5480 | |
| 5481 | /** |
| 5482 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5483 | * @adapter: board private structure |
| 5484 | * |
| 5485 | * Free all transmit software resources |
| 5486 | **/ |
| 5487 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5488 | { |
| 5489 | int i; |
| 5490 | |
| 5491 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5492 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5493 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5497 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5498 | * @rx_ring: ring to clean the resources from |
| 5499 | * |
| 5500 | * Free all receive software resources |
| 5501 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5502 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5503 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5504 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5505 | |
| 5506 | vfree(rx_ring->rx_buffer_info); |
| 5507 | rx_ring->rx_buffer_info = NULL; |
| 5508 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5509 | /* if not set, then don't free */ |
| 5510 | if (!rx_ring->desc) |
| 5511 | return; |
| 5512 | |
| 5513 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5514 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5515 | |
| 5516 | rx_ring->desc = NULL; |
| 5517 | } |
| 5518 | |
| 5519 | /** |
| 5520 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5521 | * @adapter: board private structure |
| 5522 | * |
| 5523 | * Free all receive software resources |
| 5524 | **/ |
| 5525 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5526 | { |
| 5527 | int i; |
| 5528 | |
| 5529 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5530 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5531 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5535 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5536 | * @netdev: network interface device structure |
| 5537 | * @new_mtu: new value for maximum frame size |
| 5538 | * |
| 5539 | * Returns 0 on success, negative on failure |
| 5540 | **/ |
| 5541 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5542 | { |
| 5543 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5544 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5545 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5546 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5547 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5548 | return -EINVAL; |
| 5549 | |
| 5550 | /* |
| 5551 | * For 82599EB we cannot allow PF to change MTU greater than 1500 |
| 5552 | * in SR-IOV mode as it may cause buffer overruns in guest VFs that |
| 5553 | * don't allocate and chain buffers correctly. |
| 5554 | */ |
| 5555 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 5556 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
| 5557 | (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 5558 | return -EINVAL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5559 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5560 | 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] | 5561 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5562 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5563 | netdev->mtu = new_mtu; |
| 5564 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5565 | if (netif_running(netdev)) |
| 5566 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5567 | |
| 5568 | return 0; |
| 5569 | } |
| 5570 | |
| 5571 | /** |
| 5572 | * ixgbe_open - Called when a network interface is made active |
| 5573 | * @netdev: network interface device structure |
| 5574 | * |
| 5575 | * Returns 0 on success, negative value on failure |
| 5576 | * |
| 5577 | * The open entry point is called when a network interface is made |
| 5578 | * active by the system (IFF_UP). At this point all resources needed |
| 5579 | * for transmit and receive operations are allocated, the interrupt |
| 5580 | * handler is registered with the OS, the watchdog timer is started, |
| 5581 | * and the stack is notified that the interface is ready. |
| 5582 | **/ |
| 5583 | static int ixgbe_open(struct net_device *netdev) |
| 5584 | { |
| 5585 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5586 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5587 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5588 | /* disallow open during test */ |
| 5589 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5590 | return -EBUSY; |
| 5591 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5592 | netif_carrier_off(netdev); |
| 5593 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5594 | /* allocate transmit descriptors */ |
| 5595 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5596 | if (err) |
| 5597 | goto err_setup_tx; |
| 5598 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5599 | /* allocate receive descriptors */ |
| 5600 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5601 | if (err) |
| 5602 | goto err_setup_rx; |
| 5603 | |
| 5604 | ixgbe_configure(adapter); |
| 5605 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5606 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5607 | if (err) |
| 5608 | goto err_req_irq; |
| 5609 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5610 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5611 | |
| 5612 | return 0; |
| 5613 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5614 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5615 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5616 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5617 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5618 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5619 | ixgbe_reset(adapter); |
| 5620 | |
| 5621 | return err; |
| 5622 | } |
| 5623 | |
| 5624 | /** |
| 5625 | * ixgbe_close - Disables a network interface |
| 5626 | * @netdev: network interface device structure |
| 5627 | * |
| 5628 | * Returns 0, this is not allowed to fail |
| 5629 | * |
| 5630 | * The close entry point is called when an interface is de-activated |
| 5631 | * by the OS. The hardware is still under the drivers control, but |
| 5632 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5633 | * hardware, and all transmit and receive resources are freed. |
| 5634 | **/ |
| 5635 | static int ixgbe_close(struct net_device *netdev) |
| 5636 | { |
| 5637 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5638 | |
| 5639 | ixgbe_down(adapter); |
| 5640 | ixgbe_free_irq(adapter); |
| 5641 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5642 | ixgbe_fdir_filter_exit(adapter); |
| 5643 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5644 | ixgbe_free_all_tx_resources(adapter); |
| 5645 | ixgbe_free_all_rx_resources(adapter); |
| 5646 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5647 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5648 | |
| 5649 | return 0; |
| 5650 | } |
| 5651 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5652 | #ifdef CONFIG_PM |
| 5653 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5654 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5655 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5656 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5657 | u32 err; |
| 5658 | |
| 5659 | pci_set_power_state(pdev, PCI_D0); |
| 5660 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5661 | /* |
| 5662 | * pci_restore_state clears dev->state_saved so call |
| 5663 | * pci_save_state to restore it. |
| 5664 | */ |
| 5665 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5666 | |
| 5667 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5668 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5669 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5670 | return err; |
| 5671 | } |
| 5672 | pci_set_master(pdev); |
| 5673 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5674 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5675 | |
| 5676 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5677 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5678 | e_dev_err("Cannot initialize interrupts for device\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5679 | return err; |
| 5680 | } |
| 5681 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5682 | ixgbe_reset(adapter); |
| 5683 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5684 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5685 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5686 | if (netif_running(netdev)) { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5687 | err = ixgbe_open(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5688 | if (err) |
| 5689 | return err; |
| 5690 | } |
| 5691 | |
| 5692 | netif_device_attach(netdev); |
| 5693 | |
| 5694 | return 0; |
| 5695 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5696 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5697 | |
| 5698 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5699 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5700 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5701 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5702 | struct ixgbe_hw *hw = &adapter->hw; |
| 5703 | u32 ctrl, fctrl; |
| 5704 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5705 | #ifdef CONFIG_PM |
| 5706 | int retval = 0; |
| 5707 | #endif |
| 5708 | |
| 5709 | netif_device_detach(netdev); |
| 5710 | |
| 5711 | if (netif_running(netdev)) { |
| 5712 | ixgbe_down(adapter); |
| 5713 | ixgbe_free_irq(adapter); |
| 5714 | ixgbe_free_all_tx_resources(adapter); |
| 5715 | ixgbe_free_all_rx_resources(adapter); |
| 5716 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5717 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5718 | ixgbe_clear_interrupt_scheme(adapter); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 5719 | #ifdef CONFIG_DCB |
| 5720 | kfree(adapter->ixgbe_ieee_pfc); |
| 5721 | kfree(adapter->ixgbe_ieee_ets); |
| 5722 | #endif |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5723 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5724 | #ifdef CONFIG_PM |
| 5725 | retval = pci_save_state(pdev); |
| 5726 | if (retval) |
| 5727 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5728 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5729 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5730 | if (wufc) { |
| 5731 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5732 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5733 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5734 | if (wufc & IXGBE_WUFC_MC) { |
| 5735 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5736 | fctrl |= IXGBE_FCTRL_MPE; |
| 5737 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5738 | } |
| 5739 | |
| 5740 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5741 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5742 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5743 | |
| 5744 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5745 | } else { |
| 5746 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5747 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5748 | } |
| 5749 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5750 | switch (hw->mac.type) { |
| 5751 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5752 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5753 | break; |
| 5754 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5755 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5756 | pci_wake_from_d3(pdev, !!wufc); |
| 5757 | break; |
| 5758 | default: |
| 5759 | break; |
| 5760 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5761 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5762 | *enable_wake = !!wufc; |
| 5763 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5764 | ixgbe_release_hw_control(adapter); |
| 5765 | |
| 5766 | pci_disable_device(pdev); |
| 5767 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5768 | return 0; |
| 5769 | } |
| 5770 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5771 | #ifdef CONFIG_PM |
| 5772 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5773 | { |
| 5774 | int retval; |
| 5775 | bool wake; |
| 5776 | |
| 5777 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5778 | if (retval) |
| 5779 | return retval; |
| 5780 | |
| 5781 | if (wake) { |
| 5782 | pci_prepare_to_sleep(pdev); |
| 5783 | } else { |
| 5784 | pci_wake_from_d3(pdev, false); |
| 5785 | pci_set_power_state(pdev, PCI_D3hot); |
| 5786 | } |
| 5787 | |
| 5788 | return 0; |
| 5789 | } |
| 5790 | #endif /* CONFIG_PM */ |
| 5791 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5792 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5793 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5794 | bool wake; |
| 5795 | |
| 5796 | __ixgbe_shutdown(pdev, &wake); |
| 5797 | |
| 5798 | if (system_state == SYSTEM_POWER_OFF) { |
| 5799 | pci_wake_from_d3(pdev, wake); |
| 5800 | pci_set_power_state(pdev, PCI_D3hot); |
| 5801 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5805 | * ixgbe_update_stats - Update the board statistics counters. |
| 5806 | * @adapter: board private structure |
| 5807 | **/ |
| 5808 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5809 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5810 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5811 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5812 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5813 | u64 total_mpc = 0; |
| 5814 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5815 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5816 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5817 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5818 | #ifdef IXGBE_FCOE |
| 5819 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 5820 | unsigned int cpu; |
| 5821 | u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0; |
| 5822 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5823 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5824 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5825 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5826 | return; |
| 5827 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5828 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5829 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5830 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5831 | for (i = 0; i < 16; i++) |
| 5832 | adapter->hw_rx_no_dma_resources += |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5833 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5834 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5835 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5836 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5837 | } |
| 5838 | adapter->rsc_total_count = rsc_count; |
| 5839 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5842 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5843 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5844 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5845 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5846 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5847 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5848 | bytes += rx_ring->stats.bytes; |
| 5849 | packets += rx_ring->stats.packets; |
| 5850 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5851 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5852 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5853 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5854 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5855 | netdev->stats.rx_bytes = bytes; |
| 5856 | netdev->stats.rx_packets = packets; |
| 5857 | |
| 5858 | bytes = 0; |
| 5859 | packets = 0; |
| 5860 | /* gather some stats to the adapter struct that are per queue */ |
| 5861 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5862 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5863 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5864 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5865 | bytes += tx_ring->stats.bytes; |
| 5866 | packets += tx_ring->stats.packets; |
| 5867 | } |
| 5868 | adapter->restart_queue = restart_queue; |
| 5869 | adapter->tx_busy = tx_busy; |
| 5870 | netdev->stats.tx_bytes = bytes; |
| 5871 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5872 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5873 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5874 | |
| 5875 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5876 | for (i = 0; i < 8; i++) { |
| 5877 | /* for packet buffers not used, the register should read 0 */ |
| 5878 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5879 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5880 | hwstats->mpc[i] += mpc; |
| 5881 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5882 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5883 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5884 | switch (hw->mac.type) { |
| 5885 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5886 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5887 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5888 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5889 | hwstats->pxonrxc[i] += |
| 5890 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5891 | break; |
| 5892 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5893 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5894 | hwstats->pxonrxc[i] += |
| 5895 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5896 | break; |
| 5897 | default: |
| 5898 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5899 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5900 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5901 | |
| 5902 | /*16 register reads */ |
| 5903 | for (i = 0; i < 16; i++) { |
| 5904 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5905 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5906 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
| 5907 | (hw->mac.type == ixgbe_mac_X540)) { |
| 5908 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 5909 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 5910 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 5911 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 5912 | } |
| 5913 | } |
| 5914 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5915 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5916 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5917 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5918 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5919 | ixgbe_update_xoff_received(adapter); |
| 5920 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5921 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5922 | switch (hw->mac.type) { |
| 5923 | case ixgbe_mac_82598EB: |
| 5924 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5925 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5926 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5927 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5928 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5929 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5930 | /* OS2BMC stats are X540 only*/ |
| 5931 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5932 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5933 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5934 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5935 | case ixgbe_mac_82599EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5936 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5937 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5938 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5939 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5940 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5941 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5942 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5943 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5944 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5945 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5946 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5947 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5948 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5949 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5950 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5951 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5952 | /* Add up per cpu counters for total ddp aloc fail */ |
| 5953 | if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) { |
| 5954 | for_each_possible_cpu(cpu) { |
| 5955 | fcoe_noddp_counts_sum += |
| 5956 | *per_cpu_ptr(fcoe->pcpu_noddp, cpu); |
| 5957 | fcoe_noddp_ext_buff_counts_sum += |
| 5958 | *per_cpu_ptr(fcoe-> |
| 5959 | pcpu_noddp_ext_buff, cpu); |
| 5960 | } |
| 5961 | } |
| 5962 | hwstats->fcoe_noddp = fcoe_noddp_counts_sum; |
| 5963 | hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum; |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5964 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5965 | break; |
| 5966 | default: |
| 5967 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5968 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5969 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5970 | hwstats->bprc += bprc; |
| 5971 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5972 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5973 | hwstats->mprc -= bprc; |
| 5974 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5975 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5976 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5977 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5978 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5979 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5980 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5981 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5982 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5983 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5984 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5985 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5986 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5987 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5988 | /* |
| 5989 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5990 | */ |
| 5991 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5992 | hwstats->gptc -= xon_off_tot; |
| 5993 | hwstats->mptc -= xon_off_tot; |
| 5994 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5995 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5996 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 5997 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 5998 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 5999 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6000 | hwstats->ptc64 -= xon_off_tot; |
| 6001 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6002 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6003 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6004 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6005 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6006 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6007 | |
| 6008 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6009 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6010 | |
| 6011 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6012 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6013 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6014 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6015 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6016 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6020 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
| 6021 | * @adapter - pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6022 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6023 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6024 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6025 | struct ixgbe_hw *hw = &adapter->hw; |
| 6026 | int i; |
| 6027 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6028 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6029 | return; |
| 6030 | |
| 6031 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6032 | |
| 6033 | /* if interface is down do nothing */ |
| 6034 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6035 | return; |
| 6036 | |
| 6037 | /* do nothing if we are not using signature filters */ |
| 6038 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6039 | return; |
| 6040 | |
| 6041 | adapter->fdir_overflow++; |
| 6042 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6043 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6044 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6045 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6046 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6047 | /* re-enable flow director interrupts */ |
| 6048 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6049 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6050 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6051 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6052 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6053 | } |
| 6054 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6055 | /** |
| 6056 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
| 6057 | * @adapter - pointer to the device adapter structure |
| 6058 | * |
| 6059 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6060 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6061 | * 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] | 6062 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6063 | */ |
| 6064 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6065 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6066 | struct ixgbe_hw *hw = &adapter->hw; |
| 6067 | u64 eics = 0; |
| 6068 | int i; |
| 6069 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6070 | /* If we're down or resetting, just bail */ |
| 6071 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6072 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6073 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6074 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6075 | /* Force detection of hung controller */ |
| 6076 | if (netif_carrier_ok(adapter->netdev)) { |
| 6077 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6078 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6079 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6080 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6081 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6082 | /* |
| 6083 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6084 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6085 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6086 | */ |
| 6087 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6088 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6089 | } else { |
| 6090 | /* get one bit for every active tx/rx interrupt vector */ |
| 6091 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 6092 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6093 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6094 | eics |= ((u64)1 << i); |
| 6095 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6096 | } |
| 6097 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6098 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6099 | ixgbe_irq_rearm_queues(adapter, eics); |
| 6100 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6104 | * ixgbe_watchdog_update_link - update the link status |
| 6105 | * @adapter - pointer to the device adapter structure |
| 6106 | * @link_speed - pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6107 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6108 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6109 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6110 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6111 | u32 link_speed = adapter->link_speed; |
| 6112 | bool link_up = adapter->link_up; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6113 | int i; |
| 6114 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6115 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6116 | return; |
| 6117 | |
| 6118 | if (hw->mac.ops.check_link) { |
| 6119 | 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] | 6120 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6121 | /* always assume link is up, if no check link function */ |
| 6122 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6123 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6124 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6125 | if (link_up) { |
| 6126 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 6127 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 6128 | hw->mac.ops.fc_enable(hw, i); |
| 6129 | } else { |
| 6130 | hw->mac.ops.fc_enable(hw, 0); |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | if (link_up || |
| 6135 | time_after(jiffies, (adapter->link_check_timeout + |
| 6136 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6137 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6138 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6139 | IXGBE_WRITE_FLUSH(hw); |
| 6140 | } |
| 6141 | |
| 6142 | adapter->link_up = link_up; |
| 6143 | adapter->link_speed = link_speed; |
| 6144 | } |
| 6145 | |
| 6146 | /** |
| 6147 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6148 | * print link up message |
| 6149 | * @adapter - pointer to the device adapter structure |
| 6150 | **/ |
| 6151 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6152 | { |
| 6153 | struct net_device *netdev = adapter->netdev; |
| 6154 | struct ixgbe_hw *hw = &adapter->hw; |
| 6155 | u32 link_speed = adapter->link_speed; |
| 6156 | bool flow_rx, flow_tx; |
| 6157 | |
| 6158 | /* only continue if link was previously down */ |
| 6159 | if (netif_carrier_ok(netdev)) |
| 6160 | return; |
| 6161 | |
| 6162 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6163 | |
| 6164 | switch (hw->mac.type) { |
| 6165 | case ixgbe_mac_82598EB: { |
| 6166 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6167 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6168 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6169 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6170 | } |
| 6171 | break; |
| 6172 | case ixgbe_mac_X540: |
| 6173 | case ixgbe_mac_82599EB: { |
| 6174 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6175 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6176 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6177 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6178 | } |
| 6179 | break; |
| 6180 | default: |
| 6181 | flow_tx = false; |
| 6182 | flow_rx = false; |
| 6183 | break; |
| 6184 | } |
| 6185 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 6186 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 6187 | "10 Gbps" : |
| 6188 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 6189 | "1 Gbps" : |
| 6190 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6191 | "100 Mbps" : |
| 6192 | "unknown speed"))), |
| 6193 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6194 | (flow_rx ? "RX" : |
| 6195 | (flow_tx ? "TX" : "None")))); |
| 6196 | |
| 6197 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6198 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | /** |
| 6202 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6203 | * print link down message |
| 6204 | * @adapter - pointer to the adapter structure |
| 6205 | **/ |
| 6206 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) |
| 6207 | { |
| 6208 | struct net_device *netdev = adapter->netdev; |
| 6209 | struct ixgbe_hw *hw = &adapter->hw; |
| 6210 | |
| 6211 | adapter->link_up = false; |
| 6212 | adapter->link_speed = 0; |
| 6213 | |
| 6214 | /* only continue if link was up previously */ |
| 6215 | if (!netif_carrier_ok(netdev)) |
| 6216 | return; |
| 6217 | |
| 6218 | /* poll for SFP+ cable when link is down */ |
| 6219 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6220 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6221 | |
| 6222 | e_info(drv, "NIC Link is Down\n"); |
| 6223 | netif_carrier_off(netdev); |
| 6224 | } |
| 6225 | |
| 6226 | /** |
| 6227 | * ixgbe_watchdog_flush_tx - flush queues on link down |
| 6228 | * @adapter - pointer to the device adapter structure |
| 6229 | **/ |
| 6230 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6231 | { |
| 6232 | int i; |
| 6233 | int some_tx_pending = 0; |
| 6234 | |
| 6235 | if (!netif_carrier_ok(adapter->netdev)) { |
| 6236 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6237 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6238 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 6239 | some_tx_pending = 1; |
| 6240 | break; |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | if (some_tx_pending) { |
| 6245 | /* We've lost link, so the controller stops DMA, |
| 6246 | * but we've got queued Tx work that's never going |
| 6247 | * to get done, so reset controller to flush Tx. |
| 6248 | * (Do the reset outside of interrupt context). |
| 6249 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6250 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6251 | } |
| 6252 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6253 | } |
| 6254 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6255 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6256 | { |
| 6257 | u32 ssvpc; |
| 6258 | |
| 6259 | /* Do not perform spoof check for 82598 */ |
| 6260 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6261 | return; |
| 6262 | |
| 6263 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6264 | |
| 6265 | /* |
| 6266 | * ssvpc register is cleared on read, if zero then no |
| 6267 | * spoofed packets in the last interval. |
| 6268 | */ |
| 6269 | if (!ssvpc) |
| 6270 | return; |
| 6271 | |
| 6272 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); |
| 6273 | } |
| 6274 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6275 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6276 | * ixgbe_watchdog_subtask - check and bring link up |
| 6277 | * @adapter - pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6278 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6279 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6280 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6281 | /* if interface is down do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6282 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6283 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6284 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6285 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6286 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6287 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6288 | if (adapter->link_up) |
| 6289 | ixgbe_watchdog_link_is_up(adapter); |
| 6290 | else |
| 6291 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6292 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6293 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6294 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6295 | |
| 6296 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6297 | } |
| 6298 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6299 | /** |
| 6300 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
| 6301 | * @adapter - the ixgbe adapter structure |
| 6302 | **/ |
| 6303 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6304 | { |
| 6305 | struct ixgbe_hw *hw = &adapter->hw; |
| 6306 | s32 err; |
| 6307 | |
| 6308 | /* not searching for SFP so there is nothing to do here */ |
| 6309 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6310 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6311 | return; |
| 6312 | |
| 6313 | /* someone else is in init, wait until next service event */ |
| 6314 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6315 | return; |
| 6316 | |
| 6317 | err = hw->phy.ops.identify_sfp(hw); |
| 6318 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6319 | goto sfp_out; |
| 6320 | |
| 6321 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6322 | /* If no cable is present, then we need to reset |
| 6323 | * the next time we find a good cable. */ |
| 6324 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6325 | } |
| 6326 | |
| 6327 | /* exit on error */ |
| 6328 | if (err) |
| 6329 | goto sfp_out; |
| 6330 | |
| 6331 | /* exit if reset not needed */ |
| 6332 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6333 | goto sfp_out; |
| 6334 | |
| 6335 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6336 | |
| 6337 | /* |
| 6338 | * A module may be identified correctly, but the EEPROM may not have |
| 6339 | * support for that module. setup_sfp() will fail in that case, so |
| 6340 | * we should not allow that module to load. |
| 6341 | */ |
| 6342 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6343 | err = hw->phy.ops.reset(hw); |
| 6344 | else |
| 6345 | err = hw->mac.ops.setup_sfp(hw); |
| 6346 | |
| 6347 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6348 | goto sfp_out; |
| 6349 | |
| 6350 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6351 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6352 | |
| 6353 | sfp_out: |
| 6354 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6355 | |
| 6356 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6357 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6358 | e_dev_err("failed to initialize because an unsupported " |
| 6359 | "SFP+ module type was detected.\n"); |
| 6360 | e_dev_err("Reload the driver after installing a " |
| 6361 | "supported module.\n"); |
| 6362 | unregister_netdev(adapter->netdev); |
| 6363 | } |
| 6364 | } |
| 6365 | |
| 6366 | /** |
| 6367 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
| 6368 | * @adapter - the ixgbe adapter structure |
| 6369 | **/ |
| 6370 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6371 | { |
| 6372 | struct ixgbe_hw *hw = &adapter->hw; |
| 6373 | u32 autoneg; |
| 6374 | bool negotiation; |
| 6375 | |
| 6376 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6377 | return; |
| 6378 | |
| 6379 | /* someone else is in init, wait until next service event */ |
| 6380 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6381 | return; |
| 6382 | |
| 6383 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6384 | |
| 6385 | autoneg = hw->phy.autoneg_advertised; |
| 6386 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 6387 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6388 | if (hw->mac.ops.setup_link) |
| 6389 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 6390 | |
| 6391 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6392 | adapter->link_check_timeout = jiffies; |
| 6393 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6394 | } |
| 6395 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6396 | #ifdef CONFIG_PCI_IOV |
| 6397 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6398 | { |
| 6399 | int vf; |
| 6400 | struct ixgbe_hw *hw = &adapter->hw; |
| 6401 | struct net_device *netdev = adapter->netdev; |
| 6402 | u32 gpc; |
| 6403 | u32 ciaa, ciad; |
| 6404 | |
| 6405 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6406 | if (gpc) /* If incrementing then no need for the check below */ |
| 6407 | return; |
| 6408 | /* |
| 6409 | * Check to see if a bad DMA write target from an errant or |
| 6410 | * malicious VF has caused a PCIe error. If so then we can |
| 6411 | * issue a VFLR to the offending VF(s) and then resume without |
| 6412 | * requesting a full slot reset. |
| 6413 | */ |
| 6414 | |
| 6415 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 6416 | ciaa = (vf << 16) | 0x80000000; |
| 6417 | /* 32 bit read so align, we really want status at offset 6 */ |
| 6418 | ciaa |= PCI_COMMAND; |
| 6419 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6420 | ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599); |
| 6421 | ciaa &= 0x7FFFFFFF; |
| 6422 | /* disable debug mode asap after reading data */ |
| 6423 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6424 | /* Get the upper 16 bits which will be the PCI status reg */ |
| 6425 | ciad >>= 16; |
| 6426 | if (ciad & PCI_STATUS_REC_MASTER_ABORT) { |
| 6427 | netdev_err(netdev, "VF %d Hung DMA\n", vf); |
| 6428 | /* Issue VFLR */ |
| 6429 | ciaa = (vf << 16) | 0x80000000; |
| 6430 | ciaa |= 0xA8; |
| 6431 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6432 | ciad = 0x00008000; /* VFLR */ |
| 6433 | IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad); |
| 6434 | ciaa &= 0x7FFFFFFF; |
| 6435 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6436 | } |
| 6437 | } |
| 6438 | } |
| 6439 | |
| 6440 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6441 | /** |
| 6442 | * ixgbe_service_timer - Timer Call-back |
| 6443 | * @data: pointer to adapter cast into an unsigned long |
| 6444 | **/ |
| 6445 | static void ixgbe_service_timer(unsigned long data) |
| 6446 | { |
| 6447 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6448 | unsigned long next_event_offset; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6449 | bool ready = true; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6450 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6451 | #ifdef CONFIG_PCI_IOV |
| 6452 | ready = false; |
| 6453 | |
| 6454 | /* |
| 6455 | * don't bother with SR-IOV VF DMA hang check if there are |
| 6456 | * no VFs or the link is down |
| 6457 | */ |
| 6458 | if (!adapter->num_vfs || |
| 6459 | (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) { |
| 6460 | ready = true; |
| 6461 | goto normal_timer_service; |
| 6462 | } |
| 6463 | |
| 6464 | /* If we have VFs allocated then we must check for DMA hangs */ |
| 6465 | ixgbe_check_for_bad_vf(adapter); |
| 6466 | next_event_offset = HZ / 50; |
| 6467 | adapter->timer_event_accumulator++; |
| 6468 | |
| 6469 | if (adapter->timer_event_accumulator >= 100) { |
| 6470 | ready = true; |
| 6471 | adapter->timer_event_accumulator = 0; |
| 6472 | } |
| 6473 | |
| 6474 | goto schedule_event; |
| 6475 | |
| 6476 | normal_timer_service: |
| 6477 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6478 | /* poll faster when waiting for link */ |
| 6479 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6480 | next_event_offset = HZ / 10; |
| 6481 | else |
| 6482 | next_event_offset = HZ * 2; |
| 6483 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6484 | #ifdef CONFIG_PCI_IOV |
| 6485 | schedule_event: |
| 6486 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6487 | /* Reset the timer */ |
| 6488 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6489 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6490 | if (ready) |
| 6491 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6492 | } |
| 6493 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6494 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6495 | { |
| 6496 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6497 | return; |
| 6498 | |
| 6499 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6500 | |
| 6501 | /* If we're already down or resetting, just bail */ |
| 6502 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6503 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6504 | return; |
| 6505 | |
| 6506 | ixgbe_dump(adapter); |
| 6507 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6508 | adapter->tx_timeout_count++; |
| 6509 | |
| 6510 | ixgbe_reinit_locked(adapter); |
| 6511 | } |
| 6512 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6513 | /** |
| 6514 | * ixgbe_service_task - manages and runs subtasks |
| 6515 | * @work: pointer to work_struct containing our data |
| 6516 | **/ |
| 6517 | static void ixgbe_service_task(struct work_struct *work) |
| 6518 | { |
| 6519 | struct ixgbe_adapter *adapter = container_of(work, |
| 6520 | struct ixgbe_adapter, |
| 6521 | service_task); |
| 6522 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6523 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6524 | ixgbe_sfp_detection_subtask(adapter); |
| 6525 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6526 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6527 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6528 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6529 | ixgbe_check_hang_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6530 | |
| 6531 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6532 | } |
| 6533 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6534 | void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens, |
| 6535 | u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6536 | { |
| 6537 | struct ixgbe_adv_tx_context_desc *context_desc; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6538 | u16 i = tx_ring->next_to_use; |
| 6539 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6540 | context_desc = IXGBE_TX_CTXTDESC(tx_ring, i); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6541 | |
| 6542 | i++; |
| 6543 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 6544 | |
| 6545 | /* set bits to identify this as an advanced context descriptor */ |
| 6546 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 6547 | |
| 6548 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6549 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); |
| 6550 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 6551 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 6552 | } |
| 6553 | |
| 6554 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 6555 | u32 tx_flags, __be16 protocol, u8 *hdr_len) |
| 6556 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6557 | int err; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6558 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6559 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6560 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6561 | if (!skb_is_gso(skb)) |
| 6562 | return 0; |
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_header_cloned(skb)) { |
| 6565 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 6566 | if (err) |
| 6567 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6568 | } |
| 6569 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6570 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6571 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6572 | |
| 6573 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6574 | struct iphdr *iph = ip_hdr(skb); |
| 6575 | iph->tot_len = 0; |
| 6576 | iph->check = 0; |
| 6577 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6578 | iph->daddr, 0, |
| 6579 | IPPROTO_TCP, |
| 6580 | 0); |
| 6581 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6582 | } else if (skb_is_gso_v6(skb)) { |
| 6583 | ipv6_hdr(skb)->payload_len = 0; |
| 6584 | tcp_hdr(skb)->check = |
| 6585 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6586 | &ipv6_hdr(skb)->daddr, |
| 6587 | 0, IPPROTO_TCP, 0); |
| 6588 | } |
| 6589 | |
| 6590 | l4len = tcp_hdrlen(skb); |
| 6591 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6592 | |
| 6593 | /* mss_l4len_id: use 1 as index for TSO */ |
| 6594 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6595 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 6596 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 6597 | |
| 6598 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6599 | vlan_macip_lens = skb_network_header_len(skb); |
| 6600 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6601 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6602 | |
| 6603 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
| 6604 | mss_l4len_idx); |
| 6605 | |
| 6606 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6607 | } |
| 6608 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6609 | static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6610 | struct sk_buff *skb, u32 tx_flags, |
| 6611 | __be16 protocol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6612 | { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6613 | u32 vlan_macip_lens = 0; |
| 6614 | u32 mss_l4len_idx = 0; |
| 6615 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6616 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6617 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6618 | if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) && |
| 6619 | !(tx_flags & IXGBE_TX_FLAGS_TXSW)) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6620 | return false; |
| 6621 | } else { |
| 6622 | u8 l4_hdr = 0; |
| 6623 | switch (protocol) { |
| 6624 | case __constant_htons(ETH_P_IP): |
| 6625 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6626 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6627 | l4_hdr = ip_hdr(skb)->protocol; |
| 6628 | break; |
| 6629 | case __constant_htons(ETH_P_IPV6): |
| 6630 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6631 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6632 | break; |
| 6633 | default: |
| 6634 | if (unlikely(net_ratelimit())) { |
| 6635 | dev_warn(tx_ring->dev, |
| 6636 | "partial checksum but proto=%x!\n", |
| 6637 | skb->protocol); |
| 6638 | } |
| 6639 | break; |
| 6640 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6641 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6642 | switch (l4_hdr) { |
| 6643 | case IPPROTO_TCP: |
| 6644 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6645 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6646 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6647 | break; |
| 6648 | case IPPROTO_SCTP: |
| 6649 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6650 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6651 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6652 | break; |
| 6653 | case IPPROTO_UDP: |
| 6654 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6655 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6656 | break; |
| 6657 | default: |
| 6658 | if (unlikely(net_ratelimit())) { |
| 6659 | dev_warn(tx_ring->dev, |
| 6660 | "partial checksum but l4 proto=%x!\n", |
| 6661 | skb->protocol); |
| 6662 | } |
| 6663 | break; |
| 6664 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6665 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6666 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6667 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6668 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6669 | |
| 6670 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6671 | type_tucmd, mss_l4len_idx); |
| 6672 | |
| 6673 | return (skb->ip_summed == CHECKSUM_PARTIAL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6674 | } |
| 6675 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6676 | static __le32 ixgbe_tx_cmd_type(u32 tx_flags) |
| 6677 | { |
| 6678 | /* set type for advanced descriptor with frame checksum insertion */ |
| 6679 | __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA | |
| 6680 | IXGBE_ADVTXD_DCMD_IFCS | |
| 6681 | IXGBE_ADVTXD_DCMD_DEXT); |
| 6682 | |
| 6683 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6684 | if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6685 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE); |
| 6686 | |
| 6687 | /* set segmentation enable bits for TSO/FSO */ |
| 6688 | #ifdef IXGBE_FCOE |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6689 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6690 | #else |
| 6691 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6692 | #endif |
| 6693 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE); |
| 6694 | |
| 6695 | return cmd_type; |
| 6696 | } |
| 6697 | |
| 6698 | static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen) |
| 6699 | { |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6700 | __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6701 | |
| 6702 | /* enable L4 checksum for TSO and TX checksum offload */ |
| 6703 | if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6704 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM); |
| 6705 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6706 | /* enble IPv4 checksum for TSO */ |
| 6707 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6708 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6709 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6710 | /* use index 1 context for TSO/FSO/FCOE */ |
| 6711 | #ifdef IXGBE_FCOE |
| 6712 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE)) |
| 6713 | #else |
| 6714 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6715 | #endif |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6716 | olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 6717 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6718 | /* |
| 6719 | * Check Context must be set if Tx switch is enabled, which it |
| 6720 | * always is for case where virtual functions are running |
| 6721 | */ |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6722 | #ifdef IXGBE_FCOE |
| 6723 | if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE)) |
| 6724 | #else |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6725 | if (tx_flags & IXGBE_TX_FLAGS_TXSW) |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6726 | #endif |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6727 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC); |
| 6728 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6729 | return olinfo_status; |
| 6730 | } |
| 6731 | |
| 6732 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 6733 | IXGBE_TXD_CMD_RS) |
| 6734 | |
| 6735 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
| 6736 | struct sk_buff *skb, |
| 6737 | struct ixgbe_tx_buffer *first, |
| 6738 | u32 tx_flags, |
| 6739 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6740 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6741 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6742 | struct ixgbe_tx_buffer *tx_buffer_info; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6743 | union ixgbe_adv_tx_desc *tx_desc; |
| 6744 | dma_addr_t dma; |
| 6745 | __le32 cmd_type, olinfo_status; |
| 6746 | struct skb_frag_struct *frag; |
| 6747 | unsigned int f = 0; |
| 6748 | unsigned int data_len = skb->data_len; |
| 6749 | unsigned int size = skb_headlen(skb); |
| 6750 | u32 offset = 0; |
| 6751 | u32 paylen = skb->len - hdr_len; |
| 6752 | u16 i = tx_ring->next_to_use; |
| 6753 | u16 gso_segs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6754 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6755 | #ifdef IXGBE_FCOE |
| 6756 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6757 | if (data_len >= sizeof(struct fcoe_crc_eof)) { |
| 6758 | data_len -= sizeof(struct fcoe_crc_eof); |
| 6759 | } else { |
| 6760 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 6761 | data_len = 0; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6762 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6763 | } |
| 6764 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6765 | #endif |
| 6766 | dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE); |
| 6767 | if (dma_mapping_error(dev, dma)) |
| 6768 | goto dma_error; |
| 6769 | |
| 6770 | cmd_type = ixgbe_tx_cmd_type(tx_flags); |
| 6771 | olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen); |
| 6772 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6773 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6774 | |
| 6775 | for (;;) { |
| 6776 | while (size > IXGBE_MAX_DATA_PER_TXD) { |
| 6777 | tx_desc->read.buffer_addr = cpu_to_le64(dma + offset); |
| 6778 | tx_desc->read.cmd_type_len = |
| 6779 | cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD); |
| 6780 | tx_desc->read.olinfo_status = olinfo_status; |
| 6781 | |
| 6782 | offset += IXGBE_MAX_DATA_PER_TXD; |
| 6783 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 6784 | |
| 6785 | tx_desc++; |
| 6786 | i++; |
| 6787 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6788 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6789 | i = 0; |
| 6790 | } |
| 6791 | } |
| 6792 | |
| 6793 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6794 | tx_buffer_info->length = offset + size; |
| 6795 | tx_buffer_info->tx_flags = tx_flags; |
| 6796 | tx_buffer_info->dma = dma; |
| 6797 | |
| 6798 | tx_desc->read.buffer_addr = cpu_to_le64(dma + offset); |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 6799 | if (unlikely(skb->no_fcs)) |
| 6800 | cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6801 | tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size); |
| 6802 | tx_desc->read.olinfo_status = olinfo_status; |
| 6803 | |
| 6804 | if (!data_len) |
| 6805 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6806 | |
| 6807 | frag = &skb_shinfo(skb)->frags[f]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6808 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6809 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6810 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6811 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6812 | #endif |
| 6813 | data_len -= size; |
| 6814 | f++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6815 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6816 | offset = 0; |
| 6817 | tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6818 | |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 6819 | dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6820 | if (dma_mapping_error(dev, dma)) |
| 6821 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6822 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6823 | tx_desc++; |
| 6824 | i++; |
| 6825 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6826 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6827 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6828 | } |
| 6829 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6830 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6831 | tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD); |
| 6832 | |
| 6833 | i++; |
| 6834 | if (i == tx_ring->count) |
| 6835 | i = 0; |
| 6836 | |
| 6837 | tx_ring->next_to_use = i; |
| 6838 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6839 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6840 | gso_segs = skb_shinfo(skb)->gso_segs; |
| 6841 | #ifdef IXGBE_FCOE |
| 6842 | /* adjust for FCoE Sequence Offload */ |
| 6843 | else if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6844 | gso_segs = DIV_ROUND_UP(skb->len - hdr_len, |
| 6845 | skb_shinfo(skb)->gso_size); |
| 6846 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6847 | else |
| 6848 | gso_segs = 1; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6849 | |
| 6850 | /* multiply data chunks by size of headers */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6851 | tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len); |
| 6852 | tx_buffer_info->gso_segs = gso_segs; |
| 6853 | tx_buffer_info->skb = skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6854 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 6855 | netdev_tx_sent_queue(txring_txq(tx_ring), tx_buffer_info->bytecount); |
| 6856 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6857 | /* set the timestamp */ |
| 6858 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6859 | |
| 6860 | /* |
| 6861 | * Force memory writes to complete before letting h/w |
| 6862 | * know there are new descriptors to fetch. (Only |
| 6863 | * applicable for weak-ordered memory model archs, |
| 6864 | * such as IA-64). |
| 6865 | */ |
| 6866 | wmb(); |
| 6867 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6868 | /* set next_to_watch value indicating a packet is present */ |
| 6869 | first->next_to_watch = tx_desc; |
| 6870 | |
| 6871 | /* notify HW of packet */ |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6872 | writel(i, tx_ring->tail); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6873 | |
| 6874 | return; |
| 6875 | dma_error: |
| 6876 | dev_err(dev, "TX DMA map failed\n"); |
| 6877 | |
| 6878 | /* clear dma mappings for failed tx_buffer_info map */ |
| 6879 | for (;;) { |
| 6880 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6881 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info); |
| 6882 | if (tx_buffer_info == first) |
| 6883 | break; |
| 6884 | if (i == 0) |
| 6885 | i = tx_ring->count; |
| 6886 | i--; |
| 6887 | } |
| 6888 | |
| 6889 | dev_kfree_skb_any(skb); |
| 6890 | |
| 6891 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6892 | } |
| 6893 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6894 | static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb, |
| 6895 | u32 tx_flags, __be16 protocol) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6896 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6897 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6898 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6899 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6900 | union { |
| 6901 | unsigned char *network; |
| 6902 | struct iphdr *ipv4; |
| 6903 | struct ipv6hdr *ipv6; |
| 6904 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6905 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6906 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6907 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6908 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6909 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6910 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6911 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6912 | /* do nothing if sampling is disabled */ |
| 6913 | if (!ring->atr_sample_rate) |
| 6914 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6915 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6916 | ring->atr_count++; |
| 6917 | |
| 6918 | /* snag network header to get L4 type and address */ |
| 6919 | hdr.network = skb_network_header(skb); |
| 6920 | |
| 6921 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 6922 | if ((protocol != __constant_htons(ETH_P_IPV6) || |
| 6923 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
| 6924 | (protocol != __constant_htons(ETH_P_IP) || |
| 6925 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6926 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6927 | |
| 6928 | th = tcp_hdr(skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6929 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6930 | /* skip this packet since it is invalid or the socket is closing */ |
| 6931 | if (!th || th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6932 | return; |
| 6933 | |
| 6934 | /* sample on all syn packets or once every atr sample count */ |
| 6935 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6936 | return; |
| 6937 | |
| 6938 | /* reset sample count */ |
| 6939 | ring->atr_count = 0; |
| 6940 | |
| 6941 | vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6942 | |
| 6943 | /* |
| 6944 | * src and dst are inverted, think how the receiver sees them |
| 6945 | * |
| 6946 | * The input is broken into two sections, a non-compressed section |
| 6947 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6948 | * is XORed together and stored in the compressed dword. |
| 6949 | */ |
| 6950 | input.formatted.vlan_id = vlan_id; |
| 6951 | |
| 6952 | /* |
| 6953 | * since src port and flex bytes occupy the same word XOR them together |
| 6954 | * and write the value to source port portion of compressed dword |
| 6955 | */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6956 | 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] | 6957 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6958 | else |
| 6959 | common.port.src ^= th->dest ^ protocol; |
| 6960 | common.port.dst ^= th->source; |
| 6961 | |
| 6962 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6963 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6964 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6965 | } else { |
| 6966 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6967 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6968 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6969 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6970 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6971 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6972 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6973 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6974 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6975 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6976 | |
| 6977 | /* 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] | 6978 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6979 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6980 | } |
| 6981 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6982 | 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] | 6983 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6984 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6985 | /* Herbert's original patch had: |
| 6986 | * smp_mb__after_netif_stop_queue(); |
| 6987 | * but since that doesn't exist yet, just open code it. */ |
| 6988 | smp_mb(); |
| 6989 | |
| 6990 | /* We need to check again in a case another CPU has just |
| 6991 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6992 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6993 | return -EBUSY; |
| 6994 | |
| 6995 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6996 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6997 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6998 | return 0; |
| 6999 | } |
| 7000 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 7001 | 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] | 7002 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 7003 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7004 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7005 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7006 | } |
| 7007 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7008 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 7009 | { |
| 7010 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 7011 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 7012 | smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 7013 | #ifdef IXGBE_FCOE |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 7014 | __be16 protocol = vlan_get_protocol(skb); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7015 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 7016 | if (((protocol == htons(ETH_P_FCOE)) || |
| 7017 | (protocol == htons(ETH_P_FIP))) && |
| 7018 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
| 7019 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 7020 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 7021 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 7022 | } |
| 7023 | #endif |
| 7024 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7025 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 7026 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 7027 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7028 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7029 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7030 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7031 | return skb_tx_hash(dev, skb); |
| 7032 | } |
| 7033 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7034 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7035 | struct ixgbe_adapter *adapter, |
| 7036 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7037 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7038 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7039 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7040 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7041 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 7042 | unsigned short f; |
| 7043 | #endif |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7044 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7045 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7046 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7047 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7048 | /* |
| 7049 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 7050 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7051 | * + 2 desc gap to keep tail from touching head, |
| 7052 | * + 1 desc for context descriptor, |
| 7053 | * otherwise try next time |
| 7054 | */ |
| 7055 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 7056 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 7057 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 7058 | #else |
| 7059 | count += skb_shinfo(skb)->nr_frags; |
| 7060 | #endif |
| 7061 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 7062 | tx_ring->tx_stats.tx_busy++; |
| 7063 | return NETDEV_TX_BUSY; |
| 7064 | } |
| 7065 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7066 | /* if we have a HW VLAN tag being added default to the HW one */ |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 7067 | if (vlan_tx_tag_present(skb)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7068 | tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 7069 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7070 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
| 7071 | } else if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 7072 | struct vlan_hdr *vhdr, _vhdr; |
| 7073 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 7074 | if (!vhdr) |
| 7075 | goto out_drop; |
| 7076 | |
| 7077 | protocol = vhdr->h_vlan_encapsulated_proto; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7078 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 7079 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7080 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7081 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7082 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7083 | #ifdef CONFIG_PCI_IOV |
| 7084 | /* |
| 7085 | * Use the l2switch_enable flag - would be false if the DMA |
| 7086 | * Tx switch had been disabled. |
| 7087 | */ |
| 7088 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7089 | tx_flags |= IXGBE_TX_FLAGS_TXSW; |
| 7090 | |
| 7091 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7092 | /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7093 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 7094 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 7095 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7096 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7097 | tx_flags |= (skb->priority & 0x7) << |
| 7098 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7099 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 7100 | struct vlan_ethhdr *vhdr; |
| 7101 | if (skb_header_cloned(skb) && |
| 7102 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 7103 | goto out_drop; |
| 7104 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 7105 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 7106 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 7107 | } else { |
| 7108 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7109 | } |
| 7110 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7111 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7112 | /* record the location of the first descriptor for this packet */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7113 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7114 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7115 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7116 | /* setup tx offload for FCoE */ |
| 7117 | if ((protocol == __constant_htons(ETH_P_FCOE)) && |
| 7118 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7119 | tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len); |
| 7120 | if (tso < 0) |
| 7121 | goto out_drop; |
| 7122 | else if (tso) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7123 | tx_flags |= IXGBE_TX_FLAGS_FSO | |
| 7124 | IXGBE_TX_FLAGS_FCOE; |
| 7125 | else |
| 7126 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7127 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7128 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7129 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7130 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7131 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7132 | /* setup IPv4/IPv6 offloads */ |
| 7133 | if (protocol == __constant_htons(ETH_P_IP)) |
| 7134 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7135 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7136 | tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len); |
| 7137 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7138 | goto out_drop; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7139 | else if (tso) |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 7140 | tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7141 | else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol)) |
| 7142 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7143 | |
| 7144 | /* add the ATR filter if ATR is on */ |
| 7145 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
| 7146 | ixgbe_atr(tx_ring, skb, tx_flags, protocol); |
| 7147 | |
| 7148 | #ifdef IXGBE_FCOE |
| 7149 | xmit_fcoe: |
| 7150 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7151 | ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len); |
| 7152 | |
| 7153 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7154 | |
| 7155 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7156 | |
| 7157 | out_drop: |
| 7158 | dev_kfree_skb_any(skb); |
| 7159 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7160 | } |
| 7161 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7162 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7163 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7164 | { |
| 7165 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7166 | struct ixgbe_ring *tx_ring; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7167 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7168 | if (skb->len <= 0) { |
| 7169 | dev_kfree_skb_any(skb); |
| 7170 | return NETDEV_TX_OK; |
| 7171 | } |
| 7172 | |
| 7173 | /* |
| 7174 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 7175 | * in order to meet this minimum size requirement. |
| 7176 | */ |
| 7177 | if (skb->len < 17) { |
| 7178 | if (skb_padto(skb, 17)) |
| 7179 | return NETDEV_TX_OK; |
| 7180 | skb->len = 17; |
| 7181 | } |
| 7182 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7183 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
| 7184 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7185 | } |
| 7186 | |
| 7187 | /** |
| 7188 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7189 | * @netdev: network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7190 | * @p: pointer to an address structure |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7191 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7192 | * Returns 0 on success, negative on failure |
| 7193 | **/ |
| 7194 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7195 | { |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7196 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7197 | struct ixgbe_hw *hw = &adapter->hw; |
| 7198 | struct sockaddr *addr = p; |
| 7199 | |
| 7200 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7201 | return -EADDRNOTAVAIL; |
| 7202 | |
| 7203 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 7204 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
| 7205 | |
| 7206 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 7207 | IXGBE_RAH_AV); |
| 7208 | |
| 7209 | return 0; |
| 7210 | } |
| 7211 | |
| 7212 | static int |
| 7213 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7214 | { |
| 7215 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7216 | struct ixgbe_hw *hw = &adapter->hw; |
| 7217 | u16 value; |
| 7218 | int rc; |
| 7219 | |
| 7220 | if (prtad != hw->phy.mdio.prtad) |
| 7221 | return -EINVAL; |
| 7222 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7223 | if (!rc) |
| 7224 | rc = value; |
| 7225 | return rc; |
| 7226 | } |
| 7227 | |
| 7228 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7229 | u16 addr, u16 value) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7230 | { |
| 7231 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7232 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7233 | |
| 7234 | if (prtad != hw->phy.mdio.prtad) |
| 7235 | return -EINVAL; |
| 7236 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7237 | } |
| 7238 | |
| 7239 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7240 | { |
| 7241 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7242 | |
| 7243 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 7244 | } |
| 7245 | |
| 7246 | /** |
| 7247 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
| 7248 | * netdev->dev_addrs |
| 7249 | * @netdev: network interface device structure |
| 7250 | * |
| 7251 | * Returns non-zero on failure |
| 7252 | **/ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7253 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7254 | { |
| 7255 | int err = 0; |
| 7256 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7257 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7258 | |
| 7259 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7260 | rtnl_lock(); |
| 7261 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7262 | rtnl_unlock(); |
| 7263 | } |
| 7264 | return err; |
| 7265 | } |
| 7266 | |
| 7267 | /** |
| 7268 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
| 7269 | * netdev->dev_addrs |
| 7270 | * @netdev: network interface device structure |
| 7271 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7272 | * Returns non-zero on failure |
| 7273 | **/ |
| 7274 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 7275 | { |
| 7276 | int err = 0; |
| 7277 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7278 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7279 | |
| 7280 | if (is_valid_ether_addr(mac->san_addr)) { |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7281 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7282 | 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] | 7283 | rtnl_unlock(); |
| 7284 | } |
| 7285 | return err; |
| 7286 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7287 | |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7288 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7289 | /* |
| 7290 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7291 | * without having to re-enable interrupts. It's not called while |
| 7292 | * the interrupt routine is executing. |
| 7293 | */ |
| 7294 | static void ixgbe_netpoll(struct net_device *netdev) |
| 7295 | { |
| 7296 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7297 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7298 | |
| 7299 | /* if interface is down do nothing */ |
| 7300 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7301 | return; |
| 7302 | |
| 7303 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7304 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7305 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 7306 | for (i = 0; i < num_q_vectors; i++) { |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7307 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 7308 | ixgbe_msix_clean_rings(0, q_vector); |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7309 | } |
| 7310 | } else { |
| 7311 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 7312 | } |
| 7313 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
| 7314 | } |
| 7315 | #endif |
| 7316 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7317 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 7318 | struct rtnl_link_stats64 *stats) |
| 7319 | { |
| 7320 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7321 | int i; |
| 7322 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7323 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7324 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7325 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7326 | u64 bytes, packets; |
| 7327 | unsigned int start; |
| 7328 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7329 | if (ring) { |
| 7330 | do { |
| 7331 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7332 | packets = ring->stats.packets; |
| 7333 | bytes = ring->stats.bytes; |
| 7334 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7335 | stats->rx_packets += packets; |
| 7336 | stats->rx_bytes += bytes; |
| 7337 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7338 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7339 | |
| 7340 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7341 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7342 | u64 bytes, packets; |
| 7343 | unsigned int start; |
| 7344 | |
| 7345 | if (ring) { |
| 7346 | do { |
| 7347 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7348 | packets = ring->stats.packets; |
| 7349 | bytes = ring->stats.bytes; |
| 7350 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7351 | stats->tx_packets += packets; |
| 7352 | stats->tx_bytes += bytes; |
| 7353 | } |
| 7354 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7355 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7356 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7357 | stats->multicast = netdev->stats.multicast; |
| 7358 | stats->rx_errors = netdev->stats.rx_errors; |
| 7359 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7360 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7361 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7362 | return stats; |
| 7363 | } |
| 7364 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7365 | /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7366 | * #adapter: pointer to ixgbe_adapter |
| 7367 | * @tc: number of traffic classes currently enabled |
| 7368 | * |
| 7369 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7370 | * 802.1Q priority maps to a packet buffer that exists. |
| 7371 | */ |
| 7372 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7373 | { |
| 7374 | struct ixgbe_hw *hw = &adapter->hw; |
| 7375 | u32 reg, rsave; |
| 7376 | int i; |
| 7377 | |
| 7378 | /* 82598 have a static priority to TC mapping that can not |
| 7379 | * be changed so no validation is needed. |
| 7380 | */ |
| 7381 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7382 | return; |
| 7383 | |
| 7384 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7385 | rsave = reg; |
| 7386 | |
| 7387 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7388 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7389 | |
| 7390 | /* If up2tc is out of bounds default to zero */ |
| 7391 | if (up2tc > tc) |
| 7392 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7393 | } |
| 7394 | |
| 7395 | if (reg != rsave) |
| 7396 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7397 | |
| 7398 | return; |
| 7399 | } |
| 7400 | |
| 7401 | |
| 7402 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic |
| 7403 | * classes. |
| 7404 | * |
| 7405 | * @netdev: net device to configure |
| 7406 | * @tc: number of traffic classes to enable |
| 7407 | */ |
| 7408 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7409 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7410 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7411 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7412 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7413 | /* Multiple traffic classes requires multiple queues */ |
| 7414 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 7415 | e_err(drv, "Enable failed, needs MSI-X\n"); |
| 7416 | return -EINVAL; |
| 7417 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7418 | |
| 7419 | /* Hardware supports up to 8 traffic classes */ |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 7420 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs || |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7421 | (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS)) |
| 7422 | return -EINVAL; |
| 7423 | |
| 7424 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 7425 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7426 | * hardware is not flexible enough to do this dynamically. |
| 7427 | */ |
| 7428 | if (netif_running(dev)) |
| 7429 | ixgbe_close(dev); |
| 7430 | ixgbe_clear_interrupt_scheme(adapter); |
| 7431 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7432 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7433 | netdev_set_num_tc(dev, tc); |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7434 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; |
| 7435 | |
| 7436 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
| 7437 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7438 | |
| 7439 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 7440 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
| 7441 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7442 | netdev_reset_tc(dev); |
| 7443 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7444 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 7445 | |
| 7446 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 7447 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7448 | |
| 7449 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 7450 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 7451 | } |
| 7452 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7453 | ixgbe_init_interrupt_scheme(adapter); |
| 7454 | ixgbe_validate_rtr(adapter, tc); |
| 7455 | if (netif_running(dev)) |
| 7456 | ixgbe_open(dev); |
| 7457 | |
| 7458 | return 0; |
| 7459 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7460 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7461 | void ixgbe_do_reset(struct net_device *netdev) |
| 7462 | { |
| 7463 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7464 | |
| 7465 | if (netif_running(netdev)) |
| 7466 | ixgbe_reinit_locked(adapter); |
| 7467 | else |
| 7468 | ixgbe_reset(adapter); |
| 7469 | } |
| 7470 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7471 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
| 7472 | netdev_features_t data) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7473 | { |
| 7474 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7475 | |
| 7476 | #ifdef CONFIG_DCB |
| 7477 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 7478 | data &= ~NETIF_F_HW_VLAN_RX; |
| 7479 | #endif |
| 7480 | |
| 7481 | /* return error if RXHASH is being enabled when RSS is not supported */ |
| 7482 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 7483 | data &= ~NETIF_F_RXHASH; |
| 7484 | |
| 7485 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
| 7486 | if (!(data & NETIF_F_RXCSUM)) |
| 7487 | data &= ~NETIF_F_LRO; |
| 7488 | |
| 7489 | /* Turn off LRO if not RSC capable or invalid ITR settings */ |
| 7490 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) { |
| 7491 | data &= ~NETIF_F_LRO; |
| 7492 | } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
| 7493 | (adapter->rx_itr_setting != 1 && |
| 7494 | adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) { |
| 7495 | data &= ~NETIF_F_LRO; |
| 7496 | e_info(probe, "rx-usecs set too low, not enabling RSC\n"); |
| 7497 | } |
| 7498 | |
| 7499 | return data; |
| 7500 | } |
| 7501 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7502 | static int ixgbe_set_features(struct net_device *netdev, |
| 7503 | netdev_features_t data) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7504 | { |
| 7505 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7506 | netdev_features_t changed = netdev->features ^ data; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7507 | bool need_reset = false; |
| 7508 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7509 | /* Make sure RSC matches LRO, reset if change */ |
| 7510 | if (!!(data & NETIF_F_LRO) != |
| 7511 | !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 7512 | adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED; |
| 7513 | switch (adapter->hw.mac.type) { |
| 7514 | case ixgbe_mac_X540: |
| 7515 | case ixgbe_mac_82599EB: |
| 7516 | need_reset = true; |
| 7517 | break; |
| 7518 | default: |
| 7519 | break; |
| 7520 | } |
| 7521 | } |
| 7522 | |
| 7523 | /* |
| 7524 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 7525 | * the state changed, we need to reset. |
| 7526 | */ |
| 7527 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { |
| 7528 | /* turn off ATR, enable perfect filters and reset */ |
| 7529 | if (data & NETIF_F_NTUPLE) { |
| 7530 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7531 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7532 | need_reset = true; |
| 7533 | } |
| 7534 | } else if (!(data & NETIF_F_NTUPLE)) { |
| 7535 | /* turn off Flow Director, set ATR and reset */ |
| 7536 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7537 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 7538 | !(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 7539 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7540 | need_reset = true; |
| 7541 | } |
| 7542 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7543 | if (changed & NETIF_F_RXALL) |
| 7544 | need_reset = true; |
| 7545 | |
| 7546 | netdev->features = data; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7547 | if (need_reset) |
| 7548 | ixgbe_do_reset(netdev); |
| 7549 | |
| 7550 | return 0; |
| 7551 | |
| 7552 | } |
| 7553 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7554 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7555 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7556 | .ndo_stop = ixgbe_close, |
| 7557 | .ndo_start_xmit = ixgbe_xmit_frame, |
| 7558 | .ndo_select_queue = ixgbe_select_queue, |
| 7559 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7560 | .ndo_validate_addr = eth_validate_addr, |
| 7561 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7562 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7563 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7564 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7565 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7566 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7567 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7568 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7569 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 7570 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7571 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7572 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7573 | .ndo_setup_tc = ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7574 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7575 | .ndo_poll_controller = ixgbe_netpoll, |
| 7576 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7577 | #ifdef IXGBE_FCOE |
| 7578 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7579 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7580 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7581 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7582 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7583 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 7584 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7585 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7586 | .ndo_set_features = ixgbe_set_features, |
| 7587 | .ndo_fix_features = ixgbe_fix_features, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7588 | }; |
| 7589 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7590 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 7591 | const struct ixgbe_info *ii) |
| 7592 | { |
| 7593 | #ifdef CONFIG_PCI_IOV |
| 7594 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7595 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 7596 | if (hw->mac.type == ixgbe_mac_82598EB) |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7597 | return; |
| 7598 | |
| 7599 | /* The 82599 supports up to 64 VFs per physical function |
| 7600 | * but this implementation limits allocation to 63 so that |
| 7601 | * basic networking resources are still available to the |
| 7602 | * physical function |
| 7603 | */ |
| 7604 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 7605 | ixgbe_enable_sriov(adapter, ii); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7606 | #endif /* CONFIG_PCI_IOV */ |
| 7607 | } |
| 7608 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7609 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7610 | * ixgbe_probe - Device Initialization Routine |
| 7611 | * @pdev: PCI device information struct |
| 7612 | * @ent: entry in ixgbe_pci_tbl |
| 7613 | * |
| 7614 | * Returns 0 on success, negative on failure |
| 7615 | * |
| 7616 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7617 | * The OS initialization, configuring of the adapter private structure, |
| 7618 | * and a hardware reset occur. |
| 7619 | **/ |
| 7620 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7621 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7622 | { |
| 7623 | struct net_device *netdev; |
| 7624 | struct ixgbe_adapter *adapter = NULL; |
| 7625 | struct ixgbe_hw *hw; |
| 7626 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7627 | static int cards_found; |
| 7628 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7629 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7630 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7631 | #ifdef IXGBE_FCOE |
| 7632 | u16 device_caps; |
| 7633 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7634 | u32 eec; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7635 | u16 wol_cap; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7636 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7637 | /* Catch broken hardware that put the wrong VF device ID in |
| 7638 | * the PCIe SR-IOV capability. |
| 7639 | */ |
| 7640 | if (pdev->is_virtfn) { |
| 7641 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7642 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7643 | return -EINVAL; |
| 7644 | } |
| 7645 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7646 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7647 | if (err) |
| 7648 | return err; |
| 7649 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7650 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7651 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7652 | pci_using_dac = 1; |
| 7653 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7654 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7655 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7656 | err = dma_set_coherent_mask(&pdev->dev, |
| 7657 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7658 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7659 | dev_err(&pdev->dev, |
| 7660 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7661 | goto err_dma; |
| 7662 | } |
| 7663 | } |
| 7664 | pci_using_dac = 0; |
| 7665 | } |
| 7666 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7667 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7668 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7669 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7670 | dev_err(&pdev->dev, |
| 7671 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7672 | goto err_pci_reg; |
| 7673 | } |
| 7674 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7675 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7676 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7677 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7678 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7679 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7680 | #ifdef CONFIG_IXGBE_DCB |
| 7681 | indices *= MAX_TRAFFIC_CLASS; |
| 7682 | #endif |
| 7683 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7684 | if (ii->mac == ixgbe_mac_82598EB) |
| 7685 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7686 | else |
| 7687 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7688 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7689 | #ifdef IXGBE_FCOE |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7690 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7691 | IXGBE_MAX_FCOE_INDICES); |
| 7692 | #endif |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7693 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7694 | if (!netdev) { |
| 7695 | err = -ENOMEM; |
| 7696 | goto err_alloc_etherdev; |
| 7697 | } |
| 7698 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7699 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7700 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7701 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7702 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7703 | |
| 7704 | adapter->netdev = netdev; |
| 7705 | adapter->pdev = pdev; |
| 7706 | hw = &adapter->hw; |
| 7707 | hw->back = adapter; |
| 7708 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 7709 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7710 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7711 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7712 | if (!hw->hw_addr) { |
| 7713 | err = -EIO; |
| 7714 | goto err_ioremap; |
| 7715 | } |
| 7716 | |
| 7717 | for (i = 1; i <= 5; i++) { |
| 7718 | if (pci_resource_len(pdev, i) == 0) |
| 7719 | continue; |
| 7720 | } |
| 7721 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7722 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7723 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7724 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7725 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7726 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7727 | adapter->bd_number = cards_found; |
| 7728 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7729 | /* Setup hw api */ |
| 7730 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7731 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7732 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7733 | /* EEPROM */ |
| 7734 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7735 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7736 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7737 | if (!(eec & (1 << 8))) |
| 7738 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7739 | |
| 7740 | /* PHY */ |
| 7741 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7742 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7743 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7744 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7745 | hw->phy.mdio.mmds = 0; |
| 7746 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7747 | hw->phy.mdio.dev = netdev; |
| 7748 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7749 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7750 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7751 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7752 | |
| 7753 | /* setup the private structure */ |
| 7754 | err = ixgbe_sw_init(adapter); |
| 7755 | if (err) |
| 7756 | goto err_sw_init; |
| 7757 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7758 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7759 | switch (adapter->hw.mac.type) { |
| 7760 | case ixgbe_mac_82599EB: |
| 7761 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7762 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7763 | break; |
| 7764 | default: |
| 7765 | break; |
| 7766 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7767 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7768 | /* |
| 7769 | * If there is a fan on this device and it has failed log the |
| 7770 | * failure. |
| 7771 | */ |
| 7772 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7773 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7774 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7775 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7776 | } |
| 7777 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 7778 | if (allow_unsupported_sfp) |
| 7779 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 7780 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7781 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7782 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7783 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7784 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7785 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7786 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7787 | err = 0; |
| 7788 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7789 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7790 | "module type was detected.\n"); |
| 7791 | e_dev_err("Reload the driver after installing a supported " |
| 7792 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7793 | goto err_sw_init; |
| 7794 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7795 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7796 | goto err_sw_init; |
| 7797 | } |
| 7798 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7799 | ixgbe_probe_vf(adapter, ii); |
| 7800 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7801 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7802 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7803 | NETIF_F_IPV6_CSUM | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7804 | NETIF_F_HW_VLAN_TX | |
| 7805 | NETIF_F_HW_VLAN_RX | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7806 | NETIF_F_HW_VLAN_FILTER | |
| 7807 | NETIF_F_TSO | |
| 7808 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7809 | NETIF_F_RXHASH | |
| 7810 | NETIF_F_RXCSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7811 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7812 | netdev->hw_features = netdev->features; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7813 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7814 | switch (adapter->hw.mac.type) { |
| 7815 | case ixgbe_mac_82599EB: |
| 7816 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7817 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7818 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 7819 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7820 | break; |
| 7821 | default: |
| 7822 | break; |
| 7823 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7824 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7825 | netdev->hw_features |= NETIF_F_RXALL; |
| 7826 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7827 | netdev->vlan_features |= NETIF_F_TSO; |
| 7828 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7829 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7830 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7831 | netdev->vlan_features |= NETIF_F_SG; |
| 7832 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7833 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 7834 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7835 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7836 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7837 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 7838 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7839 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7840 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7841 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7842 | #endif |
| 7843 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7844 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7845 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7846 | if (hw->mac.ops.get_device_caps) { |
| 7847 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7848 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7849 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7850 | } |
| 7851 | } |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7852 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
| 7853 | netdev->vlan_features |= NETIF_F_FCOE_CRC; |
| 7854 | netdev->vlan_features |= NETIF_F_FSO; |
| 7855 | netdev->vlan_features |= NETIF_F_FCOE_MTU; |
| 7856 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7857 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7858 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7859 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7860 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7861 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7862 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7863 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 7864 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7865 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7866 | netdev->features |= NETIF_F_LRO; |
| 7867 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7868 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7869 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7870 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7871 | err = -EIO; |
| 7872 | goto err_eeprom; |
| 7873 | } |
| 7874 | |
| 7875 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7876 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7877 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7878 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7879 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7880 | err = -EIO; |
| 7881 | goto err_eeprom; |
| 7882 | } |
| 7883 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7884 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
| 7885 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7886 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7887 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7888 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7889 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7890 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7891 | if (err) |
| 7892 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7893 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7894 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
| 7895 | netdev->hw_features &= ~NETIF_F_RXHASH; |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7896 | netdev->features &= ~NETIF_F_RXHASH; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7897 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7898 | |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7899 | /* WOL not supported for all but the following */ |
| 7900 | adapter->wol = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7901 | switch (pdev->device) { |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7902 | case IXGBE_DEV_ID_82599_SFP: |
Don Skidmore | 0e22d04 | 2011-12-10 06:49:43 +0000 | [diff] [blame] | 7903 | /* Only these subdevice supports WOL */ |
| 7904 | switch (pdev->subsystem_device) { |
| 7905 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 7906 | /* only support first port */ |
| 7907 | if (hw->bus.func != 0) |
| 7908 | break; |
| 7909 | case IXGBE_SUBDEV_ID_82599_SFP: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7910 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0e22d04 | 2011-12-10 06:49:43 +0000 | [diff] [blame] | 7911 | break; |
| 7912 | } |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7913 | break; |
Alexander Duyck | 50d6c68 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 7914 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7915 | /* All except this subdevice support WOL */ |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7916 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7917 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7918 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7919 | case IXGBE_DEV_ID_82599_KX4: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7920 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7921 | break; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7922 | case IXGBE_DEV_ID_X540T: |
| 7923 | /* Check eeprom to see if it is enabled */ |
| 7924 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
| 7925 | wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 7926 | |
| 7927 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 7928 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 7929 | (hw->bus.func == 0))) |
| 7930 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7931 | break; |
| 7932 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7933 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7934 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 7935 | /* save off EEPROM version number */ |
| 7936 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 7937 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 7938 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7939 | /* pick up the PCI bus settings for reporting later */ |
| 7940 | hw->mac.ops.get_bus_info(hw); |
| 7941 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7942 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7943 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7944 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7945 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7946 | "Unknown"), |
| 7947 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7948 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7949 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7950 | "Unknown"), |
| 7951 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7952 | |
| 7953 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7954 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7955 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7956 | 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] | 7957 | 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] | 7958 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7959 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7960 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7961 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7962 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7963 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7964 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7965 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7966 | "not sufficient for optimal performance.\n"); |
| 7967 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7968 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7969 | } |
| 7970 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7971 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7972 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7973 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7974 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7975 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7976 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7977 | "Please be aware there may be issues associated " |
| 7978 | "with your hardware. If you are experiencing " |
| 7979 | "problems please contact your Intel or hardware " |
| 7980 | "representative who provided you with this " |
| 7981 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7982 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7983 | strcpy(netdev->name, "eth%d"); |
| 7984 | err = register_netdev(netdev); |
| 7985 | if (err) |
| 7986 | goto err_register; |
| 7987 | |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 7988 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 7989 | if (hw->mac.ops.disable_tx_laser && |
| 7990 | ((hw->phy.multispeed_fiber) || |
| 7991 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
| 7992 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 7993 | hw->mac.ops.disable_tx_laser(hw); |
| 7994 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 7995 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7996 | netif_carrier_off(netdev); |
| 7997 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7998 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 7999 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8000 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8001 | ixgbe_setup_dca(adapter); |
| 8002 | } |
| 8003 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8004 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8005 | 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] | 8006 | for (i = 0; i < adapter->num_vfs; i++) |
| 8007 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 8008 | } |
| 8009 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8010 | /* firmware requires driver version to be 0xFFFFFFFF |
| 8011 | * since os does not support feature |
| 8012 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8013 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8014 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 8015 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8016 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8017 | /* add san mac addr to netdev */ |
| 8018 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8019 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8020 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8021 | cards_found++; |
| 8022 | return 0; |
| 8023 | |
| 8024 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8025 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8026 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8027 | err_sw_init: |
| 8028 | err_eeprom: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8029 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 8030 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8031 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8032 | iounmap(hw->hw_addr); |
| 8033 | err_ioremap: |
| 8034 | free_netdev(netdev); |
| 8035 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8036 | pci_release_selected_regions(pdev, |
| 8037 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8038 | err_pci_reg: |
| 8039 | err_dma: |
| 8040 | pci_disable_device(pdev); |
| 8041 | return err; |
| 8042 | } |
| 8043 | |
| 8044 | /** |
| 8045 | * ixgbe_remove - Device Removal Routine |
| 8046 | * @pdev: PCI device information struct |
| 8047 | * |
| 8048 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 8049 | * that it should release a PCI device. The could be caused by a |
| 8050 | * Hot-Plug event, or because the driver is going to be removed from |
| 8051 | * memory. |
| 8052 | **/ |
| 8053 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 8054 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8055 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8056 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8057 | |
| 8058 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8059 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8060 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8061 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8062 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 8063 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 8064 | dca_remove_requester(&pdev->dev); |
| 8065 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 8066 | } |
| 8067 | |
| 8068 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8069 | #ifdef IXGBE_FCOE |
| 8070 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 8071 | ixgbe_cleanup_fcoe(adapter); |
| 8072 | |
| 8073 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8074 | |
| 8075 | /* remove the added san mac */ |
| 8076 | ixgbe_del_sanmac_netdev(netdev); |
| 8077 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 8078 | if (netdev->reg_state == NETREG_REGISTERED) |
| 8079 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8080 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 8081 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 8082 | if (!(ixgbe_check_vf_assignment(adapter))) |
| 8083 | ixgbe_disable_sriov(adapter); |
| 8084 | else |
| 8085 | e_dev_warn("Unloading driver while VFs are assigned " |
| 8086 | "- VFs will not be deallocated\n"); |
| 8087 | } |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8088 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8089 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8090 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8091 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8092 | |
| 8093 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8094 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8095 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8096 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8097 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8098 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8099 | free_netdev(netdev); |
| 8100 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 8101 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8102 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8103 | pci_disable_device(pdev); |
| 8104 | } |
| 8105 | |
| 8106 | /** |
| 8107 | * ixgbe_io_error_detected - called when PCI error is detected |
| 8108 | * @pdev: Pointer to PCI device |
| 8109 | * @state: The current pci connection state |
| 8110 | * |
| 8111 | * This function is called after a PCI bus error affecting |
| 8112 | * this device has been detected. |
| 8113 | */ |
| 8114 | 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] | 8115 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8116 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8117 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8118 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8119 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8120 | #ifdef CONFIG_PCI_IOV |
| 8121 | struct pci_dev *bdev, *vfdev; |
| 8122 | u32 dw0, dw1, dw2, dw3; |
| 8123 | int vf, pos; |
| 8124 | u16 req_id, pf_func; |
| 8125 | |
| 8126 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 8127 | adapter->num_vfs == 0) |
| 8128 | goto skip_bad_vf_detection; |
| 8129 | |
| 8130 | bdev = pdev->bus->self; |
| 8131 | while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT)) |
| 8132 | bdev = bdev->bus->self; |
| 8133 | |
| 8134 | if (!bdev) |
| 8135 | goto skip_bad_vf_detection; |
| 8136 | |
| 8137 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 8138 | if (!pos) |
| 8139 | goto skip_bad_vf_detection; |
| 8140 | |
| 8141 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0); |
| 8142 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1); |
| 8143 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2); |
| 8144 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3); |
| 8145 | |
| 8146 | req_id = dw1 >> 16; |
| 8147 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 8148 | if (!(req_id & 0x0080)) |
| 8149 | goto skip_bad_vf_detection; |
| 8150 | |
| 8151 | pf_func = req_id & 0x01; |
| 8152 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 8153 | unsigned int device_id; |
| 8154 | |
| 8155 | vf = (req_id & 0x7F) >> 1; |
| 8156 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 8157 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 8158 | "%8.8x\tdw3: %8.8x\n", |
| 8159 | dw0, dw1, dw2, dw3); |
| 8160 | switch (adapter->hw.mac.type) { |
| 8161 | case ixgbe_mac_82599EB: |
| 8162 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 8163 | break; |
| 8164 | case ixgbe_mac_X540: |
| 8165 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 8166 | break; |
| 8167 | default: |
| 8168 | device_id = 0; |
| 8169 | break; |
| 8170 | } |
| 8171 | |
| 8172 | /* Find the pci device of the offending VF */ |
| 8173 | vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL); |
| 8174 | while (vfdev) { |
| 8175 | if (vfdev->devfn == (req_id & 0xFF)) |
| 8176 | break; |
| 8177 | vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, |
| 8178 | device_id, vfdev); |
| 8179 | } |
| 8180 | /* |
| 8181 | * There's a slim chance the VF could have been hot plugged, |
| 8182 | * so if it is no longer present we don't need to issue the |
| 8183 | * VFLR. Just clean up the AER in that case. |
| 8184 | */ |
| 8185 | if (vfdev) { |
| 8186 | e_dev_err("Issuing VFLR to VF %d\n", vf); |
| 8187 | pci_write_config_dword(vfdev, 0xA8, 0x00008000); |
| 8188 | } |
| 8189 | |
| 8190 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8191 | } |
| 8192 | |
| 8193 | /* |
| 8194 | * Even though the error may have occurred on the other port |
| 8195 | * we still need to increment the vf error reference count for |
| 8196 | * both ports because the I/O resume function will be called |
| 8197 | * for both of them. |
| 8198 | */ |
| 8199 | adapter->vferr_refcount++; |
| 8200 | |
| 8201 | return PCI_ERS_RESULT_RECOVERED; |
| 8202 | |
| 8203 | skip_bad_vf_detection: |
| 8204 | #endif /* CONFIG_PCI_IOV */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8205 | netif_device_detach(netdev); |
| 8206 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 8207 | if (state == pci_channel_io_perm_failure) |
| 8208 | return PCI_ERS_RESULT_DISCONNECT; |
| 8209 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8210 | if (netif_running(netdev)) |
| 8211 | ixgbe_down(adapter); |
| 8212 | pci_disable_device(pdev); |
| 8213 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8214 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8215 | return PCI_ERS_RESULT_NEED_RESET; |
| 8216 | } |
| 8217 | |
| 8218 | /** |
| 8219 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 8220 | * @pdev: Pointer to PCI device |
| 8221 | * |
| 8222 | * Restart the card from scratch, as if from a cold-boot. |
| 8223 | */ |
| 8224 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 8225 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8226 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8227 | pci_ers_result_t result; |
| 8228 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8229 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8230 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8231 | 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] | 8232 | result = PCI_ERS_RESULT_DISCONNECT; |
| 8233 | } else { |
| 8234 | pci_set_master(pdev); |
| 8235 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 8236 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8237 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 8238 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8239 | |
| 8240 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 8241 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8242 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8243 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8244 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8245 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8246 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8247 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 8248 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8249 | /* non-fatal, continue */ |
| 8250 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8251 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8252 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8253 | } |
| 8254 | |
| 8255 | /** |
| 8256 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 8257 | * @pdev: Pointer to PCI device |
| 8258 | * |
| 8259 | * This callback is called when the error recovery driver tells us that |
| 8260 | * its OK to resume normal operation. |
| 8261 | */ |
| 8262 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 8263 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8264 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8265 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8266 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8267 | #ifdef CONFIG_PCI_IOV |
| 8268 | if (adapter->vferr_refcount) { |
| 8269 | e_info(drv, "Resuming after VF err\n"); |
| 8270 | adapter->vferr_refcount--; |
| 8271 | return; |
| 8272 | } |
| 8273 | |
| 8274 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 8275 | if (netif_running(netdev)) |
| 8276 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8277 | |
| 8278 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8279 | } |
| 8280 | |
| 8281 | static struct pci_error_handlers ixgbe_err_handler = { |
| 8282 | .error_detected = ixgbe_io_error_detected, |
| 8283 | .slot_reset = ixgbe_io_slot_reset, |
| 8284 | .resume = ixgbe_io_resume, |
| 8285 | }; |
| 8286 | |
| 8287 | static struct pci_driver ixgbe_driver = { |
| 8288 | .name = ixgbe_driver_name, |
| 8289 | .id_table = ixgbe_pci_tbl, |
| 8290 | .probe = ixgbe_probe, |
| 8291 | .remove = __devexit_p(ixgbe_remove), |
| 8292 | #ifdef CONFIG_PM |
| 8293 | .suspend = ixgbe_suspend, |
| 8294 | .resume = ixgbe_resume, |
| 8295 | #endif |
| 8296 | .shutdown = ixgbe_shutdown, |
| 8297 | .err_handler = &ixgbe_err_handler |
| 8298 | }; |
| 8299 | |
| 8300 | /** |
| 8301 | * ixgbe_init_module - Driver Registration Routine |
| 8302 | * |
| 8303 | * ixgbe_init_module is the first routine called when the driver is |
| 8304 | * loaded. All it does is register with the PCI subsystem. |
| 8305 | **/ |
| 8306 | static int __init ixgbe_init_module(void) |
| 8307 | { |
| 8308 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 8309 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8310 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8311 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8312 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8313 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8314 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8315 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8316 | ret = pci_register_driver(&ixgbe_driver); |
| 8317 | return ret; |
| 8318 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8319 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8320 | module_init(ixgbe_init_module); |
| 8321 | |
| 8322 | /** |
| 8323 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 8324 | * |
| 8325 | * ixgbe_exit_module is called just before the driver is removed |
| 8326 | * from memory. |
| 8327 | **/ |
| 8328 | static void __exit ixgbe_exit_module(void) |
| 8329 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8330 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8331 | dca_unregister_notify(&dca_notifier); |
| 8332 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8333 | pci_unregister_driver(&ixgbe_driver); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8334 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8335 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8336 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8337 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8338 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8339 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8340 | { |
| 8341 | int ret_val; |
| 8342 | |
| 8343 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8344 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8345 | |
| 8346 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 8347 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8348 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 8349 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8350 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8351 | module_exit(ixgbe_exit_module); |
| 8352 | |
| 8353 | /* ixgbe_main.c */ |