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; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 292 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 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]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 332 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 333 | pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 334 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 335 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 336 | dma_unmap_len(tx_buffer, len), |
| 337 | tx_buffer->next_to_watch, |
| 338 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /* Print TX Rings */ |
| 342 | if (!netif_msg_tx_done(adapter)) |
| 343 | goto rx_ring_summary; |
| 344 | |
| 345 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 346 | |
| 347 | /* Transmit Descriptor Formats |
| 348 | * |
| 349 | * Advanced Transmit Descriptor |
| 350 | * +--------------------------------------------------------------+ |
| 351 | * 0 | Buffer Address [63:0] | |
| 352 | * +--------------------------------------------------------------+ |
| 353 | * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
| 354 | * +--------------------------------------------------------------+ |
| 355 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 |
| 356 | */ |
| 357 | |
| 358 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 359 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 360 | pr_info("------------------------------------\n"); |
| 361 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 362 | pr_info("------------------------------------\n"); |
| 363 | pr_info("T [desc] [address 63:0 ] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 364 | "[PlPOIdStDDt Ln] [bi->dma ] " |
| 365 | "leng ntw timestamp bi->skb\n"); |
| 366 | |
| 367 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 368 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 369 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 370 | u0 = (struct my_u0 *)tx_desc; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 371 | pr_info("T [0x%03X] %016llX %016llX %016llX" |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 372 | " %04X %p %016llX %p", i, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 373 | le64_to_cpu(u0->a), |
| 374 | le64_to_cpu(u0->b), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 375 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 376 | dma_unmap_len(tx_buffer, len), |
| 377 | tx_buffer->next_to_watch, |
| 378 | (u64)tx_buffer->time_stamp, |
| 379 | tx_buffer->skb); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 380 | if (i == tx_ring->next_to_use && |
| 381 | i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 382 | pr_cont(" NTC/U\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 383 | else if (i == tx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 384 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 385 | else if (i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 386 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 387 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 388 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 389 | |
| 390 | if (netif_msg_pktdata(adapter) && |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 391 | dma_unmap_len(tx_buffer, len) != 0) |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 392 | print_hex_dump(KERN_INFO, "", |
| 393 | DUMP_PREFIX_ADDRESS, 16, 1, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 394 | phys_to_virt(dma_unmap_addr(tx_buffer, |
| 395 | dma)), |
| 396 | dma_unmap_len(tx_buffer, len), |
| 397 | true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
| 401 | /* Print RX Rings Summary */ |
| 402 | rx_ring_summary: |
| 403 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 404 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 405 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 406 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 407 | pr_info("%5d %5X %5X\n", |
| 408 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /* Print RX Rings */ |
| 412 | if (!netif_msg_rx_status(adapter)) |
| 413 | goto exit; |
| 414 | |
| 415 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 416 | |
| 417 | /* Advanced Receive Descriptor (Read) Format |
| 418 | * 63 1 0 |
| 419 | * +-----------------------------------------------------+ |
| 420 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 421 | * +----------------------------------------------+------+ |
| 422 | * 8 | Header Buffer Address [63:1] | DD | |
| 423 | * +-----------------------------------------------------+ |
| 424 | * |
| 425 | * |
| 426 | * Advanced Receive Descriptor (Write-Back) Format |
| 427 | * |
| 428 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 429 | * +------------------------------------------------------+ |
| 430 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | |
| 431 | * | Checksum Ident | | | | Type | Type | |
| 432 | * +------------------------------------------------------+ |
| 433 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 434 | * +------------------------------------------------------+ |
| 435 | * 63 48 47 32 31 20 19 0 |
| 436 | */ |
| 437 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 438 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 439 | pr_info("------------------------------------\n"); |
| 440 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 441 | pr_info("------------------------------------\n"); |
| 442 | pr_info("R [desc] [ PktBuf A0] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 443 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " |
| 444 | "<-- Adv Rx Read format\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 445 | pr_info("RWB[desc] [PcsmIpSHl PtRs] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 446 | "[vl er S cks ln] ---------------- [bi->skb] " |
| 447 | "<-- Adv Rx Write-Back format\n"); |
| 448 | |
| 449 | for (i = 0; i < rx_ring->count; i++) { |
| 450 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 451 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 452 | u0 = (struct my_u0 *)rx_desc; |
| 453 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 454 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 455 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 456 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 457 | "%016llX ---------------- %p", i, |
| 458 | le64_to_cpu(u0->a), |
| 459 | le64_to_cpu(u0->b), |
| 460 | rx_buffer_info->skb); |
| 461 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 462 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 463 | "%016llX %016llX %p", i, |
| 464 | le64_to_cpu(u0->a), |
| 465 | le64_to_cpu(u0->b), |
| 466 | (u64)rx_buffer_info->dma, |
| 467 | rx_buffer_info->skb); |
| 468 | |
| 469 | if (netif_msg_pktdata(adapter)) { |
| 470 | print_hex_dump(KERN_INFO, "", |
| 471 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 472 | phys_to_virt(rx_buffer_info->dma), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 473 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 478 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 479 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 480 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 481 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 482 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 483 | |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | exit: |
| 488 | return; |
| 489 | } |
| 490 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 491 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 492 | { |
| 493 | u32 ctrl_ext; |
| 494 | |
| 495 | /* Let firmware take over control of h/w */ |
| 496 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 497 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 498 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 502 | { |
| 503 | u32 ctrl_ext; |
| 504 | |
| 505 | /* Let firmware know the driver has taken over */ |
| 506 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 507 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 508 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 509 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 510 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 511 | /* |
| 512 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 513 | * @adapter: pointer to adapter struct |
| 514 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 515 | * @queue: queue to map the corresponding interrupt to |
| 516 | * @msix_vector: the vector to map to the corresponding queue |
| 517 | * |
| 518 | */ |
| 519 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 520 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 521 | { |
| 522 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 523 | struct ixgbe_hw *hw = &adapter->hw; |
| 524 | switch (hw->mac.type) { |
| 525 | case ixgbe_mac_82598EB: |
| 526 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 527 | if (direction == -1) |
| 528 | direction = 0; |
| 529 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 530 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 531 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 532 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 533 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 534 | break; |
| 535 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 536 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 537 | if (direction == -1) { |
| 538 | /* other causes */ |
| 539 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 540 | index = ((queue & 1) * 8); |
| 541 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 542 | ivar &= ~(0xFF << index); |
| 543 | ivar |= (msix_vector << index); |
| 544 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 545 | break; |
| 546 | } else { |
| 547 | /* tx or rx causes */ |
| 548 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 549 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 550 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 551 | ivar &= ~(0xFF << index); |
| 552 | ivar |= (msix_vector << index); |
| 553 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 554 | break; |
| 555 | } |
| 556 | default: |
| 557 | break; |
| 558 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 561 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 562 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 563 | { |
| 564 | u32 mask; |
| 565 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 566 | switch (adapter->hw.mac.type) { |
| 567 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 568 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 569 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 570 | break; |
| 571 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 572 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 573 | mask = (qmask & 0xFFFFFFFF); |
| 574 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 575 | mask = (qmask >> 32); |
| 576 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 577 | break; |
| 578 | default: |
| 579 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 583 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring, |
| 584 | struct ixgbe_tx_buffer *tx_buffer) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 585 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 586 | if (tx_buffer->skb) { |
| 587 | dev_kfree_skb_any(tx_buffer->skb); |
| 588 | if (dma_unmap_len(tx_buffer, len)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 589 | dma_unmap_single(ring->dev, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 590 | dma_unmap_addr(tx_buffer, dma), |
| 591 | dma_unmap_len(tx_buffer, len), |
| 592 | DMA_TO_DEVICE); |
| 593 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 594 | dma_unmap_page(ring->dev, |
| 595 | dma_unmap_addr(tx_buffer, dma), |
| 596 | dma_unmap_len(tx_buffer, len), |
| 597 | DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 598 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 599 | tx_buffer->next_to_watch = NULL; |
| 600 | tx_buffer->skb = NULL; |
| 601 | dma_unmap_len_set(tx_buffer, len, 0); |
| 602 | /* tx_buffer must be completely set up in the transmit path */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 603 | } |
| 604 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 605 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 606 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 607 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 608 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 609 | u32 data = 0; |
| 610 | u32 xoff[8] = {0}; |
| 611 | int i; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 612 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 613 | if ((hw->fc.current_mode == ixgbe_fc_full) || |
| 614 | (hw->fc.current_mode == ixgbe_fc_rx_pause)) { |
| 615 | switch (hw->mac.type) { |
| 616 | case ixgbe_mac_82598EB: |
| 617 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 618 | break; |
| 619 | default: |
| 620 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 621 | } |
| 622 | hwstats->lxoffrxc += data; |
| 623 | |
| 624 | /* refill credits (no tx hang) if we received xoff */ |
| 625 | if (!data) |
| 626 | return; |
| 627 | |
| 628 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 629 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 630 | &adapter->tx_ring[i]->state); |
| 631 | return; |
| 632 | } else if (!(adapter->dcb_cfg.pfc_mode_enable)) |
| 633 | return; |
| 634 | |
| 635 | /* update stats for each tc, only valid with PFC enabled */ |
| 636 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
| 637 | switch (hw->mac.type) { |
| 638 | case ixgbe_mac_82598EB: |
| 639 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 640 | break; |
| 641 | default: |
| 642 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 643 | } |
| 644 | hwstats->pxoffrxc[i] += xoff[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 645 | } |
| 646 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 647 | /* disarm tx queues that have received xoff frames */ |
| 648 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 649 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | fb5475f | 2011-04-26 07:26:36 +0000 | [diff] [blame] | 650 | u8 tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 651 | |
| 652 | if (xoff[tc]) |
| 653 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 658 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 659 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 663 | { |
| 664 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); |
| 665 | struct ixgbe_hw *hw = &adapter->hw; |
| 666 | |
| 667 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 668 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
| 669 | |
| 670 | if (head != tail) |
| 671 | return (head < tail) ? |
| 672 | tail - head : (tail + ring->count - head); |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 678 | { |
| 679 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 680 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 681 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 682 | bool ret = false; |
| 683 | |
| 684 | clear_check_for_tx_hang(tx_ring); |
| 685 | |
| 686 | /* |
| 687 | * Check for a hung queue, but be thorough. This verifies |
| 688 | * that a transmit has been completed since the previous |
| 689 | * check AND there is at least one packet pending. The |
| 690 | * ARMED bit is set to indicate a potential hang. The |
| 691 | * bit is cleared if a pause frame is received to remove |
| 692 | * false hang detection due to PFC or 802.3x frames. By |
| 693 | * requiring this to fail twice we avoid races with |
| 694 | * pfc clearing the ARMED bit and conditions where we |
| 695 | * run the check_tx_hang logic with a transmit completion |
| 696 | * pending but without time to complete it yet. |
| 697 | */ |
| 698 | if ((tx_done_old == tx_done) && tx_pending) { |
| 699 | /* make sure it is true for two checks in a row */ |
| 700 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 701 | &tx_ring->state); |
| 702 | } else { |
| 703 | /* update completed stats and continue */ |
| 704 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 705 | /* reset the countdown */ |
| 706 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 707 | } |
| 708 | |
| 709 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 712 | /** |
| 713 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 714 | * @adapter: driver private struct |
| 715 | **/ |
| 716 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 717 | { |
| 718 | |
| 719 | /* Do the reset outside of interrupt context */ |
| 720 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 721 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 722 | ixgbe_service_event_schedule(adapter); |
| 723 | } |
| 724 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 725 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 726 | /** |
| 727 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 728 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 729 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 730 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 731 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 732 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 733 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 734 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 735 | struct ixgbe_tx_buffer *tx_buffer; |
| 736 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 737 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 738 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 739 | unsigned int i = tx_ring->next_to_clean; |
| 740 | |
| 741 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 742 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 743 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 744 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 745 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 746 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 747 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 748 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 749 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 750 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 751 | /* if next_to_watch is not set then there is no work pending */ |
| 752 | if (!eop_desc) |
| 753 | break; |
| 754 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 755 | /* prevent any other reads prior to eop_desc */ |
| 756 | rmb(); |
| 757 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 758 | /* if DD is not set pending work has not been completed */ |
| 759 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 760 | break; |
| 761 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 762 | /* clear next_to_watch to prevent false hangs */ |
| 763 | tx_buffer->next_to_watch = NULL; |
| 764 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 765 | /* update the statistics for this packet */ |
| 766 | total_bytes += tx_buffer->bytecount; |
| 767 | total_packets += tx_buffer->gso_segs; |
| 768 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 769 | /* free the skb */ |
| 770 | dev_kfree_skb_any(tx_buffer->skb); |
| 771 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 772 | /* unmap skb header data */ |
| 773 | dma_unmap_single(tx_ring->dev, |
| 774 | dma_unmap_addr(tx_buffer, dma), |
| 775 | dma_unmap_len(tx_buffer, len), |
| 776 | DMA_TO_DEVICE); |
| 777 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 778 | /* clear tx_buffer data */ |
| 779 | tx_buffer->skb = NULL; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 780 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 781 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 782 | /* unmap remaining buffers */ |
| 783 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 784 | tx_buffer++; |
| 785 | tx_desc++; |
| 786 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 787 | if (unlikely(!i)) { |
| 788 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 789 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 790 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 793 | /* unmap any remaining paged data */ |
| 794 | if (dma_unmap_len(tx_buffer, len)) { |
| 795 | dma_unmap_page(tx_ring->dev, |
| 796 | dma_unmap_addr(tx_buffer, dma), |
| 797 | dma_unmap_len(tx_buffer, len), |
| 798 | DMA_TO_DEVICE); |
| 799 | dma_unmap_len_set(tx_buffer, len, 0); |
| 800 | } |
| 801 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 802 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 803 | /* move us one more past the eop_desc for start of next pkt */ |
| 804 | tx_buffer++; |
| 805 | tx_desc++; |
| 806 | i++; |
| 807 | if (unlikely(!i)) { |
| 808 | i -= tx_ring->count; |
| 809 | tx_buffer = tx_ring->tx_buffer_info; |
| 810 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 811 | } |
| 812 | |
| 813 | /* issue prefetch for next Tx descriptor */ |
| 814 | prefetch(tx_desc); |
| 815 | |
| 816 | /* update budget accounting */ |
| 817 | budget--; |
| 818 | } while (likely(budget)); |
| 819 | |
| 820 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 821 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 822 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 823 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 824 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 825 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 826 | q_vector->tx.total_bytes += total_bytes; |
| 827 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 828 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 829 | 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] | 830 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 831 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 832 | e_err(drv, "Detected Tx Unit Hang\n" |
| 833 | " Tx Queue <%d>\n" |
| 834 | " TDH, TDT <%x>, <%x>\n" |
| 835 | " next_to_use <%x>\n" |
| 836 | " next_to_clean <%x>\n" |
| 837 | "tx_buffer_info[next_to_clean]\n" |
| 838 | " time_stamp <%lx>\n" |
| 839 | " jiffies <%lx>\n", |
| 840 | tx_ring->queue_index, |
| 841 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 842 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 843 | tx_ring->next_to_use, i, |
| 844 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 845 | |
| 846 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 847 | |
| 848 | e_info(probe, |
| 849 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 850 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 851 | |
| 852 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 853 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 854 | |
| 855 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 856 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 857 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 858 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 859 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 860 | total_packets, total_bytes); |
| 861 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 862 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 863 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 864 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 865 | /* Make sure that anybody stopping the queue after this |
| 866 | * sees the new next_to_clean. |
| 867 | */ |
| 868 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 869 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 870 | tx_ring->queue_index) |
| 871 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 872 | netif_wake_subqueue(tx_ring->netdev, |
| 873 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 874 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 875 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 876 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 877 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 878 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 881 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 882 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 883 | struct ixgbe_ring *tx_ring, |
| 884 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 885 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 886 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 887 | u32 txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 888 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 889 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 890 | switch (hw->mac.type) { |
| 891 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 892 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 893 | break; |
| 894 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 895 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 896 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 897 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 898 | break; |
| 899 | default: |
| 900 | /* for unknown hardware do not write register */ |
| 901 | return; |
| 902 | } |
| 903 | |
| 904 | /* |
| 905 | * We can enable relaxed ordering for reads, but not writes when |
| 906 | * DCA is enabled. This is due to a known issue in some chipsets |
| 907 | * which will cause the DCA tag to be cleared. |
| 908 | */ |
| 909 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 910 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 911 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 912 | |
| 913 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 914 | } |
| 915 | |
| 916 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 917 | struct ixgbe_ring *rx_ring, |
| 918 | int cpu) |
| 919 | { |
| 920 | struct ixgbe_hw *hw = &adapter->hw; |
| 921 | u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
| 922 | u8 reg_idx = rx_ring->reg_idx; |
| 923 | |
| 924 | |
| 925 | switch (hw->mac.type) { |
| 926 | case ixgbe_mac_82599EB: |
| 927 | case ixgbe_mac_X540: |
| 928 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 929 | break; |
| 930 | default: |
| 931 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 932 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 933 | |
| 934 | /* |
| 935 | * We can enable relaxed ordering for reads, but not writes when |
| 936 | * DCA is enabled. This is due to a known issue in some chipsets |
| 937 | * which will cause the DCA tag to be cleared. |
| 938 | */ |
| 939 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
| 940 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
| 941 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 942 | |
| 943 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 947 | { |
| 948 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 949 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 950 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 951 | |
| 952 | if (q_vector->cpu == cpu) |
| 953 | goto out_no_update; |
| 954 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 955 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 956 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 957 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 958 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 959 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 960 | |
| 961 | q_vector->cpu = cpu; |
| 962 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 963 | put_cpu(); |
| 964 | } |
| 965 | |
| 966 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 967 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 968 | int num_q_vectors; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 969 | int i; |
| 970 | |
| 971 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 972 | return; |
| 973 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 974 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 975 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 976 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 977 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 978 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 979 | else |
| 980 | num_q_vectors = 1; |
| 981 | |
| 982 | for (i = 0; i < num_q_vectors; i++) { |
| 983 | adapter->q_vector[i]->cpu = -1; |
| 984 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
| 988 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 989 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 990 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 991 | unsigned long event = *(unsigned long *)data; |
| 992 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 993 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 994 | return 0; |
| 995 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 996 | switch (event) { |
| 997 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 998 | /* if we're already enabled, don't do it again */ |
| 999 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1000 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1001 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1002 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1003 | ixgbe_setup_dca(adapter); |
| 1004 | break; |
| 1005 | } |
| 1006 | /* Fall Through since DCA is disabled. */ |
| 1007 | case DCA_PROVIDER_REMOVE: |
| 1008 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1009 | dca_remove_requester(dev); |
| 1010 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 1011 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 1012 | } |
| 1013 | break; |
| 1014 | } |
| 1015 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1016 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1017 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1018 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1019 | #endif /* CONFIG_IXGBE_DCA */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1020 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1021 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1022 | struct sk_buff *skb) |
| 1023 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1024 | if (ring->netdev->features & NETIF_F_RXHASH) |
| 1025 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1028 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1029 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1030 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
| 1031 | * @adapter: address of board private structure |
| 1032 | * @rx_desc: advanced rx descriptor |
| 1033 | * |
| 1034 | * Returns : true if it is FCoE pkt |
| 1035 | */ |
| 1036 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter, |
| 1037 | union ixgbe_adv_rx_desc *rx_desc) |
| 1038 | { |
| 1039 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1040 | |
| 1041 | return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 1042 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1043 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1044 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1045 | } |
| 1046 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1047 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1048 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1049 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1050 | * @ring: structure containing ring specific data |
| 1051 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1052 | * @skb: skb currently being received and modified |
| 1053 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1054 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1055 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1056 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1057 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1058 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1059 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1060 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1061 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1062 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1063 | |
| 1064 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1065 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1066 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1067 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1068 | return; |
| 1069 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1070 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1071 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1072 | return; |
| 1073 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1074 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1075 | __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] | 1076 | |
| 1077 | /* |
| 1078 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1079 | * checksum errors. |
| 1080 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1081 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1082 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1083 | return; |
| 1084 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1085 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1086 | return; |
| 1087 | } |
| 1088 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1089 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1090 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1093 | 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] | 1094 | { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1095 | rx_ring->next_to_use = val; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1096 | |
| 1097 | /* update next to alloc since we have filled the ring */ |
| 1098 | rx_ring->next_to_alloc = val; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1099 | /* |
| 1100 | * Force memory writes to complete before letting h/w |
| 1101 | * know there are new descriptors to fetch. (Only |
| 1102 | * applicable for weak-ordered memory model archs, |
| 1103 | * such as IA-64). |
| 1104 | */ |
| 1105 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1106 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1109 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1110 | struct ixgbe_rx_buffer *bi) |
| 1111 | { |
| 1112 | struct page *page = bi->page; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1113 | dma_addr_t dma = bi->dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1114 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1115 | /* since we are recycling buffers we should seldom need to alloc */ |
| 1116 | if (likely(dma)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1117 | return true; |
| 1118 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1119 | /* alloc new page for storage */ |
| 1120 | if (likely(!page)) { |
| 1121 | page = alloc_pages(GFP_ATOMIC | __GFP_COLD, |
| 1122 | ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1123 | if (unlikely(!page)) { |
| 1124 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1125 | return false; |
| 1126 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1127 | bi->page = page; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1130 | /* map page for use */ |
| 1131 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1132 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1133 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1134 | /* |
| 1135 | * if mapping failed free memory back to system since |
| 1136 | * there isn't much point in holding memory we can't use |
| 1137 | */ |
| 1138 | if (dma_mapping_error(rx_ring->dev, dma)) { |
| 1139 | put_page(page); |
| 1140 | bi->page = NULL; |
| 1141 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1142 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1143 | return false; |
| 1144 | } |
| 1145 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1146 | bi->dma = dma; |
| 1147 | bi->page_offset ^= ixgbe_rx_bufsz(rx_ring); |
| 1148 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1149 | return true; |
| 1150 | } |
| 1151 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1152 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1153 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1154 | * @rx_ring: ring to place buffers on |
| 1155 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1156 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1157 | 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] | 1158 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1159 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1160 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1161 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1162 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1163 | /* nothing to do */ |
| 1164 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1165 | return; |
| 1166 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1167 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1168 | bi = &rx_ring->rx_buffer_info[i]; |
| 1169 | i -= rx_ring->count; |
| 1170 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1171 | do { |
| 1172 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1173 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1174 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1175 | /* |
| 1176 | * Refresh the desc even if buffer_addrs didn't change |
| 1177 | * because each write-back erases this info. |
| 1178 | */ |
| 1179 | 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] | 1180 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1181 | rx_desc++; |
| 1182 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1183 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1184 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1185 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1186 | bi = rx_ring->rx_buffer_info; |
| 1187 | i -= rx_ring->count; |
| 1188 | } |
| 1189 | |
| 1190 | /* clear the hdr_addr for the next_to_use descriptor */ |
| 1191 | rx_desc->read.hdr_addr = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1192 | |
| 1193 | cleaned_count--; |
| 1194 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1195 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1196 | i += rx_ring->count; |
| 1197 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1198 | if (rx_ring->next_to_use != i) |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1199 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1202 | /** |
| 1203 | * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE |
| 1204 | * @data: pointer to the start of the headers |
| 1205 | * @max_len: total length of section to find headers in |
| 1206 | * |
| 1207 | * This function is meant to determine the length of headers that will |
| 1208 | * be recognized by hardware for LRO, GRO, and RSC offloads. The main |
| 1209 | * motivation of doing this is to only perform one pull for IPv4 TCP |
| 1210 | * packets so that we can do basic things like calculating the gso_size |
| 1211 | * based on the average data per packet. |
| 1212 | **/ |
| 1213 | static unsigned int ixgbe_get_headlen(unsigned char *data, |
| 1214 | unsigned int max_len) |
| 1215 | { |
| 1216 | union { |
| 1217 | unsigned char *network; |
| 1218 | /* l2 headers */ |
| 1219 | struct ethhdr *eth; |
| 1220 | struct vlan_hdr *vlan; |
| 1221 | /* l3 headers */ |
| 1222 | struct iphdr *ipv4; |
| 1223 | } hdr; |
| 1224 | __be16 protocol; |
| 1225 | u8 nexthdr = 0; /* default to not TCP */ |
| 1226 | u8 hlen; |
| 1227 | |
| 1228 | /* this should never happen, but better safe than sorry */ |
| 1229 | if (max_len < ETH_HLEN) |
| 1230 | return max_len; |
| 1231 | |
| 1232 | /* initialize network frame pointer */ |
| 1233 | hdr.network = data; |
| 1234 | |
| 1235 | /* set first protocol and move network header forward */ |
| 1236 | protocol = hdr.eth->h_proto; |
| 1237 | hdr.network += ETH_HLEN; |
| 1238 | |
| 1239 | /* handle any vlan tag if present */ |
| 1240 | if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 1241 | if ((hdr.network - data) > (max_len - VLAN_HLEN)) |
| 1242 | return max_len; |
| 1243 | |
| 1244 | protocol = hdr.vlan->h_vlan_encapsulated_proto; |
| 1245 | hdr.network += VLAN_HLEN; |
| 1246 | } |
| 1247 | |
| 1248 | /* handle L3 protocols */ |
| 1249 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 1250 | if ((hdr.network - data) > (max_len - sizeof(struct iphdr))) |
| 1251 | return max_len; |
| 1252 | |
| 1253 | /* access ihl as a u8 to avoid unaligned access on ia64 */ |
| 1254 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 1255 | |
| 1256 | /* verify hlen meets minimum size requirements */ |
| 1257 | if (hlen < sizeof(struct iphdr)) |
| 1258 | return hdr.network - data; |
| 1259 | |
| 1260 | /* record next protocol */ |
| 1261 | nexthdr = hdr.ipv4->protocol; |
| 1262 | hdr.network += hlen; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1263 | #ifdef IXGBE_FCOE |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1264 | } else if (protocol == __constant_htons(ETH_P_FCOE)) { |
| 1265 | if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN)) |
| 1266 | return max_len; |
| 1267 | hdr.network += FCOE_HEADER_LEN; |
| 1268 | #endif |
| 1269 | } else { |
| 1270 | return hdr.network - data; |
| 1271 | } |
| 1272 | |
| 1273 | /* finally sort out TCP */ |
| 1274 | if (nexthdr == IPPROTO_TCP) { |
| 1275 | if ((hdr.network - data) > (max_len - sizeof(struct tcphdr))) |
| 1276 | return max_len; |
| 1277 | |
| 1278 | /* access doff as a u8 to avoid unaligned access on ia64 */ |
| 1279 | hlen = (hdr.network[12] & 0xF0) >> 2; |
| 1280 | |
| 1281 | /* verify hlen meets minimum size requirements */ |
| 1282 | if (hlen < sizeof(struct tcphdr)) |
| 1283 | return hdr.network - data; |
| 1284 | |
| 1285 | hdr.network += hlen; |
| 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * If everything has gone correctly hdr.network should be the |
| 1290 | * data section of the packet and will be the end of the header. |
| 1291 | * If not then it probably represents the end of the last recognized |
| 1292 | * header. |
| 1293 | */ |
| 1294 | if ((hdr.network - data) < max_len) |
| 1295 | return hdr.network - data; |
| 1296 | else |
| 1297 | return max_len; |
| 1298 | } |
| 1299 | |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1300 | static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring, |
| 1301 | union ixgbe_adv_rx_desc *rx_desc, |
| 1302 | struct sk_buff *skb) |
| 1303 | { |
| 1304 | __le32 rsc_enabled; |
| 1305 | u32 rsc_cnt; |
| 1306 | |
| 1307 | if (!ring_is_rsc_enabled(rx_ring)) |
| 1308 | return; |
| 1309 | |
| 1310 | rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1311 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1312 | |
| 1313 | /* If this is an RSC frame rsc_cnt should be non-zero */ |
| 1314 | if (!rsc_enabled) |
| 1315 | return; |
| 1316 | |
| 1317 | rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1318 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1319 | |
| 1320 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1321 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1322 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1323 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1324 | struct sk_buff *skb) |
| 1325 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1326 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1327 | |
| 1328 | /* set gso_size to avoid messing up TCP MSS */ |
| 1329 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1330 | IXGBE_CB(skb)->append_cnt); |
| 1331 | } |
| 1332 | |
| 1333 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1334 | struct sk_buff *skb) |
| 1335 | { |
| 1336 | /* if append_cnt is 0 then frame is not RSC */ |
| 1337 | if (!IXGBE_CB(skb)->append_cnt) |
| 1338 | return; |
| 1339 | |
| 1340 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1341 | rx_ring->rx_stats.rsc_flush++; |
| 1342 | |
| 1343 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1344 | |
| 1345 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1346 | IXGBE_CB(skb)->append_cnt = 0; |
| 1347 | } |
| 1348 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1349 | /** |
| 1350 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1351 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1352 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1353 | * @skb: pointer to current skb being populated |
| 1354 | * |
| 1355 | * This function checks the ring, descriptor, and packet information in |
| 1356 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1357 | * other fields within the skb. |
| 1358 | **/ |
| 1359 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1360 | union ixgbe_adv_rx_desc *rx_desc, |
| 1361 | struct sk_buff *skb) |
| 1362 | { |
| 1363 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1364 | |
| 1365 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1366 | |
| 1367 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1368 | |
| 1369 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
| 1370 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
| 1371 | __vlan_hwaccel_put_tag(skb, vid); |
| 1372 | } |
| 1373 | |
| 1374 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1375 | |
| 1376 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
| 1377 | } |
| 1378 | |
| 1379 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1380 | struct sk_buff *skb) |
| 1381 | { |
| 1382 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1383 | |
| 1384 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1385 | napi_gro_receive(&q_vector->napi, skb); |
| 1386 | else |
| 1387 | netif_rx(skb); |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1390 | /** |
| 1391 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1392 | * @rx_ring: Rx ring being processed |
| 1393 | * @rx_desc: Rx descriptor for current buffer |
| 1394 | * @skb: Current socket buffer containing buffer in progress |
| 1395 | * |
| 1396 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1397 | * this function exits returning false, otherwise it will place the |
| 1398 | * sk_buff in the next buffer to be chained and return true indicating |
| 1399 | * that this is in fact a non-EOP buffer. |
| 1400 | **/ |
| 1401 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1402 | union ixgbe_adv_rx_desc *rx_desc, |
| 1403 | struct sk_buff *skb) |
| 1404 | { |
| 1405 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1406 | |
| 1407 | /* fetch, update, and store next to clean */ |
| 1408 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1409 | rx_ring->next_to_clean = ntc; |
| 1410 | |
| 1411 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1412 | |
| 1413 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1414 | return false; |
| 1415 | |
| 1416 | /* append_cnt indicates packet is RSC, if so fetch nextp */ |
| 1417 | if (IXGBE_CB(skb)->append_cnt) { |
| 1418 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1419 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1420 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1421 | } |
| 1422 | |
| 1423 | /* place skb in next buffer to be received */ |
| 1424 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1425 | rx_ring->rx_stats.non_eop_descs++; |
| 1426 | |
| 1427 | return true; |
| 1428 | } |
| 1429 | |
| 1430 | /** |
| 1431 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1432 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1433 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1434 | * @skb: pointer to current skb being fixed |
| 1435 | * |
| 1436 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1437 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1438 | * should be very rare. |
| 1439 | * |
| 1440 | * Also address the case where we are pulling data in on pages only |
| 1441 | * and as such no data is present in the skb header. |
| 1442 | * |
| 1443 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1444 | * it is large enough to qualify as a valid Ethernet frame. |
| 1445 | * |
| 1446 | * Returns true if an error was encountered and skb was freed. |
| 1447 | **/ |
| 1448 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1449 | union ixgbe_adv_rx_desc *rx_desc, |
| 1450 | struct sk_buff *skb) |
| 1451 | { |
| 1452 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1453 | struct net_device *netdev = rx_ring->netdev; |
| 1454 | unsigned char *va; |
| 1455 | unsigned int pull_len; |
| 1456 | |
| 1457 | /* if the page was released unmap it, else just sync our portion */ |
| 1458 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1459 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1460 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1461 | IXGBE_CB(skb)->page_released = false; |
| 1462 | } else { |
| 1463 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1464 | IXGBE_CB(skb)->dma, |
| 1465 | frag->page_offset, |
| 1466 | ixgbe_rx_bufsz(rx_ring), |
| 1467 | DMA_FROM_DEVICE); |
| 1468 | } |
| 1469 | IXGBE_CB(skb)->dma = 0; |
| 1470 | |
| 1471 | /* verify that the packet does not have any known errors */ |
| 1472 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1473 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1474 | !(netdev->features & NETIF_F_RXALL))) { |
| 1475 | dev_kfree_skb_any(skb); |
| 1476 | return true; |
| 1477 | } |
| 1478 | |
| 1479 | /* |
| 1480 | * it is valid to use page_address instead of kmap since we are |
| 1481 | * working with pages allocated out of the lomem pool per |
| 1482 | * alloc_page(GFP_ATOMIC) |
| 1483 | */ |
| 1484 | va = skb_frag_address(frag); |
| 1485 | |
| 1486 | /* |
| 1487 | * we need the header to contain the greater of either ETH_HLEN or |
| 1488 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1489 | */ |
| 1490 | pull_len = skb_frag_size(frag); |
| 1491 | if (pull_len > 256) |
| 1492 | pull_len = ixgbe_get_headlen(va, pull_len); |
| 1493 | |
| 1494 | /* align pull length to size of long to optimize memcpy performance */ |
| 1495 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1496 | |
| 1497 | /* update all of the pointers */ |
| 1498 | skb_frag_size_sub(frag, pull_len); |
| 1499 | frag->page_offset += pull_len; |
| 1500 | skb->data_len -= pull_len; |
| 1501 | skb->tail += pull_len; |
| 1502 | |
| 1503 | /* |
| 1504 | * if we sucked the frag empty then we should free it, |
| 1505 | * if there are other frags here something is screwed up in hardware |
| 1506 | */ |
| 1507 | if (skb_frag_size(frag) == 0) { |
| 1508 | BUG_ON(skb_shinfo(skb)->nr_frags != 1); |
| 1509 | skb_shinfo(skb)->nr_frags = 0; |
| 1510 | __skb_frag_unref(frag); |
| 1511 | skb->truesize -= ixgbe_rx_bufsz(rx_ring); |
| 1512 | } |
| 1513 | |
| 1514 | /* if skb_pad returns an error the skb was freed */ |
| 1515 | if (unlikely(skb->len < 60)) { |
| 1516 | int pad_len = 60 - skb->len; |
| 1517 | |
| 1518 | if (skb_pad(skb, pad_len)) |
| 1519 | return true; |
| 1520 | __skb_put(skb, pad_len); |
| 1521 | } |
| 1522 | |
| 1523 | return false; |
| 1524 | } |
| 1525 | |
| 1526 | /** |
| 1527 | * ixgbe_can_reuse_page - determine if we can reuse a page |
| 1528 | * @rx_buffer: pointer to rx_buffer containing the page we want to reuse |
| 1529 | * |
| 1530 | * Returns true if page can be reused in another Rx buffer |
| 1531 | **/ |
| 1532 | static inline bool ixgbe_can_reuse_page(struct ixgbe_rx_buffer *rx_buffer) |
| 1533 | { |
| 1534 | struct page *page = rx_buffer->page; |
| 1535 | |
| 1536 | /* if we are only owner of page and it is local we can reuse it */ |
| 1537 | return likely(page_count(page) == 1) && |
| 1538 | likely(page_to_nid(page) == numa_node_id()); |
| 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1543 | * @rx_ring: rx descriptor ring to store buffers on |
| 1544 | * @old_buff: donor buffer to have page reused |
| 1545 | * |
| 1546 | * Syncronizes page for reuse by the adapter |
| 1547 | **/ |
| 1548 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1549 | struct ixgbe_rx_buffer *old_buff) |
| 1550 | { |
| 1551 | struct ixgbe_rx_buffer *new_buff; |
| 1552 | u16 nta = rx_ring->next_to_alloc; |
| 1553 | u16 bufsz = ixgbe_rx_bufsz(rx_ring); |
| 1554 | |
| 1555 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1556 | |
| 1557 | /* update, and store next to alloc */ |
| 1558 | nta++; |
| 1559 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1560 | |
| 1561 | /* transfer page from old buffer to new buffer */ |
| 1562 | new_buff->page = old_buff->page; |
| 1563 | new_buff->dma = old_buff->dma; |
| 1564 | |
| 1565 | /* flip page offset to other buffer and store to new_buff */ |
| 1566 | new_buff->page_offset = old_buff->page_offset ^ bufsz; |
| 1567 | |
| 1568 | /* sync the buffer for use by the device */ |
| 1569 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
| 1570 | new_buff->page_offset, bufsz, |
| 1571 | DMA_FROM_DEVICE); |
| 1572 | |
| 1573 | /* bump ref count on page before it is given to the stack */ |
| 1574 | get_page(new_buff->page); |
| 1575 | } |
| 1576 | |
| 1577 | /** |
| 1578 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1579 | * @rx_ring: rx descriptor ring to transact packets on |
| 1580 | * @rx_buffer: buffer containing page to add |
| 1581 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1582 | * @skb: sk_buff to place the data into |
| 1583 | * |
| 1584 | * This function is based on skb_add_rx_frag. I would have used that |
| 1585 | * function however it doesn't handle the truesize case correctly since we |
| 1586 | * are allocating more memory than might be used for a single receive. |
| 1587 | **/ |
| 1588 | static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
| 1589 | struct ixgbe_rx_buffer *rx_buffer, |
| 1590 | struct sk_buff *skb, int size) |
| 1591 | { |
| 1592 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
| 1593 | rx_buffer->page, rx_buffer->page_offset, |
| 1594 | size); |
| 1595 | skb->len += size; |
| 1596 | skb->data_len += size; |
| 1597 | skb->truesize += ixgbe_rx_bufsz(rx_ring); |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 1602 | * @q_vector: structure containing interrupt and ring information |
| 1603 | * @rx_ring: rx descriptor ring to transact packets on |
| 1604 | * @budget: Total limit on number of packets to process |
| 1605 | * |
| 1606 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 1607 | * processing. The advantage to this is that on systems that have |
| 1608 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 1609 | * it by maintaining the mapping of the page to the syste. |
| 1610 | * |
| 1611 | * Returns true if all work is completed without reaching budget |
| 1612 | **/ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1613 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1614 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1615 | int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1616 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1617 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 1618 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1619 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1620 | int ddp_bytes = 0; |
| 1621 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1622 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1623 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1624 | do { |
| 1625 | struct ixgbe_rx_buffer *rx_buffer; |
| 1626 | union ixgbe_adv_rx_desc *rx_desc; |
| 1627 | struct sk_buff *skb; |
| 1628 | struct page *page; |
| 1629 | u16 ntc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1630 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1631 | /* return some buffers to hardware, one at a time is too slow */ |
| 1632 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 1633 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1634 | cleaned_count = 0; |
| 1635 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1636 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1637 | ntc = rx_ring->next_to_clean; |
| 1638 | rx_desc = IXGBE_RX_DESC(rx_ring, ntc); |
| 1639 | rx_buffer = &rx_ring->rx_buffer_info[ntc]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1640 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1641 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) |
| 1642 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1643 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1644 | /* |
| 1645 | * This memory barrier is needed to keep us from reading |
| 1646 | * any other fields out of the rx_desc until we know the |
| 1647 | * RXD_STAT_DD bit is set |
| 1648 | */ |
| 1649 | rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1650 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1651 | page = rx_buffer->page; |
| 1652 | prefetchw(page); |
| 1653 | |
| 1654 | skb = rx_buffer->skb; |
| 1655 | |
| 1656 | if (likely(!skb)) { |
| 1657 | void *page_addr = page_address(page) + |
| 1658 | rx_buffer->page_offset; |
| 1659 | |
| 1660 | /* prefetch first cache line of first page */ |
| 1661 | prefetch(page_addr); |
| 1662 | #if L1_CACHE_BYTES < 128 |
| 1663 | prefetch(page_addr + L1_CACHE_BYTES); |
| 1664 | #endif |
| 1665 | |
| 1666 | /* allocate a skb to store the frags */ |
| 1667 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
| 1668 | IXGBE_RX_HDR_SIZE); |
| 1669 | if (unlikely(!skb)) { |
| 1670 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 1671 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1672 | } |
| 1673 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1674 | /* |
| 1675 | * we will be copying header into skb->data in |
| 1676 | * pskb_may_pull so it is in our interest to prefetch |
| 1677 | * it now to avoid a possible cache miss |
| 1678 | */ |
| 1679 | prefetchw(skb->data); |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1680 | |
| 1681 | /* |
| 1682 | * Delay unmapping of the first packet. It carries the |
| 1683 | * header information, HW may still access the header |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1684 | * after the writeback. Only unmap it when EOP is |
| 1685 | * reached |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1686 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1687 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1688 | } else { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1689 | /* we are reusing so sync this buffer for CPU use */ |
| 1690 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1691 | rx_buffer->dma, |
| 1692 | rx_buffer->page_offset, |
| 1693 | ixgbe_rx_bufsz(rx_ring), |
| 1694 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1697 | /* pull page into skb */ |
| 1698 | ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, |
| 1699 | le16_to_cpu(rx_desc->wb.upper.length)); |
| 1700 | |
| 1701 | if (ixgbe_can_reuse_page(rx_buffer)) { |
| 1702 | /* hand second half of page back to the ring */ |
| 1703 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 1704 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 1705 | /* the page has been released from the ring */ |
| 1706 | IXGBE_CB(skb)->page_released = true; |
| 1707 | } else { |
| 1708 | /* we are not reusing the buffer so unmap it */ |
| 1709 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 1710 | ixgbe_rx_pg_size(rx_ring), |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1711 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1714 | /* clear contents of buffer_info */ |
| 1715 | rx_buffer->skb = NULL; |
| 1716 | rx_buffer->dma = 0; |
| 1717 | rx_buffer->page = NULL; |
| 1718 | |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 1719 | ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb); |
| 1720 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1721 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1722 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1723 | /* place incomplete frames back on ring for completion */ |
| 1724 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 1725 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1726 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1727 | /* verify the packet layout is correct */ |
| 1728 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 1729 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1730 | |
| 1731 | /* probably a little skewed due to removing CRC */ |
| 1732 | total_rx_bytes += skb->len; |
| 1733 | total_rx_packets++; |
| 1734 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1735 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 1736 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 1737 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1738 | #ifdef IXGBE_FCOE |
| 1739 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1740 | if (ixgbe_rx_is_fcoe(adapter, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1741 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1742 | if (!ddp_bytes) { |
| 1743 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1744 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1745 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1746 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1747 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1748 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1749 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1750 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1751 | /* update budget accounting */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1752 | budget--; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1753 | } while (likely(budget)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1754 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1755 | #ifdef IXGBE_FCOE |
| 1756 | /* include DDPed FCoE data */ |
| 1757 | if (ddp_bytes > 0) { |
| 1758 | unsigned int mss; |
| 1759 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1760 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1761 | sizeof(struct fc_frame_header) - |
| 1762 | sizeof(struct fcoe_crc_eof); |
| 1763 | if (mss > 512) |
| 1764 | mss &= ~511; |
| 1765 | total_rx_bytes += ddp_bytes; |
| 1766 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1767 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1768 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1769 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1770 | u64_stats_update_begin(&rx_ring->syncp); |
| 1771 | rx_ring->stats.packets += total_rx_packets; |
| 1772 | rx_ring->stats.bytes += total_rx_bytes; |
| 1773 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1774 | q_vector->rx.total_packets += total_rx_packets; |
| 1775 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1776 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1777 | if (cleaned_count) |
| 1778 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1779 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 1780 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1783 | /** |
| 1784 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1785 | * @adapter: board private structure |
| 1786 | * |
| 1787 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1788 | * interrupts. |
| 1789 | **/ |
| 1790 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1791 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1792 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1793 | int q_vectors, v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1794 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1795 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1796 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1797 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 1798 | /* Populate MSIX to EITR Select */ |
| 1799 | if (adapter->num_vfs > 32) { |
| 1800 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 1801 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 1802 | } |
| 1803 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1804 | /* |
| 1805 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1806 | * corresponding register. |
| 1807 | */ |
| 1808 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1809 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1810 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1811 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1812 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1813 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1814 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1815 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1816 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1817 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1818 | if (q_vector->tx.ring && !q_vector->rx.ring) { |
| 1819 | /* tx only vector */ |
| 1820 | if (adapter->tx_itr_setting == 1) |
| 1821 | q_vector->itr = IXGBE_10K_ITR; |
| 1822 | else |
| 1823 | q_vector->itr = adapter->tx_itr_setting; |
| 1824 | } else { |
| 1825 | /* rx or rx/tx vector */ |
| 1826 | if (adapter->rx_itr_setting == 1) |
| 1827 | q_vector->itr = IXGBE_20K_ITR; |
| 1828 | else |
| 1829 | q_vector->itr = adapter->rx_itr_setting; |
| 1830 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1831 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1832 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1835 | switch (adapter->hw.mac.type) { |
| 1836 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1837 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1838 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1839 | break; |
| 1840 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1841 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1842 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1843 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1844 | default: |
| 1845 | break; |
| 1846 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1847 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1848 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1849 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1850 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1851 | mask &= ~(IXGBE_EIMS_OTHER | |
| 1852 | IXGBE_EIMS_MAILBOX | |
| 1853 | IXGBE_EIMS_LSC); |
| 1854 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1855 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1858 | enum latency_range { |
| 1859 | lowest_latency = 0, |
| 1860 | low_latency = 1, |
| 1861 | bulk_latency = 2, |
| 1862 | latency_invalid = 255 |
| 1863 | }; |
| 1864 | |
| 1865 | /** |
| 1866 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1867 | * @q_vector: structure containing interrupt and ring information |
| 1868 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1869 | * |
| 1870 | * Stores a new ITR value based on packets and byte |
| 1871 | * counts during the last interrupt. The advantage of per interrupt |
| 1872 | * computation is faster updates and more accurate ITR for the current |
| 1873 | * traffic pattern. Constants in this function were computed |
| 1874 | * based on theoretical maximum wire speed and thresholds were set based |
| 1875 | * on testing data as well as attempting to minimize response time |
| 1876 | * while increasing bulk throughput. |
| 1877 | * this functionality is controlled by the InterruptThrottleRate module |
| 1878 | * parameter (see ixgbe_param.c) |
| 1879 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1880 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 1881 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1882 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1883 | int bytes = ring_container->total_bytes; |
| 1884 | int packets = ring_container->total_packets; |
| 1885 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1886 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1887 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1888 | |
| 1889 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1890 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1891 | |
| 1892 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1893 | * 0-10MB/s lowest (100000 ints/s) |
| 1894 | * 10-20MB/s low (20000 ints/s) |
| 1895 | * 20-1249MB/s bulk (8000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1896 | */ |
| 1897 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1898 | timepassed_us = q_vector->itr >> 2; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1899 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1900 | |
| 1901 | switch (itr_setting) { |
| 1902 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1903 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1904 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1905 | break; |
| 1906 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1907 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1908 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1909 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1910 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1911 | break; |
| 1912 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 1913 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1914 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1915 | break; |
| 1916 | } |
| 1917 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1918 | /* clear work counters since we have the values we need */ |
| 1919 | ring_container->total_bytes = 0; |
| 1920 | ring_container->total_packets = 0; |
| 1921 | |
| 1922 | /* write updated itr to ring container */ |
| 1923 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1924 | } |
| 1925 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1926 | /** |
| 1927 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1928 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1929 | * |
| 1930 | * This function is made to be called by ethtool and by the driver |
| 1931 | * when it needs to update EITR registers at runtime. Hardware |
| 1932 | * specific quirks/differences are taken care of here. |
| 1933 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1934 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1935 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1936 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1937 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1938 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 1939 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1940 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1941 | switch (adapter->hw.mac.type) { |
| 1942 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1943 | /* must write high and low 16 bits to reset counter */ |
| 1944 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1945 | break; |
| 1946 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1947 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1948 | /* |
| 1949 | * set the WDIS bit to not clear the timer bits and cause an |
| 1950 | * immediate assertion of the interrupt |
| 1951 | */ |
| 1952 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1953 | break; |
| 1954 | default: |
| 1955 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1956 | } |
| 1957 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1958 | } |
| 1959 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1960 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1961 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1962 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1963 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1964 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1965 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 1966 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1967 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1968 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1969 | |
| 1970 | switch (current_itr) { |
| 1971 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1972 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1973 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1974 | break; |
| 1975 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1976 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1977 | break; |
| 1978 | case bulk_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1979 | new_itr = IXGBE_8K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1980 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1981 | default: |
| 1982 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1983 | } |
| 1984 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1985 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1986 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 1987 | new_itr = (10 * new_itr * q_vector->itr) / |
| 1988 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1989 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1990 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 1991 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1992 | |
| 1993 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1994 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1995 | } |
| 1996 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1997 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 1998 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1999 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2000 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2001 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2002 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2003 | struct ixgbe_hw *hw = &adapter->hw; |
| 2004 | u32 eicr = adapter->interrupt_event; |
| 2005 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2006 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2007 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2008 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2009 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2010 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2011 | return; |
| 2012 | |
| 2013 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2014 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2015 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2016 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2017 | /* |
| 2018 | * Since the warning interrupt is for both ports |
| 2019 | * we don't have to check if: |
| 2020 | * - This interrupt wasn't for our port. |
| 2021 | * - We may have missed the interrupt so always have to |
| 2022 | * check if we got a LSC |
| 2023 | */ |
| 2024 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 2025 | !(eicr & IXGBE_EICR_LSC)) |
| 2026 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2027 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2028 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
| 2029 | u32 autoneg; |
| 2030 | bool link_up = false; |
| 2031 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2032 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2033 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2034 | if (link_up) |
| 2035 | return; |
| 2036 | } |
| 2037 | |
| 2038 | /* Check if this is not due to overtemp */ |
| 2039 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2040 | return; |
| 2041 | |
| 2042 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2043 | default: |
| 2044 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 2045 | return; |
| 2046 | break; |
| 2047 | } |
| 2048 | e_crit(drv, |
| 2049 | "Network adapter has been stopped because it has over heated. " |
| 2050 | "Restart the computer. If the problem persists, " |
| 2051 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2052 | |
| 2053 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2056 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2057 | { |
| 2058 | struct ixgbe_hw *hw = &adapter->hw; |
| 2059 | |
| 2060 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 2061 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2062 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2063 | /* write to clear the interrupt */ |
| 2064 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 2065 | } |
| 2066 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2067 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2068 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2069 | { |
| 2070 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2071 | return; |
| 2072 | |
| 2073 | switch (adapter->hw.mac.type) { |
| 2074 | case ixgbe_mac_82599EB: |
| 2075 | /* |
| 2076 | * Need to check link state so complete overtemp check |
| 2077 | * on service task |
| 2078 | */ |
| 2079 | if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) && |
| 2080 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2081 | adapter->interrupt_event = eicr; |
| 2082 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2083 | ixgbe_service_event_schedule(adapter); |
| 2084 | return; |
| 2085 | } |
| 2086 | return; |
| 2087 | case ixgbe_mac_X540: |
| 2088 | if (!(eicr & IXGBE_EICR_TS)) |
| 2089 | return; |
| 2090 | break; |
| 2091 | default: |
| 2092 | return; |
| 2093 | } |
| 2094 | |
| 2095 | e_crit(drv, |
| 2096 | "Network adapter has been stopped because it has over heated. " |
| 2097 | "Restart the computer. If the problem persists, " |
| 2098 | "power off the system and replace the adapter\n"); |
| 2099 | } |
| 2100 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2101 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2102 | { |
| 2103 | struct ixgbe_hw *hw = &adapter->hw; |
| 2104 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2105 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 2106 | /* Clear the interrupt */ |
| 2107 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2108 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2109 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 2110 | ixgbe_service_event_schedule(adapter); |
| 2111 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2112 | } |
| 2113 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2114 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 2115 | /* Clear the interrupt */ |
| 2116 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2117 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2118 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2119 | ixgbe_service_event_schedule(adapter); |
| 2120 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2121 | } |
| 2122 | } |
| 2123 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2124 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2125 | { |
| 2126 | struct ixgbe_hw *hw = &adapter->hw; |
| 2127 | |
| 2128 | adapter->lsc_int++; |
| 2129 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2130 | adapter->link_check_timeout = jiffies; |
| 2131 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2132 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2133 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2134 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2135 | } |
| 2136 | } |
| 2137 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2138 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2139 | u64 qmask) |
| 2140 | { |
| 2141 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2142 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2143 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2144 | switch (hw->mac.type) { |
| 2145 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2146 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2147 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2148 | break; |
| 2149 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2150 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2151 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2152 | if (mask) |
| 2153 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2154 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2155 | if (mask) |
| 2156 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2157 | break; |
| 2158 | default: |
| 2159 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2160 | } |
| 2161 | /* skip the flush */ |
| 2162 | } |
| 2163 | |
| 2164 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2165 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2166 | { |
| 2167 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2168 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2169 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2170 | switch (hw->mac.type) { |
| 2171 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2172 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2173 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2174 | break; |
| 2175 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2176 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2177 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2178 | if (mask) |
| 2179 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2180 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2181 | if (mask) |
| 2182 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2183 | break; |
| 2184 | default: |
| 2185 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2186 | } |
| 2187 | /* skip the flush */ |
| 2188 | } |
| 2189 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2190 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2191 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2192 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2193 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2194 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2195 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2196 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2197 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2198 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2199 | /* don't reenable LSC while waiting for link */ |
| 2200 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2201 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2202 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2203 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2204 | switch (adapter->hw.mac.type) { |
| 2205 | case ixgbe_mac_82599EB: |
| 2206 | mask |= IXGBE_EIMS_GPI_SDP0; |
| 2207 | break; |
| 2208 | case ixgbe_mac_X540: |
| 2209 | mask |= IXGBE_EIMS_TS; |
| 2210 | break; |
| 2211 | default: |
| 2212 | break; |
| 2213 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2214 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2215 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2216 | switch (adapter->hw.mac.type) { |
| 2217 | case ixgbe_mac_82599EB: |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2218 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2219 | mask |= IXGBE_EIMS_GPI_SDP2; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2220 | case ixgbe_mac_X540: |
| 2221 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2222 | mask |= IXGBE_EIMS_MAILBOX; |
| 2223 | break; |
| 2224 | default: |
| 2225 | break; |
| 2226 | } |
| 2227 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2228 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2229 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2230 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2231 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2232 | if (queues) |
| 2233 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2234 | if (flush) |
| 2235 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2238 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2239 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2240 | struct ixgbe_adapter *adapter = data; |
| 2241 | struct ixgbe_hw *hw = &adapter->hw; |
| 2242 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2243 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2244 | /* |
| 2245 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2246 | * of clear-by-read. Reading with EICS will return the |
| 2247 | * interrupt causes without clearing, which later be done |
| 2248 | * with the write to EICR. |
| 2249 | */ |
| 2250 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 2251 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2252 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2253 | if (eicr & IXGBE_EICR_LSC) |
| 2254 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2255 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2256 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2257 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2258 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2259 | switch (hw->mac.type) { |
| 2260 | case ixgbe_mac_82599EB: |
| 2261 | case ixgbe_mac_X540: |
| 2262 | if (eicr & IXGBE_EICR_ECC) |
| 2263 | e_info(link, "Received unrecoverable ECC Err, please " |
| 2264 | "reboot\n"); |
| 2265 | /* Handle Flow Director Full threshold interrupt */ |
| 2266 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2267 | int reinit_count = 0; |
| 2268 | int i; |
| 2269 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2270 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2271 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2272 | &ring->state)) |
| 2273 | reinit_count++; |
| 2274 | } |
| 2275 | if (reinit_count) { |
| 2276 | /* no more flow director interrupts until after init */ |
| 2277 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2278 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2279 | ixgbe_service_event_schedule(adapter); |
| 2280 | } |
| 2281 | } |
| 2282 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2283 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2284 | break; |
| 2285 | default: |
| 2286 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2289 | ixgbe_check_fan_failure(adapter, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2290 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2291 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2292 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2293 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2294 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2295 | return IRQ_HANDLED; |
| 2296 | } |
| 2297 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2298 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2299 | { |
| 2300 | struct ixgbe_q_vector *q_vector = data; |
| 2301 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2302 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2303 | |
| 2304 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 2305 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2306 | |
| 2307 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2310 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2311 | * ixgbe_poll - NAPI Rx polling callback |
| 2312 | * @napi: structure for representing this polling device |
| 2313 | * @budget: how many packets driver is allowed to clean |
| 2314 | * |
| 2315 | * This function is used for legacy and MSI, NAPI mode |
| 2316 | **/ |
| 2317 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
| 2318 | { |
| 2319 | struct ixgbe_q_vector *q_vector = |
| 2320 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2321 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2322 | struct ixgbe_ring *ring; |
| 2323 | int per_ring_budget; |
| 2324 | bool clean_complete = true; |
| 2325 | |
| 2326 | #ifdef CONFIG_IXGBE_DCA |
| 2327 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2328 | ixgbe_update_dca(q_vector); |
| 2329 | #endif |
| 2330 | |
| 2331 | ixgbe_for_each_ring(ring, q_vector->tx) |
| 2332 | clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring); |
| 2333 | |
| 2334 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2335 | * the budget to go below 1 because we'll exit polling */ |
| 2336 | if (q_vector->rx.count > 1) |
| 2337 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2338 | else |
| 2339 | per_ring_budget = budget; |
| 2340 | |
| 2341 | ixgbe_for_each_ring(ring, q_vector->rx) |
| 2342 | clean_complete &= ixgbe_clean_rx_irq(q_vector, ring, |
| 2343 | per_ring_budget); |
| 2344 | |
| 2345 | /* If all work not completed, return budget and keep polling */ |
| 2346 | if (!clean_complete) |
| 2347 | return budget; |
| 2348 | |
| 2349 | /* all work done, exit the polling mode */ |
| 2350 | napi_complete(napi); |
| 2351 | if (adapter->rx_itr_setting & 1) |
| 2352 | ixgbe_set_itr(q_vector); |
| 2353 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2354 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 2355 | |
| 2356 | return 0; |
| 2357 | } |
| 2358 | |
| 2359 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2360 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2361 | * @adapter: board private structure |
| 2362 | * |
| 2363 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2364 | * interrupts from the kernel. |
| 2365 | **/ |
| 2366 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2367 | { |
| 2368 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2369 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2370 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2371 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2372 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2373 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2374 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2375 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2376 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2377 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2378 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2379 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2380 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2381 | } else if (q_vector->rx.ring) { |
| 2382 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2383 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2384 | } else if (q_vector->tx.ring) { |
| 2385 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2386 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2387 | } else { |
| 2388 | /* skip this unused q_vector */ |
| 2389 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2390 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2391 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2392 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2393 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2394 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2395 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2396 | goto free_queue_irqs; |
| 2397 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2398 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2399 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2400 | /* assign the mask for this irq */ |
| 2401 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2402 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2403 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2404 | } |
| 2405 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2406 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2407 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2408 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2409 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2410 | goto free_queue_irqs; |
| 2411 | } |
| 2412 | |
| 2413 | return 0; |
| 2414 | |
| 2415 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2416 | while (vector) { |
| 2417 | vector--; |
| 2418 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2419 | NULL); |
| 2420 | free_irq(adapter->msix_entries[vector].vector, |
| 2421 | adapter->q_vector[vector]); |
| 2422 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2423 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2424 | pci_disable_msix(adapter->pdev); |
| 2425 | kfree(adapter->msix_entries); |
| 2426 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2427 | return err; |
| 2428 | } |
| 2429 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2430 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2431 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2432 | * @irq: interrupt number |
| 2433 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2434 | **/ |
| 2435 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2436 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2437 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2438 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2439 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2440 | u32 eicr; |
| 2441 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2442 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2443 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2444 | * before the read of EICR. |
| 2445 | */ |
| 2446 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2447 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2448 | /* 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] | 2449 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2450 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2451 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2452 | /* |
| 2453 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2454 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2455 | * have disabled interrupts due to EIAM |
| 2456 | * finish the workaround of silicon errata on 82598. Unmask |
| 2457 | * the interrupt that we masked before the EICR read. |
| 2458 | */ |
| 2459 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2460 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2461 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2462 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2463 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2464 | if (eicr & IXGBE_EICR_LSC) |
| 2465 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2466 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2467 | switch (hw->mac.type) { |
| 2468 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2469 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 2470 | /* Fall through */ |
| 2471 | case ixgbe_mac_X540: |
| 2472 | if (eicr & IXGBE_EICR_ECC) |
| 2473 | e_info(link, "Received unrecoverable ECC err, please " |
| 2474 | "reboot\n"); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2475 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2476 | break; |
| 2477 | default: |
| 2478 | break; |
| 2479 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2480 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2481 | ixgbe_check_fan_failure(adapter, eicr); |
| 2482 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 2483 | /* would disable interrupts here but EIAM disabled it */ |
| 2484 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2485 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2486 | /* |
| 2487 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2488 | * ixgbe_poll will re-enable the queue interrupts |
| 2489 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2490 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2491 | ixgbe_irq_enable(adapter, false, false); |
| 2492 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2493 | return IRQ_HANDLED; |
| 2494 | } |
| 2495 | |
| 2496 | /** |
| 2497 | * ixgbe_request_irq - initialize interrupts |
| 2498 | * @adapter: board private structure |
| 2499 | * |
| 2500 | * Attempts to configure interrupts using the best available |
| 2501 | * capabilities of the hardware and kernel. |
| 2502 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2503 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2504 | { |
| 2505 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2506 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2507 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2508 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2509 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2510 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2511 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2512 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2513 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2514 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2515 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2516 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2517 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2518 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2519 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2520 | return err; |
| 2521 | } |
| 2522 | |
| 2523 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2524 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2525 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2526 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2527 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2528 | q_vectors = adapter->num_msix_vectors; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2529 | i = q_vectors - 1; |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2530 | free_irq(adapter->msix_entries[i].vector, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2531 | i--; |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2532 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2533 | for (; i >= 0; i--) { |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2534 | /* free only the irqs that were actually requested */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2535 | if (!adapter->q_vector[i]->rx.ring && |
| 2536 | !adapter->q_vector[i]->tx.ring) |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2537 | continue; |
| 2538 | |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2539 | /* clear the affinity_mask in the IRQ descriptor */ |
| 2540 | irq_set_affinity_hint(adapter->msix_entries[i].vector, |
| 2541 | NULL); |
| 2542 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2543 | free_irq(adapter->msix_entries[i].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2544 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2545 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2546 | } else { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2547 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2552 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2553 | * @adapter: board private structure |
| 2554 | **/ |
| 2555 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2556 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2557 | switch (adapter->hw.mac.type) { |
| 2558 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2559 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2560 | break; |
| 2561 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2562 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2563 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2564 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2565 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2566 | break; |
| 2567 | default: |
| 2568 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2569 | } |
| 2570 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2571 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2572 | int i; |
| 2573 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 2574 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2575 | } else { |
| 2576 | synchronize_irq(adapter->pdev->irq); |
| 2577 | } |
| 2578 | } |
| 2579 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2580 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2581 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2582 | * |
| 2583 | **/ |
| 2584 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2585 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2586 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2587 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2588 | /* rx/tx vector */ |
| 2589 | if (adapter->rx_itr_setting == 1) |
| 2590 | q_vector->itr = IXGBE_20K_ITR; |
| 2591 | else |
| 2592 | q_vector->itr = adapter->rx_itr_setting; |
| 2593 | |
| 2594 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2595 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2596 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2597 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2598 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2599 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2602 | /** |
| 2603 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2604 | * @adapter: board private structure |
| 2605 | * @ring: structure containing ring specific data |
| 2606 | * |
| 2607 | * Configure the Tx descriptor ring after a reset. |
| 2608 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2609 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2610 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2611 | { |
| 2612 | struct ixgbe_hw *hw = &adapter->hw; |
| 2613 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2614 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2615 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2616 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2617 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2618 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2619 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2620 | IXGBE_WRITE_FLUSH(hw); |
| 2621 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2622 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2623 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2624 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2625 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2626 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2627 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2628 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2629 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2630 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2631 | /* |
| 2632 | * set WTHRESH to encourage burst writeback, it should not be set |
| 2633 | * higher than 1 when ITR is 0 as it could cause false TX hangs |
| 2634 | * |
| 2635 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 2636 | * to or less than the number of on chip descriptors, which is |
| 2637 | * currently 40. |
| 2638 | */ |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2639 | if (!ring->q_vector || (ring->q_vector->itr < 8)) |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2640 | txdctl |= (1 << 16); /* WTHRESH = 1 */ |
| 2641 | else |
| 2642 | txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 2643 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2644 | /* |
| 2645 | * Setting PTHRESH to 32 both improves performance |
| 2646 | * and avoids a TX hang with DFP enabled |
| 2647 | */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2648 | txdctl |= (1 << 8) | /* HTHRESH = 1 */ |
| 2649 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2650 | |
| 2651 | /* reinitialize flowdirector state */ |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2652 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2653 | adapter->atr_sample_rate) { |
| 2654 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2655 | ring->atr_count = 0; |
| 2656 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2657 | } else { |
| 2658 | ring->atr_sample_rate = 0; |
| 2659 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2660 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2661 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2662 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2663 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2664 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2665 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 2666 | netdev_tx_reset_queue(txring_txq(ring)); |
| 2667 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2668 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2669 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2670 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2671 | return; |
| 2672 | |
| 2673 | /* poll to verify queue is enabled */ |
| 2674 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2675 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2676 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2677 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2678 | if (!wait_loop) |
| 2679 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2682 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2683 | { |
| 2684 | struct ixgbe_hw *hw = &adapter->hw; |
| 2685 | u32 rttdcs; |
John Fastabend | 72a32f1 | 2011-04-26 07:25:58 +0000 | [diff] [blame] | 2686 | u32 reg; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2687 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2688 | |
| 2689 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2690 | return; |
| 2691 | |
| 2692 | /* disable the arbiter while setting MTQC */ |
| 2693 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2694 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2695 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2696 | |
| 2697 | /* set transmit pool layout */ |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2698 | switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2699 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2700 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2701 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2702 | break; |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2703 | default: |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2704 | if (!tcs) |
| 2705 | reg = IXGBE_MTQC_64Q_1PB; |
| 2706 | else if (tcs <= 4) |
| 2707 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2708 | else |
| 2709 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2710 | |
| 2711 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg); |
| 2712 | |
| 2713 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 2714 | if (tcs) { |
| 2715 | reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 2716 | reg |= IXGBE_SECTX_DCB; |
| 2717 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg); |
| 2718 | } |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2719 | break; |
| 2720 | } |
| 2721 | |
| 2722 | /* re-enable the arbiter */ |
| 2723 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2724 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2725 | } |
| 2726 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2727 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2728 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2729 | * @adapter: board private structure |
| 2730 | * |
| 2731 | * Configure the Tx unit of the MAC after a reset. |
| 2732 | **/ |
| 2733 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2734 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2735 | struct ixgbe_hw *hw = &adapter->hw; |
| 2736 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2737 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2738 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2739 | ixgbe_setup_mtqc(adapter); |
| 2740 | |
| 2741 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2742 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2743 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2744 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2745 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2746 | } |
| 2747 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2748 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2749 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2750 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2753 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2754 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2755 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2756 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2757 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2758 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2759 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2760 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2761 | switch (adapter->hw.mac.type) { |
| 2762 | case ixgbe_mac_82598EB: { |
| 2763 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
| 2764 | const int mask = feature[RING_F_RSS].mask; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2765 | reg_idx = reg_idx & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2766 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2767 | break; |
| 2768 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2769 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2770 | default: |
| 2771 | break; |
| 2772 | } |
| 2773 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2774 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2775 | |
| 2776 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2777 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2778 | if (adapter->num_vfs) |
| 2779 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2780 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2781 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2782 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2783 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2784 | #if PAGE_SIZE > IXGBE_MAX_RXBUFFER |
| 2785 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2786 | #else |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2787 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2788 | #endif |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2789 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2790 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2791 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2792 | } |
| 2793 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2794 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2795 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2796 | struct ixgbe_hw *hw = &adapter->hw; |
| 2797 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2798 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2799 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2800 | u32 mrqc = 0, reta = 0; |
| 2801 | u32 rxcsum; |
| 2802 | int i, j; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2803 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2804 | int maxq = adapter->ring_feature[RING_F_RSS].indices; |
| 2805 | |
| 2806 | if (tcs) |
| 2807 | maxq = min(maxq, adapter->num_tx_queues / tcs); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2808 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2809 | /* Fill out hash function seeds */ |
| 2810 | for (i = 0; i < 10; i++) |
| 2811 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2812 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2813 | /* Fill out redirection table */ |
| 2814 | for (i = 0, j = 0; i < 128; i++, j++) { |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2815 | if (j == maxq) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2816 | j = 0; |
| 2817 | /* reta = 4-byte sliding window of |
| 2818 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2819 | reta = (reta << 8) | (j * 0x11); |
| 2820 | if ((i & 3) == 3) |
| 2821 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 2822 | } |
| 2823 | |
| 2824 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 2825 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2826 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2827 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 2828 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2829 | if (adapter->hw.mac.type == ixgbe_mac_82598EB && |
| 2830 | (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2831 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2832 | } else { |
| 2833 | int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2834 | | IXGBE_FLAG_SRIOV_ENABLED); |
| 2835 | |
| 2836 | switch (mask) { |
| 2837 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2838 | if (!tcs) |
| 2839 | mrqc = IXGBE_MRQC_RSSEN; |
| 2840 | else if (tcs <= 4) |
| 2841 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 2842 | else |
| 2843 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 2844 | break; |
| 2845 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2846 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2847 | break; |
| 2848 | default: |
| 2849 | break; |
| 2850 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2853 | /* Perform hash on these packet types */ |
| 2854 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2855 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2856 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2857 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2858 | |
| 2859 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2862 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2863 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2864 | * @adapter: address of board private structure |
| 2865 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2866 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 2867 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2868 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2869 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2870 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2871 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2872 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2873 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2874 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2875 | return; |
| 2876 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2877 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2878 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2879 | /* |
| 2880 | * we must limit the number of descriptors so that the |
| 2881 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 2882 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2883 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2884 | #if (PAGE_SIZE <= 8192) |
| 2885 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2886 | #elif (PAGE_SIZE <= 16384) |
| 2887 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2888 | #else |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2889 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2890 | #endif |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2891 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2892 | } |
| 2893 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2894 | /** |
| 2895 | * ixgbe_set_uta - Set unicast filter table address |
| 2896 | * @adapter: board private structure |
| 2897 | * |
| 2898 | * The unicast table address is a register array of 32-bit registers. |
| 2899 | * The table is meant to be used in a way similar to how the MTA is used |
| 2900 | * however due to certain limitations in the hardware it is necessary to |
| 2901 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 2902 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
| 2903 | **/ |
| 2904 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) |
| 2905 | { |
| 2906 | struct ixgbe_hw *hw = &adapter->hw; |
| 2907 | int i; |
| 2908 | |
| 2909 | /* The UTA table only exists on 82599 hardware and newer */ |
| 2910 | if (hw->mac.type < ixgbe_mac_82599EB) |
| 2911 | return; |
| 2912 | |
| 2913 | /* we only need to do this if VMDq is enabled */ |
| 2914 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2915 | return; |
| 2916 | |
| 2917 | for (i = 0; i < 128; i++) |
| 2918 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); |
| 2919 | } |
| 2920 | |
| 2921 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2922 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2923 | struct ixgbe_ring *ring) |
| 2924 | { |
| 2925 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2926 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2927 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2928 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2929 | |
| 2930 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2931 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2932 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2933 | return; |
| 2934 | |
| 2935 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2936 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2937 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2938 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2939 | |
| 2940 | if (!wait_loop) { |
| 2941 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 2942 | "the polling period\n", reg_idx); |
| 2943 | } |
| 2944 | } |
| 2945 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2946 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 2947 | struct ixgbe_ring *ring) |
| 2948 | { |
| 2949 | struct ixgbe_hw *hw = &adapter->hw; |
| 2950 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2951 | u32 rxdctl; |
| 2952 | u8 reg_idx = ring->reg_idx; |
| 2953 | |
| 2954 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2955 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 2956 | |
| 2957 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 2958 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2959 | |
| 2960 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2961 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2962 | return; |
| 2963 | |
| 2964 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 2965 | do { |
| 2966 | udelay(10); |
| 2967 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2968 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2969 | |
| 2970 | if (!wait_loop) { |
| 2971 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 2972 | "the polling period\n", reg_idx); |
| 2973 | } |
| 2974 | } |
| 2975 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2976 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 2977 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2978 | { |
| 2979 | struct ixgbe_hw *hw = &adapter->hw; |
| 2980 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2981 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2982 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2983 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2984 | /* disable queue to avoid issues while updating state */ |
| 2985 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2986 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2987 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2988 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 2989 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 2990 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 2991 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 2992 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 2993 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2994 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2995 | |
| 2996 | ixgbe_configure_srrctl(adapter, ring); |
| 2997 | ixgbe_configure_rscctl(adapter, ring); |
| 2998 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 2999 | /* If operating in IOV mode set RLPML for X540 */ |
| 3000 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 3001 | hw->mac.type == ixgbe_mac_X540) { |
| 3002 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 3003 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 3004 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 3005 | } |
| 3006 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3007 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3008 | /* |
| 3009 | * enable cache line friendly hardware writes: |
| 3010 | * PTHRESH=32 descriptors (half the internal cache), |
| 3011 | * this also removes ugly rx_no_buffer_count increment |
| 3012 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3013 | * WTHRESH=8 burst writeback up to two cache lines |
| 3014 | */ |
| 3015 | rxdctl &= ~0x3FFFFF; |
| 3016 | rxdctl |= 0x080420; |
| 3017 | } |
| 3018 | |
| 3019 | /* enable receive descriptor ring */ |
| 3020 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3021 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3022 | |
| 3023 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3024 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3025 | } |
| 3026 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3027 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3028 | { |
| 3029 | struct ixgbe_hw *hw = &adapter->hw; |
| 3030 | int p; |
| 3031 | |
| 3032 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3033 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3034 | IXGBE_PSRTYPE_UDPHDR | |
| 3035 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3036 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3037 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3038 | |
| 3039 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3040 | return; |
| 3041 | |
| 3042 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) |
| 3043 | psrtype |= (adapter->num_rx_queues_per_pool << 29); |
| 3044 | |
| 3045 | for (p = 0; p < adapter->num_rx_pools; p++) |
| 3046 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), |
| 3047 | psrtype); |
| 3048 | } |
| 3049 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3050 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3051 | { |
| 3052 | struct ixgbe_hw *hw = &adapter->hw; |
| 3053 | u32 gcr_ext; |
| 3054 | u32 vt_reg_bits; |
| 3055 | u32 reg_offset, vf_shift; |
| 3056 | u32 vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3057 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3058 | |
| 3059 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3060 | return; |
| 3061 | |
| 3062 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 3063 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; |
| 3064 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); |
| 3065 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 3066 | |
| 3067 | vf_shift = adapter->num_vfs % 32; |
Greg Rose | 4cd6923 | 2012-01-25 07:59:37 +0000 | [diff] [blame] | 3068 | reg_offset = (adapter->num_vfs >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3069 | |
| 3070 | /* Enable only the PF's pool for Tx/Rx */ |
| 3071 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 3072 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); |
| 3073 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 3074 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); |
| 3075 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 3076 | |
| 3077 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
| 3078 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 3079 | |
| 3080 | /* |
| 3081 | * Set up VF register offsets for selected VT Mode, |
| 3082 | * i.e. 32 or 64 VFs for SR-IOV |
| 3083 | */ |
| 3084 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3085 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; |
| 3086 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; |
| 3087 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3088 | |
| 3089 | /* enable Tx loopback for VF/PF communication */ |
| 3090 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3091 | /* Enable MAC Anti-Spoofing */ |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3092 | hw->mac.ops.set_mac_anti_spoofing(hw, |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3093 | (adapter->num_vfs != 0), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3094 | adapter->num_vfs); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3095 | /* For VFs that have spoof checking turned off */ |
| 3096 | for (i = 0; i < adapter->num_vfs; i++) { |
| 3097 | if (!adapter->vfinfo[i].spoofchk_enabled) |
| 3098 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false); |
| 3099 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3100 | } |
| 3101 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3102 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3103 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3104 | struct ixgbe_hw *hw = &adapter->hw; |
| 3105 | struct net_device *netdev = adapter->netdev; |
| 3106 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3107 | struct ixgbe_ring *rx_ring; |
| 3108 | int i; |
| 3109 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3110 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3111 | #ifdef IXGBE_FCOE |
| 3112 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3113 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3114 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3115 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3116 | |
| 3117 | #endif /* IXGBE_FCOE */ |
| 3118 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3119 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3120 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3121 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3122 | |
| 3123 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
Alexander Duyck | 919e78a | 2011-08-26 09:52:38 +0000 | [diff] [blame] | 3126 | /* MHADD will allow an extra 4 bytes past for vlan tagged frames */ |
| 3127 | max_frame += VLAN_HLEN; |
| 3128 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3129 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3130 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3131 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3132 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3133 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3134 | /* |
| 3135 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3136 | * the Base and Length of the Rx Descriptor Ring |
| 3137 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3138 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3139 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3140 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3141 | set_ring_rsc_enabled(rx_ring); |
| 3142 | else |
| 3143 | clear_ring_rsc_enabled(rx_ring); |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3144 | #ifdef IXGBE_FCOE |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3145 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3146 | struct ixgbe_ring_feature *f; |
| 3147 | f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3148 | if ((i >= f->mask) && (i < f->mask + f->indices)) |
| 3149 | set_bit(__IXGBE_RX_FCOE_BUFSZ, &rx_ring->state); |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3150 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3151 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3152 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3155 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3156 | { |
| 3157 | struct ixgbe_hw *hw = &adapter->hw; |
| 3158 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3159 | |
| 3160 | switch (hw->mac.type) { |
| 3161 | case ixgbe_mac_82598EB: |
| 3162 | /* |
| 3163 | * For VMDq support of different descriptor types or |
| 3164 | * buffer sizes through the use of multiple SRRCTL |
| 3165 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3166 | * |
| 3167 | * also, the manual doesn't mention it clearly but DCA hints |
| 3168 | * will only use queue 0's tags unless this bit is set. Side |
| 3169 | * effects of setting this bit are only that SRRCTL must be |
| 3170 | * fully programmed [0..15] |
| 3171 | */ |
| 3172 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3173 | break; |
| 3174 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3175 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3176 | /* Disable RSC for ACK packets */ |
| 3177 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3178 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3179 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3180 | /* hardware requires some bits to be set by default */ |
| 3181 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3182 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3183 | break; |
| 3184 | default: |
| 3185 | /* We should do nothing since we don't know this hardware */ |
| 3186 | return; |
| 3187 | } |
| 3188 | |
| 3189 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3190 | } |
| 3191 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3192 | /** |
| 3193 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3194 | * @adapter: board private structure |
| 3195 | * |
| 3196 | * Configure the Rx unit of the MAC after a reset. |
| 3197 | **/ |
| 3198 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3199 | { |
| 3200 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3201 | int i; |
| 3202 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3203 | |
| 3204 | /* disable receives while setting up the descriptors */ |
| 3205 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3206 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3207 | |
| 3208 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3209 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3210 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3211 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3212 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3213 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3214 | ixgbe_set_uta(adapter); |
| 3215 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3216 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3217 | ixgbe_set_rx_buffer_len(adapter); |
| 3218 | |
| 3219 | /* |
| 3220 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3221 | * the Base and Length of the Rx Descriptor Ring |
| 3222 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3223 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3224 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3225 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3226 | /* disable drop enable for 82598 parts */ |
| 3227 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3228 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3229 | |
| 3230 | /* enable all receives */ |
| 3231 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3232 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3235 | 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] | 3236 | { |
| 3237 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3238 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3239 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3240 | |
| 3241 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3242 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3243 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3244 | |
| 3245 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3246 | } |
| 3247 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3248 | 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] | 3249 | { |
| 3250 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3251 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3252 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3253 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3254 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3255 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3256 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3257 | |
| 3258 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3261 | /** |
| 3262 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3263 | * @adapter: driver data |
| 3264 | */ |
| 3265 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3266 | { |
| 3267 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3268 | u32 vlnctrl; |
| 3269 | |
| 3270 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3271 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3272 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3273 | } |
| 3274 | |
| 3275 | /** |
| 3276 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3277 | * @adapter: driver data |
| 3278 | */ |
| 3279 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3280 | { |
| 3281 | struct ixgbe_hw *hw = &adapter->hw; |
| 3282 | u32 vlnctrl; |
| 3283 | |
| 3284 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3285 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3286 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3287 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3288 | } |
| 3289 | |
| 3290 | /** |
| 3291 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3292 | * @adapter: driver data |
| 3293 | */ |
| 3294 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3295 | { |
| 3296 | struct ixgbe_hw *hw = &adapter->hw; |
| 3297 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3298 | int i, j; |
| 3299 | |
| 3300 | switch (hw->mac.type) { |
| 3301 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3302 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3303 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3304 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3305 | break; |
| 3306 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3307 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3308 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3309 | j = adapter->rx_ring[i]->reg_idx; |
| 3310 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3311 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3312 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3313 | } |
| 3314 | break; |
| 3315 | default: |
| 3316 | break; |
| 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3321 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3322 | * @adapter: driver data |
| 3323 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3324 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3325 | { |
| 3326 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3327 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3328 | int i, j; |
| 3329 | |
| 3330 | switch (hw->mac.type) { |
| 3331 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3332 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3333 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3334 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3335 | break; |
| 3336 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3337 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3338 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3339 | j = adapter->rx_ring[i]->reg_idx; |
| 3340 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3341 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3342 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3343 | } |
| 3344 | break; |
| 3345 | default: |
| 3346 | break; |
| 3347 | } |
| 3348 | } |
| 3349 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3350 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3351 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3352 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3353 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3354 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3355 | |
| 3356 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3357 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3361 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3362 | * @netdev: network interface device structure |
| 3363 | * |
| 3364 | * Writes unicast address list to the RAR table. |
| 3365 | * Returns: -ENOMEM on failure/insufficient address space |
| 3366 | * 0 on no addresses written |
| 3367 | * X on writing X addresses to the RAR table |
| 3368 | **/ |
| 3369 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3370 | { |
| 3371 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3372 | struct ixgbe_hw *hw = &adapter->hw; |
| 3373 | unsigned int vfn = adapter->num_vfs; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3374 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3375 | int count = 0; |
| 3376 | |
| 3377 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3378 | if (netdev_uc_count(netdev) > rar_entries) |
| 3379 | return -ENOMEM; |
| 3380 | |
| 3381 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3382 | struct netdev_hw_addr *ha; |
| 3383 | /* return error if we do not support writing to RAR table */ |
| 3384 | if (!hw->mac.ops.set_rar) |
| 3385 | return -ENOMEM; |
| 3386 | |
| 3387 | netdev_for_each_uc_addr(ha, netdev) { |
| 3388 | if (!rar_entries) |
| 3389 | break; |
| 3390 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
| 3391 | vfn, IXGBE_RAH_AV); |
| 3392 | count++; |
| 3393 | } |
| 3394 | } |
| 3395 | /* write the addresses in reverse order to avoid write combining */ |
| 3396 | for (; rar_entries > 0 ; rar_entries--) |
| 3397 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3398 | |
| 3399 | return count; |
| 3400 | } |
| 3401 | |
| 3402 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3403 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3404 | * @netdev: network interface device structure |
| 3405 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3406 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3407 | * address list or the network interface flags are updated. This routine is |
| 3408 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3409 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3410 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3411 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3412 | { |
| 3413 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3414 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3415 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3416 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3417 | |
| 3418 | /* Check for Promiscuous and All Multicast modes */ |
| 3419 | |
| 3420 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3421 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3422 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3423 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3424 | fctrl |= IXGBE_FCTRL_BAM; |
| 3425 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3426 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3427 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3428 | /* clear the bits we are changing the status of */ |
| 3429 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3430 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3431 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3432 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3433 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3434 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3435 | /* don't hardware filter vlans in promisc mode */ |
| 3436 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3437 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3438 | if (netdev->flags & IFF_ALLMULTI) { |
| 3439 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3440 | vmolr |= IXGBE_VMOLR_MPE; |
| 3441 | } else { |
| 3442 | /* |
| 3443 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3444 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3445 | * that we can at least receive multicast traffic |
| 3446 | */ |
| 3447 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3448 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3449 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3450 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3451 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3452 | /* |
| 3453 | * Write addresses to available RAR registers, if there is not |
| 3454 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3455 | * unicast promiscuous mode |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3456 | */ |
| 3457 | count = ixgbe_write_uc_addr_list(netdev); |
| 3458 | if (count < 0) { |
| 3459 | fctrl |= IXGBE_FCTRL_UPE; |
| 3460 | vmolr |= IXGBE_VMOLR_ROPE; |
| 3461 | } |
| 3462 | } |
| 3463 | |
| 3464 | if (adapter->num_vfs) { |
| 3465 | ixgbe_restore_vf_multicasts(adapter); |
| 3466 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & |
| 3467 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3468 | IXGBE_VMOLR_ROPE); |
| 3469 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3472 | /* This is useful for sniffing bad packets. */ |
| 3473 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3474 | /* UPE and MPE will be handled by normal PROMISC logic |
| 3475 | * in e1000e_set_rx_mode */ |
| 3476 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 3477 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 3478 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 3479 | |
| 3480 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 3481 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 3482 | } |
| 3483 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3484 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3485 | |
| 3486 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3487 | ixgbe_vlan_strip_enable(adapter); |
| 3488 | else |
| 3489 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3490 | } |
| 3491 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3492 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3493 | { |
| 3494 | int q_idx; |
| 3495 | struct ixgbe_q_vector *q_vector; |
| 3496 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3497 | |
| 3498 | /* legacy and MSI only use one vector */ |
| 3499 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3500 | q_vectors = 1; |
| 3501 | |
| 3502 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3503 | q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3504 | napi_enable(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3505 | } |
| 3506 | } |
| 3507 | |
| 3508 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3509 | { |
| 3510 | int q_idx; |
| 3511 | struct ixgbe_q_vector *q_vector; |
| 3512 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3513 | |
| 3514 | /* legacy and MSI only use one vector */ |
| 3515 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3516 | q_vectors = 1; |
| 3517 | |
| 3518 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3519 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3520 | napi_disable(&q_vector->napi); |
| 3521 | } |
| 3522 | } |
| 3523 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3524 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3525 | /* |
| 3526 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3527 | * @adapter: ixgbe adapter struct |
| 3528 | * |
| 3529 | * This is called by the driver on open to configure the DCB hardware. |
| 3530 | * This is also called by the gennetlink interface when reconfiguring |
| 3531 | * the DCB state. |
| 3532 | */ |
| 3533 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3534 | { |
| 3535 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307a | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3536 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3537 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3538 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3539 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3540 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3541 | return; |
| 3542 | } |
| 3543 | |
| 3544 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3545 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3546 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3547 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3548 | /* Enable VLAN tag insert/strip */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3549 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3550 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3551 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3552 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3553 | #ifdef IXGBE_FCOE |
| 3554 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3555 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3556 | #endif |
| 3557 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3558 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3559 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3560 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3561 | DCB_TX_CONFIG); |
| 3562 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3563 | DCB_RX_CONFIG); |
| 3564 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3565 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 3566 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 3567 | adapter->ixgbe_ieee_ets, |
| 3568 | max_frame); |
| 3569 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 3570 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 3571 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3572 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3573 | |
| 3574 | /* Enable RSS Hash per TC */ |
| 3575 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3576 | int i; |
| 3577 | u32 reg = 0; |
| 3578 | |
| 3579 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 3580 | u8 msb = 0; |
| 3581 | u8 cnt = adapter->netdev->tc_to_txq[i].count; |
| 3582 | |
| 3583 | while (cnt >>= 1) |
| 3584 | msb++; |
| 3585 | |
| 3586 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); |
| 3587 | } |
| 3588 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); |
| 3589 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3590 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3591 | #endif |
| 3592 | |
| 3593 | /* Additional bittime to account for IXGBE framing */ |
| 3594 | #define IXGBE_ETH_FRAMING 20 |
| 3595 | |
| 3596 | /* |
| 3597 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 3598 | * |
| 3599 | * @adapter: board private structure to calculate for |
| 3600 | * @pb - packet buffer to calculate |
| 3601 | */ |
| 3602 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 3603 | { |
| 3604 | struct ixgbe_hw *hw = &adapter->hw; |
| 3605 | struct net_device *dev = adapter->netdev; |
| 3606 | int link, tc, kb, marker; |
| 3607 | u32 dv_id, rx_pba; |
| 3608 | |
| 3609 | /* Calculate max LAN frame size */ |
| 3610 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 3611 | |
| 3612 | #ifdef IXGBE_FCOE |
| 3613 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 3614 | if (dev->features & NETIF_F_FCOE_MTU) { |
| 3615 | int fcoe_pb = 0; |
| 3616 | |
| 3617 | #ifdef CONFIG_IXGBE_DCB |
| 3618 | fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3619 | |
| 3620 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3621 | if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 3622 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3623 | } |
| 3624 | #endif |
| 3625 | |
| 3626 | /* Calculate delay value for device */ |
| 3627 | switch (hw->mac.type) { |
| 3628 | case ixgbe_mac_X540: |
| 3629 | dv_id = IXGBE_DV_X540(link, tc); |
| 3630 | break; |
| 3631 | default: |
| 3632 | dv_id = IXGBE_DV(link, tc); |
| 3633 | break; |
| 3634 | } |
| 3635 | |
| 3636 | /* Loopback switch introduces additional latency */ |
| 3637 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3638 | dv_id += IXGBE_B2BT(tc); |
| 3639 | |
| 3640 | /* Delay value is calculated in bit times convert to KB */ |
| 3641 | kb = IXGBE_BT2KB(dv_id); |
| 3642 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 3643 | |
| 3644 | marker = rx_pba - kb; |
| 3645 | |
| 3646 | /* It is possible that the packet buffer is not large enough |
| 3647 | * to provide required headroom. In this case throw an error |
| 3648 | * to user and a do the best we can. |
| 3649 | */ |
| 3650 | if (marker < 0) { |
| 3651 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 3652 | "headroom to support flow control." |
| 3653 | "Decrease MTU or number of traffic classes\n", pb); |
| 3654 | marker = tc + 1; |
| 3655 | } |
| 3656 | |
| 3657 | return marker; |
| 3658 | } |
| 3659 | |
| 3660 | /* |
| 3661 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 3662 | * |
| 3663 | * @adapter: board private structure to calculate for |
| 3664 | * @pb - packet buffer to calculate |
| 3665 | */ |
| 3666 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter) |
| 3667 | { |
| 3668 | struct ixgbe_hw *hw = &adapter->hw; |
| 3669 | struct net_device *dev = adapter->netdev; |
| 3670 | int tc; |
| 3671 | u32 dv_id; |
| 3672 | |
| 3673 | /* Calculate max LAN frame size */ |
| 3674 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3675 | |
| 3676 | /* Calculate delay value for device */ |
| 3677 | switch (hw->mac.type) { |
| 3678 | case ixgbe_mac_X540: |
| 3679 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 3680 | break; |
| 3681 | default: |
| 3682 | dv_id = IXGBE_LOW_DV(tc); |
| 3683 | break; |
| 3684 | } |
| 3685 | |
| 3686 | /* Delay value is calculated in bit times convert to KB */ |
| 3687 | return IXGBE_BT2KB(dv_id); |
| 3688 | } |
| 3689 | |
| 3690 | /* |
| 3691 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 3692 | */ |
| 3693 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 3694 | { |
| 3695 | struct ixgbe_hw *hw = &adapter->hw; |
| 3696 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3697 | int i; |
| 3698 | |
| 3699 | if (!num_tc) |
| 3700 | num_tc = 1; |
| 3701 | |
| 3702 | hw->fc.low_water = ixgbe_lpbthresh(adapter); |
| 3703 | |
| 3704 | for (i = 0; i < num_tc; i++) { |
| 3705 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
| 3706 | |
| 3707 | /* Low water marks must not be larger than high water marks */ |
| 3708 | if (hw->fc.low_water > hw->fc.high_water[i]) |
| 3709 | hw->fc.low_water = 0; |
| 3710 | } |
| 3711 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3712 | |
| 3713 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3714 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3715 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3716 | int hdrm; |
| 3717 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3718 | |
| 3719 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3720 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3721 | hdrm = 32 << adapter->fdir_pballoc; |
| 3722 | else |
| 3723 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3724 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 3725 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3726 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3727 | } |
| 3728 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3729 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 3730 | { |
| 3731 | struct ixgbe_hw *hw = &adapter->hw; |
| 3732 | struct hlist_node *node, *node2; |
| 3733 | struct ixgbe_fdir_filter *filter; |
| 3734 | |
| 3735 | spin_lock(&adapter->fdir_perfect_lock); |
| 3736 | |
| 3737 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 3738 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 3739 | |
| 3740 | hlist_for_each_entry_safe(filter, node, node2, |
| 3741 | &adapter->fdir_filter_list, fdir_node) { |
| 3742 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 3743 | &filter->filter, |
| 3744 | filter->sw_idx, |
| 3745 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 3746 | IXGBE_FDIR_DROP_QUEUE : |
| 3747 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | spin_unlock(&adapter->fdir_perfect_lock); |
| 3751 | } |
| 3752 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3753 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3754 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3755 | struct ixgbe_hw *hw = &adapter->hw; |
| 3756 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3757 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3758 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3759 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3760 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3761 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3762 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3763 | ixgbe_restore_vlan(adapter); |
| 3764 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3765 | #ifdef IXGBE_FCOE |
| 3766 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 3767 | ixgbe_configure_fcoe(adapter); |
| 3768 | |
| 3769 | #endif /* IXGBE_FCOE */ |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3770 | |
| 3771 | switch (hw->mac.type) { |
| 3772 | case ixgbe_mac_82599EB: |
| 3773 | case ixgbe_mac_X540: |
| 3774 | hw->mac.ops.disable_rx_buff(hw); |
| 3775 | break; |
| 3776 | default: |
| 3777 | break; |
| 3778 | } |
| 3779 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3780 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3781 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 3782 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3783 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3784 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 3785 | adapter->fdir_pballoc); |
| 3786 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3787 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 3788 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 3789 | switch (hw->mac.type) { |
| 3790 | case ixgbe_mac_82599EB: |
| 3791 | case ixgbe_mac_X540: |
| 3792 | hw->mac.ops.enable_rx_buff(hw); |
| 3793 | break; |
| 3794 | default: |
| 3795 | break; |
| 3796 | } |
| 3797 | |
Alexander Duyck | 933d41f | 2010-09-07 21:34:29 +0000 | [diff] [blame] | 3798 | ixgbe_configure_virtualization(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3799 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3800 | ixgbe_configure_tx(adapter); |
| 3801 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3804 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3805 | { |
| 3806 | switch (hw->phy.type) { |
| 3807 | case ixgbe_phy_sfp_avago: |
| 3808 | case ixgbe_phy_sfp_ftl: |
| 3809 | case ixgbe_phy_sfp_intel: |
| 3810 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3811 | case ixgbe_phy_sfp_passive_tyco: |
| 3812 | case ixgbe_phy_sfp_passive_unknown: |
| 3813 | case ixgbe_phy_sfp_active_unknown: |
| 3814 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3815 | return true; |
Alexander Duyck | 8917b44 | 2011-07-21 00:40:51 +0000 | [diff] [blame] | 3816 | case ixgbe_phy_nl: |
| 3817 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3818 | return true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3819 | default: |
| 3820 | return false; |
| 3821 | } |
| 3822 | } |
| 3823 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3824 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3825 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3826 | * @adapter: pointer to private adapter struct |
| 3827 | **/ |
| 3828 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3829 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3830 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 3831 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3832 | * is that an SFP was inserted/removed after the reset |
| 3833 | * but before SFP detection was enabled. As such the best |
| 3834 | * solution is to just start searching as soon as we start |
| 3835 | */ |
| 3836 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3837 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3838 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3839 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | /** |
| 3843 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3844 | * @hw: pointer to private hardware struct |
| 3845 | * |
| 3846 | * Returns 0 on success, negative on failure |
| 3847 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3848 | 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] | 3849 | { |
| 3850 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3851 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3852 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 3853 | |
| 3854 | if (hw->mac.ops.check_link) |
| 3855 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 3856 | |
| 3857 | if (ret) |
| 3858 | goto link_cfg_out; |
| 3859 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 3860 | autoneg = hw->phy.autoneg_advertised; |
| 3861 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3862 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3863 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3864 | if (ret) |
| 3865 | goto link_cfg_out; |
| 3866 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3867 | if (hw->mac.ops.setup_link) |
| 3868 | 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] | 3869 | link_cfg_out: |
| 3870 | return ret; |
| 3871 | } |
| 3872 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3873 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3874 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3875 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3876 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3877 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3878 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3879 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 3880 | IXGBE_GPIE_OCD; |
| 3881 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3882 | /* |
| 3883 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 3884 | * this saves a register write for every interrupt |
| 3885 | */ |
| 3886 | switch (hw->mac.type) { |
| 3887 | case ixgbe_mac_82598EB: |
| 3888 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 3889 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3890 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3891 | case ixgbe_mac_X540: |
| 3892 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3893 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 3894 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 3895 | break; |
| 3896 | } |
| 3897 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3898 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 3899 | * specifically only auto mask tx and rx interrupts */ |
| 3900 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3901 | } |
| 3902 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3903 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 3904 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 3905 | |
| 3906 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3907 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 3908 | gpie |= IXGBE_GPIE_VTMODE_64; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 3911 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 3912 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 3913 | switch (adapter->hw.mac.type) { |
| 3914 | case ixgbe_mac_82599EB: |
| 3915 | gpie |= IXGBE_SDP0_GPIEN; |
| 3916 | break; |
| 3917 | case ixgbe_mac_X540: |
| 3918 | gpie |= IXGBE_EIMS_TS; |
| 3919 | break; |
| 3920 | default: |
| 3921 | break; |
| 3922 | } |
| 3923 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 3924 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3925 | /* Enable fan failure interrupt */ |
| 3926 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3927 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3928 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3929 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3930 | gpie |= IXGBE_SDP1_GPIEN; |
| 3931 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3932 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3933 | |
| 3934 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 3935 | } |
| 3936 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 3937 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3938 | { |
| 3939 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3940 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3941 | u32 ctrl_ext; |
| 3942 | |
| 3943 | ixgbe_get_hw_control(adapter); |
| 3944 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3945 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3946 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3947 | ixgbe_configure_msix(adapter); |
| 3948 | else |
| 3949 | ixgbe_configure_msi_and_legacy(adapter); |
| 3950 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3951 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ |
| 3952 | if (hw->mac.ops.enable_tx_laser && |
| 3953 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 3954 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3955 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 3956 | hw->mac.ops.enable_tx_laser(hw); |
| 3957 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3958 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3959 | ixgbe_napi_enable_all(adapter); |
| 3960 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 3961 | if (ixgbe_is_sfp(hw)) { |
| 3962 | ixgbe_sfp_link_config(adapter); |
| 3963 | } else { |
| 3964 | err = ixgbe_non_sfp_link_config(hw); |
| 3965 | if (err) |
| 3966 | e_err(probe, "link_config FAILED %d\n", err); |
| 3967 | } |
| 3968 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3969 | /* clear any pending interrupts, may auto mask */ |
| 3970 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3971 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3972 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3973 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3974 | * If this adapter has a fan, check to see if we had a failure |
| 3975 | * before we enabled the interrupt. |
| 3976 | */ |
| 3977 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 3978 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 3979 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3980 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3981 | } |
| 3982 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3983 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3984 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3985 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3986 | /* bring the link up in the watchdog, this could race with our first |
| 3987 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3988 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3989 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3990 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 3991 | |
| 3992 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 3993 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 3994 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 3995 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3998 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 3999 | { |
| 4000 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4001 | /* put off any impending NetWatchDogTimeout */ |
| 4002 | adapter->netdev->trans_start = jiffies; |
| 4003 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4004 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4005 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4006 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 4007 | /* |
| 4008 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 4009 | * back up to give the VFs time to respond to the reset. The |
| 4010 | * two second wait is based upon the watchdog timer cycle in |
| 4011 | * the VF driver. |
| 4012 | */ |
| 4013 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4014 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4015 | ixgbe_up(adapter); |
| 4016 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 4017 | } |
| 4018 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4019 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4020 | { |
| 4021 | /* hardware has been reset, we need to reload some things */ |
| 4022 | ixgbe_configure(adapter); |
| 4023 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4024 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 4028 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4029 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4030 | int err; |
| 4031 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4032 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 4033 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 4034 | usleep_range(1000, 2000); |
| 4035 | |
| 4036 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 4037 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 4038 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 4039 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 4040 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4041 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4042 | switch (err) { |
| 4043 | case 0: |
| 4044 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4045 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4046 | break; |
| 4047 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4048 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4049 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4050 | case IXGBE_ERR_EEPROM_VERSION: |
| 4051 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4052 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 4053 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4054 | "your hardware. If you are experiencing problems " |
| 4055 | "please contact your Intel or hardware " |
| 4056 | "representative who provided you with this " |
| 4057 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4058 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4059 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4060 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4061 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4062 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4063 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 4064 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4065 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4066 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 4067 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4068 | } |
| 4069 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4070 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4071 | * ixgbe_init_rx_page_offset - initialize page offset values for Rx buffers |
| 4072 | * @rx_ring: ring to setup |
| 4073 | * |
| 4074 | * On many IA platforms the L1 cache has a critical stride of 4K, this |
| 4075 | * results in each receive buffer starting in the same cache set. To help |
| 4076 | * reduce the pressure on this cache set we can interleave the offsets so |
| 4077 | * that only every other buffer will be in the same cache set. |
| 4078 | **/ |
| 4079 | static void ixgbe_init_rx_page_offset(struct ixgbe_ring *rx_ring) |
| 4080 | { |
| 4081 | struct ixgbe_rx_buffer *rx_buffer = rx_ring->rx_buffer_info; |
| 4082 | u16 i; |
| 4083 | |
| 4084 | for (i = 0; i < rx_ring->count; i += 2) { |
| 4085 | rx_buffer[0].page_offset = 0; |
| 4086 | rx_buffer[1].page_offset = ixgbe_rx_bufsz(rx_ring); |
| 4087 | rx_buffer = &rx_buffer[2]; |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4092 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4093 | * @rx_ring: ring to free buffers from |
| 4094 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4095 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4096 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4097 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4098 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4099 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4100 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4101 | /* ring already cleared, nothing to do */ |
| 4102 | if (!rx_ring->rx_buffer_info) |
| 4103 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4104 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4105 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4106 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4107 | struct ixgbe_rx_buffer *rx_buffer; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4108 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4109 | rx_buffer = &rx_ring->rx_buffer_info[i]; |
| 4110 | if (rx_buffer->skb) { |
| 4111 | struct sk_buff *skb = rx_buffer->skb; |
| 4112 | if (IXGBE_CB(skb)->page_released) { |
| 4113 | dma_unmap_page(dev, |
| 4114 | IXGBE_CB(skb)->dma, |
| 4115 | ixgbe_rx_bufsz(rx_ring), |
| 4116 | DMA_FROM_DEVICE); |
| 4117 | IXGBE_CB(skb)->page_released = false; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 4118 | } |
| 4119 | dev_kfree_skb(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4120 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4121 | rx_buffer->skb = NULL; |
| 4122 | if (rx_buffer->dma) |
| 4123 | dma_unmap_page(dev, rx_buffer->dma, |
| 4124 | ixgbe_rx_pg_size(rx_ring), |
| 4125 | DMA_FROM_DEVICE); |
| 4126 | rx_buffer->dma = 0; |
| 4127 | if (rx_buffer->page) |
| 4128 | put_page(rx_buffer->page); |
| 4129 | rx_buffer->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4133 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4134 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4135 | ixgbe_init_rx_page_offset(rx_ring); |
| 4136 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4137 | /* Zero out the descriptor ring */ |
| 4138 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4139 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 4140 | rx_ring->next_to_alloc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4141 | rx_ring->next_to_clean = 0; |
| 4142 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4143 | } |
| 4144 | |
| 4145 | /** |
| 4146 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4147 | * @tx_ring: ring to be cleaned |
| 4148 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4149 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4150 | { |
| 4151 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4152 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4153 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4154 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4155 | /* ring already cleared, nothing to do */ |
| 4156 | if (!tx_ring->tx_buffer_info) |
| 4157 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4158 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4159 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4160 | for (i = 0; i < tx_ring->count; i++) { |
| 4161 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4162 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4166 | memset(tx_ring->tx_buffer_info, 0, size); |
| 4167 | |
| 4168 | /* Zero out the descriptor ring */ |
| 4169 | memset(tx_ring->desc, 0, tx_ring->size); |
| 4170 | |
| 4171 | tx_ring->next_to_use = 0; |
| 4172 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4176 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4177 | * @adapter: board private structure |
| 4178 | **/ |
| 4179 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4180 | { |
| 4181 | int i; |
| 4182 | |
| 4183 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4184 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4187 | /** |
| 4188 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4189 | * @adapter: board private structure |
| 4190 | **/ |
| 4191 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4192 | { |
| 4193 | int i; |
| 4194 | |
| 4195 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4196 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4197 | } |
| 4198 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4199 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4200 | { |
| 4201 | struct hlist_node *node, *node2; |
| 4202 | struct ixgbe_fdir_filter *filter; |
| 4203 | |
| 4204 | spin_lock(&adapter->fdir_perfect_lock); |
| 4205 | |
| 4206 | hlist_for_each_entry_safe(filter, node, node2, |
| 4207 | &adapter->fdir_filter_list, fdir_node) { |
| 4208 | hlist_del(&filter->fdir_node); |
| 4209 | kfree(filter); |
| 4210 | } |
| 4211 | adapter->fdir_filter_count = 0; |
| 4212 | |
| 4213 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4214 | } |
| 4215 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4216 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4217 | { |
| 4218 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4219 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4220 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4221 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4222 | |
| 4223 | /* signal that we are down to the interrupt handler */ |
| 4224 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4225 | |
| 4226 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4227 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4228 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4229 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4230 | /* disable all enabled rx queues */ |
| 4231 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4232 | /* this call also flushes the previous write */ |
| 4233 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4234 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4235 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4236 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4237 | netif_tx_stop_all_queues(netdev); |
| 4238 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4239 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4240 | netif_carrier_off(netdev); |
| 4241 | netif_tx_disable(netdev); |
| 4242 | |
| 4243 | ixgbe_irq_disable(adapter); |
| 4244 | |
| 4245 | ixgbe_napi_disable_all(adapter); |
| 4246 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4247 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4248 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4249 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4250 | |
| 4251 | del_timer_sync(&adapter->service_timer); |
| 4252 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4253 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4254 | /* Clear EITR Select mapping */ |
| 4255 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 4256 | |
| 4257 | /* Mark all the VFs as inactive */ |
| 4258 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4259 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4260 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4261 | /* 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] | 4262 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4263 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4264 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4265 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4266 | } |
| 4267 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4268 | /* disable transmits in the hardware now that interrupts are off */ |
| 4269 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4270 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4271 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4272 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4273 | |
| 4274 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4275 | switch (hw->mac.type) { |
| 4276 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4277 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4278 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4279 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4280 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4281 | break; |
| 4282 | default: |
| 4283 | break; |
| 4284 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4285 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4286 | if (!pci_channel_offline(adapter->pdev)) |
| 4287 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4288 | |
| 4289 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 4290 | if (hw->mac.ops.disable_tx_laser && |
| 4291 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 4292 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4293 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 4294 | hw->mac.ops.disable_tx_laser(hw); |
| 4295 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4296 | ixgbe_clean_all_tx_rings(adapter); |
| 4297 | ixgbe_clean_all_rx_rings(adapter); |
| 4298 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4299 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4300 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4301 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4302 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4303 | } |
| 4304 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4305 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4306 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4307 | * @netdev: network interface device structure |
| 4308 | **/ |
| 4309 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4310 | { |
| 4311 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4312 | |
| 4313 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4314 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4317 | /** |
| 4318 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 4319 | * @adapter: board private structure to initialize |
| 4320 | * |
| 4321 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 4322 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 4323 | * |
| 4324 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4325 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 4326 | { |
| 4327 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4328 | 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] | 4329 | |
| 4330 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4331 | f->mask = 0xF; |
| 4332 | adapter->num_rx_queues = f->indices; |
| 4333 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4334 | ret = true; |
| 4335 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4336 | ret = false; |
| 4337 | } |
| 4338 | |
| 4339 | return ret; |
| 4340 | } |
| 4341 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4342 | /** |
| 4343 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 4344 | * @adapter: board private structure to initialize |
| 4345 | * |
| 4346 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 4347 | * to the original CPU that initiated the Tx session. This runs in addition |
| 4348 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 4349 | * Rx load across CPUs using RSS. |
| 4350 | * |
| 4351 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4352 | 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] | 4353 | { |
| 4354 | bool ret = false; |
| 4355 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 4356 | |
| 4357 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 4358 | f_fdir->mask = 0; |
| 4359 | |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 4360 | /* |
| 4361 | * Use RSS in addition to Flow Director to ensure the best |
| 4362 | * distribution of flows across cores, even when an FDIR flow |
| 4363 | * isn't matched. |
| 4364 | */ |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4365 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4366 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4367 | adapter->num_tx_queues = f_fdir->indices; |
| 4368 | adapter->num_rx_queues = f_fdir->indices; |
| 4369 | ret = true; |
| 4370 | } else { |
| 4371 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4372 | } |
| 4373 | return ret; |
| 4374 | } |
| 4375 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4376 | #ifdef IXGBE_FCOE |
| 4377 | /** |
| 4378 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 4379 | * @adapter: board private structure to initialize |
| 4380 | * |
| 4381 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 4382 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 4383 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 4384 | * index of the first rx queue used by FCoE. |
| 4385 | * |
| 4386 | **/ |
| 4387 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 4388 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4389 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 4390 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4391 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4392 | return false; |
| 4393 | |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4394 | f->indices = min_t(int, num_online_cpus(), f->indices); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4395 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4396 | adapter->num_rx_queues = 1; |
| 4397 | adapter->num_tx_queues = 1; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4398 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4399 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 4400 | e_info(probe, "FCoE enabled with RSS\n"); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4401 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4402 | ixgbe_set_fdir_queues(adapter); |
| 4403 | else |
| 4404 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4405 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4406 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4407 | /* adding FCoE rx rings to the end */ |
| 4408 | f->mask = adapter->num_rx_queues; |
| 4409 | adapter->num_rx_queues += f->indices; |
| 4410 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4411 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4412 | return true; |
| 4413 | } |
| 4414 | #endif /* IXGBE_FCOE */ |
| 4415 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4416 | /* Artificial max queue cap per traffic class in DCB mode */ |
| 4417 | #define DCB_QUEUE_CAP 8 |
| 4418 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4419 | #ifdef CONFIG_IXGBE_DCB |
| 4420 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
| 4421 | { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4422 | int per_tc_q, q, i, offset = 0; |
| 4423 | struct net_device *dev = adapter->netdev; |
| 4424 | int tcs = netdev_get_num_tc(dev); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4425 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4426 | if (!tcs) |
| 4427 | return false; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4428 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4429 | /* Map queue offset and counts onto allocated tx queues */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4430 | per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP); |
| 4431 | q = min_t(int, num_online_cpus(), per_tc_q); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4432 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4433 | for (i = 0; i < tcs; i++) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4434 | netdev_set_tc_queue(dev, i, q, offset); |
| 4435 | offset += q; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4436 | } |
| 4437 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4438 | adapter->num_tx_queues = q * tcs; |
| 4439 | adapter->num_rx_queues = q * tcs; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4440 | |
| 4441 | #ifdef IXGBE_FCOE |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4442 | /* FCoE enabled queues require special configuration indexed |
| 4443 | * by feature specific indices and mask. Here we map FCoE |
| 4444 | * indices onto the DCB queue pairs allowing FCoE to own |
| 4445 | * configuration later. |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4446 | */ |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4447 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
John Fastabend | cdf485b | 2012-02-11 06:26:00 +0000 | [diff] [blame] | 4448 | u8 prio_tc[MAX_USER_PRIORITY] = {0}; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4449 | int tc; |
| 4450 | struct ixgbe_ring_feature *f = |
| 4451 | &adapter->ring_feature[RING_F_FCOE]; |
| 4452 | |
John Fastabend | cdf485b | 2012-02-11 06:26:00 +0000 | [diff] [blame] | 4453 | ixgbe_dcb_unpack_map(&adapter->dcb_cfg, DCB_TX_CONFIG, prio_tc); |
| 4454 | tc = prio_tc[adapter->fcoe.up]; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4455 | f->indices = dev->tc_to_txq[tc].count; |
| 4456 | f->mask = dev->tc_to_txq[tc].offset; |
| 4457 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4458 | #endif |
| 4459 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4460 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4461 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4462 | #endif |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4463 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4464 | /** |
| 4465 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 4466 | * @adapter: board private structure to initialize |
| 4467 | * |
| 4468 | * IOV doesn't actually use anything, so just NAK the |
| 4469 | * request for now and let the other queue routines |
| 4470 | * figure out what to do. |
| 4471 | */ |
| 4472 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 4473 | { |
| 4474 | return false; |
| 4475 | } |
| 4476 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4477 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4478 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4479 | * @adapter: board private structure to initialize |
| 4480 | * |
| 4481 | * This is the top level queue allocation routine. The order here is very |
| 4482 | * important, starting with the "most" number of features turned on at once, |
| 4483 | * and ending with the smallest set of features. This way large combinations |
| 4484 | * can be allocated if they're turned on, and smaller combinations are the |
| 4485 | * fallthrough conditions. |
| 4486 | * |
| 4487 | **/ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4488 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4489 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4490 | /* Start with base case */ |
| 4491 | adapter->num_rx_queues = 1; |
| 4492 | adapter->num_tx_queues = 1; |
| 4493 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 4494 | adapter->num_rx_queues_per_pool = 1; |
| 4495 | |
| 4496 | if (ixgbe_set_sriov_queues(adapter)) |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4497 | goto done; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4498 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4499 | #ifdef CONFIG_IXGBE_DCB |
| 4500 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4501 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4502 | |
| 4503 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4504 | #ifdef IXGBE_FCOE |
| 4505 | if (ixgbe_set_fcoe_queues(adapter)) |
| 4506 | goto done; |
| 4507 | |
| 4508 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4509 | if (ixgbe_set_fdir_queues(adapter)) |
| 4510 | goto done; |
| 4511 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4512 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4513 | goto done; |
| 4514 | |
| 4515 | /* fallback to base case */ |
| 4516 | adapter->num_rx_queues = 1; |
| 4517 | adapter->num_tx_queues = 1; |
| 4518 | |
| 4519 | done: |
Yi Zou | 9d837ea | 2012-01-07 08:39:50 +0000 | [diff] [blame] | 4520 | if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) || |
| 4521 | (adapter->netdev->reg_state == NETREG_UNREGISTERING)) |
| 4522 | return 0; |
| 4523 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4524 | /* Notify the stack of the (possibly) reduced queue counts. */ |
John Fastabend | f0796d5 | 2010-07-01 13:21:57 +0000 | [diff] [blame] | 4525 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4526 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 4527 | adapter->num_rx_queues); |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4530 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4531 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4532 | { |
| 4533 | int err, vector_threshold; |
| 4534 | |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4535 | /* We'll want at least 2 (vector_threshold): |
| 4536 | * 1) TxQ[0] + RxQ[0] handler |
| 4537 | * 2) Other (Link Status Change, etc.) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4538 | */ |
| 4539 | vector_threshold = MIN_MSIX_COUNT; |
| 4540 | |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 4541 | /* |
| 4542 | * 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] | 4543 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 4544 | * Right now, we simply care about how many we'll get; we'll |
| 4545 | * set them up later while requesting irq's. |
| 4546 | */ |
| 4547 | while (vectors >= vector_threshold) { |
| 4548 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4549 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4550 | if (!err) /* Success in acquiring all requested vectors. */ |
| 4551 | break; |
| 4552 | else if (err < 0) |
| 4553 | vectors = 0; /* Nasty failure, quit now */ |
| 4554 | else /* err == number of vectors we should try again with */ |
| 4555 | vectors = err; |
| 4556 | } |
| 4557 | |
| 4558 | if (vectors < vector_threshold) { |
| 4559 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 4560 | * This just means we'll go with either a single MSI |
| 4561 | * vector or fall back to legacy interrupts. |
| 4562 | */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4563 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4564 | "Unable to allocate MSI-X interrupts\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4565 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4566 | kfree(adapter->msix_entries); |
| 4567 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4568 | } else { |
| 4569 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 4570 | /* |
| 4571 | * Adjust for only the vectors we'll use, which is minimum |
| 4572 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 4573 | * vectors we were allocated. |
| 4574 | */ |
| 4575 | adapter->num_msix_vectors = min(vectors, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4576 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4577 | } |
| 4578 | } |
| 4579 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4580 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4581 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4582 | * @adapter: board private structure to initialize |
| 4583 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4584 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 4585 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4586 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4587 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4588 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4589 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4590 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4591 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 4592 | return false; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4593 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4594 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4595 | adapter->rx_ring[i]->reg_idx = i; |
| 4596 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4597 | adapter->tx_ring[i]->reg_idx = i; |
| 4598 | |
| 4599 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4603 | |
| 4604 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 4605 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, |
| 4606 | unsigned int *tx, unsigned int *rx) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4607 | { |
| 4608 | struct net_device *dev = adapter->netdev; |
| 4609 | struct ixgbe_hw *hw = &adapter->hw; |
| 4610 | u8 num_tcs = netdev_get_num_tc(dev); |
| 4611 | |
| 4612 | *tx = 0; |
| 4613 | *rx = 0; |
| 4614 | |
| 4615 | switch (hw->mac.type) { |
| 4616 | case ixgbe_mac_82598EB: |
John Fastabend | aba70d5 | 2011-04-26 07:26:14 +0000 | [diff] [blame] | 4617 | *tx = tc << 2; |
| 4618 | *rx = tc << 3; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4619 | break; |
| 4620 | case ixgbe_mac_82599EB: |
| 4621 | case ixgbe_mac_X540: |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4622 | if (num_tcs > 4) { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4623 | if (tc < 3) { |
| 4624 | *tx = tc << 5; |
| 4625 | *rx = tc << 4; |
| 4626 | } else if (tc < 5) { |
| 4627 | *tx = ((tc + 2) << 4); |
| 4628 | *rx = tc << 4; |
| 4629 | } else if (tc < num_tcs) { |
| 4630 | *tx = ((tc + 8) << 3); |
| 4631 | *rx = tc << 4; |
| 4632 | } |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4633 | } else { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4634 | *rx = tc << 5; |
| 4635 | switch (tc) { |
| 4636 | case 0: |
| 4637 | *tx = 0; |
| 4638 | break; |
| 4639 | case 1: |
| 4640 | *tx = 64; |
| 4641 | break; |
| 4642 | case 2: |
| 4643 | *tx = 96; |
| 4644 | break; |
| 4645 | case 3: |
| 4646 | *tx = 112; |
| 4647 | break; |
| 4648 | default: |
| 4649 | break; |
| 4650 | } |
| 4651 | } |
| 4652 | break; |
| 4653 | default: |
| 4654 | break; |
| 4655 | } |
| 4656 | } |
| 4657 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4658 | /** |
| 4659 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 4660 | * @adapter: board private structure to initialize |
| 4661 | * |
| 4662 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 4663 | * |
| 4664 | **/ |
| 4665 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 4666 | { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4667 | struct net_device *dev = adapter->netdev; |
| 4668 | int i, j, k; |
| 4669 | u8 num_tcs = netdev_get_num_tc(dev); |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4670 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4671 | if (!num_tcs) |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4672 | return false; |
| 4673 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4674 | for (i = 0, k = 0; i < num_tcs; i++) { |
| 4675 | unsigned int tx_s, rx_s; |
| 4676 | u16 count = dev->tc_to_txq[i].count; |
| 4677 | |
| 4678 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); |
| 4679 | for (j = 0; j < count; j++, k++) { |
| 4680 | adapter->tx_ring[k]->reg_idx = tx_s + j; |
| 4681 | adapter->rx_ring[k]->reg_idx = rx_s + j; |
| 4682 | adapter->tx_ring[k]->dcb_tc = i; |
| 4683 | adapter->rx_ring[k]->dcb_tc = i; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4684 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4685 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4686 | |
| 4687 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4688 | } |
| 4689 | #endif |
| 4690 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4691 | /** |
| 4692 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 4693 | * @adapter: board private structure to initialize |
| 4694 | * |
| 4695 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 4696 | * |
| 4697 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4698 | 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] | 4699 | { |
| 4700 | int i; |
| 4701 | bool ret = false; |
| 4702 | |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4703 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4704 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4705 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4706 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4707 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4708 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4709 | ret = true; |
| 4710 | } |
| 4711 | |
| 4712 | return ret; |
| 4713 | } |
| 4714 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4715 | #ifdef IXGBE_FCOE |
| 4716 | /** |
| 4717 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 4718 | * @adapter: board private structure to initialize |
| 4719 | * |
| 4720 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 4721 | * |
| 4722 | */ |
| 4723 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 4724 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4725 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4726 | int i; |
| 4727 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4728 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4729 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4730 | return false; |
| 4731 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4732 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4733 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4734 | ixgbe_cache_ring_fdir(adapter); |
| 4735 | else |
| 4736 | ixgbe_cache_ring_rss(adapter); |
| 4737 | |
| 4738 | fcoe_rx_i = f->mask; |
| 4739 | fcoe_tx_i = f->mask; |
| 4740 | } |
| 4741 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 4742 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 4743 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
| 4744 | } |
| 4745 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4749 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4750 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 4751 | * @adapter: board private structure to initialize |
| 4752 | * |
| 4753 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 4754 | * no other mapping is used. |
| 4755 | * |
| 4756 | */ |
| 4757 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 4758 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4759 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 4760 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4761 | if (adapter->num_vfs) |
| 4762 | return true; |
| 4763 | else |
| 4764 | return false; |
| 4765 | } |
| 4766 | |
| 4767 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4768 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 4769 | * @adapter: board private structure to initialize |
| 4770 | * |
| 4771 | * Once we know the feature-set enabled for the device, we'll cache |
| 4772 | * the register offset the descriptor ring is assigned to. |
| 4773 | * |
| 4774 | * Note, the order the various feature calls is important. It must start with |
| 4775 | * the "most" features enabled at the same time, then trickle down to the |
| 4776 | * least amount of features turned on at once. |
| 4777 | **/ |
| 4778 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 4779 | { |
| 4780 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4781 | adapter->rx_ring[0]->reg_idx = 0; |
| 4782 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4783 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4784 | if (ixgbe_cache_ring_sriov(adapter)) |
| 4785 | return; |
| 4786 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4787 | #ifdef CONFIG_IXGBE_DCB |
| 4788 | if (ixgbe_cache_ring_dcb(adapter)) |
| 4789 | return; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4790 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4791 | |
| 4792 | #ifdef IXGBE_FCOE |
| 4793 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 4794 | return; |
| 4795 | #endif /* IXGBE_FCOE */ |
| 4796 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4797 | if (ixgbe_cache_ring_fdir(adapter)) |
| 4798 | return; |
| 4799 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4800 | if (ixgbe_cache_ring_rss(adapter)) |
| 4801 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4802 | } |
| 4803 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4804 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4805 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 4806 | * @adapter: board private structure to initialize |
| 4807 | * |
| 4808 | * Attempt to configure the interrupts using the best available |
| 4809 | * capabilities of the hardware and the kernel. |
| 4810 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 4811 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4812 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4813 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4814 | int err = 0; |
| 4815 | int vector, v_budget; |
| 4816 | |
| 4817 | /* |
| 4818 | * It's easy to be greedy for MSI-X vectors, but it really |
| 4819 | * doesn't do us much good if we have a lot more vectors |
| 4820 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 4821 | * (roughly) the same number of vectors as there are CPU's. |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4822 | * The default is to use pairs of vectors. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4823 | */ |
Alexander Duyck | 8f15486 | 2012-02-10 02:08:37 +0000 | [diff] [blame] | 4824 | v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues); |
| 4825 | v_budget = min_t(int, v_budget, num_online_cpus()); |
| 4826 | v_budget += NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4827 | |
| 4828 | /* |
| 4829 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4830 | * hw.mac->max_msix_vectors vectors. With features |
| 4831 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 4832 | * descriptor queues supported by our device. Thus, we cap it off in |
| 4833 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4834 | */ |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4835 | v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4836 | |
| 4837 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 4838 | * mean we disable MSI-X capabilities of the adapter. */ |
| 4839 | adapter->msix_entries = kcalloc(v_budget, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4840 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4841 | if (adapter->msix_entries) { |
| 4842 | for (vector = 0; vector < v_budget; vector++) |
| 4843 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4844 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4845 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 4846 | |
| 4847 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4848 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4849 | } |
David S. Miller | 26d2784 | 2010-05-03 15:18:22 -0700 | [diff] [blame] | 4850 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4851 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 4852 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4853 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4854 | e_err(probe, |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4855 | "ATR is not supported while multiple " |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4856 | "queues are disabled. Disabling Flow Director\n"); |
| 4857 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4858 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4859 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4860 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4861 | ixgbe_disable_sriov(adapter); |
| 4862 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4863 | err = ixgbe_set_num_queues(adapter); |
| 4864 | if (err) |
| 4865 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4866 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4867 | err = pci_enable_msi(adapter->pdev); |
| 4868 | if (!err) { |
| 4869 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 4870 | } else { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4871 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4872 | "Unable to allocate MSI interrupt, " |
| 4873 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4874 | /* reset err */ |
| 4875 | err = 0; |
| 4876 | } |
| 4877 | |
| 4878 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4879 | return err; |
| 4880 | } |
| 4881 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 4882 | static void ixgbe_add_ring(struct ixgbe_ring *ring, |
| 4883 | struct ixgbe_ring_container *head) |
| 4884 | { |
| 4885 | ring->next = head->ring; |
| 4886 | head->ring = ring; |
| 4887 | head->count++; |
| 4888 | } |
| 4889 | |
| 4890 | /** |
| 4891 | * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector |
| 4892 | * @adapter: board private structure to initialize |
| 4893 | * @v_idx: index of vector in adapter struct |
| 4894 | * |
| 4895 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 4896 | **/ |
| 4897 | static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx, |
| 4898 | int txr_count, int txr_idx, |
| 4899 | int rxr_count, int rxr_idx) |
| 4900 | { |
| 4901 | struct ixgbe_q_vector *q_vector; |
| 4902 | struct ixgbe_ring *ring; |
| 4903 | int node = -1; |
| 4904 | int cpu = -1; |
| 4905 | int ring_count, size; |
| 4906 | |
| 4907 | ring_count = txr_count + rxr_count; |
| 4908 | size = sizeof(struct ixgbe_q_vector) + |
| 4909 | (sizeof(struct ixgbe_ring) * ring_count); |
| 4910 | |
| 4911 | /* customize cpu for Flow Director mapping */ |
| 4912 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 4913 | if (cpu_online(v_idx)) { |
| 4914 | cpu = v_idx; |
| 4915 | node = cpu_to_node(cpu); |
| 4916 | } |
| 4917 | } |
| 4918 | |
| 4919 | /* allocate q_vector and rings */ |
| 4920 | q_vector = kzalloc_node(size, GFP_KERNEL, node); |
| 4921 | if (!q_vector) |
| 4922 | q_vector = kzalloc(size, GFP_KERNEL); |
| 4923 | if (!q_vector) |
| 4924 | return -ENOMEM; |
| 4925 | |
| 4926 | /* setup affinity mask and node */ |
| 4927 | if (cpu != -1) |
| 4928 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
| 4929 | else |
| 4930 | cpumask_copy(&q_vector->affinity_mask, cpu_online_mask); |
| 4931 | q_vector->numa_node = node; |
| 4932 | |
| 4933 | /* initialize NAPI */ |
| 4934 | netif_napi_add(adapter->netdev, &q_vector->napi, |
| 4935 | ixgbe_poll, 64); |
| 4936 | |
| 4937 | /* tie q_vector and adapter together */ |
| 4938 | adapter->q_vector[v_idx] = q_vector; |
| 4939 | q_vector->adapter = adapter; |
| 4940 | q_vector->v_idx = v_idx; |
| 4941 | |
| 4942 | /* initialize work limits */ |
| 4943 | q_vector->tx.work_limit = adapter->tx_work_limit; |
| 4944 | |
| 4945 | /* initialize pointer to rings */ |
| 4946 | ring = q_vector->ring; |
| 4947 | |
| 4948 | while (txr_count) { |
| 4949 | /* assign generic ring traits */ |
| 4950 | ring->dev = &adapter->pdev->dev; |
| 4951 | ring->netdev = adapter->netdev; |
| 4952 | |
| 4953 | /* configure backlink on ring */ |
| 4954 | ring->q_vector = q_vector; |
| 4955 | |
| 4956 | /* update q_vector Tx values */ |
| 4957 | ixgbe_add_ring(ring, &q_vector->tx); |
| 4958 | |
| 4959 | /* apply Tx specific ring traits */ |
| 4960 | ring->count = adapter->tx_ring_count; |
| 4961 | ring->queue_index = txr_idx; |
| 4962 | |
| 4963 | /* assign ring to adapter */ |
| 4964 | adapter->tx_ring[txr_idx] = ring; |
| 4965 | |
| 4966 | /* update count and index */ |
| 4967 | txr_count--; |
| 4968 | txr_idx++; |
| 4969 | |
| 4970 | /* push pointer to next ring */ |
| 4971 | ring++; |
| 4972 | } |
| 4973 | |
| 4974 | while (rxr_count) { |
| 4975 | /* assign generic ring traits */ |
| 4976 | ring->dev = &adapter->pdev->dev; |
| 4977 | ring->netdev = adapter->netdev; |
| 4978 | |
| 4979 | /* configure backlink on ring */ |
| 4980 | ring->q_vector = q_vector; |
| 4981 | |
| 4982 | /* update q_vector Rx values */ |
| 4983 | ixgbe_add_ring(ring, &q_vector->rx); |
| 4984 | |
| 4985 | /* |
| 4986 | * 82599 errata, UDP frames with a 0 checksum |
| 4987 | * can be marked as checksum errors. |
| 4988 | */ |
| 4989 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 4990 | set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state); |
| 4991 | |
| 4992 | /* apply Rx specific ring traits */ |
| 4993 | ring->count = adapter->rx_ring_count; |
| 4994 | ring->queue_index = rxr_idx; |
| 4995 | |
| 4996 | /* assign ring to adapter */ |
| 4997 | adapter->rx_ring[rxr_idx] = ring; |
| 4998 | |
| 4999 | /* update count and index */ |
| 5000 | rxr_count--; |
| 5001 | rxr_idx++; |
| 5002 | |
| 5003 | /* push pointer to next ring */ |
| 5004 | ring++; |
| 5005 | } |
| 5006 | |
| 5007 | return 0; |
| 5008 | } |
| 5009 | |
| 5010 | /** |
| 5011 | * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector |
| 5012 | * @adapter: board private structure to initialize |
| 5013 | * @v_idx: Index of vector to be freed |
| 5014 | * |
| 5015 | * This function frees the memory allocated to the q_vector. In addition if |
| 5016 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 5017 | * to freeing the q_vector. |
| 5018 | **/ |
| 5019 | static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx) |
| 5020 | { |
| 5021 | struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 5022 | struct ixgbe_ring *ring; |
| 5023 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 5024 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5025 | adapter->tx_ring[ring->queue_index] = NULL; |
| 5026 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 5027 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5028 | adapter->rx_ring[ring->queue_index] = NULL; |
| 5029 | |
| 5030 | adapter->q_vector[v_idx] = NULL; |
| 5031 | netif_napi_del(&q_vector->napi); |
| 5032 | |
| 5033 | /* |
| 5034 | * ixgbe_get_stats64() might access the rings on this vector, |
| 5035 | * we must wait a grace period before freeing it. |
| 5036 | */ |
| 5037 | kfree_rcu(q_vector, rcu); |
| 5038 | } |
| 5039 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5040 | /** |
| 5041 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 5042 | * @adapter: board private structure to initialize |
| 5043 | * |
| 5044 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 5045 | * return -ENOMEM. |
| 5046 | **/ |
| 5047 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 5048 | { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5049 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5050 | int rxr_remaining = adapter->num_rx_queues; |
| 5051 | int txr_remaining = adapter->num_tx_queues; |
| 5052 | int rxr_idx = 0, txr_idx = 0, v_idx = 0; |
| 5053 | int err; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5054 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5055 | /* only one q_vector if MSI-X is disabled. */ |
| 5056 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 5057 | q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5058 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5059 | if (q_vectors >= (rxr_remaining + txr_remaining)) { |
| 5060 | for (; rxr_remaining; v_idx++, q_vectors--) { |
| 5061 | int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 5062 | err = ixgbe_alloc_q_vector(adapter, v_idx, |
| 5063 | 0, 0, rqpv, rxr_idx); |
| 5064 | |
| 5065 | if (err) |
| 5066 | goto err_out; |
| 5067 | |
| 5068 | /* update counts and index */ |
| 5069 | rxr_remaining -= rqpv; |
| 5070 | rxr_idx += rqpv; |
| 5071 | } |
| 5072 | } |
| 5073 | |
| 5074 | for (; q_vectors; v_idx++, q_vectors--) { |
| 5075 | int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 5076 | int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors); |
| 5077 | err = ixgbe_alloc_q_vector(adapter, v_idx, |
| 5078 | tqpv, txr_idx, |
| 5079 | rqpv, rxr_idx); |
| 5080 | |
| 5081 | if (err) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5082 | goto err_out; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 5083 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5084 | /* update counts and index */ |
| 5085 | rxr_remaining -= rqpv; |
| 5086 | rxr_idx += rqpv; |
| 5087 | txr_remaining -= tqpv; |
| 5088 | txr_idx += tqpv; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | return 0; |
| 5092 | |
| 5093 | err_out: |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 5094 | while (v_idx) { |
| 5095 | v_idx--; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5096 | ixgbe_free_q_vector(adapter, v_idx); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5097 | } |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5098 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5099 | return -ENOMEM; |
| 5100 | } |
| 5101 | |
| 5102 | /** |
| 5103 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 5104 | * @adapter: board private structure to initialize |
| 5105 | * |
| 5106 | * This function frees the memory allocated to the q_vectors. In addition if |
| 5107 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 5108 | * to freeing the q_vector. |
| 5109 | **/ |
| 5110 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 5111 | { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5112 | int v_idx, q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5113 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5114 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5115 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5116 | else |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5117 | q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5118 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5119 | for (v_idx = 0; v_idx < q_vectors; v_idx++) |
| 5120 | ixgbe_free_q_vector(adapter, v_idx); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5121 | } |
| 5122 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 5123 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5124 | { |
| 5125 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5126 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 5127 | pci_disable_msix(adapter->pdev); |
| 5128 | kfree(adapter->msix_entries); |
| 5129 | adapter->msix_entries = NULL; |
| 5130 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 5131 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 5132 | pci_disable_msi(adapter->pdev); |
| 5133 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | /** |
| 5137 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 5138 | * @adapter: board private structure to initialize |
| 5139 | * |
| 5140 | * We determine which interrupt scheme to use based on... |
| 5141 | * - Kernel support (MSI, MSI-X) |
| 5142 | * - which can be user-defined (via MODULE_PARAM) |
| 5143 | * - Hardware queue count (num_*_queues) |
| 5144 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 5145 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5146 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5147 | { |
| 5148 | int err; |
| 5149 | |
| 5150 | /* Number of supported queues */ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 5151 | err = ixgbe_set_num_queues(adapter); |
| 5152 | if (err) |
| 5153 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5154 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5155 | err = ixgbe_set_interrupt_capability(adapter); |
| 5156 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5157 | e_dev_err("Unable to setup interrupt capabilities\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5158 | goto err_set_interrupt; |
| 5159 | } |
| 5160 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5161 | err = ixgbe_alloc_q_vectors(adapter); |
| 5162 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5163 | e_dev_err("Unable to allocate memory for queue vectors\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5164 | goto err_alloc_q_vectors; |
| 5165 | } |
| 5166 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5167 | ixgbe_cache_ring_register(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5168 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5169 | 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] | 5170 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 5171 | adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5172 | |
| 5173 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5174 | |
| 5175 | return 0; |
| 5176 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5177 | err_alloc_q_vectors: |
| 5178 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5179 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5180 | return err; |
| 5181 | } |
| 5182 | |
| 5183 | /** |
| 5184 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 5185 | * @adapter: board private structure to clear interrupt scheme on |
| 5186 | * |
| 5187 | * We go through and clear interrupt specific resources and reset the structure |
| 5188 | * to pre-load conditions |
| 5189 | **/ |
| 5190 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 5191 | { |
Don Skidmore | b8eb3a1 | 2010-12-01 20:54:53 +0000 | [diff] [blame] | 5192 | adapter->num_tx_queues = 0; |
| 5193 | adapter->num_rx_queues = 0; |
| 5194 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5195 | ixgbe_free_q_vectors(adapter); |
| 5196 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | /** |
| 5200 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5201 | * @adapter: board private structure to initialize |
| 5202 | * |
| 5203 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5204 | * Fields are initialized based on PCI device information and |
| 5205 | * OS network device settings (MTU size). |
| 5206 | **/ |
| 5207 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 5208 | { |
| 5209 | struct ixgbe_hw *hw = &adapter->hw; |
| 5210 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5211 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5212 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5213 | int j; |
| 5214 | struct tc_configuration *tc; |
| 5215 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5216 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5217 | /* PCI config space info */ |
| 5218 | |
| 5219 | hw->vendor_id = pdev->vendor; |
| 5220 | hw->device_id = pdev->device; |
| 5221 | hw->revision_id = pdev->revision; |
| 5222 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5223 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5224 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5225 | /* Set capability flags */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 5226 | rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus()); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5227 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 5228 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5229 | switch (hw->mac.type) { |
| 5230 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5231 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5232 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5233 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5234 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5235 | case ixgbe_mac_X540: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 5236 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 5237 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5238 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5239 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5240 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5241 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5242 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 5243 | /* Flow Director hash filters enabled */ |
| 5244 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5245 | adapter->atr_sample_rate = 20; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5246 | adapter->ring_feature[RING_F_FDIR].indices = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5247 | IXGBE_MAX_FDIR_INDICES; |
Alexander Duyck | c04f6ca | 2011-05-11 07:18:36 +0000 | [diff] [blame] | 5248 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5249 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5250 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5251 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5252 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5253 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 5254 | /* Default traffic class to use for FCoE */ |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 5255 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5256 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5257 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5258 | break; |
| 5259 | default: |
| 5260 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5261 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5262 | |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5263 | /* n-tuple support exists, always init our spinlock */ |
| 5264 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5265 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5266 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5267 | switch (hw->mac.type) { |
| 5268 | case ixgbe_mac_X540: |
| 5269 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5270 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5271 | break; |
| 5272 | default: |
| 5273 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5274 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5275 | break; |
| 5276 | } |
| 5277 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5278 | /* Configure DCB traffic classes */ |
| 5279 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5280 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5281 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5282 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5283 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5284 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5285 | tc->dcb_pfc = pfc_disabled; |
| 5286 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5287 | |
| 5288 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5289 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5290 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5291 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5292 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5293 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5294 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5295 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5296 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5297 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5298 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 5299 | MAX_TRAFFIC_CLASS); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5300 | |
| 5301 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5302 | |
| 5303 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5304 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5305 | 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] | 5306 | #ifdef CONFIG_DCB |
| 5307 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 5308 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5309 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5310 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5311 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5312 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5313 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5314 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5315 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5316 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5317 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5318 | /* set default ring sizes */ |
| 5319 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5320 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5321 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5322 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5323 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5324 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5325 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5326 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5327 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5328 | return -EIO; |
| 5329 | } |
| 5330 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5331 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5332 | |
| 5333 | return 0; |
| 5334 | } |
| 5335 | |
| 5336 | /** |
| 5337 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5338 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5339 | * |
| 5340 | * Return 0 on success, negative on failure |
| 5341 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5342 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5343 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5344 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5345 | int orig_node = dev_to_node(dev); |
| 5346 | int numa_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5347 | int size; |
| 5348 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5349 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5350 | |
| 5351 | if (tx_ring->q_vector) |
| 5352 | numa_node = tx_ring->q_vector->numa_node; |
| 5353 | |
| 5354 | tx_ring->tx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5355 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5356 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5357 | if (!tx_ring->tx_buffer_info) |
| 5358 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5359 | |
| 5360 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5361 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5362 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5363 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5364 | set_dev_node(dev, numa_node); |
| 5365 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5366 | tx_ring->size, |
| 5367 | &tx_ring->dma, |
| 5368 | GFP_KERNEL); |
| 5369 | set_dev_node(dev, orig_node); |
| 5370 | if (!tx_ring->desc) |
| 5371 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5372 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5373 | if (!tx_ring->desc) |
| 5374 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5375 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5376 | tx_ring->next_to_use = 0; |
| 5377 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5378 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5379 | |
| 5380 | err: |
| 5381 | vfree(tx_ring->tx_buffer_info); |
| 5382 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5383 | 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] | 5384 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5388 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5389 | * @adapter: board private structure |
| 5390 | * |
| 5391 | * If this function returns with an error, then it's possible one or |
| 5392 | * more of the rings is populated (while the rest are not). It is the |
| 5393 | * callers duty to clean those orphaned rings. |
| 5394 | * |
| 5395 | * Return 0 on success, negative on failure |
| 5396 | **/ |
| 5397 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5398 | { |
| 5399 | int i, err = 0; |
| 5400 | |
| 5401 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5402 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5403 | if (!err) |
| 5404 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5405 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5406 | break; |
| 5407 | } |
| 5408 | |
| 5409 | return err; |
| 5410 | } |
| 5411 | |
| 5412 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5413 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5414 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5415 | * |
| 5416 | * Returns 0 on success, negative on failure |
| 5417 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5418 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5419 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5420 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5421 | int orig_node = dev_to_node(dev); |
| 5422 | int numa_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5423 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5424 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5425 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5426 | |
| 5427 | if (rx_ring->q_vector) |
| 5428 | numa_node = rx_ring->q_vector->numa_node; |
| 5429 | |
| 5430 | rx_ring->rx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5431 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5432 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5433 | if (!rx_ring->rx_buffer_info) |
| 5434 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5435 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5436 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5437 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5438 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5439 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5440 | set_dev_node(dev, numa_node); |
| 5441 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5442 | rx_ring->size, |
| 5443 | &rx_ring->dma, |
| 5444 | GFP_KERNEL); |
| 5445 | set_dev_node(dev, orig_node); |
| 5446 | if (!rx_ring->desc) |
| 5447 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5448 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5449 | if (!rx_ring->desc) |
| 5450 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5451 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5452 | rx_ring->next_to_clean = 0; |
| 5453 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5454 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 5455 | ixgbe_init_rx_page_offset(rx_ring); |
| 5456 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5457 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5458 | err: |
| 5459 | vfree(rx_ring->rx_buffer_info); |
| 5460 | rx_ring->rx_buffer_info = NULL; |
| 5461 | 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] | 5462 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5466 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5467 | * @adapter: board private structure |
| 5468 | * |
| 5469 | * If this function returns with an error, then it's possible one or |
| 5470 | * more of the rings is populated (while the rest are not). It is the |
| 5471 | * callers duty to clean those orphaned rings. |
| 5472 | * |
| 5473 | * Return 0 on success, negative on failure |
| 5474 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5475 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5476 | { |
| 5477 | int i, err = 0; |
| 5478 | |
| 5479 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5480 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5481 | if (!err) |
| 5482 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5483 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5484 | break; |
| 5485 | } |
| 5486 | |
| 5487 | return err; |
| 5488 | } |
| 5489 | |
| 5490 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5491 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5492 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5493 | * |
| 5494 | * Free all transmit software resources |
| 5495 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5496 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5497 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5498 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5499 | |
| 5500 | vfree(tx_ring->tx_buffer_info); |
| 5501 | tx_ring->tx_buffer_info = NULL; |
| 5502 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5503 | /* if not set, then don't free */ |
| 5504 | if (!tx_ring->desc) |
| 5505 | return; |
| 5506 | |
| 5507 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5508 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5509 | |
| 5510 | tx_ring->desc = NULL; |
| 5511 | } |
| 5512 | |
| 5513 | /** |
| 5514 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5515 | * @adapter: board private structure |
| 5516 | * |
| 5517 | * Free all transmit software resources |
| 5518 | **/ |
| 5519 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5520 | { |
| 5521 | int i; |
| 5522 | |
| 5523 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5524 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5525 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5529 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5530 | * @rx_ring: ring to clean the resources from |
| 5531 | * |
| 5532 | * Free all receive software resources |
| 5533 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5534 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5535 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5536 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5537 | |
| 5538 | vfree(rx_ring->rx_buffer_info); |
| 5539 | rx_ring->rx_buffer_info = NULL; |
| 5540 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5541 | /* if not set, then don't free */ |
| 5542 | if (!rx_ring->desc) |
| 5543 | return; |
| 5544 | |
| 5545 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5546 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5547 | |
| 5548 | rx_ring->desc = NULL; |
| 5549 | } |
| 5550 | |
| 5551 | /** |
| 5552 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5553 | * @adapter: board private structure |
| 5554 | * |
| 5555 | * Free all receive software resources |
| 5556 | **/ |
| 5557 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5558 | { |
| 5559 | int i; |
| 5560 | |
| 5561 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5562 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5563 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5564 | } |
| 5565 | |
| 5566 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5567 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5568 | * @netdev: network interface device structure |
| 5569 | * @new_mtu: new value for maximum frame size |
| 5570 | * |
| 5571 | * Returns 0 on success, negative on failure |
| 5572 | **/ |
| 5573 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5574 | { |
| 5575 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5576 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5577 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5578 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5579 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5580 | return -EINVAL; |
| 5581 | |
| 5582 | /* |
| 5583 | * For 82599EB we cannot allow PF to change MTU greater than 1500 |
| 5584 | * in SR-IOV mode as it may cause buffer overruns in guest VFs that |
| 5585 | * don't allocate and chain buffers correctly. |
| 5586 | */ |
| 5587 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 5588 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
| 5589 | (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 5590 | return -EINVAL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5591 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5592 | 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] | 5593 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5594 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5595 | netdev->mtu = new_mtu; |
| 5596 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5597 | if (netif_running(netdev)) |
| 5598 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5599 | |
| 5600 | return 0; |
| 5601 | } |
| 5602 | |
| 5603 | /** |
| 5604 | * ixgbe_open - Called when a network interface is made active |
| 5605 | * @netdev: network interface device structure |
| 5606 | * |
| 5607 | * Returns 0 on success, negative value on failure |
| 5608 | * |
| 5609 | * The open entry point is called when a network interface is made |
| 5610 | * active by the system (IFF_UP). At this point all resources needed |
| 5611 | * for transmit and receive operations are allocated, the interrupt |
| 5612 | * handler is registered with the OS, the watchdog timer is started, |
| 5613 | * and the stack is notified that the interface is ready. |
| 5614 | **/ |
| 5615 | static int ixgbe_open(struct net_device *netdev) |
| 5616 | { |
| 5617 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5618 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5619 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5620 | /* disallow open during test */ |
| 5621 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5622 | return -EBUSY; |
| 5623 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5624 | netif_carrier_off(netdev); |
| 5625 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5626 | /* allocate transmit descriptors */ |
| 5627 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5628 | if (err) |
| 5629 | goto err_setup_tx; |
| 5630 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5631 | /* allocate receive descriptors */ |
| 5632 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5633 | if (err) |
| 5634 | goto err_setup_rx; |
| 5635 | |
| 5636 | ixgbe_configure(adapter); |
| 5637 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5638 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5639 | if (err) |
| 5640 | goto err_req_irq; |
| 5641 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5642 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5643 | |
| 5644 | return 0; |
| 5645 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5646 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5647 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5648 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5649 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5650 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5651 | ixgbe_reset(adapter); |
| 5652 | |
| 5653 | return err; |
| 5654 | } |
| 5655 | |
| 5656 | /** |
| 5657 | * ixgbe_close - Disables a network interface |
| 5658 | * @netdev: network interface device structure |
| 5659 | * |
| 5660 | * Returns 0, this is not allowed to fail |
| 5661 | * |
| 5662 | * The close entry point is called when an interface is de-activated |
| 5663 | * by the OS. The hardware is still under the drivers control, but |
| 5664 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5665 | * hardware, and all transmit and receive resources are freed. |
| 5666 | **/ |
| 5667 | static int ixgbe_close(struct net_device *netdev) |
| 5668 | { |
| 5669 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5670 | |
| 5671 | ixgbe_down(adapter); |
| 5672 | ixgbe_free_irq(adapter); |
| 5673 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5674 | ixgbe_fdir_filter_exit(adapter); |
| 5675 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5676 | ixgbe_free_all_tx_resources(adapter); |
| 5677 | ixgbe_free_all_rx_resources(adapter); |
| 5678 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5679 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5680 | |
| 5681 | return 0; |
| 5682 | } |
| 5683 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5684 | #ifdef CONFIG_PM |
| 5685 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5686 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5687 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5688 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5689 | u32 err; |
| 5690 | |
| 5691 | pci_set_power_state(pdev, PCI_D0); |
| 5692 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5693 | /* |
| 5694 | * pci_restore_state clears dev->state_saved so call |
| 5695 | * pci_save_state to restore it. |
| 5696 | */ |
| 5697 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5698 | |
| 5699 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5700 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5701 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5702 | return err; |
| 5703 | } |
| 5704 | pci_set_master(pdev); |
| 5705 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5706 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5707 | |
| 5708 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5709 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5710 | e_dev_err("Cannot initialize interrupts for device\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5711 | return err; |
| 5712 | } |
| 5713 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5714 | ixgbe_reset(adapter); |
| 5715 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5716 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5717 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5718 | if (netif_running(netdev)) { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5719 | err = ixgbe_open(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5720 | if (err) |
| 5721 | return err; |
| 5722 | } |
| 5723 | |
| 5724 | netif_device_attach(netdev); |
| 5725 | |
| 5726 | return 0; |
| 5727 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5728 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5729 | |
| 5730 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5731 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5732 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5733 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5734 | struct ixgbe_hw *hw = &adapter->hw; |
| 5735 | u32 ctrl, fctrl; |
| 5736 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5737 | #ifdef CONFIG_PM |
| 5738 | int retval = 0; |
| 5739 | #endif |
| 5740 | |
| 5741 | netif_device_detach(netdev); |
| 5742 | |
| 5743 | if (netif_running(netdev)) { |
| 5744 | ixgbe_down(adapter); |
| 5745 | ixgbe_free_irq(adapter); |
| 5746 | ixgbe_free_all_tx_resources(adapter); |
| 5747 | ixgbe_free_all_rx_resources(adapter); |
| 5748 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5749 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5750 | ixgbe_clear_interrupt_scheme(adapter); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 5751 | #ifdef CONFIG_DCB |
| 5752 | kfree(adapter->ixgbe_ieee_pfc); |
| 5753 | kfree(adapter->ixgbe_ieee_ets); |
| 5754 | #endif |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5755 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5756 | #ifdef CONFIG_PM |
| 5757 | retval = pci_save_state(pdev); |
| 5758 | if (retval) |
| 5759 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5760 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5761 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5762 | if (wufc) { |
| 5763 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5764 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5765 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5766 | if (wufc & IXGBE_WUFC_MC) { |
| 5767 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5768 | fctrl |= IXGBE_FCTRL_MPE; |
| 5769 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5770 | } |
| 5771 | |
| 5772 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5773 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5774 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5775 | |
| 5776 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5777 | } else { |
| 5778 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5779 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5780 | } |
| 5781 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5782 | switch (hw->mac.type) { |
| 5783 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5784 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5785 | break; |
| 5786 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5787 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5788 | pci_wake_from_d3(pdev, !!wufc); |
| 5789 | break; |
| 5790 | default: |
| 5791 | break; |
| 5792 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5793 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5794 | *enable_wake = !!wufc; |
| 5795 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5796 | ixgbe_release_hw_control(adapter); |
| 5797 | |
| 5798 | pci_disable_device(pdev); |
| 5799 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5800 | return 0; |
| 5801 | } |
| 5802 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5803 | #ifdef CONFIG_PM |
| 5804 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5805 | { |
| 5806 | int retval; |
| 5807 | bool wake; |
| 5808 | |
| 5809 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5810 | if (retval) |
| 5811 | return retval; |
| 5812 | |
| 5813 | if (wake) { |
| 5814 | pci_prepare_to_sleep(pdev); |
| 5815 | } else { |
| 5816 | pci_wake_from_d3(pdev, false); |
| 5817 | pci_set_power_state(pdev, PCI_D3hot); |
| 5818 | } |
| 5819 | |
| 5820 | return 0; |
| 5821 | } |
| 5822 | #endif /* CONFIG_PM */ |
| 5823 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5824 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5825 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5826 | bool wake; |
| 5827 | |
| 5828 | __ixgbe_shutdown(pdev, &wake); |
| 5829 | |
| 5830 | if (system_state == SYSTEM_POWER_OFF) { |
| 5831 | pci_wake_from_d3(pdev, wake); |
| 5832 | pci_set_power_state(pdev, PCI_D3hot); |
| 5833 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5837 | * ixgbe_update_stats - Update the board statistics counters. |
| 5838 | * @adapter: board private structure |
| 5839 | **/ |
| 5840 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5841 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5842 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5843 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5844 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5845 | u64 total_mpc = 0; |
| 5846 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5847 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5848 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5849 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5850 | #ifdef IXGBE_FCOE |
| 5851 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 5852 | unsigned int cpu; |
| 5853 | u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0; |
| 5854 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5855 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5856 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5857 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5858 | return; |
| 5859 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5860 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5861 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5862 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5863 | for (i = 0; i < 16; i++) |
| 5864 | adapter->hw_rx_no_dma_resources += |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5865 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5866 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5867 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5868 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5869 | } |
| 5870 | adapter->rsc_total_count = rsc_count; |
| 5871 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5874 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5875 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5876 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5877 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5878 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5879 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5880 | bytes += rx_ring->stats.bytes; |
| 5881 | packets += rx_ring->stats.packets; |
| 5882 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5883 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5884 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5885 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5886 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5887 | netdev->stats.rx_bytes = bytes; |
| 5888 | netdev->stats.rx_packets = packets; |
| 5889 | |
| 5890 | bytes = 0; |
| 5891 | packets = 0; |
| 5892 | /* gather some stats to the adapter struct that are per queue */ |
| 5893 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5894 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5895 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5896 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5897 | bytes += tx_ring->stats.bytes; |
| 5898 | packets += tx_ring->stats.packets; |
| 5899 | } |
| 5900 | adapter->restart_queue = restart_queue; |
| 5901 | adapter->tx_busy = tx_busy; |
| 5902 | netdev->stats.tx_bytes = bytes; |
| 5903 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5904 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5905 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5906 | |
| 5907 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5908 | for (i = 0; i < 8; i++) { |
| 5909 | /* for packet buffers not used, the register should read 0 */ |
| 5910 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5911 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5912 | hwstats->mpc[i] += mpc; |
| 5913 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5914 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5915 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5916 | switch (hw->mac.type) { |
| 5917 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5918 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5919 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5920 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5921 | hwstats->pxonrxc[i] += |
| 5922 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5923 | break; |
| 5924 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5925 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5926 | hwstats->pxonrxc[i] += |
| 5927 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5928 | break; |
| 5929 | default: |
| 5930 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5931 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5932 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5933 | |
| 5934 | /*16 register reads */ |
| 5935 | for (i = 0; i < 16; i++) { |
| 5936 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5937 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5938 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
| 5939 | (hw->mac.type == ixgbe_mac_X540)) { |
| 5940 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 5941 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 5942 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 5943 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 5944 | } |
| 5945 | } |
| 5946 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5947 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5948 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5949 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5950 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5951 | ixgbe_update_xoff_received(adapter); |
| 5952 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5953 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5954 | switch (hw->mac.type) { |
| 5955 | case ixgbe_mac_82598EB: |
| 5956 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5957 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5958 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5959 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5960 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5961 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5962 | /* OS2BMC stats are X540 only*/ |
| 5963 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5964 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5965 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5966 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5967 | case ixgbe_mac_82599EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5968 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5969 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5970 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5971 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5972 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5973 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5974 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5975 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5976 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5977 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5978 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5979 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5980 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5981 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5982 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5983 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5984 | /* Add up per cpu counters for total ddp aloc fail */ |
| 5985 | if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) { |
| 5986 | for_each_possible_cpu(cpu) { |
| 5987 | fcoe_noddp_counts_sum += |
| 5988 | *per_cpu_ptr(fcoe->pcpu_noddp, cpu); |
| 5989 | fcoe_noddp_ext_buff_counts_sum += |
| 5990 | *per_cpu_ptr(fcoe-> |
| 5991 | pcpu_noddp_ext_buff, cpu); |
| 5992 | } |
| 5993 | } |
| 5994 | hwstats->fcoe_noddp = fcoe_noddp_counts_sum; |
| 5995 | hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum; |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5996 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5997 | break; |
| 5998 | default: |
| 5999 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6000 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6001 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6002 | hwstats->bprc += bprc; |
| 6003 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6004 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6005 | hwstats->mprc -= bprc; |
| 6006 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 6007 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 6008 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 6009 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 6010 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 6011 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 6012 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 6013 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6014 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6015 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6016 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6017 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6018 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 6019 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6020 | /* |
| 6021 | * 82598 errata - tx of flow control packets is included in tx counters |
| 6022 | */ |
| 6023 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6024 | hwstats->gptc -= xon_off_tot; |
| 6025 | hwstats->mptc -= xon_off_tot; |
| 6026 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 6027 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6028 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6029 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6030 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6031 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6032 | hwstats->ptc64 -= xon_off_tot; |
| 6033 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6034 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6035 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6036 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6037 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6038 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6039 | |
| 6040 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6041 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6042 | |
| 6043 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6044 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6045 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6046 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 6047 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6048 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6052 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
| 6053 | * @adapter - pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6054 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6055 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6056 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6057 | struct ixgbe_hw *hw = &adapter->hw; |
| 6058 | int i; |
| 6059 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6060 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 6061 | return; |
| 6062 | |
| 6063 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 6064 | |
| 6065 | /* if interface is down do nothing */ |
| 6066 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6067 | return; |
| 6068 | |
| 6069 | /* do nothing if we are not using signature filters */ |
| 6070 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6071 | return; |
| 6072 | |
| 6073 | adapter->fdir_overflow++; |
| 6074 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6075 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6076 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6077 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6078 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6079 | /* re-enable flow director interrupts */ |
| 6080 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6081 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6082 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6083 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6084 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6085 | } |
| 6086 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6087 | /** |
| 6088 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
| 6089 | * @adapter - pointer to the device adapter structure |
| 6090 | * |
| 6091 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 6092 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6093 | * 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] | 6094 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6095 | */ |
| 6096 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6097 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6098 | struct ixgbe_hw *hw = &adapter->hw; |
| 6099 | u64 eics = 0; |
| 6100 | int i; |
| 6101 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6102 | /* If we're down or resetting, just bail */ |
| 6103 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6104 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6105 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6106 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6107 | /* Force detection of hung controller */ |
| 6108 | if (netif_carrier_ok(adapter->netdev)) { |
| 6109 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6110 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6111 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6112 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6113 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6114 | /* |
| 6115 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6116 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6117 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6118 | */ |
| 6119 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6120 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6121 | } else { |
| 6122 | /* get one bit for every active tx/rx interrupt vector */ |
| 6123 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 6124 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 6125 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6126 | eics |= ((u64)1 << i); |
| 6127 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6128 | } |
| 6129 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6130 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6131 | ixgbe_irq_rearm_queues(adapter, eics); |
| 6132 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6136 | * ixgbe_watchdog_update_link - update the link status |
| 6137 | * @adapter - pointer to the device adapter structure |
| 6138 | * @link_speed - pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6139 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6140 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6141 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6142 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6143 | u32 link_speed = adapter->link_speed; |
| 6144 | bool link_up = adapter->link_up; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6145 | int i; |
| 6146 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6147 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6148 | return; |
| 6149 | |
| 6150 | if (hw->mac.ops.check_link) { |
| 6151 | 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] | 6152 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6153 | /* always assume link is up, if no check link function */ |
| 6154 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6155 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6156 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6157 | if (link_up) { |
| 6158 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 6159 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 6160 | hw->mac.ops.fc_enable(hw, i); |
| 6161 | } else { |
| 6162 | hw->mac.ops.fc_enable(hw, 0); |
| 6163 | } |
| 6164 | } |
| 6165 | |
| 6166 | if (link_up || |
| 6167 | time_after(jiffies, (adapter->link_check_timeout + |
| 6168 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6169 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6170 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6171 | IXGBE_WRITE_FLUSH(hw); |
| 6172 | } |
| 6173 | |
| 6174 | adapter->link_up = link_up; |
| 6175 | adapter->link_speed = link_speed; |
| 6176 | } |
| 6177 | |
| 6178 | /** |
| 6179 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6180 | * print link up message |
| 6181 | * @adapter - pointer to the device adapter structure |
| 6182 | **/ |
| 6183 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6184 | { |
| 6185 | struct net_device *netdev = adapter->netdev; |
| 6186 | struct ixgbe_hw *hw = &adapter->hw; |
| 6187 | u32 link_speed = adapter->link_speed; |
| 6188 | bool flow_rx, flow_tx; |
| 6189 | |
| 6190 | /* only continue if link was previously down */ |
| 6191 | if (netif_carrier_ok(netdev)) |
| 6192 | return; |
| 6193 | |
| 6194 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6195 | |
| 6196 | switch (hw->mac.type) { |
| 6197 | case ixgbe_mac_82598EB: { |
| 6198 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6199 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6200 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6201 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6202 | } |
| 6203 | break; |
| 6204 | case ixgbe_mac_X540: |
| 6205 | case ixgbe_mac_82599EB: { |
| 6206 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6207 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6208 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6209 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6210 | } |
| 6211 | break; |
| 6212 | default: |
| 6213 | flow_tx = false; |
| 6214 | flow_rx = false; |
| 6215 | break; |
| 6216 | } |
| 6217 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 6218 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 6219 | "10 Gbps" : |
| 6220 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 6221 | "1 Gbps" : |
| 6222 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6223 | "100 Mbps" : |
| 6224 | "unknown speed"))), |
| 6225 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6226 | (flow_rx ? "RX" : |
| 6227 | (flow_tx ? "TX" : "None")))); |
| 6228 | |
| 6229 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6230 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | /** |
| 6234 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6235 | * print link down message |
| 6236 | * @adapter - pointer to the adapter structure |
| 6237 | **/ |
| 6238 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) |
| 6239 | { |
| 6240 | struct net_device *netdev = adapter->netdev; |
| 6241 | struct ixgbe_hw *hw = &adapter->hw; |
| 6242 | |
| 6243 | adapter->link_up = false; |
| 6244 | adapter->link_speed = 0; |
| 6245 | |
| 6246 | /* only continue if link was up previously */ |
| 6247 | if (!netif_carrier_ok(netdev)) |
| 6248 | return; |
| 6249 | |
| 6250 | /* poll for SFP+ cable when link is down */ |
| 6251 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6252 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6253 | |
| 6254 | e_info(drv, "NIC Link is Down\n"); |
| 6255 | netif_carrier_off(netdev); |
| 6256 | } |
| 6257 | |
| 6258 | /** |
| 6259 | * ixgbe_watchdog_flush_tx - flush queues on link down |
| 6260 | * @adapter - pointer to the device adapter structure |
| 6261 | **/ |
| 6262 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6263 | { |
| 6264 | int i; |
| 6265 | int some_tx_pending = 0; |
| 6266 | |
| 6267 | if (!netif_carrier_ok(adapter->netdev)) { |
| 6268 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6269 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6270 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 6271 | some_tx_pending = 1; |
| 6272 | break; |
| 6273 | } |
| 6274 | } |
| 6275 | |
| 6276 | if (some_tx_pending) { |
| 6277 | /* We've lost link, so the controller stops DMA, |
| 6278 | * but we've got queued Tx work that's never going |
| 6279 | * to get done, so reset controller to flush Tx. |
| 6280 | * (Do the reset outside of interrupt context). |
| 6281 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6282 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6283 | } |
| 6284 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6285 | } |
| 6286 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6287 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6288 | { |
| 6289 | u32 ssvpc; |
| 6290 | |
| 6291 | /* Do not perform spoof check for 82598 */ |
| 6292 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6293 | return; |
| 6294 | |
| 6295 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6296 | |
| 6297 | /* |
| 6298 | * ssvpc register is cleared on read, if zero then no |
| 6299 | * spoofed packets in the last interval. |
| 6300 | */ |
| 6301 | if (!ssvpc) |
| 6302 | return; |
| 6303 | |
| 6304 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); |
| 6305 | } |
| 6306 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6307 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6308 | * ixgbe_watchdog_subtask - check and bring link up |
| 6309 | * @adapter - pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6310 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6311 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6312 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6313 | /* if interface is down do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6314 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6315 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6316 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6317 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6318 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6319 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6320 | if (adapter->link_up) |
| 6321 | ixgbe_watchdog_link_is_up(adapter); |
| 6322 | else |
| 6323 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6324 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6325 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6326 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6327 | |
| 6328 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6329 | } |
| 6330 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6331 | /** |
| 6332 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
| 6333 | * @adapter - the ixgbe adapter structure |
| 6334 | **/ |
| 6335 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6336 | { |
| 6337 | struct ixgbe_hw *hw = &adapter->hw; |
| 6338 | s32 err; |
| 6339 | |
| 6340 | /* not searching for SFP so there is nothing to do here */ |
| 6341 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6342 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6343 | return; |
| 6344 | |
| 6345 | /* someone else is in init, wait until next service event */ |
| 6346 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6347 | return; |
| 6348 | |
| 6349 | err = hw->phy.ops.identify_sfp(hw); |
| 6350 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6351 | goto sfp_out; |
| 6352 | |
| 6353 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6354 | /* If no cable is present, then we need to reset |
| 6355 | * the next time we find a good cable. */ |
| 6356 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6357 | } |
| 6358 | |
| 6359 | /* exit on error */ |
| 6360 | if (err) |
| 6361 | goto sfp_out; |
| 6362 | |
| 6363 | /* exit if reset not needed */ |
| 6364 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6365 | goto sfp_out; |
| 6366 | |
| 6367 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6368 | |
| 6369 | /* |
| 6370 | * A module may be identified correctly, but the EEPROM may not have |
| 6371 | * support for that module. setup_sfp() will fail in that case, so |
| 6372 | * we should not allow that module to load. |
| 6373 | */ |
| 6374 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6375 | err = hw->phy.ops.reset(hw); |
| 6376 | else |
| 6377 | err = hw->mac.ops.setup_sfp(hw); |
| 6378 | |
| 6379 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6380 | goto sfp_out; |
| 6381 | |
| 6382 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6383 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6384 | |
| 6385 | sfp_out: |
| 6386 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6387 | |
| 6388 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6389 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6390 | e_dev_err("failed to initialize because an unsupported " |
| 6391 | "SFP+ module type was detected.\n"); |
| 6392 | e_dev_err("Reload the driver after installing a " |
| 6393 | "supported module.\n"); |
| 6394 | unregister_netdev(adapter->netdev); |
| 6395 | } |
| 6396 | } |
| 6397 | |
| 6398 | /** |
| 6399 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
| 6400 | * @adapter - the ixgbe adapter structure |
| 6401 | **/ |
| 6402 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6403 | { |
| 6404 | struct ixgbe_hw *hw = &adapter->hw; |
| 6405 | u32 autoneg; |
| 6406 | bool negotiation; |
| 6407 | |
| 6408 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6409 | return; |
| 6410 | |
| 6411 | /* someone else is in init, wait until next service event */ |
| 6412 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6413 | return; |
| 6414 | |
| 6415 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6416 | |
| 6417 | autoneg = hw->phy.autoneg_advertised; |
| 6418 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 6419 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6420 | if (hw->mac.ops.setup_link) |
| 6421 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 6422 | |
| 6423 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6424 | adapter->link_check_timeout = jiffies; |
| 6425 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6426 | } |
| 6427 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6428 | #ifdef CONFIG_PCI_IOV |
| 6429 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6430 | { |
| 6431 | int vf; |
| 6432 | struct ixgbe_hw *hw = &adapter->hw; |
| 6433 | struct net_device *netdev = adapter->netdev; |
| 6434 | u32 gpc; |
| 6435 | u32 ciaa, ciad; |
| 6436 | |
| 6437 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6438 | if (gpc) /* If incrementing then no need for the check below */ |
| 6439 | return; |
| 6440 | /* |
| 6441 | * Check to see if a bad DMA write target from an errant or |
| 6442 | * malicious VF has caused a PCIe error. If so then we can |
| 6443 | * issue a VFLR to the offending VF(s) and then resume without |
| 6444 | * requesting a full slot reset. |
| 6445 | */ |
| 6446 | |
| 6447 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 6448 | ciaa = (vf << 16) | 0x80000000; |
| 6449 | /* 32 bit read so align, we really want status at offset 6 */ |
| 6450 | ciaa |= PCI_COMMAND; |
| 6451 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6452 | ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599); |
| 6453 | ciaa &= 0x7FFFFFFF; |
| 6454 | /* disable debug mode asap after reading data */ |
| 6455 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6456 | /* Get the upper 16 bits which will be the PCI status reg */ |
| 6457 | ciad >>= 16; |
| 6458 | if (ciad & PCI_STATUS_REC_MASTER_ABORT) { |
| 6459 | netdev_err(netdev, "VF %d Hung DMA\n", vf); |
| 6460 | /* Issue VFLR */ |
| 6461 | ciaa = (vf << 16) | 0x80000000; |
| 6462 | ciaa |= 0xA8; |
| 6463 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6464 | ciad = 0x00008000; /* VFLR */ |
| 6465 | IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad); |
| 6466 | ciaa &= 0x7FFFFFFF; |
| 6467 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6468 | } |
| 6469 | } |
| 6470 | } |
| 6471 | |
| 6472 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6473 | /** |
| 6474 | * ixgbe_service_timer - Timer Call-back |
| 6475 | * @data: pointer to adapter cast into an unsigned long |
| 6476 | **/ |
| 6477 | static void ixgbe_service_timer(unsigned long data) |
| 6478 | { |
| 6479 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6480 | unsigned long next_event_offset; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6481 | bool ready = true; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6482 | |
| 6483 | /* poll faster when waiting for link */ |
| 6484 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6485 | next_event_offset = HZ / 10; |
| 6486 | else |
| 6487 | next_event_offset = HZ * 2; |
| 6488 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6489 | #ifdef CONFIG_PCI_IOV |
Alexander Duyck | 6bb78cf | 2012-02-08 07:51:22 +0000 | [diff] [blame] | 6490 | /* |
| 6491 | * don't bother with SR-IOV VF DMA hang check if there are |
| 6492 | * no VFs or the link is down |
| 6493 | */ |
| 6494 | if (!adapter->num_vfs || |
| 6495 | (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6496 | goto normal_timer_service; |
| 6497 | |
| 6498 | /* If we have VFs allocated then we must check for DMA hangs */ |
| 6499 | ixgbe_check_for_bad_vf(adapter); |
| 6500 | next_event_offset = HZ / 50; |
| 6501 | adapter->timer_event_accumulator++; |
| 6502 | |
| 6503 | if (adapter->timer_event_accumulator >= 100) |
| 6504 | adapter->timer_event_accumulator = 0; |
| 6505 | else |
| 6506 | ready = false; |
| 6507 | |
| 6508 | normal_timer_service: |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6509 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6510 | /* Reset the timer */ |
| 6511 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6512 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6513 | if (ready) |
| 6514 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6515 | } |
| 6516 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6517 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6518 | { |
| 6519 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6520 | return; |
| 6521 | |
| 6522 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6523 | |
| 6524 | /* If we're already down or resetting, just bail */ |
| 6525 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6526 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6527 | return; |
| 6528 | |
| 6529 | ixgbe_dump(adapter); |
| 6530 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6531 | adapter->tx_timeout_count++; |
| 6532 | |
| 6533 | ixgbe_reinit_locked(adapter); |
| 6534 | } |
| 6535 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6536 | /** |
| 6537 | * ixgbe_service_task - manages and runs subtasks |
| 6538 | * @work: pointer to work_struct containing our data |
| 6539 | **/ |
| 6540 | static void ixgbe_service_task(struct work_struct *work) |
| 6541 | { |
| 6542 | struct ixgbe_adapter *adapter = container_of(work, |
| 6543 | struct ixgbe_adapter, |
| 6544 | service_task); |
| 6545 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6546 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6547 | ixgbe_sfp_detection_subtask(adapter); |
| 6548 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6549 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6550 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6551 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6552 | ixgbe_check_hang_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6553 | |
| 6554 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6555 | } |
| 6556 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6557 | void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens, |
| 6558 | u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6559 | { |
| 6560 | struct ixgbe_adv_tx_context_desc *context_desc; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6561 | u16 i = tx_ring->next_to_use; |
| 6562 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6563 | context_desc = IXGBE_TX_CTXTDESC(tx_ring, i); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6564 | |
| 6565 | i++; |
| 6566 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 6567 | |
| 6568 | /* set bits to identify this as an advanced context descriptor */ |
| 6569 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 6570 | |
| 6571 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6572 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); |
| 6573 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 6574 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 6575 | } |
| 6576 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6577 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 6578 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6579 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6580 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6581 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6582 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6583 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6584 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6585 | if (!skb_is_gso(skb)) |
| 6586 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6587 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6588 | if (skb_header_cloned(skb)) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6589 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6590 | if (err) |
| 6591 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6592 | } |
| 6593 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6594 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6595 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6596 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6597 | if (first->protocol == __constant_htons(ETH_P_IP)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6598 | struct iphdr *iph = ip_hdr(skb); |
| 6599 | iph->tot_len = 0; |
| 6600 | iph->check = 0; |
| 6601 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6602 | iph->daddr, 0, |
| 6603 | IPPROTO_TCP, |
| 6604 | 0); |
| 6605 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6606 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 6607 | IXGBE_TX_FLAGS_CSUM | |
| 6608 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6609 | } else if (skb_is_gso_v6(skb)) { |
| 6610 | ipv6_hdr(skb)->payload_len = 0; |
| 6611 | tcp_hdr(skb)->check = |
| 6612 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6613 | &ipv6_hdr(skb)->daddr, |
| 6614 | 0, IPPROTO_TCP, 0); |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6615 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 6616 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6617 | } |
| 6618 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6619 | /* compute header lengths */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6620 | l4len = tcp_hdrlen(skb); |
| 6621 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6622 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6623 | /* update gso size and bytecount with header size */ |
| 6624 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 6625 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 6626 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6627 | /* mss_l4len_id: use 1 as index for TSO */ |
| 6628 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6629 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 6630 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 6631 | |
| 6632 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6633 | vlan_macip_lens = skb_network_header_len(skb); |
| 6634 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6635 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6636 | |
| 6637 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6638 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6639 | |
| 6640 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6641 | } |
| 6642 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6643 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 6644 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6645 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6646 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6647 | u32 vlan_macip_lens = 0; |
| 6648 | u32 mss_l4len_idx = 0; |
| 6649 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6650 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6651 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6652 | if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) && |
| 6653 | !(first->tx_flags & IXGBE_TX_FLAGS_TXSW)) |
| 6654 | return; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6655 | } else { |
| 6656 | u8 l4_hdr = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6657 | switch (first->protocol) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6658 | case __constant_htons(ETH_P_IP): |
| 6659 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6660 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6661 | l4_hdr = ip_hdr(skb)->protocol; |
| 6662 | break; |
| 6663 | case __constant_htons(ETH_P_IPV6): |
| 6664 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6665 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6666 | break; |
| 6667 | default: |
| 6668 | if (unlikely(net_ratelimit())) { |
| 6669 | dev_warn(tx_ring->dev, |
| 6670 | "partial checksum but proto=%x!\n", |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6671 | first->protocol); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6672 | } |
| 6673 | break; |
| 6674 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6675 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6676 | switch (l4_hdr) { |
| 6677 | case IPPROTO_TCP: |
| 6678 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6679 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6680 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6681 | break; |
| 6682 | case IPPROTO_SCTP: |
| 6683 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6684 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6685 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6686 | break; |
| 6687 | case IPPROTO_UDP: |
| 6688 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6689 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6690 | break; |
| 6691 | default: |
| 6692 | if (unlikely(net_ratelimit())) { |
| 6693 | dev_warn(tx_ring->dev, |
| 6694 | "partial checksum but l4 proto=%x!\n", |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6695 | l4_hdr); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6696 | } |
| 6697 | break; |
| 6698 | } |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6699 | |
| 6700 | /* update TX checksum flag */ |
| 6701 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6702 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6703 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6704 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6705 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6706 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6707 | |
| 6708 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6709 | type_tucmd, mss_l4len_idx); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6710 | } |
| 6711 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6712 | static __le32 ixgbe_tx_cmd_type(u32 tx_flags) |
| 6713 | { |
| 6714 | /* set type for advanced descriptor with frame checksum insertion */ |
| 6715 | __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA | |
| 6716 | IXGBE_ADVTXD_DCMD_IFCS | |
| 6717 | IXGBE_ADVTXD_DCMD_DEXT); |
| 6718 | |
| 6719 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6720 | if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6721 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE); |
| 6722 | |
| 6723 | /* set segmentation enable bits for TSO/FSO */ |
| 6724 | #ifdef IXGBE_FCOE |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6725 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6726 | #else |
| 6727 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6728 | #endif |
| 6729 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE); |
| 6730 | |
| 6731 | return cmd_type; |
| 6732 | } |
| 6733 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6734 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 6735 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6736 | { |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6737 | __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6738 | |
| 6739 | /* enable L4 checksum for TSO and TX checksum offload */ |
| 6740 | if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6741 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM); |
| 6742 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6743 | /* enble IPv4 checksum for TSO */ |
| 6744 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6745 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6746 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6747 | /* use index 1 context for TSO/FSO/FCOE */ |
| 6748 | #ifdef IXGBE_FCOE |
| 6749 | if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE)) |
| 6750 | #else |
| 6751 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6752 | #endif |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6753 | olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 6754 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6755 | /* |
| 6756 | * Check Context must be set if Tx switch is enabled, which it |
| 6757 | * always is for case where virtual functions are running |
| 6758 | */ |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6759 | #ifdef IXGBE_FCOE |
| 6760 | if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE)) |
| 6761 | #else |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6762 | if (tx_flags & IXGBE_TX_FLAGS_TXSW) |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6763 | #endif |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6764 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC); |
| 6765 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6766 | tx_desc->read.olinfo_status = olinfo_status; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 6770 | IXGBE_TXD_CMD_RS) |
| 6771 | |
| 6772 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6773 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6774 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6775 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6776 | dma_addr_t dma; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6777 | struct sk_buff *skb = first->skb; |
| 6778 | struct ixgbe_tx_buffer *tx_buffer; |
| 6779 | union ixgbe_adv_tx_desc *tx_desc; |
| 6780 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6781 | unsigned int data_len = skb->data_len; |
| 6782 | unsigned int size = skb_headlen(skb); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6783 | unsigned int paylen = skb->len - hdr_len; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6784 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6785 | __le32 cmd_type; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6786 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6787 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6788 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 6789 | |
| 6790 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen); |
| 6791 | cmd_type = ixgbe_tx_cmd_type(tx_flags); |
| 6792 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6793 | #ifdef IXGBE_FCOE |
| 6794 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6795 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6796 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 6797 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6798 | } else { |
| 6799 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6800 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6801 | } |
| 6802 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6803 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6804 | dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE); |
| 6805 | if (dma_mapping_error(tx_ring->dev, dma)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6806 | goto dma_error; |
| 6807 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6808 | /* record length, and DMA address */ |
| 6809 | dma_unmap_len_set(first, len, size); |
| 6810 | dma_unmap_addr_set(first, dma, dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6811 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6812 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6813 | |
| 6814 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6815 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6816 | tx_desc->read.cmd_type_len = |
| 6817 | cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6818 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6819 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6820 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6821 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6822 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6823 | i = 0; |
| 6824 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6825 | |
| 6826 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 6827 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 6828 | |
| 6829 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 6830 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6831 | } |
| 6832 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6833 | if (likely(!data_len)) |
| 6834 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6835 | |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 6836 | if (unlikely(skb->no_fcs)) |
| 6837 | cmd_type &= ~(cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6838 | tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6839 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6840 | i++; |
| 6841 | tx_desc++; |
| 6842 | if (i == tx_ring->count) { |
| 6843 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 6844 | i = 0; |
| 6845 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6846 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6847 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6848 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6849 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6850 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6851 | #endif |
| 6852 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6853 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6854 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 6855 | DMA_TO_DEVICE); |
| 6856 | if (dma_mapping_error(tx_ring->dev, dma)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6857 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6858 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6859 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 6860 | dma_unmap_len_set(tx_buffer, len, size); |
| 6861 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 6862 | |
| 6863 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 6864 | tx_desc->read.olinfo_status = 0; |
| 6865 | |
| 6866 | frag++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6867 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6868 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6869 | /* write last descriptor with RS and EOP bits */ |
| 6870 | cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD); |
| 6871 | tx_desc->read.cmd_type_len = cmd_type; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6872 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6873 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 6874 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6875 | /* set the timestamp */ |
| 6876 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6877 | |
| 6878 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6879 | * Force memory writes to complete before letting h/w know there |
| 6880 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 6881 | * memory model archs, such as IA-64). |
| 6882 | * |
| 6883 | * We also need this memory barrier to make certain all of the |
| 6884 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6885 | */ |
| 6886 | wmb(); |
| 6887 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6888 | /* set next_to_watch value indicating a packet is present */ |
| 6889 | first->next_to_watch = tx_desc; |
| 6890 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6891 | i++; |
| 6892 | if (i == tx_ring->count) |
| 6893 | i = 0; |
| 6894 | |
| 6895 | tx_ring->next_to_use = i; |
| 6896 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6897 | /* notify HW of packet */ |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6898 | writel(i, tx_ring->tail); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6899 | |
| 6900 | return; |
| 6901 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6902 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6903 | |
| 6904 | /* clear dma mappings for failed tx_buffer_info map */ |
| 6905 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6906 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 6907 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
| 6908 | if (tx_buffer == first) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6909 | break; |
| 6910 | if (i == 0) |
| 6911 | i = tx_ring->count; |
| 6912 | i--; |
| 6913 | } |
| 6914 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6915 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6916 | } |
| 6917 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6918 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6919 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6920 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6921 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6922 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6923 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6924 | union { |
| 6925 | unsigned char *network; |
| 6926 | struct iphdr *ipv4; |
| 6927 | struct ipv6hdr *ipv6; |
| 6928 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6929 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6930 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6931 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6932 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6933 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6934 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6935 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6936 | /* do nothing if sampling is disabled */ |
| 6937 | if (!ring->atr_sample_rate) |
| 6938 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6939 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6940 | ring->atr_count++; |
| 6941 | |
| 6942 | /* snag network header to get L4 type and address */ |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6943 | hdr.network = skb_network_header(first->skb); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6944 | |
| 6945 | /* Currently only IPv4/IPv6 with TCP is supported */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6946 | if ((first->protocol != __constant_htons(ETH_P_IPV6) || |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6947 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6948 | (first->protocol != __constant_htons(ETH_P_IP) || |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6949 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6950 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6951 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6952 | th = tcp_hdr(first->skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6953 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6954 | /* skip this packet since it is invalid or the socket is closing */ |
| 6955 | if (!th || th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6956 | return; |
| 6957 | |
| 6958 | /* sample on all syn packets or once every atr sample count */ |
| 6959 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6960 | return; |
| 6961 | |
| 6962 | /* reset sample count */ |
| 6963 | ring->atr_count = 0; |
| 6964 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6965 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6966 | |
| 6967 | /* |
| 6968 | * src and dst are inverted, think how the receiver sees them |
| 6969 | * |
| 6970 | * The input is broken into two sections, a non-compressed section |
| 6971 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6972 | * is XORed together and stored in the compressed dword. |
| 6973 | */ |
| 6974 | input.formatted.vlan_id = vlan_id; |
| 6975 | |
| 6976 | /* |
| 6977 | * since src port and flex bytes occupy the same word XOR them together |
| 6978 | * and write the value to source port portion of compressed dword |
| 6979 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6980 | if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN)) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6981 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6982 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6983 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6984 | common.port.dst ^= th->source; |
| 6985 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6986 | if (first->protocol == __constant_htons(ETH_P_IP)) { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6987 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6988 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6989 | } else { |
| 6990 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6991 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6992 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6993 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6994 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6995 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6996 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6997 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6998 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6999 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7000 | |
| 7001 | /* 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] | 7002 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 7003 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7004 | } |
| 7005 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7006 | 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] | 7007 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7008 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7009 | /* Herbert's original patch had: |
| 7010 | * smp_mb__after_netif_stop_queue(); |
| 7011 | * but since that doesn't exist yet, just open code it. */ |
| 7012 | smp_mb(); |
| 7013 | |
| 7014 | /* We need to check again in a case another CPU has just |
| 7015 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 7016 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7017 | return -EBUSY; |
| 7018 | |
| 7019 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7020 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 7021 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7022 | return 0; |
| 7023 | } |
| 7024 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 7025 | 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] | 7026 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 7027 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7028 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7029 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 7030 | } |
| 7031 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7032 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 7033 | { |
| 7034 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 7035 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 7036 | smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 7037 | #ifdef IXGBE_FCOE |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 7038 | __be16 protocol = vlan_get_protocol(skb); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7039 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 7040 | if (((protocol == htons(ETH_P_FCOE)) || |
| 7041 | (protocol == htons(ETH_P_FIP))) && |
| 7042 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
| 7043 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 7044 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 7045 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 7046 | } |
| 7047 | #endif |
| 7048 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7049 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 7050 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 7051 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7052 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 7053 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7054 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7055 | return skb_tx_hash(dev, skb); |
| 7056 | } |
| 7057 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7058 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7059 | struct ixgbe_adapter *adapter, |
| 7060 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7061 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7062 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 7063 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7064 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7065 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 7066 | unsigned short f; |
| 7067 | #endif |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7068 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7069 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 7070 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7071 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7072 | /* |
| 7073 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 7074 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7075 | * + 2 desc gap to keep tail from touching head, |
| 7076 | * + 1 desc for context descriptor, |
| 7077 | * otherwise try next time |
| 7078 | */ |
| 7079 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 7080 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 7081 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 7082 | #else |
| 7083 | count += skb_shinfo(skb)->nr_frags; |
| 7084 | #endif |
| 7085 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 7086 | tx_ring->tx_stats.tx_busy++; |
| 7087 | return NETDEV_TX_BUSY; |
| 7088 | } |
| 7089 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7090 | /* record the location of the first descriptor for this packet */ |
| 7091 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 7092 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7093 | first->bytecount = skb->len; |
| 7094 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7095 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7096 | /* 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] | 7097 | if (vlan_tx_tag_present(skb)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7098 | tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 7099 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7100 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
| 7101 | } else if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 7102 | struct vlan_hdr *vhdr, _vhdr; |
| 7103 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 7104 | if (!vhdr) |
| 7105 | goto out_drop; |
| 7106 | |
| 7107 | protocol = vhdr->h_vlan_encapsulated_proto; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7108 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 7109 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7110 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7111 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7112 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 7113 | #ifdef CONFIG_PCI_IOV |
| 7114 | /* |
| 7115 | * Use the l2switch_enable flag - would be false if the DMA |
| 7116 | * Tx switch had been disabled. |
| 7117 | */ |
| 7118 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7119 | tx_flags |= IXGBE_TX_FLAGS_TXSW; |
| 7120 | |
| 7121 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7122 | /* 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] | 7123 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 7124 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 7125 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7126 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 7127 | tx_flags |= (skb->priority & 0x7) << |
| 7128 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7129 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 7130 | struct vlan_ethhdr *vhdr; |
| 7131 | if (skb_header_cloned(skb) && |
| 7132 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 7133 | goto out_drop; |
| 7134 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 7135 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 7136 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 7137 | } else { |
| 7138 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 7139 | } |
| 7140 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 7141 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7142 | /* record initial flags and protocol */ |
| 7143 | first->tx_flags = tx_flags; |
| 7144 | first->protocol = protocol; |
| 7145 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7146 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7147 | /* setup tx offload for FCoE */ |
| 7148 | if ((protocol == __constant_htons(ETH_P_FCOE)) && |
| 7149 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7150 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7151 | if (tso < 0) |
| 7152 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7153 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7154 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7155 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7156 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7157 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7158 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7159 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7160 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7161 | else if (!tso) |
| 7162 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7163 | |
| 7164 | /* add the ATR filter if ATR is on */ |
| 7165 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7166 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 7167 | |
| 7168 | #ifdef IXGBE_FCOE |
| 7169 | xmit_fcoe: |
| 7170 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7171 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7172 | |
| 7173 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7174 | |
| 7175 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7176 | |
| 7177 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7178 | dev_kfree_skb_any(first->skb); |
| 7179 | first->skb = NULL; |
| 7180 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7181 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7182 | } |
| 7183 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7184 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7185 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7186 | { |
| 7187 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7188 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7189 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7190 | if (skb->len <= 0) { |
| 7191 | dev_kfree_skb_any(skb); |
| 7192 | return NETDEV_TX_OK; |
| 7193 | } |
| 7194 | |
| 7195 | /* |
| 7196 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 7197 | * in order to meet this minimum size requirement. |
| 7198 | */ |
| 7199 | if (skb->len < 17) { |
| 7200 | if (skb_padto(skb, 17)) |
| 7201 | return NETDEV_TX_OK; |
| 7202 | skb->len = 17; |
| 7203 | } |
| 7204 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7205 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
| 7206 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7207 | } |
| 7208 | |
| 7209 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7210 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7211 | * @netdev: network interface device structure |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7212 | * @p: pointer to an address structure |
| 7213 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7214 | * Returns 0 on success, negative on failure |
| 7215 | **/ |
| 7216 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7217 | { |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7218 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7219 | struct ixgbe_hw *hw = &adapter->hw; |
| 7220 | struct sockaddr *addr = p; |
| 7221 | |
| 7222 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7223 | return -EADDRNOTAVAIL; |
| 7224 | |
| 7225 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 7226 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
| 7227 | |
| 7228 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 7229 | IXGBE_RAH_AV); |
| 7230 | |
| 7231 | return 0; |
| 7232 | } |
| 7233 | |
| 7234 | static int |
| 7235 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7236 | { |
| 7237 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7238 | struct ixgbe_hw *hw = &adapter->hw; |
| 7239 | u16 value; |
| 7240 | int rc; |
| 7241 | |
| 7242 | if (prtad != hw->phy.mdio.prtad) |
| 7243 | return -EINVAL; |
| 7244 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7245 | if (!rc) |
| 7246 | rc = value; |
| 7247 | return rc; |
| 7248 | } |
| 7249 | |
| 7250 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7251 | u16 addr, u16 value) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7252 | { |
| 7253 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7254 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7255 | |
| 7256 | if (prtad != hw->phy.mdio.prtad) |
| 7257 | return -EINVAL; |
| 7258 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7259 | } |
| 7260 | |
| 7261 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7262 | { |
| 7263 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7264 | |
| 7265 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 7266 | } |
| 7267 | |
| 7268 | /** |
| 7269 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
| 7270 | * netdev->dev_addrs |
| 7271 | * @netdev: network interface device structure |
| 7272 | * |
| 7273 | * Returns non-zero on failure |
| 7274 | **/ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7275 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7276 | { |
| 7277 | int err = 0; |
| 7278 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7279 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7280 | |
| 7281 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7282 | rtnl_lock(); |
| 7283 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7284 | rtnl_unlock(); |
| 7285 | } |
| 7286 | return err; |
| 7287 | } |
| 7288 | |
| 7289 | /** |
| 7290 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
| 7291 | * netdev->dev_addrs |
| 7292 | * @netdev: network interface device structure |
| 7293 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7294 | * Returns non-zero on failure |
| 7295 | **/ |
| 7296 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 7297 | { |
| 7298 | int err = 0; |
| 7299 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7300 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7301 | |
| 7302 | if (is_valid_ether_addr(mac->san_addr)) { |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7303 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7304 | 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] | 7305 | rtnl_unlock(); |
| 7306 | } |
| 7307 | return err; |
| 7308 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7309 | |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7310 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7311 | /* |
| 7312 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7313 | * without having to re-enable interrupts. It's not called while |
| 7314 | * the interrupt routine is executing. |
| 7315 | */ |
| 7316 | static void ixgbe_netpoll(struct net_device *netdev) |
| 7317 | { |
| 7318 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7319 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7320 | |
| 7321 | /* if interface is down do nothing */ |
| 7322 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7323 | return; |
| 7324 | |
| 7325 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7326 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7327 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 7328 | for (i = 0; i < num_q_vectors; i++) { |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7329 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 7330 | ixgbe_msix_clean_rings(0, q_vector); |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7331 | } |
| 7332 | } else { |
| 7333 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 7334 | } |
| 7335 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
| 7336 | } |
| 7337 | #endif |
| 7338 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7339 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 7340 | struct rtnl_link_stats64 *stats) |
| 7341 | { |
| 7342 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7343 | int i; |
| 7344 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7345 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7346 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7347 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7348 | u64 bytes, packets; |
| 7349 | unsigned int start; |
| 7350 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7351 | if (ring) { |
| 7352 | do { |
| 7353 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7354 | packets = ring->stats.packets; |
| 7355 | bytes = ring->stats.bytes; |
| 7356 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7357 | stats->rx_packets += packets; |
| 7358 | stats->rx_bytes += bytes; |
| 7359 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7360 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7361 | |
| 7362 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7363 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7364 | u64 bytes, packets; |
| 7365 | unsigned int start; |
| 7366 | |
| 7367 | if (ring) { |
| 7368 | do { |
| 7369 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7370 | packets = ring->stats.packets; |
| 7371 | bytes = ring->stats.bytes; |
| 7372 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7373 | stats->tx_packets += packets; |
| 7374 | stats->tx_bytes += bytes; |
| 7375 | } |
| 7376 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7377 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7378 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7379 | stats->multicast = netdev->stats.multicast; |
| 7380 | stats->rx_errors = netdev->stats.rx_errors; |
| 7381 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7382 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7383 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7384 | return stats; |
| 7385 | } |
| 7386 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7387 | /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7388 | * #adapter: pointer to ixgbe_adapter |
| 7389 | * @tc: number of traffic classes currently enabled |
| 7390 | * |
| 7391 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7392 | * 802.1Q priority maps to a packet buffer that exists. |
| 7393 | */ |
| 7394 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7395 | { |
| 7396 | struct ixgbe_hw *hw = &adapter->hw; |
| 7397 | u32 reg, rsave; |
| 7398 | int i; |
| 7399 | |
| 7400 | /* 82598 have a static priority to TC mapping that can not |
| 7401 | * be changed so no validation is needed. |
| 7402 | */ |
| 7403 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7404 | return; |
| 7405 | |
| 7406 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7407 | rsave = reg; |
| 7408 | |
| 7409 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7410 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7411 | |
| 7412 | /* If up2tc is out of bounds default to zero */ |
| 7413 | if (up2tc > tc) |
| 7414 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7415 | } |
| 7416 | |
| 7417 | if (reg != rsave) |
| 7418 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7419 | |
| 7420 | return; |
| 7421 | } |
| 7422 | |
| 7423 | |
| 7424 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic |
| 7425 | * classes. |
| 7426 | * |
| 7427 | * @netdev: net device to configure |
| 7428 | * @tc: number of traffic classes to enable |
| 7429 | */ |
| 7430 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7431 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7432 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7433 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7434 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7435 | /* Multiple traffic classes requires multiple queues */ |
| 7436 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 7437 | e_err(drv, "Enable failed, needs MSI-X\n"); |
| 7438 | return -EINVAL; |
| 7439 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7440 | |
| 7441 | /* Hardware supports up to 8 traffic classes */ |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 7442 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs || |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7443 | (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS)) |
| 7444 | return -EINVAL; |
| 7445 | |
| 7446 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 7447 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7448 | * hardware is not flexible enough to do this dynamically. |
| 7449 | */ |
| 7450 | if (netif_running(dev)) |
| 7451 | ixgbe_close(dev); |
| 7452 | ixgbe_clear_interrupt_scheme(adapter); |
| 7453 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7454 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7455 | netdev_set_num_tc(dev, tc); |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7456 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; |
| 7457 | |
| 7458 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
| 7459 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7460 | |
| 7461 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 7462 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
| 7463 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7464 | netdev_reset_tc(dev); |
| 7465 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7466 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 7467 | |
| 7468 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 7469 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7470 | |
| 7471 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 7472 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 7473 | } |
| 7474 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7475 | ixgbe_init_interrupt_scheme(adapter); |
| 7476 | ixgbe_validate_rtr(adapter, tc); |
| 7477 | if (netif_running(dev)) |
| 7478 | ixgbe_open(dev); |
| 7479 | |
| 7480 | return 0; |
| 7481 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7482 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7483 | void ixgbe_do_reset(struct net_device *netdev) |
| 7484 | { |
| 7485 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7486 | |
| 7487 | if (netif_running(netdev)) |
| 7488 | ixgbe_reinit_locked(adapter); |
| 7489 | else |
| 7490 | ixgbe_reset(adapter); |
| 7491 | } |
| 7492 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7493 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
| 7494 | netdev_features_t data) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7495 | { |
| 7496 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7497 | |
| 7498 | #ifdef CONFIG_DCB |
| 7499 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 7500 | data &= ~NETIF_F_HW_VLAN_RX; |
| 7501 | #endif |
| 7502 | |
| 7503 | /* return error if RXHASH is being enabled when RSS is not supported */ |
| 7504 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 7505 | data &= ~NETIF_F_RXHASH; |
| 7506 | |
| 7507 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
| 7508 | if (!(data & NETIF_F_RXCSUM)) |
| 7509 | data &= ~NETIF_F_LRO; |
| 7510 | |
| 7511 | /* Turn off LRO if not RSC capable or invalid ITR settings */ |
| 7512 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) { |
| 7513 | data &= ~NETIF_F_LRO; |
| 7514 | } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
| 7515 | (adapter->rx_itr_setting != 1 && |
| 7516 | adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) { |
| 7517 | data &= ~NETIF_F_LRO; |
| 7518 | e_info(probe, "rx-usecs set too low, not enabling RSC\n"); |
| 7519 | } |
| 7520 | |
| 7521 | return data; |
| 7522 | } |
| 7523 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7524 | static int ixgbe_set_features(struct net_device *netdev, |
| 7525 | netdev_features_t data) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7526 | { |
| 7527 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7528 | netdev_features_t changed = netdev->features ^ data; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7529 | bool need_reset = false; |
| 7530 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7531 | /* Make sure RSC matches LRO, reset if change */ |
| 7532 | if (!!(data & NETIF_F_LRO) != |
| 7533 | !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 7534 | adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED; |
| 7535 | switch (adapter->hw.mac.type) { |
| 7536 | case ixgbe_mac_X540: |
| 7537 | case ixgbe_mac_82599EB: |
| 7538 | need_reset = true; |
| 7539 | break; |
| 7540 | default: |
| 7541 | break; |
| 7542 | } |
| 7543 | } |
| 7544 | |
| 7545 | /* |
| 7546 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 7547 | * the state changed, we need to reset. |
| 7548 | */ |
| 7549 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { |
| 7550 | /* turn off ATR, enable perfect filters and reset */ |
| 7551 | if (data & NETIF_F_NTUPLE) { |
| 7552 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7553 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7554 | need_reset = true; |
| 7555 | } |
| 7556 | } else if (!(data & NETIF_F_NTUPLE)) { |
| 7557 | /* turn off Flow Director, set ATR and reset */ |
| 7558 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7559 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 7560 | !(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 7561 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7562 | need_reset = true; |
| 7563 | } |
| 7564 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7565 | if (changed & NETIF_F_RXALL) |
| 7566 | need_reset = true; |
| 7567 | |
| 7568 | netdev->features = data; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7569 | if (need_reset) |
| 7570 | ixgbe_do_reset(netdev); |
| 7571 | |
| 7572 | return 0; |
| 7573 | |
| 7574 | } |
| 7575 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7576 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7577 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7578 | .ndo_stop = ixgbe_close, |
| 7579 | .ndo_start_xmit = ixgbe_xmit_frame, |
| 7580 | .ndo_select_queue = ixgbe_select_queue, |
| 7581 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7582 | .ndo_validate_addr = eth_validate_addr, |
| 7583 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7584 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7585 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7586 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7587 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7588 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7589 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7590 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7591 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 7592 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7593 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7594 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7595 | .ndo_setup_tc = ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7596 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7597 | .ndo_poll_controller = ixgbe_netpoll, |
| 7598 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7599 | #ifdef IXGBE_FCOE |
| 7600 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7601 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7602 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7603 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7604 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7605 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 7606 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7607 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7608 | .ndo_set_features = ixgbe_set_features, |
| 7609 | .ndo_fix_features = ixgbe_fix_features, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7610 | }; |
| 7611 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7612 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 7613 | const struct ixgbe_info *ii) |
| 7614 | { |
| 7615 | #ifdef CONFIG_PCI_IOV |
| 7616 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7617 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 7618 | if (hw->mac.type == ixgbe_mac_82598EB) |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7619 | return; |
| 7620 | |
| 7621 | /* The 82599 supports up to 64 VFs per physical function |
| 7622 | * but this implementation limits allocation to 63 so that |
| 7623 | * basic networking resources are still available to the |
| 7624 | * physical function |
| 7625 | */ |
| 7626 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 7627 | ixgbe_enable_sriov(adapter, ii); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7628 | #endif /* CONFIG_PCI_IOV */ |
| 7629 | } |
| 7630 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7631 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7632 | * ixgbe_probe - Device Initialization Routine |
| 7633 | * @pdev: PCI device information struct |
| 7634 | * @ent: entry in ixgbe_pci_tbl |
| 7635 | * |
| 7636 | * Returns 0 on success, negative on failure |
| 7637 | * |
| 7638 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7639 | * The OS initialization, configuring of the adapter private structure, |
| 7640 | * and a hardware reset occur. |
| 7641 | **/ |
| 7642 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7643 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7644 | { |
| 7645 | struct net_device *netdev; |
| 7646 | struct ixgbe_adapter *adapter = NULL; |
| 7647 | struct ixgbe_hw *hw; |
| 7648 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7649 | static int cards_found; |
| 7650 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7651 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7652 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7653 | #ifdef IXGBE_FCOE |
| 7654 | u16 device_caps; |
| 7655 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7656 | u32 eec; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7657 | u16 wol_cap; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7658 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7659 | /* Catch broken hardware that put the wrong VF device ID in |
| 7660 | * the PCIe SR-IOV capability. |
| 7661 | */ |
| 7662 | if (pdev->is_virtfn) { |
| 7663 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7664 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7665 | return -EINVAL; |
| 7666 | } |
| 7667 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7668 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7669 | if (err) |
| 7670 | return err; |
| 7671 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7672 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7673 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7674 | pci_using_dac = 1; |
| 7675 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7676 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7677 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7678 | err = dma_set_coherent_mask(&pdev->dev, |
| 7679 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7680 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7681 | dev_err(&pdev->dev, |
| 7682 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7683 | goto err_dma; |
| 7684 | } |
| 7685 | } |
| 7686 | pci_using_dac = 0; |
| 7687 | } |
| 7688 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7689 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7690 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7691 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7692 | dev_err(&pdev->dev, |
| 7693 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7694 | goto err_pci_reg; |
| 7695 | } |
| 7696 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7697 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7698 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7699 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7700 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7701 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7702 | #ifdef CONFIG_IXGBE_DCB |
| 7703 | indices *= MAX_TRAFFIC_CLASS; |
| 7704 | #endif |
| 7705 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7706 | if (ii->mac == ixgbe_mac_82598EB) |
| 7707 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7708 | else |
| 7709 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7710 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7711 | #ifdef IXGBE_FCOE |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7712 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7713 | IXGBE_MAX_FCOE_INDICES); |
| 7714 | #endif |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7715 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7716 | if (!netdev) { |
| 7717 | err = -ENOMEM; |
| 7718 | goto err_alloc_etherdev; |
| 7719 | } |
| 7720 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7721 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7722 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7723 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7724 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7725 | |
| 7726 | adapter->netdev = netdev; |
| 7727 | adapter->pdev = pdev; |
| 7728 | hw = &adapter->hw; |
| 7729 | hw->back = adapter; |
| 7730 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 7731 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7732 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7733 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7734 | if (!hw->hw_addr) { |
| 7735 | err = -EIO; |
| 7736 | goto err_ioremap; |
| 7737 | } |
| 7738 | |
| 7739 | for (i = 1; i <= 5; i++) { |
| 7740 | if (pci_resource_len(pdev, i) == 0) |
| 7741 | continue; |
| 7742 | } |
| 7743 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7744 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7745 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7746 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7747 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7748 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7749 | adapter->bd_number = cards_found; |
| 7750 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7751 | /* Setup hw api */ |
| 7752 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7753 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7754 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7755 | /* EEPROM */ |
| 7756 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7757 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7758 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7759 | if (!(eec & (1 << 8))) |
| 7760 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7761 | |
| 7762 | /* PHY */ |
| 7763 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7764 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7765 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7766 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7767 | hw->phy.mdio.mmds = 0; |
| 7768 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7769 | hw->phy.mdio.dev = netdev; |
| 7770 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7771 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7772 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7773 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7774 | |
| 7775 | /* setup the private structure */ |
| 7776 | err = ixgbe_sw_init(adapter); |
| 7777 | if (err) |
| 7778 | goto err_sw_init; |
| 7779 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7780 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7781 | switch (adapter->hw.mac.type) { |
| 7782 | case ixgbe_mac_82599EB: |
| 7783 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7784 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7785 | break; |
| 7786 | default: |
| 7787 | break; |
| 7788 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7789 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7790 | /* |
| 7791 | * If there is a fan on this device and it has failed log the |
| 7792 | * failure. |
| 7793 | */ |
| 7794 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7795 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7796 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7797 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7798 | } |
| 7799 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 7800 | if (allow_unsupported_sfp) |
| 7801 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 7802 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7803 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7804 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7805 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7806 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7807 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7808 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7809 | err = 0; |
| 7810 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7811 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7812 | "module type was detected.\n"); |
| 7813 | e_dev_err("Reload the driver after installing a supported " |
| 7814 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7815 | goto err_sw_init; |
| 7816 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7817 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7818 | goto err_sw_init; |
| 7819 | } |
| 7820 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7821 | ixgbe_probe_vf(adapter, ii); |
| 7822 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7823 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7824 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7825 | NETIF_F_IPV6_CSUM | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7826 | NETIF_F_HW_VLAN_TX | |
| 7827 | NETIF_F_HW_VLAN_RX | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7828 | NETIF_F_HW_VLAN_FILTER | |
| 7829 | NETIF_F_TSO | |
| 7830 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7831 | NETIF_F_RXHASH | |
| 7832 | NETIF_F_RXCSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7833 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7834 | netdev->hw_features = netdev->features; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7835 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7836 | switch (adapter->hw.mac.type) { |
| 7837 | case ixgbe_mac_82599EB: |
| 7838 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7839 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7840 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 7841 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7842 | break; |
| 7843 | default: |
| 7844 | break; |
| 7845 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7846 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7847 | netdev->hw_features |= NETIF_F_RXALL; |
| 7848 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7849 | netdev->vlan_features |= NETIF_F_TSO; |
| 7850 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7851 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7852 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7853 | netdev->vlan_features |= NETIF_F_SG; |
| 7854 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7855 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 7856 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7857 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7858 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7859 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 7860 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7861 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7862 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7863 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7864 | #endif |
| 7865 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7866 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7867 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7868 | if (hw->mac.ops.get_device_caps) { |
| 7869 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7870 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7871 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7872 | } |
| 7873 | } |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7874 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
| 7875 | netdev->vlan_features |= NETIF_F_FCOE_CRC; |
| 7876 | netdev->vlan_features |= NETIF_F_FSO; |
| 7877 | netdev->vlan_features |= NETIF_F_FCOE_MTU; |
| 7878 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7879 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7880 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7881 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7882 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7883 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7884 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7885 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 7886 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7887 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7888 | netdev->features |= NETIF_F_LRO; |
| 7889 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7890 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7891 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7892 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7893 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame^] | 7894 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7895 | } |
| 7896 | |
| 7897 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7898 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7899 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7900 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7901 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7902 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame^] | 7903 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7904 | } |
| 7905 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7906 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
| 7907 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7908 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7909 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7910 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7911 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7912 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7913 | if (err) |
| 7914 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7915 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7916 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
| 7917 | netdev->hw_features &= ~NETIF_F_RXHASH; |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7918 | netdev->features &= ~NETIF_F_RXHASH; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7919 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7920 | |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7921 | /* WOL not supported for all but the following */ |
| 7922 | adapter->wol = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7923 | switch (pdev->device) { |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7924 | case IXGBE_DEV_ID_82599_SFP: |
Don Skidmore | 0e22d04 | 2011-12-10 06:49:43 +0000 | [diff] [blame] | 7925 | /* Only these subdevice supports WOL */ |
| 7926 | switch (pdev->subsystem_device) { |
| 7927 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 7928 | /* only support first port */ |
| 7929 | if (hw->bus.func != 0) |
| 7930 | break; |
| 7931 | case IXGBE_SUBDEV_ID_82599_SFP: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7932 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0e22d04 | 2011-12-10 06:49:43 +0000 | [diff] [blame] | 7933 | break; |
| 7934 | } |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7935 | break; |
Alexander Duyck | 50d6c68 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 7936 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7937 | /* All except this subdevice support WOL */ |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7938 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7939 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7940 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7941 | case IXGBE_DEV_ID_82599_KX4: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7942 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7943 | break; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 7944 | case IXGBE_DEV_ID_X540T: |
| 7945 | /* Check eeprom to see if it is enabled */ |
| 7946 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
| 7947 | wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 7948 | |
| 7949 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 7950 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 7951 | (hw->bus.func == 0))) |
| 7952 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7953 | break; |
| 7954 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7955 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7956 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 7957 | /* save off EEPROM version number */ |
| 7958 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 7959 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 7960 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7961 | /* pick up the PCI bus settings for reporting later */ |
| 7962 | hw->mac.ops.get_bus_info(hw); |
| 7963 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7964 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7965 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7966 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7967 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7968 | "Unknown"), |
| 7969 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7970 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7971 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7972 | "Unknown"), |
| 7973 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7974 | |
| 7975 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7976 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7977 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7978 | 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] | 7979 | 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] | 7980 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7981 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7982 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7983 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7984 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7985 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7986 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7987 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7988 | "not sufficient for optimal performance.\n"); |
| 7989 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7990 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7991 | } |
| 7992 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7993 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7994 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7995 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7996 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7997 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7998 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7999 | "Please be aware there may be issues associated " |
| 8000 | "with your hardware. If you are experiencing " |
| 8001 | "problems please contact your Intel or hardware " |
| 8002 | "representative who provided you with this " |
| 8003 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 8004 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8005 | strcpy(netdev->name, "eth%d"); |
| 8006 | err = register_netdev(netdev); |
| 8007 | if (err) |
| 8008 | goto err_register; |
| 8009 | |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 8010 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 8011 | if (hw->mac.ops.disable_tx_laser && |
| 8012 | ((hw->phy.multispeed_fiber) || |
| 8013 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
| 8014 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 8015 | hw->mac.ops.disable_tx_laser(hw); |
| 8016 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 8017 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 8018 | netif_carrier_off(netdev); |
| 8019 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8020 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 8021 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8022 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8023 | ixgbe_setup_dca(adapter); |
| 8024 | } |
| 8025 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8026 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8027 | 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] | 8028 | for (i = 0; i < adapter->num_vfs; i++) |
| 8029 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 8030 | } |
| 8031 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8032 | /* firmware requires driver version to be 0xFFFFFFFF |
| 8033 | * since os does not support feature |
| 8034 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8035 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8036 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 8037 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8038 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8039 | /* add san mac addr to netdev */ |
| 8040 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8041 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8042 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8043 | cards_found++; |
| 8044 | return 0; |
| 8045 | |
| 8046 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8047 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8048 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8049 | err_sw_init: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8050 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 8051 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8052 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8053 | iounmap(hw->hw_addr); |
| 8054 | err_ioremap: |
| 8055 | free_netdev(netdev); |
| 8056 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8057 | pci_release_selected_regions(pdev, |
| 8058 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8059 | err_pci_reg: |
| 8060 | err_dma: |
| 8061 | pci_disable_device(pdev); |
| 8062 | return err; |
| 8063 | } |
| 8064 | |
| 8065 | /** |
| 8066 | * ixgbe_remove - Device Removal Routine |
| 8067 | * @pdev: PCI device information struct |
| 8068 | * |
| 8069 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 8070 | * that it should release a PCI device. The could be caused by a |
| 8071 | * Hot-Plug event, or because the driver is going to be removed from |
| 8072 | * memory. |
| 8073 | **/ |
| 8074 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 8075 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8076 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8077 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8078 | |
| 8079 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8080 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8081 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8082 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8083 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 8084 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 8085 | dca_remove_requester(&pdev->dev); |
| 8086 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 8087 | } |
| 8088 | |
| 8089 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 8090 | #ifdef IXGBE_FCOE |
| 8091 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 8092 | ixgbe_cleanup_fcoe(adapter); |
| 8093 | |
| 8094 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8095 | |
| 8096 | /* remove the added san mac */ |
| 8097 | ixgbe_del_sanmac_netdev(netdev); |
| 8098 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 8099 | if (netdev->reg_state == NETREG_REGISTERED) |
| 8100 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8101 | |
Greg Rose | c6bda30 | 2011-08-24 02:37:55 +0000 | [diff] [blame] | 8102 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 8103 | if (!(ixgbe_check_vf_assignment(adapter))) |
| 8104 | ixgbe_disable_sriov(adapter); |
| 8105 | else |
| 8106 | e_dev_warn("Unloading driver while VFs are assigned " |
| 8107 | "- VFs will not be deallocated\n"); |
| 8108 | } |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8109 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8110 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8111 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8112 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8113 | |
| 8114 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8115 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8116 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8117 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8118 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8119 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8120 | free_netdev(netdev); |
| 8121 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 8122 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8123 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8124 | pci_disable_device(pdev); |
| 8125 | } |
| 8126 | |
| 8127 | /** |
| 8128 | * ixgbe_io_error_detected - called when PCI error is detected |
| 8129 | * @pdev: Pointer to PCI device |
| 8130 | * @state: The current pci connection state |
| 8131 | * |
| 8132 | * This function is called after a PCI bus error affecting |
| 8133 | * this device has been detected. |
| 8134 | */ |
| 8135 | 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] | 8136 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8137 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8138 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8139 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8140 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8141 | #ifdef CONFIG_PCI_IOV |
| 8142 | struct pci_dev *bdev, *vfdev; |
| 8143 | u32 dw0, dw1, dw2, dw3; |
| 8144 | int vf, pos; |
| 8145 | u16 req_id, pf_func; |
| 8146 | |
| 8147 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 8148 | adapter->num_vfs == 0) |
| 8149 | goto skip_bad_vf_detection; |
| 8150 | |
| 8151 | bdev = pdev->bus->self; |
| 8152 | while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT)) |
| 8153 | bdev = bdev->bus->self; |
| 8154 | |
| 8155 | if (!bdev) |
| 8156 | goto skip_bad_vf_detection; |
| 8157 | |
| 8158 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 8159 | if (!pos) |
| 8160 | goto skip_bad_vf_detection; |
| 8161 | |
| 8162 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0); |
| 8163 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1); |
| 8164 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2); |
| 8165 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3); |
| 8166 | |
| 8167 | req_id = dw1 >> 16; |
| 8168 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 8169 | if (!(req_id & 0x0080)) |
| 8170 | goto skip_bad_vf_detection; |
| 8171 | |
| 8172 | pf_func = req_id & 0x01; |
| 8173 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 8174 | unsigned int device_id; |
| 8175 | |
| 8176 | vf = (req_id & 0x7F) >> 1; |
| 8177 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 8178 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 8179 | "%8.8x\tdw3: %8.8x\n", |
| 8180 | dw0, dw1, dw2, dw3); |
| 8181 | switch (adapter->hw.mac.type) { |
| 8182 | case ixgbe_mac_82599EB: |
| 8183 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 8184 | break; |
| 8185 | case ixgbe_mac_X540: |
| 8186 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 8187 | break; |
| 8188 | default: |
| 8189 | device_id = 0; |
| 8190 | break; |
| 8191 | } |
| 8192 | |
| 8193 | /* Find the pci device of the offending VF */ |
| 8194 | vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL); |
| 8195 | while (vfdev) { |
| 8196 | if (vfdev->devfn == (req_id & 0xFF)) |
| 8197 | break; |
| 8198 | vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, |
| 8199 | device_id, vfdev); |
| 8200 | } |
| 8201 | /* |
| 8202 | * There's a slim chance the VF could have been hot plugged, |
| 8203 | * so if it is no longer present we don't need to issue the |
| 8204 | * VFLR. Just clean up the AER in that case. |
| 8205 | */ |
| 8206 | if (vfdev) { |
| 8207 | e_dev_err("Issuing VFLR to VF %d\n", vf); |
| 8208 | pci_write_config_dword(vfdev, 0xA8, 0x00008000); |
| 8209 | } |
| 8210 | |
| 8211 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8212 | } |
| 8213 | |
| 8214 | /* |
| 8215 | * Even though the error may have occurred on the other port |
| 8216 | * we still need to increment the vf error reference count for |
| 8217 | * both ports because the I/O resume function will be called |
| 8218 | * for both of them. |
| 8219 | */ |
| 8220 | adapter->vferr_refcount++; |
| 8221 | |
| 8222 | return PCI_ERS_RESULT_RECOVERED; |
| 8223 | |
| 8224 | skip_bad_vf_detection: |
| 8225 | #endif /* CONFIG_PCI_IOV */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8226 | netif_device_detach(netdev); |
| 8227 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 8228 | if (state == pci_channel_io_perm_failure) |
| 8229 | return PCI_ERS_RESULT_DISCONNECT; |
| 8230 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8231 | if (netif_running(netdev)) |
| 8232 | ixgbe_down(adapter); |
| 8233 | pci_disable_device(pdev); |
| 8234 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8235 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8236 | return PCI_ERS_RESULT_NEED_RESET; |
| 8237 | } |
| 8238 | |
| 8239 | /** |
| 8240 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 8241 | * @pdev: Pointer to PCI device |
| 8242 | * |
| 8243 | * Restart the card from scratch, as if from a cold-boot. |
| 8244 | */ |
| 8245 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 8246 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8247 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8248 | pci_ers_result_t result; |
| 8249 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8250 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8251 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8252 | 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] | 8253 | result = PCI_ERS_RESULT_DISCONNECT; |
| 8254 | } else { |
| 8255 | pci_set_master(pdev); |
| 8256 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 8257 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8258 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 8259 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8260 | |
| 8261 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 8262 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8263 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8264 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8265 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8266 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8267 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8268 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 8269 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8270 | /* non-fatal, continue */ |
| 8271 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8272 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8273 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8274 | } |
| 8275 | |
| 8276 | /** |
| 8277 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 8278 | * @pdev: Pointer to PCI device |
| 8279 | * |
| 8280 | * This callback is called when the error recovery driver tells us that |
| 8281 | * its OK to resume normal operation. |
| 8282 | */ |
| 8283 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 8284 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8285 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8286 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8287 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8288 | #ifdef CONFIG_PCI_IOV |
| 8289 | if (adapter->vferr_refcount) { |
| 8290 | e_info(drv, "Resuming after VF err\n"); |
| 8291 | adapter->vferr_refcount--; |
| 8292 | return; |
| 8293 | } |
| 8294 | |
| 8295 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 8296 | if (netif_running(netdev)) |
| 8297 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8298 | |
| 8299 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8300 | } |
| 8301 | |
| 8302 | static struct pci_error_handlers ixgbe_err_handler = { |
| 8303 | .error_detected = ixgbe_io_error_detected, |
| 8304 | .slot_reset = ixgbe_io_slot_reset, |
| 8305 | .resume = ixgbe_io_resume, |
| 8306 | }; |
| 8307 | |
| 8308 | static struct pci_driver ixgbe_driver = { |
| 8309 | .name = ixgbe_driver_name, |
| 8310 | .id_table = ixgbe_pci_tbl, |
| 8311 | .probe = ixgbe_probe, |
| 8312 | .remove = __devexit_p(ixgbe_remove), |
| 8313 | #ifdef CONFIG_PM |
| 8314 | .suspend = ixgbe_suspend, |
| 8315 | .resume = ixgbe_resume, |
| 8316 | #endif |
| 8317 | .shutdown = ixgbe_shutdown, |
| 8318 | .err_handler = &ixgbe_err_handler |
| 8319 | }; |
| 8320 | |
| 8321 | /** |
| 8322 | * ixgbe_init_module - Driver Registration Routine |
| 8323 | * |
| 8324 | * ixgbe_init_module is the first routine called when the driver is |
| 8325 | * loaded. All it does is register with the PCI subsystem. |
| 8326 | **/ |
| 8327 | static int __init ixgbe_init_module(void) |
| 8328 | { |
| 8329 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 8330 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8331 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8332 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8333 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8334 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8335 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8336 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8337 | ret = pci_register_driver(&ixgbe_driver); |
| 8338 | return ret; |
| 8339 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8340 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8341 | module_init(ixgbe_init_module); |
| 8342 | |
| 8343 | /** |
| 8344 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 8345 | * |
| 8346 | * ixgbe_exit_module is called just before the driver is removed |
| 8347 | * from memory. |
| 8348 | **/ |
| 8349 | static void __exit ixgbe_exit_module(void) |
| 8350 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8351 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8352 | dca_unregister_notify(&dca_notifier); |
| 8353 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8354 | pci_unregister_driver(&ixgbe_driver); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8355 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8356 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8357 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8358 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8359 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8360 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8361 | { |
| 8362 | int ret_val; |
| 8363 | |
| 8364 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8365 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8366 | |
| 8367 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 8368 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8369 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 8370 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8371 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8372 | module_exit(ixgbe_exit_module); |
| 8373 | |
| 8374 | /* ixgbe_main.c */ |