Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2011 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> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 38 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 39 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 41 | #include <net/checksum.h> |
| 42 | #include <net/ip6_checksum.h> |
| 43 | #include <linux/ethtool.h> |
| 44 | #include <linux/if_vlan.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 45 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 46 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 47 | |
| 48 | #include "ixgbe.h" |
| 49 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 50 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 51 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 52 | |
| 53 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 54 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 55 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 56 | #define MAJ 3 |
Don Skidmore | c89c711 | 2011-04-14 07:40:11 +0000 | [diff] [blame] | 57 | #define MIN 3 |
| 58 | #define BUILD 8 |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 59 | #define KFIX 2 |
| 60 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ |
| 61 | __stringify(BUILD) "-k" __stringify(KFIX) |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 62 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 63 | static const char ixgbe_copyright[] = |
| 64 | "Copyright (c) 1999-2011 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 65 | |
| 66 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 67 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 68 | [board_82599] = &ixgbe_82599_info, |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 69 | [board_X540] = &ixgbe_X540_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 73 | * |
| 74 | * Wildcard entries (PCI_ANY_ID) should come last |
| 75 | * Last entry must be all 0s |
| 76 | * |
| 77 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 78 | * Class, Class Mask, private data (not used) } |
| 79 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 80 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 82 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 84 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 86 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 88 | board_82598 }, |
Peter P Waskiewicz Jr | 3845bec | 2009-07-16 15:50:52 +0000 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), |
| 90 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 92 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 94 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 96 | board_82598 }, |
| 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 98 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 100 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 102 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 104 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 106 | board_82599 }, |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
| 108 | board_82599 }, |
Don Skidmore | 74757d4 | 2009-12-08 07:22:23 +0000 | [diff] [blame] | 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), |
| 110 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 112 | board_82599 }, |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame] | 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
| 114 | board_82599 }, |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
| 116 | board_82599 }, |
Peter P Waskiewicz Jr | 8911184 | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
| 118 | board_82599 }, |
Don Skidmore | dbffcb2 | 2010-12-03 03:32:34 +0000 | [diff] [blame] | 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), |
| 120 | board_82599 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), |
| 122 | board_82599 }, |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), |
| 124 | board_82599 }, |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
| 126 | board_82599 }, |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), |
Don Skidmore | d994653 | 2010-12-09 06:55:19 +0000 | [diff] [blame] | 128 | board_X540 }, |
Emil Tantilov | 4c40ef0 | 2011-03-24 07:06:02 +0000 | [diff] [blame] | 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), |
| 130 | board_82599 }, |
Don Skidmore | 4f6290c | 2011-05-14 06:36:35 +0000 | [diff] [blame] | 131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), |
| 132 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 133 | |
| 134 | /* required last entry */ |
| 135 | {0, } |
| 136 | }; |
| 137 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 138 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 139 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 140 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 141 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 142 | static struct notifier_block dca_notifier = { |
| 143 | .notifier_call = ixgbe_notify_dca, |
| 144 | .next = NULL, |
| 145 | .priority = 0 |
| 146 | }; |
| 147 | #endif |
| 148 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 149 | #ifdef CONFIG_PCI_IOV |
| 150 | static unsigned int max_vfs; |
| 151 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 152 | MODULE_PARM_DESC(max_vfs, |
| 153 | "Maximum number of virtual functions to allocate per physical function"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 154 | #endif /* CONFIG_PCI_IOV */ |
| 155 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 156 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 157 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 158 | MODULE_LICENSE("GPL"); |
| 159 | MODULE_VERSION(DRV_VERSION); |
| 160 | |
| 161 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 162 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 163 | static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) |
| 164 | { |
| 165 | struct ixgbe_hw *hw = &adapter->hw; |
| 166 | u32 gcr; |
| 167 | u32 gpie; |
| 168 | u32 vmdctl; |
| 169 | |
| 170 | #ifdef CONFIG_PCI_IOV |
| 171 | /* disable iov and allow time for transactions to clear */ |
| 172 | pci_disable_sriov(adapter->pdev); |
| 173 | #endif |
| 174 | |
| 175 | /* turn off device IOV mode */ |
| 176 | gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 177 | gcr &= ~(IXGBE_GCR_EXT_SRIOV); |
| 178 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr); |
| 179 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 180 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 181 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 182 | |
| 183 | /* set default pool back to 0 */ |
| 184 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 185 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
| 186 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
| 187 | |
| 188 | /* take a breather then clean up driver data */ |
| 189 | msleep(100); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 190 | |
| 191 | kfree(adapter->vfinfo); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 192 | adapter->vfinfo = NULL; |
| 193 | |
| 194 | adapter->num_vfs = 0; |
| 195 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 196 | } |
| 197 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 198 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 199 | { |
| 200 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
| 201 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
| 202 | schedule_work(&adapter->service_task); |
| 203 | } |
| 204 | |
| 205 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 206 | { |
| 207 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 208 | |
| 209 | /* flush memory to make sure state is correct before next watchog */ |
| 210 | smp_mb__before_clear_bit(); |
| 211 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 212 | } |
| 213 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 214 | struct ixgbe_reg_info { |
| 215 | u32 ofs; |
| 216 | char *name; |
| 217 | }; |
| 218 | |
| 219 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 220 | |
| 221 | /* General Registers */ |
| 222 | {IXGBE_CTRL, "CTRL"}, |
| 223 | {IXGBE_STATUS, "STATUS"}, |
| 224 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 225 | |
| 226 | /* Interrupt Registers */ |
| 227 | {IXGBE_EICR, "EICR"}, |
| 228 | |
| 229 | /* RX Registers */ |
| 230 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 231 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 232 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 233 | {IXGBE_RDH(0), "RDH"}, |
| 234 | {IXGBE_RDT(0), "RDT"}, |
| 235 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 236 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 237 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 238 | |
| 239 | /* TX Registers */ |
| 240 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 241 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 242 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 243 | {IXGBE_TDH(0), "TDH"}, |
| 244 | {IXGBE_TDT(0), "TDT"}, |
| 245 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 246 | |
| 247 | /* List Terminator */ |
| 248 | {} |
| 249 | }; |
| 250 | |
| 251 | |
| 252 | /* |
| 253 | * ixgbe_regdump - register printout routine |
| 254 | */ |
| 255 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 256 | { |
| 257 | int i = 0, j = 0; |
| 258 | char rname[16]; |
| 259 | u32 regs[64]; |
| 260 | |
| 261 | switch (reginfo->ofs) { |
| 262 | case IXGBE_SRRCTL(0): |
| 263 | for (i = 0; i < 64; i++) |
| 264 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 265 | break; |
| 266 | case IXGBE_DCA_RXCTRL(0): |
| 267 | for (i = 0; i < 64; i++) |
| 268 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 269 | break; |
| 270 | case IXGBE_RDLEN(0): |
| 271 | for (i = 0; i < 64; i++) |
| 272 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 273 | break; |
| 274 | case IXGBE_RDH(0): |
| 275 | for (i = 0; i < 64; i++) |
| 276 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 277 | break; |
| 278 | case IXGBE_RDT(0): |
| 279 | for (i = 0; i < 64; i++) |
| 280 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 281 | break; |
| 282 | case IXGBE_RXDCTL(0): |
| 283 | for (i = 0; i < 64; i++) |
| 284 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 285 | break; |
| 286 | case IXGBE_RDBAL(0): |
| 287 | for (i = 0; i < 64; i++) |
| 288 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 289 | break; |
| 290 | case IXGBE_RDBAH(0): |
| 291 | for (i = 0; i < 64; i++) |
| 292 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 293 | break; |
| 294 | case IXGBE_TDBAL(0): |
| 295 | for (i = 0; i < 64; i++) |
| 296 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 297 | break; |
| 298 | case IXGBE_TDBAH(0): |
| 299 | for (i = 0; i < 64; i++) |
| 300 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 301 | break; |
| 302 | case IXGBE_TDLEN(0): |
| 303 | for (i = 0; i < 64; i++) |
| 304 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 305 | break; |
| 306 | case IXGBE_TDH(0): |
| 307 | for (i = 0; i < 64; i++) |
| 308 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 309 | break; |
| 310 | case IXGBE_TDT(0): |
| 311 | for (i = 0; i < 64; i++) |
| 312 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 313 | break; |
| 314 | case IXGBE_TXDCTL(0): |
| 315 | for (i = 0; i < 64; i++) |
| 316 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 317 | break; |
| 318 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 319 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 320 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | for (i = 0; i < 8; i++) { |
| 325 | 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] | 326 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 327 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 328 | pr_cont(" %08x", regs[i*8+j]); |
| 329 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 336 | */ |
| 337 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 338 | { |
| 339 | struct net_device *netdev = adapter->netdev; |
| 340 | struct ixgbe_hw *hw = &adapter->hw; |
| 341 | struct ixgbe_reg_info *reginfo; |
| 342 | int n = 0; |
| 343 | struct ixgbe_ring *tx_ring; |
| 344 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 345 | union ixgbe_adv_tx_desc *tx_desc; |
| 346 | struct my_u0 { u64 a; u64 b; } *u0; |
| 347 | struct ixgbe_ring *rx_ring; |
| 348 | union ixgbe_adv_rx_desc *rx_desc; |
| 349 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 350 | u32 staterr; |
| 351 | int i = 0; |
| 352 | |
| 353 | if (!netif_msg_hw(adapter)) |
| 354 | return; |
| 355 | |
| 356 | /* Print netdevice Info */ |
| 357 | if (netdev) { |
| 358 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 359 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 360 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 361 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 362 | netdev->name, |
| 363 | netdev->state, |
| 364 | netdev->trans_start, |
| 365 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /* Print Registers */ |
| 369 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 370 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 371 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 372 | reginfo->name; reginfo++) { |
| 373 | ixgbe_regdump(hw, reginfo); |
| 374 | } |
| 375 | |
| 376 | /* Print TX Ring Summary */ |
| 377 | if (!netdev || !netif_running(netdev)) |
| 378 | goto exit; |
| 379 | |
| 380 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 381 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 382 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 383 | tx_ring = adapter->tx_ring[n]; |
| 384 | tx_buffer_info = |
| 385 | &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 386 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 387 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 388 | (u64)tx_buffer_info->dma, |
| 389 | tx_buffer_info->length, |
| 390 | tx_buffer_info->next_to_watch, |
| 391 | (u64)tx_buffer_info->time_stamp); |
| 392 | } |
| 393 | |
| 394 | /* Print TX Rings */ |
| 395 | if (!netif_msg_tx_done(adapter)) |
| 396 | goto rx_ring_summary; |
| 397 | |
| 398 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 399 | |
| 400 | /* Transmit Descriptor Formats |
| 401 | * |
| 402 | * Advanced Transmit Descriptor |
| 403 | * +--------------------------------------------------------------+ |
| 404 | * 0 | Buffer Address [63:0] | |
| 405 | * +--------------------------------------------------------------+ |
| 406 | * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
| 407 | * +--------------------------------------------------------------+ |
| 408 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 |
| 409 | */ |
| 410 | |
| 411 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 412 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 413 | pr_info("------------------------------------\n"); |
| 414 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 415 | pr_info("------------------------------------\n"); |
| 416 | pr_info("T [desc] [address 63:0 ] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 417 | "[PlPOIdStDDt Ln] [bi->dma ] " |
| 418 | "leng ntw timestamp bi->skb\n"); |
| 419 | |
| 420 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 421 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 422 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 423 | u0 = (struct my_u0 *)tx_desc; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 424 | pr_info("T [0x%03X] %016llX %016llX %016llX" |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 425 | " %04X %3X %016llX %p", i, |
| 426 | le64_to_cpu(u0->a), |
| 427 | le64_to_cpu(u0->b), |
| 428 | (u64)tx_buffer_info->dma, |
| 429 | tx_buffer_info->length, |
| 430 | tx_buffer_info->next_to_watch, |
| 431 | (u64)tx_buffer_info->time_stamp, |
| 432 | tx_buffer_info->skb); |
| 433 | if (i == tx_ring->next_to_use && |
| 434 | i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 435 | pr_cont(" NTC/U\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 436 | else if (i == tx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 437 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 438 | else if (i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 439 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 440 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 441 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 442 | |
| 443 | if (netif_msg_pktdata(adapter) && |
| 444 | tx_buffer_info->dma != 0) |
| 445 | print_hex_dump(KERN_INFO, "", |
| 446 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 447 | phys_to_virt(tx_buffer_info->dma), |
| 448 | tx_buffer_info->length, true); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /* Print RX Rings Summary */ |
| 453 | rx_ring_summary: |
| 454 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 455 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 456 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 457 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 458 | pr_info("%5d %5X %5X\n", |
| 459 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /* Print RX Rings */ |
| 463 | if (!netif_msg_rx_status(adapter)) |
| 464 | goto exit; |
| 465 | |
| 466 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 467 | |
| 468 | /* Advanced Receive Descriptor (Read) Format |
| 469 | * 63 1 0 |
| 470 | * +-----------------------------------------------------+ |
| 471 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 472 | * +----------------------------------------------+------+ |
| 473 | * 8 | Header Buffer Address [63:1] | DD | |
| 474 | * +-----------------------------------------------------+ |
| 475 | * |
| 476 | * |
| 477 | * Advanced Receive Descriptor (Write-Back) Format |
| 478 | * |
| 479 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 480 | * +------------------------------------------------------+ |
| 481 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | |
| 482 | * | Checksum Ident | | | | Type | Type | |
| 483 | * +------------------------------------------------------+ |
| 484 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 485 | * +------------------------------------------------------+ |
| 486 | * 63 48 47 32 31 20 19 0 |
| 487 | */ |
| 488 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 489 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 490 | pr_info("------------------------------------\n"); |
| 491 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 492 | pr_info("------------------------------------\n"); |
| 493 | pr_info("R [desc] [ PktBuf A0] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 494 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " |
| 495 | "<-- Adv Rx Read format\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 496 | pr_info("RWB[desc] [PcsmIpSHl PtRs] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 497 | "[vl er S cks ln] ---------------- [bi->skb] " |
| 498 | "<-- Adv Rx Write-Back format\n"); |
| 499 | |
| 500 | for (i = 0; i < rx_ring->count; i++) { |
| 501 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 502 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 503 | u0 = (struct my_u0 *)rx_desc; |
| 504 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 505 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 506 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 507 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 508 | "%016llX ---------------- %p", i, |
| 509 | le64_to_cpu(u0->a), |
| 510 | le64_to_cpu(u0->b), |
| 511 | rx_buffer_info->skb); |
| 512 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 513 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 514 | "%016llX %016llX %p", i, |
| 515 | le64_to_cpu(u0->a), |
| 516 | le64_to_cpu(u0->b), |
| 517 | (u64)rx_buffer_info->dma, |
| 518 | rx_buffer_info->skb); |
| 519 | |
| 520 | if (netif_msg_pktdata(adapter)) { |
| 521 | print_hex_dump(KERN_INFO, "", |
| 522 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 523 | phys_to_virt(rx_buffer_info->dma), |
| 524 | rx_ring->rx_buf_len, true); |
| 525 | |
| 526 | if (rx_ring->rx_buf_len |
| 527 | < IXGBE_RXBUFFER_2048) |
| 528 | print_hex_dump(KERN_INFO, "", |
| 529 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 530 | phys_to_virt( |
| 531 | rx_buffer_info->page_dma + |
| 532 | rx_buffer_info->page_offset |
| 533 | ), |
| 534 | PAGE_SIZE/2, true); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 539 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 540 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 541 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 542 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 543 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 544 | |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | exit: |
| 549 | return; |
| 550 | } |
| 551 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 552 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 553 | { |
| 554 | u32 ctrl_ext; |
| 555 | |
| 556 | /* Let firmware take over control of h/w */ |
| 557 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 558 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 559 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 563 | { |
| 564 | u32 ctrl_ext; |
| 565 | |
| 566 | /* Let firmware know the driver has taken over */ |
| 567 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 568 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 569 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 570 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 571 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 572 | /* |
| 573 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 574 | * @adapter: pointer to adapter struct |
| 575 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 576 | * @queue: queue to map the corresponding interrupt to |
| 577 | * @msix_vector: the vector to map to the corresponding queue |
| 578 | * |
| 579 | */ |
| 580 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 581 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 582 | { |
| 583 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 584 | struct ixgbe_hw *hw = &adapter->hw; |
| 585 | switch (hw->mac.type) { |
| 586 | case ixgbe_mac_82598EB: |
| 587 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 588 | if (direction == -1) |
| 589 | direction = 0; |
| 590 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 591 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 592 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 593 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 594 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 595 | break; |
| 596 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 597 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 598 | if (direction == -1) { |
| 599 | /* other causes */ |
| 600 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 601 | index = ((queue & 1) * 8); |
| 602 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 603 | ivar &= ~(0xFF << index); |
| 604 | ivar |= (msix_vector << index); |
| 605 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 606 | break; |
| 607 | } else { |
| 608 | /* tx or rx causes */ |
| 609 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 610 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 611 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 612 | ivar &= ~(0xFF << index); |
| 613 | ivar |= (msix_vector << index); |
| 614 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 615 | break; |
| 616 | } |
| 617 | default: |
| 618 | break; |
| 619 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 622 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 623 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 624 | { |
| 625 | u32 mask; |
| 626 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 627 | switch (adapter->hw.mac.type) { |
| 628 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 629 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 630 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 631 | break; |
| 632 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 633 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 634 | mask = (qmask & 0xFFFFFFFF); |
| 635 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 636 | mask = (qmask >> 32); |
| 637 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 638 | break; |
| 639 | default: |
| 640 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 644 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring, |
| 645 | struct ixgbe_tx_buffer *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 646 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 647 | if (tx_buffer_info->dma) { |
| 648 | if (tx_buffer_info->mapped_as_page) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 649 | dma_unmap_page(tx_ring->dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 650 | tx_buffer_info->dma, |
| 651 | tx_buffer_info->length, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 652 | DMA_TO_DEVICE); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 653 | else |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 654 | dma_unmap_single(tx_ring->dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 655 | tx_buffer_info->dma, |
| 656 | tx_buffer_info->length, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 657 | DMA_TO_DEVICE); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 658 | tx_buffer_info->dma = 0; |
| 659 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 660 | if (tx_buffer_info->skb) { |
| 661 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 662 | tx_buffer_info->skb = NULL; |
| 663 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 664 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 665 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 666 | } |
| 667 | |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 668 | /** |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 669 | * ixgbe_dcb_txq_to_tc - convert a reg index to a traffic class |
| 670 | * @adapter: driver private struct |
| 671 | * @index: reg idx of queue to query (0-127) |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 672 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 673 | * Helper function to determine the traffic index for a particular |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 674 | * register index. |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 675 | * |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 676 | * Returns : a tc index for use in range 0-7, or 0-3 |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 677 | */ |
Don Skidmore | 3b2ee94 | 2011-01-28 02:28:26 +0000 | [diff] [blame] | 678 | static u8 ixgbe_dcb_txq_to_tc(struct ixgbe_adapter *adapter, u8 reg_idx) |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 679 | { |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 680 | int tc = -1; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 681 | int dcb_i = netdev_get_num_tc(adapter->netdev); |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 682 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 683 | /* if DCB is not enabled the queues have no TC */ |
| 684 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 685 | return tc; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 686 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 687 | /* check valid range */ |
| 688 | if (reg_idx >= adapter->hw.mac.max_tx_queues) |
| 689 | return tc; |
| 690 | |
| 691 | switch (adapter->hw.mac.type) { |
| 692 | case ixgbe_mac_82598EB: |
| 693 | tc = reg_idx >> 2; |
| 694 | break; |
| 695 | default: |
| 696 | if (dcb_i != 4 && dcb_i != 8) |
PJ Waskiewicz | 6837e89 | 2010-01-06 17:50:29 +0000 | [diff] [blame] | 697 | break; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 698 | |
| 699 | /* if VMDq is enabled the lowest order bits determine TC */ |
| 700 | if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED | |
| 701 | IXGBE_FLAG_VMDQ_ENABLED)) { |
| 702 | tc = reg_idx & (dcb_i - 1); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 703 | break; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 704 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 705 | |
| 706 | /* |
| 707 | * Convert the reg_idx into the correct TC. This bitmask |
| 708 | * targets the last full 32 ring traffic class and assigns |
| 709 | * it a value of 1. From there the rest of the rings are |
| 710 | * based on shifting the mask further up to include the |
| 711 | * reg_idx / 16 and then reg_idx / 8. It assumes dcB_i |
| 712 | * will only ever be 8 or 4 and that reg_idx will never |
| 713 | * be greater then 128. The code without the power of 2 |
| 714 | * optimizations would be: |
| 715 | * (((reg_idx % 32) + 32) * dcb_i) >> (9 - reg_idx / 32) |
| 716 | */ |
| 717 | tc = ((reg_idx & 0X1F) + 0x20) * dcb_i; |
| 718 | tc >>= 9 - (reg_idx >> 5); |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 719 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 720 | |
| 721 | return tc; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 722 | } |
| 723 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 724 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 725 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 726 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 727 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 728 | u32 data = 0; |
| 729 | u32 xoff[8] = {0}; |
| 730 | int i; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 731 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 732 | if ((hw->fc.current_mode == ixgbe_fc_full) || |
| 733 | (hw->fc.current_mode == ixgbe_fc_rx_pause)) { |
| 734 | switch (hw->mac.type) { |
| 735 | case ixgbe_mac_82598EB: |
| 736 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 737 | break; |
| 738 | default: |
| 739 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 740 | } |
| 741 | hwstats->lxoffrxc += data; |
| 742 | |
| 743 | /* refill credits (no tx hang) if we received xoff */ |
| 744 | if (!data) |
| 745 | return; |
| 746 | |
| 747 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 748 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 749 | &adapter->tx_ring[i]->state); |
| 750 | return; |
| 751 | } else if (!(adapter->dcb_cfg.pfc_mode_enable)) |
| 752 | return; |
| 753 | |
| 754 | /* update stats for each tc, only valid with PFC enabled */ |
| 755 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
| 756 | switch (hw->mac.type) { |
| 757 | case ixgbe_mac_82598EB: |
| 758 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 759 | break; |
| 760 | default: |
| 761 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 762 | } |
| 763 | hwstats->pxoffrxc[i] += xoff[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 764 | } |
| 765 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 766 | /* disarm tx queues that have received xoff frames */ |
| 767 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 768 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 769 | u32 tc = ixgbe_dcb_txq_to_tc(adapter, tx_ring->reg_idx); |
| 770 | |
| 771 | if (xoff[tc]) |
| 772 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 777 | { |
| 778 | return ring->tx_stats.completed; |
| 779 | } |
| 780 | |
| 781 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 782 | { |
| 783 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); |
| 784 | struct ixgbe_hw *hw = &adapter->hw; |
| 785 | |
| 786 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 787 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
| 788 | |
| 789 | if (head != tail) |
| 790 | return (head < tail) ? |
| 791 | tail - head : (tail + ring->count - head); |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 797 | { |
| 798 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 799 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 800 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 801 | bool ret = false; |
| 802 | |
| 803 | clear_check_for_tx_hang(tx_ring); |
| 804 | |
| 805 | /* |
| 806 | * Check for a hung queue, but be thorough. This verifies |
| 807 | * that a transmit has been completed since the previous |
| 808 | * check AND there is at least one packet pending. The |
| 809 | * ARMED bit is set to indicate a potential hang. The |
| 810 | * bit is cleared if a pause frame is received to remove |
| 811 | * false hang detection due to PFC or 802.3x frames. By |
| 812 | * requiring this to fail twice we avoid races with |
| 813 | * pfc clearing the ARMED bit and conditions where we |
| 814 | * run the check_tx_hang logic with a transmit completion |
| 815 | * pending but without time to complete it yet. |
| 816 | */ |
| 817 | if ((tx_done_old == tx_done) && tx_pending) { |
| 818 | /* make sure it is true for two checks in a row */ |
| 819 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 820 | &tx_ring->state); |
| 821 | } else { |
| 822 | /* update completed stats and continue */ |
| 823 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 824 | /* reset the countdown */ |
| 825 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 826 | } |
| 827 | |
| 828 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 831 | #define IXGBE_MAX_TXD_PWR 14 |
| 832 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 833 | |
| 834 | /* Tx Descriptors needed, worst case */ |
| 835 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 836 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 837 | #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 838 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 839 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 840 | /** |
| 841 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 842 | * @adapter: driver private struct |
| 843 | **/ |
| 844 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 845 | { |
| 846 | |
| 847 | /* Do the reset outside of interrupt context */ |
| 848 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 849 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 850 | ixgbe_service_event_schedule(adapter); |
| 851 | } |
| 852 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 853 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 854 | /** |
| 855 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 856 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 857 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 858 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 859 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 860 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 861 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 862 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 863 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 864 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 865 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 866 | u16 i, eop, count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 867 | |
| 868 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 869 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 870 | eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 871 | |
| 872 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 873 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 874 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 875 | rmb(); /* read buffer_info after eop_desc */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 876 | for ( ; !cleaned; count++) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 877 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 878 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 879 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 880 | tx_desc->wb.status = 0; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 881 | cleaned = (i == eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 882 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 883 | i++; |
| 884 | if (i == tx_ring->count) |
| 885 | i = 0; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 886 | |
| 887 | if (cleaned && tx_buffer_info->skb) { |
| 888 | total_bytes += tx_buffer_info->bytecount; |
| 889 | total_packets += tx_buffer_info->gso_segs; |
| 890 | } |
| 891 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 892 | ixgbe_unmap_and_free_tx_resource(tx_ring, |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 893 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 894 | } |
| 895 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 896 | tx_ring->tx_stats.completed++; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 897 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 898 | eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 899 | } |
| 900 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 901 | tx_ring->next_to_clean = i; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 902 | tx_ring->total_bytes += total_bytes; |
| 903 | tx_ring->total_packets += total_packets; |
| 904 | u64_stats_update_begin(&tx_ring->syncp); |
| 905 | tx_ring->stats.packets += total_packets; |
| 906 | tx_ring->stats.bytes += total_bytes; |
| 907 | u64_stats_update_end(&tx_ring->syncp); |
| 908 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 909 | 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] | 910 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 911 | struct ixgbe_hw *hw = &adapter->hw; |
| 912 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
| 913 | e_err(drv, "Detected Tx Unit Hang\n" |
| 914 | " Tx Queue <%d>\n" |
| 915 | " TDH, TDT <%x>, <%x>\n" |
| 916 | " next_to_use <%x>\n" |
| 917 | " next_to_clean <%x>\n" |
| 918 | "tx_buffer_info[next_to_clean]\n" |
| 919 | " time_stamp <%lx>\n" |
| 920 | " jiffies <%lx>\n", |
| 921 | tx_ring->queue_index, |
| 922 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 923 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
| 924 | tx_ring->next_to_use, eop, |
| 925 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
| 926 | |
| 927 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 928 | |
| 929 | e_info(probe, |
| 930 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 931 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 932 | |
| 933 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 934 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 935 | |
| 936 | /* the adapter is about to reset, no point in enabling stuff */ |
| 937 | return true; |
| 938 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 939 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 940 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 941 | if (unlikely(count && netif_carrier_ok(tx_ring->netdev) && |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 942 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 943 | /* Make sure that anybody stopping the queue after this |
| 944 | * sees the new next_to_clean. |
| 945 | */ |
| 946 | smp_mb(); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 947 | if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) && |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 948 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 949 | netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 950 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 951 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 952 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 953 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 954 | return count < tx_ring->work_limit; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 957 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 958 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 959 | struct ixgbe_ring *rx_ring, |
| 960 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 961 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 962 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 963 | u32 rxctrl; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 964 | u8 reg_idx = rx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 965 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 966 | rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx)); |
| 967 | switch (hw->mac.type) { |
| 968 | case ixgbe_mac_82598EB: |
| 969 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 970 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 971 | break; |
| 972 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 973 | case ixgbe_mac_X540: |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 974 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 975 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 976 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 977 | break; |
| 978 | default: |
| 979 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 980 | } |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 981 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 982 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
| 983 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 984 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 988 | struct ixgbe_ring *tx_ring, |
| 989 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 990 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 991 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 992 | u32 txctrl; |
| 993 | u8 reg_idx = tx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 994 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 995 | switch (hw->mac.type) { |
| 996 | case ixgbe_mac_82598EB: |
| 997 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx)); |
| 998 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 999 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 1000 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1001 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl); |
| 1002 | break; |
| 1003 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1004 | case ixgbe_mac_X540: |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1005 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx)); |
| 1006 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 1007 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 1008 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 1009 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1010 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl); |
| 1011 | break; |
| 1012 | default: |
| 1013 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1014 | } |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1018 | { |
| 1019 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1020 | int cpu = get_cpu(); |
| 1021 | long r_idx; |
| 1022 | int i; |
| 1023 | |
| 1024 | if (q_vector->cpu == cpu) |
| 1025 | goto out_no_update; |
| 1026 | |
| 1027 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1028 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1029 | ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu); |
| 1030 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1031 | r_idx + 1); |
| 1032 | } |
| 1033 | |
| 1034 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1035 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1036 | ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu); |
| 1037 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1038 | r_idx + 1); |
| 1039 | } |
| 1040 | |
| 1041 | q_vector->cpu = cpu; |
| 1042 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1043 | put_cpu(); |
| 1044 | } |
| 1045 | |
| 1046 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1047 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1048 | int num_q_vectors; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1049 | int i; |
| 1050 | |
| 1051 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 1052 | return; |
| 1053 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1054 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 1055 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 1056 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1057 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 1058 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1059 | else |
| 1060 | num_q_vectors = 1; |
| 1061 | |
| 1062 | for (i = 0; i < num_q_vectors; i++) { |
| 1063 | adapter->q_vector[i]->cpu = -1; |
| 1064 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1069 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1070 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1071 | unsigned long event = *(unsigned long *)data; |
| 1072 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1073 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 1074 | return 0; |
| 1075 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1076 | switch (event) { |
| 1077 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1078 | /* if we're already enabled, don't do it again */ |
| 1079 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1080 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1081 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1082 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1083 | ixgbe_setup_dca(adapter); |
| 1084 | break; |
| 1085 | } |
| 1086 | /* Fall Through since DCA is disabled. */ |
| 1087 | case DCA_PROVIDER_REMOVE: |
| 1088 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1089 | dca_remove_requester(dev); |
| 1090 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 1091 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 1092 | } |
| 1093 | break; |
| 1094 | } |
| 1095 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1096 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1097 | } |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1098 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1099 | |
| 1100 | static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc, |
| 1101 | struct sk_buff *skb) |
| 1102 | { |
| 1103 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
| 1104 | } |
| 1105 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1106 | /** |
| 1107 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 1108 | * @adapter: board private structure |
| 1109 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1110 | * @status: hardware indication of status of receive |
| 1111 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 1112 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1113 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1114 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1115 | struct sk_buff *skb, u8 status, |
| 1116 | struct ixgbe_ring *ring, |
| 1117 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1118 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1119 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1120 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1121 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 1122 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1123 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 1124 | if (is_vlan && (tag & VLAN_VID_MASK)) |
| 1125 | __vlan_hwaccel_put_tag(skb, tag); |
| 1126 | |
| 1127 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1128 | napi_gro_receive(napi, skb); |
| 1129 | else |
| 1130 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1133 | /** |
| 1134 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 1135 | * @adapter: address of board private structure |
| 1136 | * @status_err: hardware indication of status of receive |
| 1137 | * @skb: skb currently being received and modified |
| 1138 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1139 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1140 | union ixgbe_adv_rx_desc *rx_desc, |
| 1141 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1142 | { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1143 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1144 | |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1145 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1146 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1147 | /* Rx csum disabled */ |
| 1148 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1149 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1150 | |
| 1151 | /* if IP and error */ |
| 1152 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 1153 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1154 | adapter->hw_csum_rx_error++; |
| 1155 | return; |
| 1156 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1157 | |
| 1158 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 1159 | return; |
| 1160 | |
| 1161 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1162 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1163 | |
| 1164 | /* |
| 1165 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1166 | * checksum errors. |
| 1167 | */ |
| 1168 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 1169 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 1170 | return; |
| 1171 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1172 | adapter->hw_csum_rx_error++; |
| 1173 | return; |
| 1174 | } |
| 1175 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1176 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1177 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1180 | 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] | 1181 | { |
| 1182 | /* |
| 1183 | * Force memory writes to complete before letting h/w |
| 1184 | * know there are new descriptors to fetch. (Only |
| 1185 | * applicable for weak-ordered memory model archs, |
| 1186 | * such as IA-64). |
| 1187 | */ |
| 1188 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1189 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1192 | /** |
| 1193 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1194 | * @rx_ring: ring to place buffers on |
| 1195 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1196 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1197 | 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] | 1198 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1199 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1200 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1201 | struct sk_buff *skb; |
| 1202 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1203 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1204 | /* do nothing if no valid netdev defined */ |
| 1205 | if (!rx_ring->netdev) |
| 1206 | return; |
| 1207 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1208 | while (cleaned_count--) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1209 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1210 | bi = &rx_ring->rx_buffer_info[i]; |
| 1211 | skb = bi->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1212 | |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1213 | if (!skb) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1214 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1215 | rx_ring->rx_buf_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1216 | if (!skb) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1217 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1218 | goto no_buffers; |
| 1219 | } |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1220 | /* initialize queue mapping */ |
| 1221 | skb_record_rx_queue(skb, rx_ring->queue_index); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1222 | bi->skb = skb; |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1223 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1224 | |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1225 | if (!bi->dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1226 | bi->dma = dma_map_single(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1227 | skb->data, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1228 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 1229 | DMA_FROM_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1230 | if (dma_mapping_error(rx_ring->dev, bi->dma)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1231 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1232 | bi->dma = 0; |
| 1233 | goto no_buffers; |
| 1234 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1235 | } |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1236 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1237 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1238 | if (!bi->page) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1239 | bi->page = netdev_alloc_page(rx_ring->netdev); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1240 | if (!bi->page) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1241 | rx_ring->rx_stats.alloc_rx_page_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1242 | goto no_buffers; |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | if (!bi->page_dma) { |
| 1247 | /* use a half page if we're re-using */ |
| 1248 | bi->page_offset ^= PAGE_SIZE / 2; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1249 | bi->page_dma = dma_map_page(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1250 | bi->page, |
| 1251 | bi->page_offset, |
| 1252 | PAGE_SIZE / 2, |
| 1253 | DMA_FROM_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1254 | if (dma_mapping_error(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1255 | bi->page_dma)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1256 | rx_ring->rx_stats.alloc_rx_page_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1257 | bi->page_dma = 0; |
| 1258 | goto no_buffers; |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | /* Refresh the desc even if buffer_addrs didn't change |
| 1263 | * because each write-back erases this info. */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1264 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 1265 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1266 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1267 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1268 | rx_desc->read.hdr_addr = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | i++; |
| 1272 | if (i == rx_ring->count) |
| 1273 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1274 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1275 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1276 | no_buffers: |
| 1277 | if (rx_ring->next_to_use != i) { |
| 1278 | rx_ring->next_to_use = i; |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1279 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1280 | } |
| 1281 | } |
| 1282 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1283 | static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1284 | { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1285 | /* HW will not DMA in data larger than the given buffer, even if it |
| 1286 | * parses the (NFS, of course) header to be larger. In that case, it |
| 1287 | * fills the header buffer and spills the rest into the page. |
| 1288 | */ |
| 1289 | u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info); |
| 1290 | u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
| 1291 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
| 1292 | if (hlen > IXGBE_RX_HDR_SIZE) |
| 1293 | hlen = IXGBE_RX_HDR_SIZE; |
| 1294 | return hlen; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1297 | /** |
| 1298 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 1299 | * @skb: pointer to the last skb in the rsc queue |
| 1300 | * |
| 1301 | * This function changes a queue full of hw rsc buffers into a completed |
| 1302 | * packet. It uses the ->prev pointers to find the first packet and then |
| 1303 | * turns it into the frag list owner. |
| 1304 | **/ |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1305 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1306 | { |
| 1307 | unsigned int frag_list_size = 0; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1308 | unsigned int skb_cnt = 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1309 | |
| 1310 | while (skb->prev) { |
| 1311 | struct sk_buff *prev = skb->prev; |
| 1312 | frag_list_size += skb->len; |
| 1313 | skb->prev = NULL; |
| 1314 | skb = prev; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1315 | skb_cnt++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | skb_shinfo(skb)->frag_list = skb->next; |
| 1319 | skb->next = NULL; |
| 1320 | skb->len += frag_list_size; |
| 1321 | skb->data_len += frag_list_size; |
| 1322 | skb->truesize += frag_list_size; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1323 | IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt; |
| 1324 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1325 | return skb; |
| 1326 | } |
| 1327 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1328 | static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc) |
| 1329 | { |
| 1330 | return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 1331 | IXGBE_RXDADV_RSCCNT_MASK); |
| 1332 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1333 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1334 | static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1335 | struct ixgbe_ring *rx_ring, |
| 1336 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1337 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1338 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1339 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 1340 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 1341 | struct sk_buff *skb; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1342 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1343 | const int current_node = numa_node_id(); |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1344 | #ifdef IXGBE_FCOE |
| 1345 | int ddp_bytes = 0; |
| 1346 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1347 | u32 staterr; |
| 1348 | u16 i; |
| 1349 | u16 cleaned_count = 0; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1350 | bool pkt_is_rsc = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1351 | |
| 1352 | i = rx_ring->next_to_clean; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1353 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1354 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1355 | |
| 1356 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1357 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1358 | |
Milton Miller | 3c945e5 | 2010-02-19 17:44:42 +0000 | [diff] [blame] | 1359 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1360 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1361 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 1362 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1363 | skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1364 | rx_buffer_info->skb = NULL; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1365 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1366 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1367 | if (ring_is_rsc_enabled(rx_ring)) |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1368 | pkt_is_rsc = ixgbe_get_rsc_state(rx_desc); |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1369 | |
| 1370 | /* if this is a skb from previous receive DMA will be 0 */ |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 1371 | if (rx_buffer_info->dma) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1372 | u16 hlen; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1373 | if (pkt_is_rsc && |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1374 | !(staterr & IXGBE_RXD_STAT_EOP) && |
| 1375 | !skb->prev) { |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1376 | /* |
| 1377 | * When HWRSC is enabled, delay unmapping |
| 1378 | * of the first packet. It carries the |
| 1379 | * header information, HW may still |
| 1380 | * access the header after the writeback. |
| 1381 | * Only unmap it when EOP is reached |
| 1382 | */ |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1383 | IXGBE_RSC_CB(skb)->delay_unmap = true; |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1384 | IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1385 | } else { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1386 | dma_unmap_single(rx_ring->dev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1387 | rx_buffer_info->dma, |
| 1388 | rx_ring->rx_buf_len, |
| 1389 | DMA_FROM_DEVICE); |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1390 | } |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 1391 | rx_buffer_info->dma = 0; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1392 | |
| 1393 | if (ring_is_ps_enabled(rx_ring)) { |
| 1394 | hlen = ixgbe_get_hlen(rx_desc); |
| 1395 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
| 1396 | } else { |
| 1397 | hlen = le16_to_cpu(rx_desc->wb.upper.length); |
| 1398 | } |
| 1399 | |
| 1400 | skb_put(skb, hlen); |
| 1401 | } else { |
| 1402 | /* assume packet split since header is unmapped */ |
| 1403 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | if (upper_len) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1407 | dma_unmap_page(rx_ring->dev, |
| 1408 | rx_buffer_info->page_dma, |
| 1409 | PAGE_SIZE / 2, |
| 1410 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1411 | rx_buffer_info->page_dma = 0; |
| 1412 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1413 | rx_buffer_info->page, |
| 1414 | rx_buffer_info->page_offset, |
| 1415 | upper_len); |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1416 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1417 | if ((page_count(rx_buffer_info->page) == 1) && |
| 1418 | (page_to_nid(rx_buffer_info->page) == current_node)) |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1419 | get_page(rx_buffer_info->page); |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1420 | else |
| 1421 | rx_buffer_info->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1422 | |
| 1423 | skb->len += upper_len; |
| 1424 | skb->data_len += upper_len; |
| 1425 | skb->truesize += upper_len; |
| 1426 | } |
| 1427 | |
| 1428 | i++; |
| 1429 | if (i == rx_ring->count) |
| 1430 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1431 | |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1432 | next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1433 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1434 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1435 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1436 | if (pkt_is_rsc) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1437 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 1438 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 1439 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1440 | } else { |
| 1441 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 1442 | } |
| 1443 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1444 | if (!(staterr & IXGBE_RXD_STAT_EOP)) { |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1445 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1446 | rx_buffer_info->skb = next_buffer->skb; |
| 1447 | rx_buffer_info->dma = next_buffer->dma; |
| 1448 | next_buffer->skb = skb; |
| 1449 | next_buffer->dma = 0; |
| 1450 | } else { |
| 1451 | skb->next = next_buffer->skb; |
| 1452 | skb->next->prev = skb; |
| 1453 | } |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1454 | rx_ring->rx_stats.non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1455 | goto next_desc; |
| 1456 | } |
| 1457 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1458 | if (skb->prev) { |
| 1459 | skb = ixgbe_transform_rsc_queue(skb); |
| 1460 | /* if we got here without RSC the packet is invalid */ |
| 1461 | if (!pkt_is_rsc) { |
| 1462 | __pskb_trim(skb, 0); |
| 1463 | rx_buffer_info->skb = skb; |
| 1464 | goto next_desc; |
| 1465 | } |
| 1466 | } |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1467 | |
| 1468 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1469 | if (IXGBE_RSC_CB(skb)->delay_unmap) { |
| 1470 | dma_unmap_single(rx_ring->dev, |
| 1471 | IXGBE_RSC_CB(skb)->dma, |
| 1472 | rx_ring->rx_buf_len, |
| 1473 | DMA_FROM_DEVICE); |
| 1474 | IXGBE_RSC_CB(skb)->dma = 0; |
| 1475 | IXGBE_RSC_CB(skb)->delay_unmap = false; |
| 1476 | } |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1477 | } |
| 1478 | if (pkt_is_rsc) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1479 | if (ring_is_ps_enabled(rx_ring)) |
| 1480 | rx_ring->rx_stats.rsc_count += |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1481 | skb_shinfo(skb)->nr_frags; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1482 | else |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1483 | rx_ring->rx_stats.rsc_count += |
| 1484 | IXGBE_RSC_CB(skb)->skb_cnt; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1485 | rx_ring->rx_stats.rsc_flush++; |
| 1486 | } |
| 1487 | |
| 1488 | /* ERR_MASK will only have valid bits if EOP set */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1489 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1490 | /* trim packet back to size 0 and recycle it */ |
| 1491 | __pskb_trim(skb, 0); |
| 1492 | rx_buffer_info->skb = skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1493 | goto next_desc; |
| 1494 | } |
| 1495 | |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1496 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1497 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 1498 | ixgbe_rx_hash(rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1499 | |
| 1500 | /* probably a little skewed due to removing CRC */ |
| 1501 | total_rx_bytes += skb->len; |
| 1502 | total_rx_packets++; |
| 1503 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1504 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1505 | #ifdef IXGBE_FCOE |
| 1506 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1507 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 1508 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 1509 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1510 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1511 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1512 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 1513 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1514 | |
| 1515 | next_desc: |
| 1516 | rx_desc->wb.upper.status_error = 0; |
| 1517 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1518 | (*work_done)++; |
| 1519 | if (*work_done >= work_to_do) |
| 1520 | break; |
| 1521 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1522 | /* return some buffers to hardware, one at a time is too slow */ |
| 1523 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1524 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1525 | cleaned_count = 0; |
| 1526 | } |
| 1527 | |
| 1528 | /* use prefetched values */ |
| 1529 | rx_desc = next_rxd; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1530 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1533 | rx_ring->next_to_clean = i; |
| 1534 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 1535 | |
| 1536 | if (cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1537 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1538 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1539 | #ifdef IXGBE_FCOE |
| 1540 | /* include DDPed FCoE data */ |
| 1541 | if (ddp_bytes > 0) { |
| 1542 | unsigned int mss; |
| 1543 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1544 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1545 | sizeof(struct fc_frame_header) - |
| 1546 | sizeof(struct fcoe_crc_eof); |
| 1547 | if (mss > 512) |
| 1548 | mss &= ~511; |
| 1549 | total_rx_bytes += ddp_bytes; |
| 1550 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1551 | } |
| 1552 | #endif /* IXGBE_FCOE */ |
| 1553 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1554 | rx_ring->total_packets += total_rx_packets; |
| 1555 | rx_ring->total_bytes += total_rx_bytes; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1556 | u64_stats_update_begin(&rx_ring->syncp); |
| 1557 | rx_ring->stats.packets += total_rx_packets; |
| 1558 | rx_ring->stats.bytes += total_rx_bytes; |
| 1559 | u64_stats_update_end(&rx_ring->syncp); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1562 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1563 | /** |
| 1564 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1565 | * @adapter: board private structure |
| 1566 | * |
| 1567 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1568 | * interrupts. |
| 1569 | **/ |
| 1570 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1571 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1572 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1573 | int i, q_vectors, v_idx, r_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1574 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1575 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1576 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1577 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1578 | /* |
| 1579 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1580 | * corresponding register. |
| 1581 | */ |
| 1582 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1583 | q_vector = adapter->q_vector[v_idx]; |
Akinobu Mita | 984b3f5 | 2010-03-05 13:41:37 -0800 | [diff] [blame] | 1584 | /* XXX for_each_set_bit(...) */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1585 | r_idx = find_first_bit(q_vector->rxr_idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1586 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1587 | |
| 1588 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1589 | u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx; |
| 1590 | ixgbe_set_ivar(adapter, 0, reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1591 | r_idx = find_next_bit(q_vector->rxr_idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1592 | adapter->num_rx_queues, |
| 1593 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1594 | } |
| 1595 | r_idx = find_first_bit(q_vector->txr_idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1596 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1597 | |
| 1598 | for (i = 0; i < q_vector->txr_count; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1599 | u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx; |
| 1600 | ixgbe_set_ivar(adapter, 1, reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1601 | r_idx = find_next_bit(q_vector->txr_idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1602 | adapter->num_tx_queues, |
| 1603 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1606 | if (q_vector->txr_count && !q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1607 | /* tx only */ |
| 1608 | q_vector->eitr = adapter->tx_eitr_param; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1609 | else if (q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1610 | /* rx or mixed */ |
| 1611 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1612 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1613 | ixgbe_write_eitr(q_vector); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 1614 | /* If Flow Director is enabled, set interrupt affinity */ |
| 1615 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 1616 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { |
| 1617 | /* |
| 1618 | * Allocate the affinity_hint cpumask, assign the mask |
| 1619 | * for this vector, and set our affinity_hint for |
| 1620 | * this irq. |
| 1621 | */ |
| 1622 | if (!alloc_cpumask_var(&q_vector->affinity_mask, |
| 1623 | GFP_KERNEL)) |
| 1624 | return; |
| 1625 | cpumask_set_cpu(v_idx, q_vector->affinity_mask); |
| 1626 | irq_set_affinity_hint(adapter->msix_entries[v_idx].vector, |
| 1627 | q_vector->affinity_mask); |
| 1628 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1631 | switch (adapter->hw.mac.type) { |
| 1632 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1633 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1634 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1635 | break; |
| 1636 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1637 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1638 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1639 | break; |
| 1640 | |
| 1641 | default: |
| 1642 | break; |
| 1643 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1644 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1645 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1646 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1647 | mask = IXGBE_EIMS_ENABLE_MASK; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1648 | if (adapter->num_vfs) |
| 1649 | mask &= ~(IXGBE_EIMS_OTHER | |
| 1650 | IXGBE_EIMS_MAILBOX | |
| 1651 | IXGBE_EIMS_LSC); |
| 1652 | else |
| 1653 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1654 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1657 | enum latency_range { |
| 1658 | lowest_latency = 0, |
| 1659 | low_latency = 1, |
| 1660 | bulk_latency = 2, |
| 1661 | latency_invalid = 255 |
| 1662 | }; |
| 1663 | |
| 1664 | /** |
| 1665 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 1666 | * @adapter: pointer to adapter |
| 1667 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 1668 | * @itr_setting: current throttle rate in ints/second |
| 1669 | * @packets: the number of packets during this measurement interval |
| 1670 | * @bytes: the number of bytes during this measurement interval |
| 1671 | * |
| 1672 | * Stores a new ITR value based on packets and byte |
| 1673 | * counts during the last interrupt. The advantage of per interrupt |
| 1674 | * computation is faster updates and more accurate ITR for the current |
| 1675 | * traffic pattern. Constants in this function were computed |
| 1676 | * based on theoretical maximum wire speed and thresholds were set based |
| 1677 | * on testing data as well as attempting to minimize response time |
| 1678 | * while increasing bulk throughput. |
| 1679 | * this functionality is controlled by the InterruptThrottleRate module |
| 1680 | * parameter (see ixgbe_param.c) |
| 1681 | **/ |
| 1682 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1683 | u32 eitr, u8 itr_setting, |
| 1684 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1685 | { |
| 1686 | unsigned int retval = itr_setting; |
| 1687 | u32 timepassed_us; |
| 1688 | u64 bytes_perint; |
| 1689 | |
| 1690 | if (packets == 0) |
| 1691 | goto update_itr_done; |
| 1692 | |
| 1693 | |
| 1694 | /* simple throttlerate management |
| 1695 | * 0-20MB/s lowest (100000 ints/s) |
| 1696 | * 20-100MB/s low (20000 ints/s) |
| 1697 | * 100-1249MB/s bulk (8000 ints/s) |
| 1698 | */ |
| 1699 | /* what was last interrupt timeslice? */ |
| 1700 | timepassed_us = 1000000/eitr; |
| 1701 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1702 | |
| 1703 | switch (itr_setting) { |
| 1704 | case lowest_latency: |
| 1705 | if (bytes_perint > adapter->eitr_low) |
| 1706 | retval = low_latency; |
| 1707 | break; |
| 1708 | case low_latency: |
| 1709 | if (bytes_perint > adapter->eitr_high) |
| 1710 | retval = bulk_latency; |
| 1711 | else if (bytes_perint <= adapter->eitr_low) |
| 1712 | retval = lowest_latency; |
| 1713 | break; |
| 1714 | case bulk_latency: |
| 1715 | if (bytes_perint <= adapter->eitr_high) |
| 1716 | retval = low_latency; |
| 1717 | break; |
| 1718 | } |
| 1719 | |
| 1720 | update_itr_done: |
| 1721 | return retval; |
| 1722 | } |
| 1723 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1724 | /** |
| 1725 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1726 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1727 | * |
| 1728 | * This function is made to be called by ethtool and by the driver |
| 1729 | * when it needs to update EITR registers at runtime. Hardware |
| 1730 | * specific quirks/differences are taken care of here. |
| 1731 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1732 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1733 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1734 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1735 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1736 | int v_idx = q_vector->v_idx; |
| 1737 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1738 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1739 | switch (adapter->hw.mac.type) { |
| 1740 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1741 | /* must write high and low 16 bits to reset counter */ |
| 1742 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1743 | break; |
| 1744 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1745 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1746 | /* |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1747 | * 82599 and X540 can support a value of zero, so allow it for |
Jesse Brandeburg | f8d1dca | 2010-04-27 01:37:20 +0000 | [diff] [blame] | 1748 | * max interrupt rate, but there is an errata where it can |
| 1749 | * not be zero with RSC |
| 1750 | */ |
| 1751 | if (itr_reg == 8 && |
| 1752 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 1753 | itr_reg = 0; |
| 1754 | |
| 1755 | /* |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1756 | * set the WDIS bit to not clear the timer bits and cause an |
| 1757 | * immediate assertion of the interrupt |
| 1758 | */ |
| 1759 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1760 | break; |
| 1761 | default: |
| 1762 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1763 | } |
| 1764 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1765 | } |
| 1766 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1767 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 1768 | { |
| 1769 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 1770 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1771 | u32 new_itr; |
| 1772 | u8 current_itr, ret_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1773 | |
| 1774 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1775 | for (i = 0; i < q_vector->txr_count; i++) { |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 1776 | struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1777 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1778 | q_vector->tx_itr, |
| 1779 | tx_ring->total_packets, |
| 1780 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1781 | /* if the result for this queue would decrease interrupt |
| 1782 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1783 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1784 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1785 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1786 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1790 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 1791 | struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1792 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1793 | q_vector->rx_itr, |
| 1794 | rx_ring->total_packets, |
| 1795 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1796 | /* if the result for this queue would decrease interrupt |
| 1797 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1798 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1799 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1800 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1801 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1802 | } |
| 1803 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1804 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1805 | |
| 1806 | switch (current_itr) { |
| 1807 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1808 | case lowest_latency: |
| 1809 | new_itr = 100000; |
| 1810 | break; |
| 1811 | case low_latency: |
| 1812 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1813 | break; |
| 1814 | case bulk_latency: |
| 1815 | default: |
| 1816 | new_itr = 8000; |
| 1817 | break; |
| 1818 | } |
| 1819 | |
| 1820 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1821 | /* do an exponential smoothing */ |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 1822 | new_itr = ((q_vector->eitr * 9) + new_itr)/10; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1823 | |
| 1824 | /* save the algorithm value here, not the smoothed one */ |
| 1825 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1826 | |
| 1827 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1828 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1831 | /** |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1832 | * ixgbe_check_overtemp_subtask - check for over tempurature |
| 1833 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1834 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1835 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1836 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1837 | struct ixgbe_hw *hw = &adapter->hw; |
| 1838 | u32 eicr = adapter->interrupt_event; |
| 1839 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1840 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1841 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1842 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1843 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1844 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 1845 | return; |
| 1846 | |
| 1847 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1848 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1849 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1850 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 1851 | /* |
| 1852 | * Since the warning interrupt is for both ports |
| 1853 | * we don't have to check if: |
| 1854 | * - This interrupt wasn't for our port. |
| 1855 | * - We may have missed the interrupt so always have to |
| 1856 | * check if we got a LSC |
| 1857 | */ |
| 1858 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 1859 | !(eicr & IXGBE_EICR_LSC)) |
| 1860 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1861 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1862 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
| 1863 | u32 autoneg; |
| 1864 | bool link_up = false; |
| 1865 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1866 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 1867 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1868 | if (link_up) |
| 1869 | return; |
| 1870 | } |
| 1871 | |
| 1872 | /* Check if this is not due to overtemp */ |
| 1873 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 1874 | return; |
| 1875 | |
| 1876 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1877 | default: |
| 1878 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 1879 | return; |
| 1880 | break; |
| 1881 | } |
| 1882 | e_crit(drv, |
| 1883 | "Network adapter has been stopped because it has over heated. " |
| 1884 | "Restart the computer. If the problem persists, " |
| 1885 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1886 | |
| 1887 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1890 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1891 | { |
| 1892 | struct ixgbe_hw *hw = &adapter->hw; |
| 1893 | |
| 1894 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1895 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 1896 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1897 | /* write to clear the interrupt */ |
| 1898 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1899 | } |
| 1900 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1901 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1902 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1903 | { |
| 1904 | struct ixgbe_hw *hw = &adapter->hw; |
| 1905 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 1906 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1907 | /* Clear the interrupt */ |
| 1908 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1909 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1910 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 1911 | ixgbe_service_event_schedule(adapter); |
| 1912 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 1913 | } |
| 1914 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1915 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1916 | /* Clear the interrupt */ |
| 1917 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1918 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1919 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 1920 | ixgbe_service_event_schedule(adapter); |
| 1921 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1925 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1926 | { |
| 1927 | struct ixgbe_hw *hw = &adapter->hw; |
| 1928 | |
| 1929 | adapter->lsc_int++; |
| 1930 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1931 | adapter->link_check_timeout = jiffies; |
| 1932 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1933 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 1934 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 1935 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1939 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1940 | { |
| 1941 | struct net_device *netdev = data; |
| 1942 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1943 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1944 | u32 eicr; |
| 1945 | |
| 1946 | /* |
| 1947 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1948 | * of clear-by-read. Reading with EICS will return the |
| 1949 | * interrupt causes without clearing, which later be done |
| 1950 | * with the write to EICR. |
| 1951 | */ |
| 1952 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1953 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1954 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1955 | if (eicr & IXGBE_EICR_LSC) |
| 1956 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1957 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1958 | if (eicr & IXGBE_EICR_MAILBOX) |
| 1959 | ixgbe_msg_task(adapter); |
| 1960 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1961 | switch (hw->mac.type) { |
| 1962 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1963 | case ixgbe_mac_X540: |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1964 | /* Handle Flow Director Full threshold interrupt */ |
| 1965 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1966 | int reinit_count = 0; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1967 | int i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1968 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1969 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1970 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1971 | &ring->state)) |
| 1972 | reinit_count++; |
| 1973 | } |
| 1974 | if (reinit_count) { |
| 1975 | /* no more flow director interrupts until after init */ |
| 1976 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 1977 | eicr &= ~IXGBE_EICR_FLOW_DIR; |
| 1978 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 1979 | ixgbe_service_event_schedule(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1980 | } |
| 1981 | } |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1982 | ixgbe_check_sfp_event(adapter, eicr); |
| 1983 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1984 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { |
| 1985 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1986 | adapter->interrupt_event = eicr; |
| 1987 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1988 | ixgbe_service_event_schedule(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1989 | } |
| 1990 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1991 | break; |
| 1992 | default: |
| 1993 | break; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1994 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1995 | |
| 1996 | ixgbe_check_fan_failure(adapter, eicr); |
| 1997 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1998 | /* re-enable the original interrupt state, no lsc, no queues */ |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1999 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2000 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr & |
| 2001 | ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2002 | |
| 2003 | return IRQ_HANDLED; |
| 2004 | } |
| 2005 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2006 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2007 | u64 qmask) |
| 2008 | { |
| 2009 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2010 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2011 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2012 | switch (hw->mac.type) { |
| 2013 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2014 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2015 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2016 | break; |
| 2017 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2018 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2019 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2020 | if (mask) |
| 2021 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2022 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2023 | if (mask) |
| 2024 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2025 | break; |
| 2026 | default: |
| 2027 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2028 | } |
| 2029 | /* skip the flush */ |
| 2030 | } |
| 2031 | |
| 2032 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2033 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2034 | { |
| 2035 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2036 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2037 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2038 | switch (hw->mac.type) { |
| 2039 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2040 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2041 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2042 | break; |
| 2043 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2044 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2045 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2046 | if (mask) |
| 2047 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2048 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2049 | if (mask) |
| 2050 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2051 | break; |
| 2052 | default: |
| 2053 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2054 | } |
| 2055 | /* skip the flush */ |
| 2056 | } |
| 2057 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2058 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 2059 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2060 | struct ixgbe_q_vector *q_vector = data; |
| 2061 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2062 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2063 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2064 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2065 | if (!q_vector->txr_count) |
| 2066 | return IRQ_HANDLED; |
| 2067 | |
| 2068 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 2069 | for (i = 0; i < q_vector->txr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2070 | tx_ring = adapter->tx_ring[r_idx]; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2071 | tx_ring->total_bytes = 0; |
| 2072 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2073 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2074 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2075 | } |
| 2076 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2077 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2078 | napi_schedule(&q_vector->napi); |
| 2079 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2080 | return IRQ_HANDLED; |
| 2081 | } |
| 2082 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2083 | /** |
| 2084 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 2085 | * @irq: unused |
| 2086 | * @data: pointer to our q_vector struct for this interrupt vector |
| 2087 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2088 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 2089 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2090 | struct ixgbe_q_vector *q_vector = data; |
| 2091 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2092 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2093 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2094 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2095 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2096 | #ifdef CONFIG_IXGBE_DCA |
| 2097 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2098 | ixgbe_update_dca(q_vector); |
| 2099 | #endif |
| 2100 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2101 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2102 | for (i = 0; i < q_vector->rxr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2103 | rx_ring = adapter->rx_ring[r_idx]; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2104 | rx_ring->total_bytes = 0; |
| 2105 | rx_ring->total_packets = 0; |
| 2106 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2107 | r_idx + 1); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2110 | if (!q_vector->rxr_count) |
| 2111 | return IRQ_HANDLED; |
| 2112 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2113 | /* EIAM disabled interrupts (on this vector) for us */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2114 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2115 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2116 | return IRQ_HANDLED; |
| 2117 | } |
| 2118 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2119 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 2120 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2121 | struct ixgbe_q_vector *q_vector = data; |
| 2122 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2123 | struct ixgbe_ring *ring; |
| 2124 | int r_idx; |
| 2125 | int i; |
| 2126 | |
| 2127 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 2128 | return IRQ_HANDLED; |
| 2129 | |
| 2130 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 2131 | for (i = 0; i < q_vector->txr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2132 | ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2133 | ring->total_bytes = 0; |
| 2134 | ring->total_packets = 0; |
| 2135 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2136 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 2140 | for (i = 0; i < q_vector->rxr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2141 | ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2142 | ring->total_bytes = 0; |
| 2143 | ring->total_packets = 0; |
| 2144 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2145 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2148 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2149 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2150 | |
| 2151 | return IRQ_HANDLED; |
| 2152 | } |
| 2153 | |
| 2154 | /** |
| 2155 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 2156 | * @napi: napi struct with our devices info in it |
| 2157 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2158 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2159 | * This function is optimized for cleaning one queue only on a single |
| 2160 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2161 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2162 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 2163 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2164 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2165 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2166 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2167 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2168 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2169 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2170 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2171 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2172 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2173 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2174 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2175 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2176 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 2177 | rx_ring = adapter->rx_ring[r_idx]; |
| 2178 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 2179 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2180 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2181 | /* If all Rx work done, exit the polling mode */ |
| 2182 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2183 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2184 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2185 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2186 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2187 | ixgbe_irq_enable_queues(adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2188 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | return work_done; |
| 2192 | } |
| 2193 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2194 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2195 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2196 | * @napi: napi struct with our devices info in it |
| 2197 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2198 | * |
| 2199 | * This function will clean more than one rx queue associated with a |
| 2200 | * q_vector. |
| 2201 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2202 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2203 | { |
| 2204 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2205 | container_of(napi, struct ixgbe_q_vector, napi); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2206 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2207 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2208 | int work_done = 0, i; |
| 2209 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2210 | bool tx_clean_complete = true; |
| 2211 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2212 | #ifdef CONFIG_IXGBE_DCA |
| 2213 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2214 | ixgbe_update_dca(q_vector); |
| 2215 | #endif |
| 2216 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2217 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 2218 | for (i = 0; i < q_vector->txr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2219 | ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2220 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 2221 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2222 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2223 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2224 | |
| 2225 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2226 | * the budget to go below 1 because we'll exit polling */ |
| 2227 | budget /= (q_vector->rxr_count ?: 1); |
| 2228 | budget = max(budget, 1); |
| 2229 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 2230 | for (i = 0; i < q_vector->rxr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2231 | ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2232 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2233 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2234 | r_idx + 1); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2238 | ring = adapter->rx_ring[r_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2239 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2240 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2241 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2242 | if (adapter->rx_itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2243 | ixgbe_set_itr_msix(q_vector); |
| 2244 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2245 | ixgbe_irq_enable_queues(adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2246 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2247 | return 0; |
| 2248 | } |
| 2249 | |
| 2250 | return work_done; |
| 2251 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2252 | |
| 2253 | /** |
| 2254 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 2255 | * @napi: napi struct with our devices info in it |
| 2256 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2257 | * |
| 2258 | * This function is optimized for cleaning one queue only on a single |
| 2259 | * q_vector!!! |
| 2260 | **/ |
| 2261 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 2262 | { |
| 2263 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2264 | container_of(napi, struct ixgbe_q_vector, napi); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2265 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2266 | struct ixgbe_ring *tx_ring = NULL; |
| 2267 | int work_done = 0; |
| 2268 | long r_idx; |
| 2269 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2270 | #ifdef CONFIG_IXGBE_DCA |
| 2271 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2272 | ixgbe_update_dca(q_vector); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2273 | #endif |
| 2274 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2275 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 2276 | tx_ring = adapter->tx_ring[r_idx]; |
| 2277 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2278 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 2279 | work_done = budget; |
| 2280 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2281 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2282 | if (work_done < budget) { |
| 2283 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2284 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2285 | ixgbe_set_itr_msix(q_vector); |
| 2286 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2287 | ixgbe_irq_enable_queues(adapter, |
| 2288 | ((u64)1 << q_vector->v_idx)); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | return work_done; |
| 2292 | } |
| 2293 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2294 | static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2295 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2296 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2297 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2298 | struct ixgbe_ring *rx_ring = a->rx_ring[r_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2299 | |
| 2300 | set_bit(r_idx, q_vector->rxr_idx); |
| 2301 | q_vector->rxr_count++; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2302 | rx_ring->q_vector = q_vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2303 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2304 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2305 | static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2306 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2307 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2308 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2309 | struct ixgbe_ring *tx_ring = a->tx_ring[t_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2310 | |
| 2311 | set_bit(t_idx, q_vector->txr_idx); |
| 2312 | q_vector->txr_count++; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2313 | tx_ring->q_vector = q_vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2314 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2315 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2316 | /** |
| 2317 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 2318 | * @adapter: board private structure to initialize |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2319 | * |
| 2320 | * This function maps descriptor rings to the queue-specific vectors |
| 2321 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 2322 | * one vector per ring/queue, but on a constrained vector budget, we |
| 2323 | * group the rings as "efficiently" as possible. You would add new |
| 2324 | * mapping configurations in here. |
| 2325 | **/ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2326 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2327 | { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2328 | int q_vectors; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2329 | int v_start = 0; |
| 2330 | int rxr_idx = 0, txr_idx = 0; |
| 2331 | int rxr_remaining = adapter->num_rx_queues; |
| 2332 | int txr_remaining = adapter->num_tx_queues; |
| 2333 | int i, j; |
| 2334 | int rqpv, tqpv; |
| 2335 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2336 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2337 | /* No mapping required if MSI-X is disabled. */ |
| 2338 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2339 | goto out; |
| 2340 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2341 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2342 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2343 | /* |
| 2344 | * The ideal configuration... |
| 2345 | * We have enough vectors to map one per queue. |
| 2346 | */ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2347 | if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2348 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 2349 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 2350 | |
| 2351 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 2352 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 2353 | |
| 2354 | goto out; |
| 2355 | } |
| 2356 | |
| 2357 | /* |
| 2358 | * If we don't have enough vectors for a 1-to-1 |
| 2359 | * mapping, we'll have to group them so there are |
| 2360 | * multiple queues per vector. |
| 2361 | */ |
| 2362 | /* Re-adjusting *qpv takes care of the remainder. */ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2363 | for (i = v_start; i < q_vectors; i++) { |
| 2364 | rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2365 | for (j = 0; j < rqpv; j++) { |
| 2366 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 2367 | rxr_idx++; |
| 2368 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2369 | } |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2370 | tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2371 | for (j = 0; j < tqpv; j++) { |
| 2372 | map_vector_to_txq(adapter, i, txr_idx); |
| 2373 | txr_idx++; |
| 2374 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2375 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2376 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2377 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2378 | return err; |
| 2379 | } |
| 2380 | |
| 2381 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2382 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2383 | * @adapter: board private structure |
| 2384 | * |
| 2385 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2386 | * interrupts from the kernel. |
| 2387 | **/ |
| 2388 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2389 | { |
| 2390 | struct net_device *netdev = adapter->netdev; |
| 2391 | irqreturn_t (*handler)(int, void *); |
| 2392 | int i, vector, q_vectors, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2393 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2394 | |
| 2395 | /* Decrement for Other and TCP Timer vectors */ |
| 2396 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2397 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2398 | err = ixgbe_map_rings_to_vectors(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2399 | if (err) |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2400 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2401 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2402 | #define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \ |
| 2403 | ? &ixgbe_msix_clean_many : \ |
| 2404 | (_v)->rxr_count ? &ixgbe_msix_clean_rx : \ |
| 2405 | (_v)->txr_count ? &ixgbe_msix_clean_tx : \ |
| 2406 | NULL) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2407 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2408 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 2409 | handler = SET_HANDLER(q_vector); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2410 | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2411 | if (handler == &ixgbe_msix_clean_rx) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2412 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2413 | "%s-%s-%d", netdev->name, "rx", ri++); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2414 | } else if (handler == &ixgbe_msix_clean_tx) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2415 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2416 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2417 | } else if (handler == &ixgbe_msix_clean_many) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2418 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2419 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2420 | ti++; |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2421 | } else { |
| 2422 | /* skip this unused q_vector */ |
| 2423 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2424 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2425 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2426 | handler, 0, q_vector->name, |
| 2427 | q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2428 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2429 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2430 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2431 | goto free_queue_irqs; |
| 2432 | } |
| 2433 | } |
| 2434 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2435 | sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2436 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2437 | ixgbe_msix_lsc, 0, adapter->lsc_int_name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2438 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2439 | e_err(probe, "request_irq for msix_lsc failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2440 | goto free_queue_irqs; |
| 2441 | } |
| 2442 | |
| 2443 | return 0; |
| 2444 | |
| 2445 | free_queue_irqs: |
| 2446 | for (i = vector - 1; i >= 0; i--) |
| 2447 | free_irq(adapter->msix_entries[--vector].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2448 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2449 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2450 | pci_disable_msix(adapter->pdev); |
| 2451 | kfree(adapter->msix_entries); |
| 2452 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2453 | return err; |
| 2454 | } |
| 2455 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2456 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 2457 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2458 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2459 | struct ixgbe_ring *rx_ring = adapter->rx_ring[0]; |
| 2460 | struct ixgbe_ring *tx_ring = adapter->tx_ring[0]; |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 2461 | u32 new_itr = q_vector->eitr; |
| 2462 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2463 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2464 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2465 | q_vector->tx_itr, |
| 2466 | tx_ring->total_packets, |
| 2467 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2468 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2469 | q_vector->rx_itr, |
| 2470 | rx_ring->total_packets, |
| 2471 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2472 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2473 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2474 | |
| 2475 | switch (current_itr) { |
| 2476 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2477 | case lowest_latency: |
| 2478 | new_itr = 100000; |
| 2479 | break; |
| 2480 | case low_latency: |
| 2481 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2482 | break; |
| 2483 | case bulk_latency: |
| 2484 | new_itr = 8000; |
| 2485 | break; |
| 2486 | default: |
| 2487 | break; |
| 2488 | } |
| 2489 | |
| 2490 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2491 | /* do an exponential smoothing */ |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 2492 | new_itr = ((q_vector->eitr * 9) + new_itr)/10; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2493 | |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 2494 | /* save the algorithm value here */ |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2495 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2496 | |
| 2497 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2498 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2499 | } |
| 2500 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2501 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2502 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2503 | * @adapter: board private structure |
| 2504 | **/ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2505 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2506 | bool flush) |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2507 | { |
| 2508 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2509 | |
| 2510 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2511 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
| 2512 | mask |= IXGBE_EIMS_GPI_SDP0; |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 2513 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2514 | mask |= IXGBE_EIMS_GPI_SDP1; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2515 | switch (adapter->hw.mac.type) { |
| 2516 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2517 | case ixgbe_mac_X540: |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2518 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2519 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2520 | mask |= IXGBE_EIMS_GPI_SDP2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2521 | if (adapter->num_vfs) |
| 2522 | mask |= IXGBE_EIMS_MAILBOX; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2523 | break; |
| 2524 | default: |
| 2525 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2526 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2527 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 2528 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 2529 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2530 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2531 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2532 | if (queues) |
| 2533 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2534 | if (flush) |
| 2535 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2536 | |
| 2537 | if (adapter->num_vfs > 32) { |
| 2538 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 2539 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2540 | } |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2541 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2542 | |
| 2543 | /** |
| 2544 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2545 | * @irq: interrupt number |
| 2546 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2547 | **/ |
| 2548 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2549 | { |
| 2550 | struct net_device *netdev = data; |
| 2551 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2552 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2553 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2554 | u32 eicr; |
| 2555 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2556 | /* |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2557 | * Workaround for silicon errata on 82598. Mask the interrupts |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2558 | * before the read of EICR. |
| 2559 | */ |
| 2560 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2561 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2562 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 2563 | * therefore no explict interrupt disable is necessary */ |
| 2564 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2565 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2566 | /* |
| 2567 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2568 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2569 | * have disabled interrupts due to EIAM |
| 2570 | * finish the workaround of silicon errata on 82598. Unmask |
| 2571 | * the interrupt that we masked before the EICR read. |
| 2572 | */ |
| 2573 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2574 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2575 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2576 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2577 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2578 | if (eicr & IXGBE_EICR_LSC) |
| 2579 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2580 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2581 | switch (hw->mac.type) { |
| 2582 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2583 | ixgbe_check_sfp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2584 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2585 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2586 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2587 | adapter->interrupt_event = eicr; |
| 2588 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2589 | ixgbe_service_event_schedule(adapter); |
| 2590 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2591 | } |
| 2592 | break; |
| 2593 | default: |
| 2594 | break; |
| 2595 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2596 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2597 | ixgbe_check_fan_failure(adapter, eicr); |
| 2598 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2599 | if (napi_schedule_prep(&(q_vector->napi))) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2600 | adapter->tx_ring[0]->total_packets = 0; |
| 2601 | adapter->tx_ring[0]->total_bytes = 0; |
| 2602 | adapter->rx_ring[0]->total_packets = 0; |
| 2603 | adapter->rx_ring[0]->total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2604 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2605 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2608 | /* |
| 2609 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2610 | * ixgbe_poll will re-enable the queue interrupts |
| 2611 | */ |
| 2612 | |
| 2613 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2614 | ixgbe_irq_enable(adapter, false, false); |
| 2615 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2616 | return IRQ_HANDLED; |
| 2617 | } |
| 2618 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2619 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 2620 | { |
| 2621 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2622 | |
| 2623 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2624 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2625 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 2626 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 2627 | q_vector->rxr_count = 0; |
| 2628 | q_vector->txr_count = 0; |
| 2629 | } |
| 2630 | } |
| 2631 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2632 | /** |
| 2633 | * ixgbe_request_irq - initialize interrupts |
| 2634 | * @adapter: board private structure |
| 2635 | * |
| 2636 | * Attempts to configure interrupts using the best available |
| 2637 | * capabilities of the hardware and kernel. |
| 2638 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2639 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2640 | { |
| 2641 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2642 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2643 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2644 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2645 | err = ixgbe_request_msix_irqs(adapter); |
| 2646 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2647 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2648 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2649 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2650 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2651 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2654 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2655 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2656 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2657 | return err; |
| 2658 | } |
| 2659 | |
| 2660 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2661 | { |
| 2662 | struct net_device *netdev = adapter->netdev; |
| 2663 | |
| 2664 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2665 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2666 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2667 | q_vectors = adapter->num_msix_vectors; |
| 2668 | |
| 2669 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2670 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2671 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2672 | i--; |
| 2673 | for (; i >= 0; i--) { |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2674 | /* free only the irqs that were actually requested */ |
| 2675 | if (!adapter->q_vector[i]->rxr_count && |
| 2676 | !adapter->q_vector[i]->txr_count) |
| 2677 | continue; |
| 2678 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2679 | free_irq(adapter->msix_entries[i].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2680 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | ixgbe_reset_q_vectors(adapter); |
| 2684 | } else { |
| 2685 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2686 | } |
| 2687 | } |
| 2688 | |
| 2689 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2690 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2691 | * @adapter: board private structure |
| 2692 | **/ |
| 2693 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2694 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2695 | switch (adapter->hw.mac.type) { |
| 2696 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2697 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2698 | break; |
| 2699 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2700 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2701 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2702 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2703 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2704 | if (adapter->num_vfs > 32) |
| 2705 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2706 | break; |
| 2707 | default: |
| 2708 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2709 | } |
| 2710 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2711 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2712 | int i; |
| 2713 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 2714 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2715 | } else { |
| 2716 | synchronize_irq(adapter->pdev->irq); |
| 2717 | } |
| 2718 | } |
| 2719 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2720 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2721 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2722 | * |
| 2723 | **/ |
| 2724 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2725 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2726 | struct ixgbe_hw *hw = &adapter->hw; |
| 2727 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2728 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2729 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2730 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2731 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2732 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2733 | |
| 2734 | map_vector_to_rxq(adapter, 0, 0); |
| 2735 | map_vector_to_txq(adapter, 0, 0); |
| 2736 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2737 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2740 | /** |
| 2741 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2742 | * @adapter: board private structure |
| 2743 | * @ring: structure containing ring specific data |
| 2744 | * |
| 2745 | * Configure the Tx descriptor ring after a reset. |
| 2746 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2747 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2748 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2749 | { |
| 2750 | struct ixgbe_hw *hw = &adapter->hw; |
| 2751 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2752 | int wait_loop = 10; |
| 2753 | u32 txdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2754 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2755 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2756 | /* disable queue to avoid issues while updating state */ |
| 2757 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2758 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), |
| 2759 | txdctl & ~IXGBE_TXDCTL_ENABLE); |
| 2760 | IXGBE_WRITE_FLUSH(hw); |
| 2761 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2762 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2763 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2764 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2765 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2766 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2767 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2768 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2769 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2770 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2771 | /* configure fetching thresholds */ |
| 2772 | if (adapter->rx_itr_setting == 0) { |
| 2773 | /* cannot set wthresh when itr==0 */ |
| 2774 | txdctl &= ~0x007F0000; |
| 2775 | } else { |
| 2776 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2777 | txdctl |= (8 << 16); |
| 2778 | } |
| 2779 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2780 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2781 | txdctl |= 32; |
| 2782 | } |
| 2783 | |
| 2784 | /* reinitialize flowdirector state */ |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2785 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2786 | adapter->atr_sample_rate) { |
| 2787 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2788 | ring->atr_count = 0; |
| 2789 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2790 | } else { |
| 2791 | ring->atr_sample_rate = 0; |
| 2792 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2793 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2794 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2795 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2796 | /* enable queue */ |
| 2797 | txdctl |= IXGBE_TXDCTL_ENABLE; |
| 2798 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2799 | |
| 2800 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2801 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2802 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2803 | return; |
| 2804 | |
| 2805 | /* poll to verify queue is enabled */ |
| 2806 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2807 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2808 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2809 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2810 | if (!wait_loop) |
| 2811 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2814 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2815 | { |
| 2816 | struct ixgbe_hw *hw = &adapter->hw; |
| 2817 | u32 rttdcs; |
| 2818 | u32 mask; |
| 2819 | |
| 2820 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2821 | return; |
| 2822 | |
| 2823 | /* disable the arbiter while setting MTQC */ |
| 2824 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2825 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2826 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2827 | |
| 2828 | /* set transmit pool layout */ |
| 2829 | mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED); |
| 2830 | switch (adapter->flags & mask) { |
| 2831 | |
| 2832 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2833 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2834 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2835 | break; |
| 2836 | |
| 2837 | case (IXGBE_FLAG_DCB_ENABLED): |
| 2838 | /* We enable 8 traffic classes, DCB only */ |
| 2839 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2840 | (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ)); |
| 2841 | break; |
| 2842 | |
| 2843 | default: |
| 2844 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB); |
| 2845 | break; |
| 2846 | } |
| 2847 | |
| 2848 | /* re-enable the arbiter */ |
| 2849 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2850 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2851 | } |
| 2852 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2853 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2854 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2855 | * @adapter: board private structure |
| 2856 | * |
| 2857 | * Configure the Tx unit of the MAC after a reset. |
| 2858 | **/ |
| 2859 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2860 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2861 | struct ixgbe_hw *hw = &adapter->hw; |
| 2862 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2863 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2864 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2865 | ixgbe_setup_mtqc(adapter); |
| 2866 | |
| 2867 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2868 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2869 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2870 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2871 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2872 | } |
| 2873 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2874 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2875 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2876 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2879 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2880 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2881 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2882 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2883 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2884 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2885 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2886 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2887 | switch (adapter->hw.mac.type) { |
| 2888 | case ixgbe_mac_82598EB: { |
| 2889 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
| 2890 | const int mask = feature[RING_F_RSS].mask; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2891 | reg_idx = reg_idx & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2892 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2893 | break; |
| 2894 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2895 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2896 | default: |
| 2897 | break; |
| 2898 | } |
| 2899 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2900 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2901 | |
| 2902 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2903 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2904 | if (adapter->num_vfs) |
| 2905 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2906 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2907 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2908 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2909 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2910 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2911 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2912 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2913 | #else |
| 2914 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2915 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2916 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2917 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2918 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2919 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2920 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2921 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2922 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2923 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2926 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2927 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2928 | struct ixgbe_hw *hw = &adapter->hw; |
| 2929 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2930 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2931 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2932 | u32 mrqc = 0, reta = 0; |
| 2933 | u32 rxcsum; |
| 2934 | int i, j; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2935 | int mask; |
| 2936 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2937 | /* Fill out hash function seeds */ |
| 2938 | for (i = 0; i < 10; i++) |
| 2939 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2940 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2941 | /* Fill out redirection table */ |
| 2942 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2943 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2944 | j = 0; |
| 2945 | /* reta = 4-byte sliding window of |
| 2946 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2947 | reta = (reta << 8) | (j * 0x11); |
| 2948 | if ((i & 3) == 3) |
| 2949 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 2950 | } |
| 2951 | |
| 2952 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 2953 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2954 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2955 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 2956 | |
| 2957 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 2958 | mask = adapter->flags & IXGBE_FLAG_RSS_ENABLED; |
| 2959 | else |
| 2960 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2961 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2962 | | IXGBE_FLAG_DCB_ENABLED |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2963 | #endif |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2964 | | IXGBE_FLAG_SRIOV_ENABLED |
| 2965 | ); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2966 | |
| 2967 | switch (mask) { |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 2968 | #ifdef CONFIG_IXGBE_DCB |
| 2969 | case (IXGBE_FLAG_DCB_ENABLED | IXGBE_FLAG_RSS_ENABLED): |
| 2970 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 2971 | break; |
| 2972 | case (IXGBE_FLAG_DCB_ENABLED): |
| 2973 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 2974 | break; |
| 2975 | #endif /* CONFIG_IXGBE_DCB */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2976 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2977 | mrqc = IXGBE_MRQC_RSSEN; |
| 2978 | break; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2979 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2980 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2981 | break; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2982 | default: |
| 2983 | break; |
| 2984 | } |
| 2985 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2986 | /* Perform hash on these packet types */ |
| 2987 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2988 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2989 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2990 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2991 | |
| 2992 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2995 | /** |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2996 | * ixgbe_clear_rscctl - disable RSC for the indicated ring |
| 2997 | * @adapter: address of board private structure |
| 2998 | * @ring: structure containing ring specific data |
| 2999 | **/ |
| 3000 | void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter, |
| 3001 | struct ixgbe_ring *ring) |
| 3002 | { |
| 3003 | struct ixgbe_hw *hw = &adapter->hw; |
| 3004 | u32 rscctrl; |
| 3005 | u8 reg_idx = ring->reg_idx; |
| 3006 | |
| 3007 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
| 3008 | rscctrl &= ~IXGBE_RSCCTL_RSCEN; |
| 3009 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
| 3010 | } |
| 3011 | |
| 3012 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3013 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3014 | * @adapter: address of board private structure |
| 3015 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3016 | **/ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3017 | void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3018 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3019 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3020 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3021 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 3022 | int rx_buf_len; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3023 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3024 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3025 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3026 | return; |
| 3027 | |
| 3028 | rx_buf_len = ring->rx_buf_len; |
| 3029 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3030 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3031 | /* |
| 3032 | * we must limit the number of descriptors so that the |
| 3033 | * total size of max desc * buf_len is not greater |
| 3034 | * than 65535 |
| 3035 | */ |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3036 | if (ring_is_ps_enabled(ring)) { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3037 | #if (MAX_SKB_FRAGS > 16) |
| 3038 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 3039 | #elif (MAX_SKB_FRAGS > 8) |
| 3040 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 3041 | #elif (MAX_SKB_FRAGS > 4) |
| 3042 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 3043 | #else |
| 3044 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 3045 | #endif |
| 3046 | } else { |
| 3047 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 3048 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 3049 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 3050 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 3051 | else |
| 3052 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 3053 | } |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3054 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3055 | } |
| 3056 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3057 | /** |
| 3058 | * ixgbe_set_uta - Set unicast filter table address |
| 3059 | * @adapter: board private structure |
| 3060 | * |
| 3061 | * The unicast table address is a register array of 32-bit registers. |
| 3062 | * The table is meant to be used in a way similar to how the MTA is used |
| 3063 | * however due to certain limitations in the hardware it is necessary to |
| 3064 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 3065 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
| 3066 | **/ |
| 3067 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) |
| 3068 | { |
| 3069 | struct ixgbe_hw *hw = &adapter->hw; |
| 3070 | int i; |
| 3071 | |
| 3072 | /* The UTA table only exists on 82599 hardware and newer */ |
| 3073 | if (hw->mac.type < ixgbe_mac_82599EB) |
| 3074 | return; |
| 3075 | |
| 3076 | /* we only need to do this if VMDq is enabled */ |
| 3077 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3078 | return; |
| 3079 | |
| 3080 | for (i = 0; i < 128; i++) |
| 3081 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); |
| 3082 | } |
| 3083 | |
| 3084 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3085 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3086 | struct ixgbe_ring *ring) |
| 3087 | { |
| 3088 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3089 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3090 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3091 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3092 | |
| 3093 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3094 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3095 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3096 | return; |
| 3097 | |
| 3098 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3099 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3100 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3101 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3102 | |
| 3103 | if (!wait_loop) { |
| 3104 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3105 | "the polling period\n", reg_idx); |
| 3106 | } |
| 3107 | } |
| 3108 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3109 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3110 | struct ixgbe_ring *ring) |
| 3111 | { |
| 3112 | struct ixgbe_hw *hw = &adapter->hw; |
| 3113 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3114 | u32 rxdctl; |
| 3115 | u8 reg_idx = ring->reg_idx; |
| 3116 | |
| 3117 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3118 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3119 | |
| 3120 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3121 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3122 | |
| 3123 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3124 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3125 | return; |
| 3126 | |
| 3127 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3128 | do { |
| 3129 | udelay(10); |
| 3130 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3131 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3132 | |
| 3133 | if (!wait_loop) { |
| 3134 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3135 | "the polling period\n", reg_idx); |
| 3136 | } |
| 3137 | } |
| 3138 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3139 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3140 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3141 | { |
| 3142 | struct ixgbe_hw *hw = &adapter->hw; |
| 3143 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3144 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3145 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3146 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3147 | /* disable queue to avoid issues while updating state */ |
| 3148 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3149 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3150 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3151 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3152 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3153 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3154 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 3155 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3156 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3157 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3158 | |
| 3159 | ixgbe_configure_srrctl(adapter, ring); |
| 3160 | ixgbe_configure_rscctl(adapter, ring); |
| 3161 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 3162 | /* If operating in IOV mode set RLPML for X540 */ |
| 3163 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 3164 | hw->mac.type == ixgbe_mac_X540) { |
| 3165 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 3166 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 3167 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 3168 | } |
| 3169 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3170 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3171 | /* |
| 3172 | * enable cache line friendly hardware writes: |
| 3173 | * PTHRESH=32 descriptors (half the internal cache), |
| 3174 | * this also removes ugly rx_no_buffer_count increment |
| 3175 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3176 | * WTHRESH=8 burst writeback up to two cache lines |
| 3177 | */ |
| 3178 | rxdctl &= ~0x3FFFFF; |
| 3179 | rxdctl |= 0x080420; |
| 3180 | } |
| 3181 | |
| 3182 | /* enable receive descriptor ring */ |
| 3183 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3184 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3185 | |
| 3186 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 3187 | ixgbe_alloc_rx_buffers(ring, IXGBE_DESC_UNUSED(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3188 | } |
| 3189 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3190 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3191 | { |
| 3192 | struct ixgbe_hw *hw = &adapter->hw; |
| 3193 | int p; |
| 3194 | |
| 3195 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3196 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3197 | IXGBE_PSRTYPE_UDPHDR | |
| 3198 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3199 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3200 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3201 | |
| 3202 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3203 | return; |
| 3204 | |
| 3205 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) |
| 3206 | psrtype |= (adapter->num_rx_queues_per_pool << 29); |
| 3207 | |
| 3208 | for (p = 0; p < adapter->num_rx_pools; p++) |
| 3209 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), |
| 3210 | psrtype); |
| 3211 | } |
| 3212 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3213 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3214 | { |
| 3215 | struct ixgbe_hw *hw = &adapter->hw; |
| 3216 | u32 gcr_ext; |
| 3217 | u32 vt_reg_bits; |
| 3218 | u32 reg_offset, vf_shift; |
| 3219 | u32 vmdctl; |
| 3220 | |
| 3221 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3222 | return; |
| 3223 | |
| 3224 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 3225 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; |
| 3226 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); |
| 3227 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 3228 | |
| 3229 | vf_shift = adapter->num_vfs % 32; |
| 3230 | reg_offset = (adapter->num_vfs > 32) ? 1 : 0; |
| 3231 | |
| 3232 | /* Enable only the PF's pool for Tx/Rx */ |
| 3233 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 3234 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); |
| 3235 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 3236 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); |
| 3237 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 3238 | |
| 3239 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
| 3240 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 3241 | |
| 3242 | /* |
| 3243 | * Set up VF register offsets for selected VT Mode, |
| 3244 | * i.e. 32 or 64 VFs for SR-IOV |
| 3245 | */ |
| 3246 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3247 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; |
| 3248 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; |
| 3249 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3250 | |
| 3251 | /* enable Tx loopback for VF/PF communication */ |
| 3252 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3253 | /* Enable MAC Anti-Spoofing */ |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3254 | hw->mac.ops.set_mac_anti_spoofing(hw, |
| 3255 | (adapter->antispoofing_enabled = |
| 3256 | (adapter->num_vfs != 0)), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3257 | adapter->num_vfs); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3260 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3261 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3262 | struct ixgbe_hw *hw = &adapter->hw; |
| 3263 | struct net_device *netdev = adapter->netdev; |
| 3264 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3265 | int rx_buf_len; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3266 | struct ixgbe_ring *rx_ring; |
| 3267 | int i; |
| 3268 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3269 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3270 | /* Decide whether to use packet split mode or not */ |
Don Skidmore | a124339 | 2011-01-18 22:53:47 +0000 | [diff] [blame] | 3271 | /* On by default */ |
| 3272 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
| 3273 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3274 | /* Do not use packet split if we're in SR-IOV Mode */ |
Don Skidmore | a124339 | 2011-01-18 22:53:47 +0000 | [diff] [blame] | 3275 | if (adapter->num_vfs) |
| 3276 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
| 3277 | |
| 3278 | /* Disable packet split due to 82599 erratum #45 */ |
| 3279 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3280 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3281 | |
| 3282 | /* Set the RX buffer length according to the mode */ |
| 3283 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3284 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3285 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3286 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3287 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3288 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3289 | else |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3290 | rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024); |
| 3291 | } |
| 3292 | |
| 3293 | #ifdef IXGBE_FCOE |
| 3294 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3295 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3296 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3297 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3298 | |
| 3299 | #endif /* IXGBE_FCOE */ |
| 3300 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3301 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3302 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3303 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3304 | |
| 3305 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3308 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3309 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3310 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3311 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3312 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3313 | /* |
| 3314 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3315 | * the Base and Length of the Rx Descriptor Ring |
| 3316 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3317 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3318 | rx_ring = adapter->rx_ring[i]; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3319 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3320 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3321 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3322 | set_ring_ps_enabled(rx_ring); |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 3323 | else |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3324 | clear_ring_ps_enabled(rx_ring); |
| 3325 | |
| 3326 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3327 | set_ring_rsc_enabled(rx_ring); |
| 3328 | else |
| 3329 | clear_ring_rsc_enabled(rx_ring); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3330 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3331 | #ifdef IXGBE_FCOE |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3332 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3333 | struct ixgbe_ring_feature *f; |
| 3334 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3335 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3336 | clear_ring_ps_enabled(rx_ring); |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3337 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 3338 | rx_ring->rx_buf_len = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3339 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3340 | } else if (!ring_is_rsc_enabled(rx_ring) && |
| 3341 | !ring_is_ps_enabled(rx_ring)) { |
| 3342 | rx_ring->rx_buf_len = |
| 3343 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3344 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3345 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3346 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3347 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3348 | } |
| 3349 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3350 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3351 | { |
| 3352 | struct ixgbe_hw *hw = &adapter->hw; |
| 3353 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3354 | |
| 3355 | switch (hw->mac.type) { |
| 3356 | case ixgbe_mac_82598EB: |
| 3357 | /* |
| 3358 | * For VMDq support of different descriptor types or |
| 3359 | * buffer sizes through the use of multiple SRRCTL |
| 3360 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3361 | * |
| 3362 | * also, the manual doesn't mention it clearly but DCA hints |
| 3363 | * will only use queue 0's tags unless this bit is set. Side |
| 3364 | * effects of setting this bit are only that SRRCTL must be |
| 3365 | * fully programmed [0..15] |
| 3366 | */ |
| 3367 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3368 | break; |
| 3369 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3370 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3371 | /* Disable RSC for ACK packets */ |
| 3372 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3373 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3374 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3375 | /* hardware requires some bits to be set by default */ |
| 3376 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3377 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3378 | break; |
| 3379 | default: |
| 3380 | /* We should do nothing since we don't know this hardware */ |
| 3381 | return; |
| 3382 | } |
| 3383 | |
| 3384 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3385 | } |
| 3386 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3387 | /** |
| 3388 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3389 | * @adapter: board private structure |
| 3390 | * |
| 3391 | * Configure the Rx unit of the MAC after a reset. |
| 3392 | **/ |
| 3393 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3394 | { |
| 3395 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3396 | int i; |
| 3397 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3398 | |
| 3399 | /* disable receives while setting up the descriptors */ |
| 3400 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3401 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3402 | |
| 3403 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3404 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3405 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3406 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3407 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3408 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3409 | ixgbe_set_uta(adapter); |
| 3410 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3411 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3412 | ixgbe_set_rx_buffer_len(adapter); |
| 3413 | |
| 3414 | /* |
| 3415 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3416 | * the Base and Length of the Rx Descriptor Ring |
| 3417 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3418 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3419 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3420 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3421 | /* disable drop enable for 82598 parts */ |
| 3422 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3423 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3424 | |
| 3425 | /* enable all receives */ |
| 3426 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3427 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3430 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 3431 | { |
| 3432 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3433 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3434 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3435 | |
| 3436 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3437 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3438 | set_bit(vid, adapter->active_vlans); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 3442 | { |
| 3443 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3444 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3445 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3446 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3447 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3448 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3449 | clear_bit(vid, adapter->active_vlans); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3450 | } |
| 3451 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3452 | /** |
| 3453 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3454 | * @adapter: driver data |
| 3455 | */ |
| 3456 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3457 | { |
| 3458 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3459 | u32 vlnctrl; |
| 3460 | |
| 3461 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3462 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3463 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3464 | } |
| 3465 | |
| 3466 | /** |
| 3467 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3468 | * @adapter: driver data |
| 3469 | */ |
| 3470 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3471 | { |
| 3472 | struct ixgbe_hw *hw = &adapter->hw; |
| 3473 | u32 vlnctrl; |
| 3474 | |
| 3475 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3476 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3477 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3478 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3479 | } |
| 3480 | |
| 3481 | /** |
| 3482 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3483 | * @adapter: driver data |
| 3484 | */ |
| 3485 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3486 | { |
| 3487 | struct ixgbe_hw *hw = &adapter->hw; |
| 3488 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3489 | int i, j; |
| 3490 | |
| 3491 | switch (hw->mac.type) { |
| 3492 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3493 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3494 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3495 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3496 | break; |
| 3497 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3498 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3499 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3500 | j = adapter->rx_ring[i]->reg_idx; |
| 3501 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3502 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3503 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3504 | } |
| 3505 | break; |
| 3506 | default: |
| 3507 | break; |
| 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3512 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3513 | * @adapter: driver data |
| 3514 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3515 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3516 | { |
| 3517 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3518 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3519 | int i, j; |
| 3520 | |
| 3521 | switch (hw->mac.type) { |
| 3522 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3523 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3524 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3525 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3526 | break; |
| 3527 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3528 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3529 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3530 | j = adapter->rx_ring[i]->reg_idx; |
| 3531 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3532 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3533 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3534 | } |
| 3535 | break; |
| 3536 | default: |
| 3537 | break; |
| 3538 | } |
| 3539 | } |
| 3540 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3541 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3542 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3543 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3544 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3545 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3546 | |
| 3547 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3548 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3552 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3553 | * @netdev: network interface device structure |
| 3554 | * |
| 3555 | * Writes unicast address list to the RAR table. |
| 3556 | * Returns: -ENOMEM on failure/insufficient address space |
| 3557 | * 0 on no addresses written |
| 3558 | * X on writing X addresses to the RAR table |
| 3559 | **/ |
| 3560 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3561 | { |
| 3562 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3563 | struct ixgbe_hw *hw = &adapter->hw; |
| 3564 | unsigned int vfn = adapter->num_vfs; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3565 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3566 | int count = 0; |
| 3567 | |
| 3568 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3569 | if (netdev_uc_count(netdev) > rar_entries) |
| 3570 | return -ENOMEM; |
| 3571 | |
| 3572 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3573 | struct netdev_hw_addr *ha; |
| 3574 | /* return error if we do not support writing to RAR table */ |
| 3575 | if (!hw->mac.ops.set_rar) |
| 3576 | return -ENOMEM; |
| 3577 | |
| 3578 | netdev_for_each_uc_addr(ha, netdev) { |
| 3579 | if (!rar_entries) |
| 3580 | break; |
| 3581 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
| 3582 | vfn, IXGBE_RAH_AV); |
| 3583 | count++; |
| 3584 | } |
| 3585 | } |
| 3586 | /* write the addresses in reverse order to avoid write combining */ |
| 3587 | for (; rar_entries > 0 ; rar_entries--) |
| 3588 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3589 | |
| 3590 | return count; |
| 3591 | } |
| 3592 | |
| 3593 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3594 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3595 | * @netdev: network interface device structure |
| 3596 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3597 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3598 | * address list or the network interface flags are updated. This routine is |
| 3599 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3600 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3601 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3602 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3603 | { |
| 3604 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3605 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3606 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3607 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3608 | |
| 3609 | /* Check for Promiscuous and All Multicast modes */ |
| 3610 | |
| 3611 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3612 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3613 | /* set all bits that we expect to always be set */ |
| 3614 | fctrl |= IXGBE_FCTRL_BAM; |
| 3615 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3616 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3617 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3618 | /* clear the bits we are changing the status of */ |
| 3619 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3620 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3621 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3622 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3623 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3624 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3625 | /* don't hardware filter vlans in promisc mode */ |
| 3626 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3627 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3628 | if (netdev->flags & IFF_ALLMULTI) { |
| 3629 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3630 | vmolr |= IXGBE_VMOLR_MPE; |
| 3631 | } else { |
| 3632 | /* |
| 3633 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3634 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3635 | * that we can at least receive multicast traffic |
| 3636 | */ |
| 3637 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3638 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3639 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3640 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3641 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3642 | /* |
| 3643 | * Write addresses to available RAR registers, if there is not |
| 3644 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3645 | * unicast promiscuous mode |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3646 | */ |
| 3647 | count = ixgbe_write_uc_addr_list(netdev); |
| 3648 | if (count < 0) { |
| 3649 | fctrl |= IXGBE_FCTRL_UPE; |
| 3650 | vmolr |= IXGBE_VMOLR_ROPE; |
| 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | if (adapter->num_vfs) { |
| 3655 | ixgbe_restore_vf_multicasts(adapter); |
| 3656 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & |
| 3657 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3658 | IXGBE_VMOLR_ROPE); |
| 3659 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3663 | |
| 3664 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3665 | ixgbe_vlan_strip_enable(adapter); |
| 3666 | else |
| 3667 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3670 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3671 | { |
| 3672 | int q_idx; |
| 3673 | struct ixgbe_q_vector *q_vector; |
| 3674 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3675 | |
| 3676 | /* legacy and MSI only use one vector */ |
| 3677 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3678 | q_vectors = 1; |
| 3679 | |
| 3680 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3681 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3682 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3683 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3684 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3685 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 3686 | if (q_vector->txr_count == 1) |
| 3687 | napi->poll = &ixgbe_clean_txonly; |
| 3688 | else if (q_vector->rxr_count == 1) |
| 3689 | napi->poll = &ixgbe_clean_rxonly; |
| 3690 | } |
| 3691 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3692 | |
| 3693 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3698 | { |
| 3699 | int q_idx; |
| 3700 | struct ixgbe_q_vector *q_vector; |
| 3701 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3702 | |
| 3703 | /* legacy and MSI only use one vector */ |
| 3704 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3705 | q_vectors = 1; |
| 3706 | |
| 3707 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3708 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3709 | napi_disable(&q_vector->napi); |
| 3710 | } |
| 3711 | } |
| 3712 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3713 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3714 | /* |
| 3715 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3716 | * @adapter: ixgbe adapter struct |
| 3717 | * |
| 3718 | * This is called by the driver on open to configure the DCB hardware. |
| 3719 | * This is also called by the gennetlink interface when reconfiguring |
| 3720 | * the DCB state. |
| 3721 | */ |
| 3722 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3723 | { |
| 3724 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3725 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3726 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3727 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3728 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3729 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3730 | return; |
| 3731 | } |
| 3732 | |
| 3733 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3734 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3735 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3736 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3737 | /* Enable VLAN tag insert/strip */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3738 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3739 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3740 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3741 | |
| 3742 | /* reconfigure the hardware */ |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3743 | if (adapter->dcbx_cap & (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE)) { |
| 3744 | #ifdef CONFIG_FCOE |
| 3745 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3746 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3747 | #endif |
| 3748 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3749 | DCB_TX_CONFIG); |
| 3750 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3751 | DCB_RX_CONFIG); |
| 3752 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
| 3753 | } else { |
| 3754 | struct net_device *dev = adapter->netdev; |
| 3755 | |
| 3756 | if (adapter->ixgbe_ieee_ets) |
| 3757 | dev->dcbnl_ops->ieee_setets(dev, |
| 3758 | adapter->ixgbe_ieee_ets); |
| 3759 | if (adapter->ixgbe_ieee_pfc) |
| 3760 | dev->dcbnl_ops->ieee_setpfc(dev, |
| 3761 | adapter->ixgbe_ieee_pfc); |
| 3762 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3763 | |
| 3764 | /* Enable RSS Hash per TC */ |
| 3765 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3766 | int i; |
| 3767 | u32 reg = 0; |
| 3768 | |
| 3769 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 3770 | u8 msb = 0; |
| 3771 | u8 cnt = adapter->netdev->tc_to_txq[i].count; |
| 3772 | |
| 3773 | while (cnt >>= 1) |
| 3774 | msb++; |
| 3775 | |
| 3776 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); |
| 3777 | } |
| 3778 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); |
| 3779 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | #endif |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame^] | 3783 | |
| 3784 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3785 | { |
| 3786 | int hdrm = 0; |
| 3787 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3788 | struct ixgbe_hw *hw = &adapter->hw; |
| 3789 | |
| 3790 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3791 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3792 | hdrm = 64 << adapter->fdir_pballoc; |
| 3793 | |
| 3794 | hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL); |
| 3795 | } |
| 3796 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3797 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3798 | { |
| 3799 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3800 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3801 | int i; |
| 3802 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame^] | 3803 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3804 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3805 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3806 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3807 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3808 | ixgbe_set_rx_mode(netdev); |
| 3809 | ixgbe_restore_vlan(adapter); |
| 3810 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3811 | #ifdef IXGBE_FCOE |
| 3812 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 3813 | ixgbe_configure_fcoe(adapter); |
| 3814 | |
| 3815 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3816 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 3817 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3818 | adapter->tx_ring[i]->atr_sample_rate = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3819 | adapter->atr_sample_rate; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3820 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 3821 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3822 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 3823 | } |
Alexander Duyck | 933d41f | 2010-09-07 21:34:29 +0000 | [diff] [blame] | 3824 | ixgbe_configure_virtualization(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3825 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3826 | ixgbe_configure_tx(adapter); |
| 3827 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3830 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3831 | { |
| 3832 | switch (hw->phy.type) { |
| 3833 | case ixgbe_phy_sfp_avago: |
| 3834 | case ixgbe_phy_sfp_ftl: |
| 3835 | case ixgbe_phy_sfp_intel: |
| 3836 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3837 | case ixgbe_phy_sfp_passive_tyco: |
| 3838 | case ixgbe_phy_sfp_passive_unknown: |
| 3839 | case ixgbe_phy_sfp_active_unknown: |
| 3840 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3841 | return true; |
| 3842 | default: |
| 3843 | return false; |
| 3844 | } |
| 3845 | } |
| 3846 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3847 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3848 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3849 | * @adapter: pointer to private adapter struct |
| 3850 | **/ |
| 3851 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3852 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3853 | /* |
| 3854 | * We are assuming the worst case scenerio here, and that |
| 3855 | * is that an SFP was inserted/removed after the reset |
| 3856 | * but before SFP detection was enabled. As such the best |
| 3857 | * solution is to just start searching as soon as we start |
| 3858 | */ |
| 3859 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3860 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3861 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3862 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | /** |
| 3866 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3867 | * @hw: pointer to private hardware struct |
| 3868 | * |
| 3869 | * Returns 0 on success, negative on failure |
| 3870 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3871 | 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] | 3872 | { |
| 3873 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3874 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3875 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 3876 | |
| 3877 | if (hw->mac.ops.check_link) |
| 3878 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 3879 | |
| 3880 | if (ret) |
| 3881 | goto link_cfg_out; |
| 3882 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 3883 | autoneg = hw->phy.autoneg_advertised; |
| 3884 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3885 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3886 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3887 | if (ret) |
| 3888 | goto link_cfg_out; |
| 3889 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3890 | if (hw->mac.ops.setup_link) |
| 3891 | 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] | 3892 | link_cfg_out: |
| 3893 | return ret; |
| 3894 | } |
| 3895 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3896 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3897 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3898 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3899 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3900 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3901 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3902 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 3903 | IXGBE_GPIE_OCD; |
| 3904 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3905 | /* |
| 3906 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 3907 | * this saves a register write for every interrupt |
| 3908 | */ |
| 3909 | switch (hw->mac.type) { |
| 3910 | case ixgbe_mac_82598EB: |
| 3911 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 3912 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3913 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3914 | case ixgbe_mac_X540: |
| 3915 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3916 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 3917 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 3918 | break; |
| 3919 | } |
| 3920 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3921 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 3922 | * specifically only auto mask tx and rx interrupts */ |
| 3923 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3924 | } |
| 3925 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3926 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 3927 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 3928 | |
| 3929 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3930 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 3931 | gpie |= IXGBE_GPIE_VTMODE_64; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 3932 | } |
| 3933 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3934 | /* Enable fan failure interrupt */ |
| 3935 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3936 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3937 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3938 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3939 | gpie |= IXGBE_SDP1_GPIEN; |
| 3940 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3941 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3942 | |
| 3943 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 3944 | } |
| 3945 | |
| 3946 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 3947 | { |
| 3948 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3949 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3950 | u32 ctrl_ext; |
| 3951 | |
| 3952 | ixgbe_get_hw_control(adapter); |
| 3953 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3954 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3955 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3956 | ixgbe_configure_msix(adapter); |
| 3957 | else |
| 3958 | ixgbe_configure_msi_and_legacy(adapter); |
| 3959 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3960 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ |
| 3961 | if (hw->mac.ops.enable_tx_laser && |
| 3962 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 3963 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3964 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 3965 | hw->mac.ops.enable_tx_laser(hw); |
| 3966 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3967 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3968 | ixgbe_napi_enable_all(adapter); |
| 3969 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 3970 | if (ixgbe_is_sfp(hw)) { |
| 3971 | ixgbe_sfp_link_config(adapter); |
| 3972 | } else { |
| 3973 | err = ixgbe_non_sfp_link_config(hw); |
| 3974 | if (err) |
| 3975 | e_err(probe, "link_config FAILED %d\n", err); |
| 3976 | } |
| 3977 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3978 | /* clear any pending interrupts, may auto mask */ |
| 3979 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3980 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3981 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3982 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3983 | * If this adapter has a fan, check to see if we had a failure |
| 3984 | * before we enabled the interrupt. |
| 3985 | */ |
| 3986 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 3987 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 3988 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3989 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3992 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3993 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3994 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3995 | /* bring the link up in the watchdog, this could race with our first |
| 3996 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3997 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3998 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3999 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 4000 | |
| 4001 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 4002 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 4003 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 4004 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
| 4005 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4006 | return 0; |
| 4007 | } |
| 4008 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4009 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 4010 | { |
| 4011 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4012 | /* put off any impending NetWatchDogTimeout */ |
| 4013 | adapter->netdev->trans_start = jiffies; |
| 4014 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4015 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4016 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4017 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 4018 | /* |
| 4019 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 4020 | * back up to give the VFs time to respond to the reset. The |
| 4021 | * two second wait is based upon the watchdog timer cycle in |
| 4022 | * the VF driver. |
| 4023 | */ |
| 4024 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4025 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4026 | ixgbe_up(adapter); |
| 4027 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 4028 | } |
| 4029 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4030 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 4031 | { |
| 4032 | /* hardware has been reset, we need to reload some things */ |
| 4033 | ixgbe_configure(adapter); |
| 4034 | |
| 4035 | return ixgbe_up_complete(adapter); |
| 4036 | } |
| 4037 | |
| 4038 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 4039 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4040 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4041 | int err; |
| 4042 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4043 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 4044 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 4045 | usleep_range(1000, 2000); |
| 4046 | |
| 4047 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 4048 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 4049 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 4050 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 4051 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4052 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4053 | switch (err) { |
| 4054 | case 0: |
| 4055 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4056 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4057 | break; |
| 4058 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4059 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4060 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4061 | case IXGBE_ERR_EEPROM_VERSION: |
| 4062 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4063 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 4064 | "Please be aware there may be issuesassociated with " |
| 4065 | "your hardware. If you are experiencing problems " |
| 4066 | "please contact your Intel or hardware " |
| 4067 | "representative who provided you with this " |
| 4068 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4069 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4070 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4071 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4072 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4073 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4074 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 4075 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4076 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4077 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 4078 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4081 | /** |
| 4082 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4083 | * @rx_ring: ring to free buffers from |
| 4084 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4085 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4086 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4087 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4088 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4089 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4090 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4091 | /* ring already cleared, nothing to do */ |
| 4092 | if (!rx_ring->rx_buffer_info) |
| 4093 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4094 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4095 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4096 | for (i = 0; i < rx_ring->count; i++) { |
| 4097 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 4098 | |
| 4099 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 4100 | if (rx_buffer_info->dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4101 | dma_unmap_single(rx_ring->dev, rx_buffer_info->dma, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4102 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 4103 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4104 | rx_buffer_info->dma = 0; |
| 4105 | } |
| 4106 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4107 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4108 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4109 | do { |
| 4110 | struct sk_buff *this = skb; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 4111 | if (IXGBE_RSC_CB(this)->delay_unmap) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4112 | dma_unmap_single(dev, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 4113 | IXGBE_RSC_CB(this)->dma, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4114 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 4115 | DMA_FROM_DEVICE); |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 4116 | IXGBE_RSC_CB(this)->dma = 0; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 4117 | IXGBE_RSC_CB(skb)->delay_unmap = false; |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 4118 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4119 | skb = skb->prev; |
| 4120 | dev_kfree_skb(this); |
| 4121 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4122 | } |
| 4123 | if (!rx_buffer_info->page) |
| 4124 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 4125 | if (rx_buffer_info->page_dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4126 | dma_unmap_page(dev, rx_buffer_info->page_dma, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 4127 | PAGE_SIZE / 2, DMA_FROM_DEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 4128 | rx_buffer_info->page_dma = 0; |
| 4129 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4130 | put_page(rx_buffer_info->page); |
| 4131 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 4132 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4136 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4137 | |
| 4138 | /* Zero out the descriptor ring */ |
| 4139 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4140 | |
| 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 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4199 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4200 | { |
| 4201 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4202 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4203 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4204 | int i; |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4205 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4206 | |
| 4207 | /* signal that we are down to the interrupt handler */ |
| 4208 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4209 | |
| 4210 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4211 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4212 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4213 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4214 | /* disable all enabled rx queues */ |
| 4215 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4216 | /* this call also flushes the previous write */ |
| 4217 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4218 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4219 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4220 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4221 | netif_tx_stop_all_queues(netdev); |
| 4222 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4223 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4224 | netif_carrier_off(netdev); |
| 4225 | netif_tx_disable(netdev); |
| 4226 | |
| 4227 | ixgbe_irq_disable(adapter); |
| 4228 | |
| 4229 | ixgbe_napi_disable_all(adapter); |
| 4230 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4231 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4232 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4233 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4234 | |
| 4235 | del_timer_sync(&adapter->service_timer); |
| 4236 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4237 | /* disable receive for all VFs and wait one second */ |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4238 | if (adapter->num_vfs) { |
| 4239 | /* 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] | 4240 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4241 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4242 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4243 | ixgbe_disable_tx_rx(adapter); |
| 4244 | |
| 4245 | /* Mark all the VFs as inactive */ |
| 4246 | for (i = 0 ; i < adapter->num_vfs; i++) |
| 4247 | adapter->vfinfo[i].clear_to_send = 0; |
| 4248 | } |
| 4249 | |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4250 | /* Cleanup the affinity_hint CPU mask memory and callback */ |
| 4251 | for (i = 0; i < num_q_vectors; i++) { |
| 4252 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 4253 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4254 | irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL); |
| 4255 | /* release the CPU mask memory */ |
| 4256 | free_cpumask_var(q_vector->affinity_mask); |
| 4257 | } |
| 4258 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4259 | /* disable transmits in the hardware now that interrupts are off */ |
| 4260 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4261 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4262 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4263 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4264 | |
| 4265 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4266 | switch (hw->mac.type) { |
| 4267 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4268 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4269 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4270 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4271 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4272 | break; |
| 4273 | default: |
| 4274 | break; |
| 4275 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4276 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4277 | if (!pci_channel_offline(adapter->pdev)) |
| 4278 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4279 | |
| 4280 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 4281 | if (hw->mac.ops.disable_tx_laser && |
| 4282 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 4283 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4284 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 4285 | hw->mac.ops.disable_tx_laser(hw); |
| 4286 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4287 | ixgbe_clean_all_tx_rings(adapter); |
| 4288 | ixgbe_clean_all_rx_rings(adapter); |
| 4289 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4290 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4291 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4292 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4293 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4294 | } |
| 4295 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4296 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4297 | * ixgbe_poll - NAPI Rx polling callback |
| 4298 | * @napi: structure for representing this polling device |
| 4299 | * @budget: how many packets driver is allowed to clean |
| 4300 | * |
| 4301 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4302 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4303 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4304 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4305 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4306 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4307 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4308 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4309 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4310 | #ifdef CONFIG_IXGBE_DCA |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 4311 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 4312 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4313 | #endif |
| 4314 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4315 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]); |
| 4316 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4317 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4318 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4319 | work_done = budget; |
| 4320 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 4321 | /* If budget not fully consumed, exit the polling mode */ |
| 4322 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 4323 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4324 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 4325 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4326 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 4327 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4328 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4329 | return work_done; |
| 4330 | } |
| 4331 | |
| 4332 | /** |
| 4333 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4334 | * @netdev: network interface device structure |
| 4335 | **/ |
| 4336 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4337 | { |
| 4338 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4339 | |
| 4340 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4341 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4342 | } |
| 4343 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4344 | /** |
| 4345 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 4346 | * @adapter: board private structure to initialize |
| 4347 | * |
| 4348 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 4349 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 4350 | * |
| 4351 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4352 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 4353 | { |
| 4354 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4355 | 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] | 4356 | |
| 4357 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4358 | f->mask = 0xF; |
| 4359 | adapter->num_rx_queues = f->indices; |
| 4360 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4361 | ret = true; |
| 4362 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4363 | ret = false; |
| 4364 | } |
| 4365 | |
| 4366 | return ret; |
| 4367 | } |
| 4368 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4369 | /** |
| 4370 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 4371 | * @adapter: board private structure to initialize |
| 4372 | * |
| 4373 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 4374 | * to the original CPU that initiated the Tx session. This runs in addition |
| 4375 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 4376 | * Rx load across CPUs using RSS. |
| 4377 | * |
| 4378 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4379 | 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] | 4380 | { |
| 4381 | bool ret = false; |
| 4382 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 4383 | |
| 4384 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 4385 | f_fdir->mask = 0; |
| 4386 | |
| 4387 | /* Flow Director must have RSS enabled */ |
| 4388 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 4389 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 4390 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 4391 | adapter->num_tx_queues = f_fdir->indices; |
| 4392 | adapter->num_rx_queues = f_fdir->indices; |
| 4393 | ret = true; |
| 4394 | } else { |
| 4395 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 4396 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 4397 | } |
| 4398 | return ret; |
| 4399 | } |
| 4400 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4401 | #ifdef IXGBE_FCOE |
| 4402 | /** |
| 4403 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 4404 | * @adapter: board private structure to initialize |
| 4405 | * |
| 4406 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 4407 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 4408 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 4409 | * index of the first rx queue used by FCoE. |
| 4410 | * |
| 4411 | **/ |
| 4412 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 4413 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4414 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 4415 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4416 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4417 | return false; |
| 4418 | |
| 4419 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4420 | #ifdef CONFIG_IXGBE_DCB |
| 4421 | int tc; |
| 4422 | struct net_device *dev = adapter->netdev; |
| 4423 | |
| 4424 | tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up); |
| 4425 | f->indices = dev->tc_to_txq[tc].count; |
| 4426 | f->mask = dev->tc_to_txq[tc].offset; |
| 4427 | #endif |
| 4428 | } else { |
| 4429 | f->indices = min((int)num_online_cpus(), f->indices); |
| 4430 | |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 4431 | adapter->num_rx_queues = 1; |
| 4432 | adapter->num_tx_queues = 1; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4433 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4434 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 4435 | e_info(probe, "FCoE enabled with RSS\n"); |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 4436 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 4437 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 4438 | ixgbe_set_fdir_queues(adapter); |
| 4439 | else |
| 4440 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4441 | } |
| 4442 | /* adding FCoE rx rings to the end */ |
| 4443 | f->mask = adapter->num_rx_queues; |
| 4444 | adapter->num_rx_queues += f->indices; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 4445 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4446 | } |
| 4447 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4448 | return true; |
| 4449 | } |
| 4450 | #endif /* IXGBE_FCOE */ |
| 4451 | |
| 4452 | #ifdef CONFIG_IXGBE_DCB |
| 4453 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
| 4454 | { |
| 4455 | bool ret = false; |
| 4456 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
| 4457 | int i, q; |
| 4458 | |
| 4459 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 4460 | return ret; |
| 4461 | |
| 4462 | f->indices = 0; |
| 4463 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 4464 | q = min((int)num_online_cpus(), MAX_TRAFFIC_CLASS); |
| 4465 | f->indices += q; |
| 4466 | } |
| 4467 | |
| 4468 | f->mask = 0x7 << 3; |
| 4469 | adapter->num_rx_queues = f->indices; |
| 4470 | adapter->num_tx_queues = f->indices; |
| 4471 | ret = true; |
| 4472 | |
| 4473 | #ifdef IXGBE_FCOE |
| 4474 | /* FCoE enabled queues require special configuration done through |
| 4475 | * configure_fcoe() and others. Here we map FCoE indices onto the |
| 4476 | * DCB queue pairs allowing FCoE to own configuration later. |
| 4477 | */ |
| 4478 | ixgbe_set_fcoe_queues(adapter); |
| 4479 | #endif |
| 4480 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4481 | return ret; |
| 4482 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4483 | #endif |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4484 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4485 | /** |
| 4486 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 4487 | * @adapter: board private structure to initialize |
| 4488 | * |
| 4489 | * IOV doesn't actually use anything, so just NAK the |
| 4490 | * request for now and let the other queue routines |
| 4491 | * figure out what to do. |
| 4492 | */ |
| 4493 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 4494 | { |
| 4495 | return false; |
| 4496 | } |
| 4497 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4498 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4499 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4500 | * @adapter: board private structure to initialize |
| 4501 | * |
| 4502 | * This is the top level queue allocation routine. The order here is very |
| 4503 | * important, starting with the "most" number of features turned on at once, |
| 4504 | * and ending with the smallest set of features. This way large combinations |
| 4505 | * can be allocated if they're turned on, and smaller combinations are the |
| 4506 | * fallthrough conditions. |
| 4507 | * |
| 4508 | **/ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4509 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4510 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4511 | /* Start with base case */ |
| 4512 | adapter->num_rx_queues = 1; |
| 4513 | adapter->num_tx_queues = 1; |
| 4514 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 4515 | adapter->num_rx_queues_per_pool = 1; |
| 4516 | |
| 4517 | if (ixgbe_set_sriov_queues(adapter)) |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4518 | goto done; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4519 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4520 | #ifdef CONFIG_IXGBE_DCB |
| 4521 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4522 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4523 | |
| 4524 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4525 | #ifdef IXGBE_FCOE |
| 4526 | if (ixgbe_set_fcoe_queues(adapter)) |
| 4527 | goto done; |
| 4528 | |
| 4529 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4530 | if (ixgbe_set_fdir_queues(adapter)) |
| 4531 | goto done; |
| 4532 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4533 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4534 | goto done; |
| 4535 | |
| 4536 | /* fallback to base case */ |
| 4537 | adapter->num_rx_queues = 1; |
| 4538 | adapter->num_tx_queues = 1; |
| 4539 | |
| 4540 | done: |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4541 | /* Notify the stack of the (possibly) reduced queue counts. */ |
John Fastabend | f0796d5 | 2010-07-01 13:21:57 +0000 | [diff] [blame] | 4542 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4543 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 4544 | adapter->num_rx_queues); |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4545 | } |
| 4546 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4547 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4548 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4549 | { |
| 4550 | int err, vector_threshold; |
| 4551 | |
| 4552 | /* We'll want at least 3 (vector_threshold): |
| 4553 | * 1) TxQ[0] Cleanup |
| 4554 | * 2) RxQ[0] Cleanup |
| 4555 | * 3) Other (Link Status Change, etc.) |
| 4556 | * 4) TCP Timer (optional) |
| 4557 | */ |
| 4558 | vector_threshold = MIN_MSIX_COUNT; |
| 4559 | |
| 4560 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 4561 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 4562 | * Right now, we simply care about how many we'll get; we'll |
| 4563 | * set them up later while requesting irq's. |
| 4564 | */ |
| 4565 | while (vectors >= vector_threshold) { |
| 4566 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4567 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4568 | if (!err) /* Success in acquiring all requested vectors. */ |
| 4569 | break; |
| 4570 | else if (err < 0) |
| 4571 | vectors = 0; /* Nasty failure, quit now */ |
| 4572 | else /* err == number of vectors we should try again with */ |
| 4573 | vectors = err; |
| 4574 | } |
| 4575 | |
| 4576 | if (vectors < vector_threshold) { |
| 4577 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 4578 | * This just means we'll go with either a single MSI |
| 4579 | * vector or fall back to legacy interrupts. |
| 4580 | */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4581 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4582 | "Unable to allocate MSI-X interrupts\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4583 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4584 | kfree(adapter->msix_entries); |
| 4585 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4586 | } else { |
| 4587 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 4588 | /* |
| 4589 | * Adjust for only the vectors we'll use, which is minimum |
| 4590 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 4591 | * vectors we were allocated. |
| 4592 | */ |
| 4593 | adapter->num_msix_vectors = min(vectors, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4594 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4598 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4599 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4600 | * @adapter: board private structure to initialize |
| 4601 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4602 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 4603 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4604 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4605 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4606 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4607 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4608 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4609 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 4610 | return false; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4611 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4612 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4613 | adapter->rx_ring[i]->reg_idx = i; |
| 4614 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4615 | adapter->tx_ring[i]->reg_idx = i; |
| 4616 | |
| 4617 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4621 | |
| 4622 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 4623 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, |
| 4624 | unsigned int *tx, unsigned int *rx) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4625 | { |
| 4626 | struct net_device *dev = adapter->netdev; |
| 4627 | struct ixgbe_hw *hw = &adapter->hw; |
| 4628 | u8 num_tcs = netdev_get_num_tc(dev); |
| 4629 | |
| 4630 | *tx = 0; |
| 4631 | *rx = 0; |
| 4632 | |
| 4633 | switch (hw->mac.type) { |
| 4634 | case ixgbe_mac_82598EB: |
| 4635 | *tx = tc << 3; |
| 4636 | *rx = tc << 2; |
| 4637 | break; |
| 4638 | case ixgbe_mac_82599EB: |
| 4639 | case ixgbe_mac_X540: |
| 4640 | if (num_tcs == 8) { |
| 4641 | if (tc < 3) { |
| 4642 | *tx = tc << 5; |
| 4643 | *rx = tc << 4; |
| 4644 | } else if (tc < 5) { |
| 4645 | *tx = ((tc + 2) << 4); |
| 4646 | *rx = tc << 4; |
| 4647 | } else if (tc < num_tcs) { |
| 4648 | *tx = ((tc + 8) << 3); |
| 4649 | *rx = tc << 4; |
| 4650 | } |
| 4651 | } else if (num_tcs == 4) { |
| 4652 | *rx = tc << 5; |
| 4653 | switch (tc) { |
| 4654 | case 0: |
| 4655 | *tx = 0; |
| 4656 | break; |
| 4657 | case 1: |
| 4658 | *tx = 64; |
| 4659 | break; |
| 4660 | case 2: |
| 4661 | *tx = 96; |
| 4662 | break; |
| 4663 | case 3: |
| 4664 | *tx = 112; |
| 4665 | break; |
| 4666 | default: |
| 4667 | break; |
| 4668 | } |
| 4669 | } |
| 4670 | break; |
| 4671 | default: |
| 4672 | break; |
| 4673 | } |
| 4674 | } |
| 4675 | |
| 4676 | #define IXGBE_MAX_Q_PER_TC (IXGBE_MAX_DCB_INDICES / MAX_TRAFFIC_CLASS) |
| 4677 | |
| 4678 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic |
| 4679 | * classes. |
| 4680 | * |
| 4681 | * @netdev: net device to configure |
| 4682 | * @tc: number of traffic classes to enable |
| 4683 | */ |
| 4684 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 4685 | { |
| 4686 | int i; |
| 4687 | unsigned int q, offset = 0; |
| 4688 | |
| 4689 | if (!tc) { |
| 4690 | netdev_reset_tc(dev); |
| 4691 | } else { |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 4692 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 4693 | |
| 4694 | /* Hardware supports up to 8 traffic classes */ |
| 4695 | if (tc > MAX_TRAFFIC_CLASS || netdev_set_num_tc(dev, tc)) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4696 | return -EINVAL; |
| 4697 | |
| 4698 | /* Partition Tx queues evenly amongst traffic classes */ |
| 4699 | for (i = 0; i < tc; i++) { |
| 4700 | q = min((int)num_online_cpus(), IXGBE_MAX_Q_PER_TC); |
| 4701 | netdev_set_prio_tc_map(dev, i, i); |
| 4702 | netdev_set_tc_queue(dev, i, q, offset); |
| 4703 | offset += q; |
| 4704 | } |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 4705 | |
| 4706 | /* This enables multiple traffic class support in the hardware |
| 4707 | * which defaults to strict priority transmission by default. |
| 4708 | * If traffic classes are already enabled perhaps through DCB |
| 4709 | * code path then existing configuration will be used. |
| 4710 | */ |
| 4711 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 4712 | dev->dcbnl_ops && dev->dcbnl_ops->setdcbx) { |
| 4713 | struct ieee_ets ets = { |
| 4714 | .prio_tc = {0, 1, 2, 3, 4, 5, 6, 7}, |
| 4715 | }; |
| 4716 | u8 mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE; |
| 4717 | |
| 4718 | dev->dcbnl_ops->setdcbx(dev, mode); |
| 4719 | dev->dcbnl_ops->ieee_setets(dev, &ets); |
| 4720 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4721 | } |
| 4722 | return 0; |
| 4723 | } |
| 4724 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4725 | /** |
| 4726 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 4727 | * @adapter: board private structure to initialize |
| 4728 | * |
| 4729 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 4730 | * |
| 4731 | **/ |
| 4732 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 4733 | { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4734 | struct net_device *dev = adapter->netdev; |
| 4735 | int i, j, k; |
| 4736 | u8 num_tcs = netdev_get_num_tc(dev); |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4737 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4738 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 4739 | return false; |
| 4740 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4741 | for (i = 0, k = 0; i < num_tcs; i++) { |
| 4742 | unsigned int tx_s, rx_s; |
| 4743 | u16 count = dev->tc_to_txq[i].count; |
| 4744 | |
| 4745 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); |
| 4746 | for (j = 0; j < count; j++, k++) { |
| 4747 | adapter->tx_ring[k]->reg_idx = tx_s + j; |
| 4748 | adapter->rx_ring[k]->reg_idx = rx_s + j; |
| 4749 | adapter->tx_ring[k]->dcb_tc = i; |
| 4750 | adapter->rx_ring[k]->dcb_tc = i; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4751 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4752 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4753 | |
| 4754 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4755 | } |
| 4756 | #endif |
| 4757 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4758 | /** |
| 4759 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 4760 | * @adapter: board private structure to initialize |
| 4761 | * |
| 4762 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 4763 | * |
| 4764 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4765 | 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] | 4766 | { |
| 4767 | int i; |
| 4768 | bool ret = false; |
| 4769 | |
| 4770 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 4771 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 4772 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 4773 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4774 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4775 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4776 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4777 | ret = true; |
| 4778 | } |
| 4779 | |
| 4780 | return ret; |
| 4781 | } |
| 4782 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4783 | #ifdef IXGBE_FCOE |
| 4784 | /** |
| 4785 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 4786 | * @adapter: board private structure to initialize |
| 4787 | * |
| 4788 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 4789 | * |
| 4790 | */ |
| 4791 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 4792 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4793 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4794 | int i; |
| 4795 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4796 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4797 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4798 | return false; |
| 4799 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4800 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 4801 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 4802 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 4803 | ixgbe_cache_ring_fdir(adapter); |
| 4804 | else |
| 4805 | ixgbe_cache_ring_rss(adapter); |
| 4806 | |
| 4807 | fcoe_rx_i = f->mask; |
| 4808 | fcoe_tx_i = f->mask; |
| 4809 | } |
| 4810 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 4811 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 4812 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
| 4813 | } |
| 4814 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4818 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4819 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 4820 | * @adapter: board private structure to initialize |
| 4821 | * |
| 4822 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 4823 | * no other mapping is used. |
| 4824 | * |
| 4825 | */ |
| 4826 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 4827 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4828 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 4829 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4830 | if (adapter->num_vfs) |
| 4831 | return true; |
| 4832 | else |
| 4833 | return false; |
| 4834 | } |
| 4835 | |
| 4836 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4837 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 4838 | * @adapter: board private structure to initialize |
| 4839 | * |
| 4840 | * Once we know the feature-set enabled for the device, we'll cache |
| 4841 | * the register offset the descriptor ring is assigned to. |
| 4842 | * |
| 4843 | * Note, the order the various feature calls is important. It must start with |
| 4844 | * the "most" features enabled at the same time, then trickle down to the |
| 4845 | * least amount of features turned on at once. |
| 4846 | **/ |
| 4847 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 4848 | { |
| 4849 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4850 | adapter->rx_ring[0]->reg_idx = 0; |
| 4851 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4852 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4853 | if (ixgbe_cache_ring_sriov(adapter)) |
| 4854 | return; |
| 4855 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4856 | #ifdef CONFIG_IXGBE_DCB |
| 4857 | if (ixgbe_cache_ring_dcb(adapter)) |
| 4858 | return; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4859 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4860 | |
| 4861 | #ifdef IXGBE_FCOE |
| 4862 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 4863 | return; |
| 4864 | #endif /* IXGBE_FCOE */ |
| 4865 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4866 | if (ixgbe_cache_ring_fdir(adapter)) |
| 4867 | return; |
| 4868 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4869 | if (ixgbe_cache_ring_rss(adapter)) |
| 4870 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4871 | } |
| 4872 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4873 | /** |
| 4874 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 4875 | * @adapter: board private structure to initialize |
| 4876 | * |
| 4877 | * We allocate one ring per queue at run-time since we don't know the |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4878 | * number of queues at compile-time. The polling_netdev array is |
| 4879 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4880 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4881 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4882 | { |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4883 | int rx = 0, tx = 0, nid = adapter->node; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4884 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4885 | if (nid < 0 || !node_online(nid)) |
| 4886 | nid = first_online_node; |
| 4887 | |
| 4888 | for (; tx < adapter->num_tx_queues; tx++) { |
| 4889 | struct ixgbe_ring *ring; |
| 4890 | |
| 4891 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4892 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4893 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4894 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4895 | goto err_allocation; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4896 | ring->count = adapter->tx_ring_count; |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4897 | ring->queue_index = tx; |
| 4898 | ring->numa_node = nid; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4899 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 4900 | ring->netdev = adapter->netdev; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4901 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4902 | adapter->tx_ring[tx] = ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4903 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4904 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4905 | for (; rx < adapter->num_rx_queues; rx++) { |
| 4906 | struct ixgbe_ring *ring; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4907 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4908 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4909 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4910 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4911 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4912 | goto err_allocation; |
| 4913 | ring->count = adapter->rx_ring_count; |
| 4914 | ring->queue_index = rx; |
| 4915 | ring->numa_node = nid; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4916 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 4917 | ring->netdev = adapter->netdev; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4918 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4919 | adapter->rx_ring[rx] = ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4920 | } |
| 4921 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4922 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4923 | |
| 4924 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4925 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4926 | err_allocation: |
| 4927 | while (tx) |
| 4928 | kfree(adapter->tx_ring[--tx]); |
| 4929 | |
| 4930 | while (rx) |
| 4931 | kfree(adapter->rx_ring[--rx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4932 | return -ENOMEM; |
| 4933 | } |
| 4934 | |
| 4935 | /** |
| 4936 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 4937 | * @adapter: board private structure to initialize |
| 4938 | * |
| 4939 | * Attempt to configure the interrupts using the best available |
| 4940 | * capabilities of the hardware and the kernel. |
| 4941 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 4942 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4943 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4944 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4945 | int err = 0; |
| 4946 | int vector, v_budget; |
| 4947 | |
| 4948 | /* |
| 4949 | * It's easy to be greedy for MSI-X vectors, but it really |
| 4950 | * doesn't do us much good if we have a lot more vectors |
| 4951 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 4952 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4953 | */ |
| 4954 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4955 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4956 | |
| 4957 | /* |
| 4958 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4959 | * hw.mac->max_msix_vectors vectors. With features |
| 4960 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 4961 | * descriptor queues supported by our device. Thus, we cap it off in |
| 4962 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4963 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4964 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4965 | |
| 4966 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 4967 | * mean we disable MSI-X capabilities of the adapter. */ |
| 4968 | adapter->msix_entries = kcalloc(v_budget, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4969 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4970 | if (adapter->msix_entries) { |
| 4971 | for (vector = 0; vector < v_budget; vector++) |
| 4972 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4973 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4974 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 4975 | |
| 4976 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4977 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4978 | } |
David S. Miller | 26d2784 | 2010-05-03 15:18:22 -0700 | [diff] [blame] | 4979 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4980 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 4981 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4982 | if (adapter->flags & (IXGBE_FLAG_FDIR_HASH_CAPABLE | |
| 4983 | IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { |
| 4984 | e_err(probe, |
| 4985 | "Flow Director is not supported while multiple " |
| 4986 | "queues are disabled. Disabling Flow Director\n"); |
| 4987 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4988 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 4989 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 4990 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4991 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4992 | ixgbe_disable_sriov(adapter); |
| 4993 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4994 | err = ixgbe_set_num_queues(adapter); |
| 4995 | if (err) |
| 4996 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4997 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4998 | err = pci_enable_msi(adapter->pdev); |
| 4999 | if (!err) { |
| 5000 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 5001 | } else { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5002 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 5003 | "Unable to allocate MSI interrupt, " |
| 5004 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5005 | /* reset err */ |
| 5006 | err = 0; |
| 5007 | } |
| 5008 | |
| 5009 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5010 | return err; |
| 5011 | } |
| 5012 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5013 | /** |
| 5014 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 5015 | * @adapter: board private structure to initialize |
| 5016 | * |
| 5017 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 5018 | * return -ENOMEM. |
| 5019 | **/ |
| 5020 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 5021 | { |
| 5022 | int q_idx, num_q_vectors; |
| 5023 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5024 | int (*poll)(struct napi_struct *, int); |
| 5025 | |
| 5026 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5027 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5028 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5029 | } else { |
| 5030 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5031 | poll = &ixgbe_poll; |
| 5032 | } |
| 5033 | |
| 5034 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5035 | q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5036 | GFP_KERNEL, adapter->node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5037 | if (!q_vector) |
| 5038 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5039 | GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5040 | if (!q_vector) |
| 5041 | goto err_out; |
| 5042 | q_vector->adapter = adapter; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5043 | if (q_vector->txr_count && !q_vector->rxr_count) |
| 5044 | q_vector->eitr = adapter->tx_eitr_param; |
| 5045 | else |
| 5046 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5047 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5048 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5049 | adapter->q_vector[q_idx] = q_vector; |
| 5050 | } |
| 5051 | |
| 5052 | return 0; |
| 5053 | |
| 5054 | err_out: |
| 5055 | while (q_idx) { |
| 5056 | q_idx--; |
| 5057 | q_vector = adapter->q_vector[q_idx]; |
| 5058 | netif_napi_del(&q_vector->napi); |
| 5059 | kfree(q_vector); |
| 5060 | adapter->q_vector[q_idx] = NULL; |
| 5061 | } |
| 5062 | return -ENOMEM; |
| 5063 | } |
| 5064 | |
| 5065 | /** |
| 5066 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 5067 | * @adapter: board private structure to initialize |
| 5068 | * |
| 5069 | * This function frees the memory allocated to the q_vectors. In addition if |
| 5070 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 5071 | * to freeing the q_vector. |
| 5072 | **/ |
| 5073 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 5074 | { |
| 5075 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5076 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5077 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5078 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5079 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5080 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5081 | |
| 5082 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 5083 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5084 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 5085 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5086 | kfree(q_vector); |
| 5087 | } |
| 5088 | } |
| 5089 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 5090 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5091 | { |
| 5092 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5093 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 5094 | pci_disable_msix(adapter->pdev); |
| 5095 | kfree(adapter->msix_entries); |
| 5096 | adapter->msix_entries = NULL; |
| 5097 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 5098 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 5099 | pci_disable_msi(adapter->pdev); |
| 5100 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | /** |
| 5104 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 5105 | * @adapter: board private structure to initialize |
| 5106 | * |
| 5107 | * We determine which interrupt scheme to use based on... |
| 5108 | * - Kernel support (MSI, MSI-X) |
| 5109 | * - which can be user-defined (via MODULE_PARAM) |
| 5110 | * - Hardware queue count (num_*_queues) |
| 5111 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 5112 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5113 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5114 | { |
| 5115 | int err; |
| 5116 | |
| 5117 | /* Number of supported queues */ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 5118 | err = ixgbe_set_num_queues(adapter); |
| 5119 | if (err) |
| 5120 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5121 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5122 | err = ixgbe_set_interrupt_capability(adapter); |
| 5123 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5124 | e_dev_err("Unable to setup interrupt capabilities\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5125 | goto err_set_interrupt; |
| 5126 | } |
| 5127 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5128 | err = ixgbe_alloc_q_vectors(adapter); |
| 5129 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5130 | e_dev_err("Unable to allocate memory for queue vectors\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5131 | goto err_alloc_q_vectors; |
| 5132 | } |
| 5133 | |
| 5134 | err = ixgbe_alloc_queues(adapter); |
| 5135 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5136 | e_dev_err("Unable to allocate memory for queues\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5137 | goto err_alloc_queues; |
| 5138 | } |
| 5139 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5140 | e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n", |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5141 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 5142 | adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5143 | |
| 5144 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5145 | |
| 5146 | return 0; |
| 5147 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5148 | err_alloc_queues: |
| 5149 | ixgbe_free_q_vectors(adapter); |
| 5150 | err_alloc_q_vectors: |
| 5151 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5152 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5153 | return err; |
| 5154 | } |
| 5155 | |
| 5156 | /** |
| 5157 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 5158 | * @adapter: board private structure to clear interrupt scheme on |
| 5159 | * |
| 5160 | * We go through and clear interrupt specific resources and reset the structure |
| 5161 | * to pre-load conditions |
| 5162 | **/ |
| 5163 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 5164 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5165 | int i; |
| 5166 | |
| 5167 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5168 | kfree(adapter->tx_ring[i]); |
| 5169 | adapter->tx_ring[i] = NULL; |
| 5170 | } |
| 5171 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 5172 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 5173 | |
| 5174 | /* ixgbe_get_stats64() might access this ring, we must wait |
| 5175 | * a grace period before freeing it. |
| 5176 | */ |
Lai Jiangshan | bcec8b6 | 2011-03-18 11:57:21 +0800 | [diff] [blame] | 5177 | kfree_rcu(ring, rcu); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5178 | adapter->rx_ring[i] = NULL; |
| 5179 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5180 | |
Don Skidmore | b8eb3a1 | 2010-12-01 20:54:53 +0000 | [diff] [blame] | 5181 | adapter->num_tx_queues = 0; |
| 5182 | adapter->num_rx_queues = 0; |
| 5183 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5184 | ixgbe_free_q_vectors(adapter); |
| 5185 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | /** |
| 5189 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5190 | * @adapter: board private structure to initialize |
| 5191 | * |
| 5192 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5193 | * Fields are initialized based on PCI device information and |
| 5194 | * OS network device settings (MTU size). |
| 5195 | **/ |
| 5196 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 5197 | { |
| 5198 | struct ixgbe_hw *hw = &adapter->hw; |
| 5199 | struct pci_dev *pdev = adapter->pdev; |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 5200 | struct net_device *dev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5201 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5202 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5203 | int j; |
| 5204 | struct tc_configuration *tc; |
| 5205 | #endif |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5206 | int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5207 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5208 | /* PCI config space info */ |
| 5209 | |
| 5210 | hw->vendor_id = pdev->vendor; |
| 5211 | hw->device_id = pdev->device; |
| 5212 | hw->revision_id = pdev->revision; |
| 5213 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5214 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5215 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5216 | /* Set capability flags */ |
| 5217 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 5218 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 5219 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5220 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5221 | switch (hw->mac.type) { |
| 5222 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5223 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5224 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5225 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5226 | break; |
| 5227 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5228 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5229 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5230 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5231 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5232 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5233 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 5234 | /* n-tuple support exists, always init our spinlock */ |
| 5235 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5236 | /* Flow Director hash filters enabled */ |
| 5237 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5238 | adapter->atr_sample_rate = 20; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5239 | adapter->ring_feature[RING_F_FDIR].indices = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5240 | IXGBE_MAX_FDIR_INDICES; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5241 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5242 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5243 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5244 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5245 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5246 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 5247 | /* Default traffic class to use for FCoE */ |
| 5248 | adapter->fcoe.tc = IXGBE_FCOE_DEFTC; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 5249 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5250 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5251 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5252 | break; |
| 5253 | default: |
| 5254 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5255 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5256 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5257 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5258 | /* Configure DCB traffic classes */ |
| 5259 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5260 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5261 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5262 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5263 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5264 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5265 | tc->dcb_pfc = pfc_disabled; |
| 5266 | } |
| 5267 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5268 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5269 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5270 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5271 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5272 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 5273 | MAX_TRAFFIC_CLASS); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5274 | |
| 5275 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5276 | |
| 5277 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5278 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5279 | 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] | 5280 | #ifdef CONFIG_DCB |
| 5281 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 5282 | #endif |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5283 | hw->fc.high_water = FC_HIGH_WATER(max_frame); |
| 5284 | hw->fc.low_water = FC_LOW_WATER(max_frame); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5285 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5286 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5287 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5288 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5289 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5290 | adapter->rx_itr_setting = 1; |
| 5291 | adapter->rx_eitr_param = 20000; |
| 5292 | adapter->tx_itr_setting = 1; |
| 5293 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5294 | |
| 5295 | /* set defaults for eitr in MegaBytes */ |
| 5296 | adapter->eitr_low = 10; |
| 5297 | adapter->eitr_high = 20; |
| 5298 | |
| 5299 | /* set default ring sizes */ |
| 5300 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5301 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5302 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5303 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5304 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5305 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5306 | return -EIO; |
| 5307 | } |
| 5308 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5309 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5310 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 5311 | |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5312 | /* get assigned NUMA node */ |
| 5313 | adapter->node = dev_to_node(&pdev->dev); |
| 5314 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5315 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5316 | |
| 5317 | return 0; |
| 5318 | } |
| 5319 | |
| 5320 | /** |
| 5321 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5322 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5323 | * |
| 5324 | * Return 0 on success, negative on failure |
| 5325 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5326 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5327 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5328 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5329 | int size; |
| 5330 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5331 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5332 | tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5333 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5334 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5335 | if (!tx_ring->tx_buffer_info) |
| 5336 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5337 | |
| 5338 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5339 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5340 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5341 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5342 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 5343 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5344 | if (!tx_ring->desc) |
| 5345 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5346 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5347 | tx_ring->next_to_use = 0; |
| 5348 | tx_ring->next_to_clean = 0; |
| 5349 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5350 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5351 | |
| 5352 | err: |
| 5353 | vfree(tx_ring->tx_buffer_info); |
| 5354 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5355 | dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n"); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5356 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5360 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5361 | * @adapter: board private structure |
| 5362 | * |
| 5363 | * If this function returns with an error, then it's possible one or |
| 5364 | * more of the rings is populated (while the rest are not). It is the |
| 5365 | * callers duty to clean those orphaned rings. |
| 5366 | * |
| 5367 | * Return 0 on success, negative on failure |
| 5368 | **/ |
| 5369 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5370 | { |
| 5371 | int i, err = 0; |
| 5372 | |
| 5373 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5374 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5375 | if (!err) |
| 5376 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5377 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5378 | break; |
| 5379 | } |
| 5380 | |
| 5381 | return err; |
| 5382 | } |
| 5383 | |
| 5384 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5385 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5386 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5387 | * |
| 5388 | * Returns 0 on success, negative on failure |
| 5389 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5390 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5391 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5392 | struct device *dev = rx_ring->dev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5393 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5394 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5395 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5396 | rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5397 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5398 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5399 | if (!rx_ring->rx_buffer_info) |
| 5400 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5401 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5402 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5403 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5404 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5405 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5406 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 5407 | &rx_ring->dma, GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5408 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5409 | if (!rx_ring->desc) |
| 5410 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5411 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5412 | rx_ring->next_to_clean = 0; |
| 5413 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5414 | |
| 5415 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5416 | err: |
| 5417 | vfree(rx_ring->rx_buffer_info); |
| 5418 | rx_ring->rx_buffer_info = NULL; |
| 5419 | 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] | 5420 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5424 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5425 | * @adapter: board private structure |
| 5426 | * |
| 5427 | * If this function returns with an error, then it's possible one or |
| 5428 | * more of the rings is populated (while the rest are not). It is the |
| 5429 | * callers duty to clean those orphaned rings. |
| 5430 | * |
| 5431 | * Return 0 on success, negative on failure |
| 5432 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5433 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5434 | { |
| 5435 | int i, err = 0; |
| 5436 | |
| 5437 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5438 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5439 | if (!err) |
| 5440 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5441 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5442 | break; |
| 5443 | } |
| 5444 | |
| 5445 | return err; |
| 5446 | } |
| 5447 | |
| 5448 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5449 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5450 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5451 | * |
| 5452 | * Free all transmit software resources |
| 5453 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5454 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5455 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5456 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5457 | |
| 5458 | vfree(tx_ring->tx_buffer_info); |
| 5459 | tx_ring->tx_buffer_info = NULL; |
| 5460 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5461 | /* if not set, then don't free */ |
| 5462 | if (!tx_ring->desc) |
| 5463 | return; |
| 5464 | |
| 5465 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5466 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5467 | |
| 5468 | tx_ring->desc = NULL; |
| 5469 | } |
| 5470 | |
| 5471 | /** |
| 5472 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5473 | * @adapter: board private structure |
| 5474 | * |
| 5475 | * Free all transmit software resources |
| 5476 | **/ |
| 5477 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5478 | { |
| 5479 | int i; |
| 5480 | |
| 5481 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5482 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5483 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5487 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5488 | * @rx_ring: ring to clean the resources from |
| 5489 | * |
| 5490 | * Free all receive software resources |
| 5491 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5492 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5493 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5494 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5495 | |
| 5496 | vfree(rx_ring->rx_buffer_info); |
| 5497 | rx_ring->rx_buffer_info = NULL; |
| 5498 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5499 | /* if not set, then don't free */ |
| 5500 | if (!rx_ring->desc) |
| 5501 | return; |
| 5502 | |
| 5503 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5504 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5505 | |
| 5506 | rx_ring->desc = NULL; |
| 5507 | } |
| 5508 | |
| 5509 | /** |
| 5510 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5511 | * @adapter: board private structure |
| 5512 | * |
| 5513 | * Free all receive software resources |
| 5514 | **/ |
| 5515 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5516 | { |
| 5517 | int i; |
| 5518 | |
| 5519 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5520 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5521 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5522 | } |
| 5523 | |
| 5524 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5525 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5526 | * @netdev: network interface device structure |
| 5527 | * @new_mtu: new value for maximum frame size |
| 5528 | * |
| 5529 | * Returns 0 on success, negative on failure |
| 5530 | **/ |
| 5531 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5532 | { |
| 5533 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5534 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5535 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5536 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5537 | /* MTU < 68 is an error and causes problems on some kernels */ |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 5538 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED && |
| 5539 | hw->mac.type != ixgbe_mac_X540) { |
| 5540 | if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
| 5541 | return -EINVAL; |
| 5542 | } else { |
| 5543 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5544 | return -EINVAL; |
| 5545 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5546 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5547 | e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5548 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5549 | netdev->mtu = new_mtu; |
| 5550 | |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5551 | hw->fc.high_water = FC_HIGH_WATER(max_frame); |
| 5552 | hw->fc.low_water = FC_LOW_WATER(max_frame); |
| 5553 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5554 | if (netif_running(netdev)) |
| 5555 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5556 | |
| 5557 | return 0; |
| 5558 | } |
| 5559 | |
| 5560 | /** |
| 5561 | * ixgbe_open - Called when a network interface is made active |
| 5562 | * @netdev: network interface device structure |
| 5563 | * |
| 5564 | * Returns 0 on success, negative value on failure |
| 5565 | * |
| 5566 | * The open entry point is called when a network interface is made |
| 5567 | * active by the system (IFF_UP). At this point all resources needed |
| 5568 | * for transmit and receive operations are allocated, the interrupt |
| 5569 | * handler is registered with the OS, the watchdog timer is started, |
| 5570 | * and the stack is notified that the interface is ready. |
| 5571 | **/ |
| 5572 | static int ixgbe_open(struct net_device *netdev) |
| 5573 | { |
| 5574 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5575 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5576 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5577 | /* disallow open during test */ |
| 5578 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5579 | return -EBUSY; |
| 5580 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5581 | netif_carrier_off(netdev); |
| 5582 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5583 | /* allocate transmit descriptors */ |
| 5584 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5585 | if (err) |
| 5586 | goto err_setup_tx; |
| 5587 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5588 | /* allocate receive descriptors */ |
| 5589 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5590 | if (err) |
| 5591 | goto err_setup_rx; |
| 5592 | |
| 5593 | ixgbe_configure(adapter); |
| 5594 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5595 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5596 | if (err) |
| 5597 | goto err_req_irq; |
| 5598 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5599 | err = ixgbe_up_complete(adapter); |
| 5600 | if (err) |
| 5601 | goto err_up; |
| 5602 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 5603 | netif_tx_start_all_queues(netdev); |
| 5604 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5605 | return 0; |
| 5606 | |
| 5607 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5608 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5609 | ixgbe_free_irq(adapter); |
| 5610 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5611 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5612 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5613 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5614 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5615 | ixgbe_reset(adapter); |
| 5616 | |
| 5617 | return err; |
| 5618 | } |
| 5619 | |
| 5620 | /** |
| 5621 | * ixgbe_close - Disables a network interface |
| 5622 | * @netdev: network interface device structure |
| 5623 | * |
| 5624 | * Returns 0, this is not allowed to fail |
| 5625 | * |
| 5626 | * The close entry point is called when an interface is de-activated |
| 5627 | * by the OS. The hardware is still under the drivers control, but |
| 5628 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5629 | * hardware, and all transmit and receive resources are freed. |
| 5630 | **/ |
| 5631 | static int ixgbe_close(struct net_device *netdev) |
| 5632 | { |
| 5633 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5634 | |
| 5635 | ixgbe_down(adapter); |
| 5636 | ixgbe_free_irq(adapter); |
| 5637 | |
| 5638 | ixgbe_free_all_tx_resources(adapter); |
| 5639 | ixgbe_free_all_rx_resources(adapter); |
| 5640 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5641 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5642 | |
| 5643 | return 0; |
| 5644 | } |
| 5645 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5646 | #ifdef CONFIG_PM |
| 5647 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5648 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5649 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5650 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5651 | u32 err; |
| 5652 | |
| 5653 | pci_set_power_state(pdev, PCI_D0); |
| 5654 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5655 | /* |
| 5656 | * pci_restore_state clears dev->state_saved so call |
| 5657 | * pci_save_state to restore it. |
| 5658 | */ |
| 5659 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5660 | |
| 5661 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5662 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5663 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5664 | return err; |
| 5665 | } |
| 5666 | pci_set_master(pdev); |
| 5667 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5668 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5669 | |
| 5670 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5671 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5672 | e_dev_err("Cannot initialize interrupts for device\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5673 | return err; |
| 5674 | } |
| 5675 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5676 | ixgbe_reset(adapter); |
| 5677 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5678 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5679 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5680 | if (netif_running(netdev)) { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5681 | err = ixgbe_open(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5682 | if (err) |
| 5683 | return err; |
| 5684 | } |
| 5685 | |
| 5686 | netif_device_attach(netdev); |
| 5687 | |
| 5688 | return 0; |
| 5689 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5690 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5691 | |
| 5692 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5693 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5694 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5695 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5696 | struct ixgbe_hw *hw = &adapter->hw; |
| 5697 | u32 ctrl, fctrl; |
| 5698 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5699 | #ifdef CONFIG_PM |
| 5700 | int retval = 0; |
| 5701 | #endif |
| 5702 | |
| 5703 | netif_device_detach(netdev); |
| 5704 | |
| 5705 | if (netif_running(netdev)) { |
| 5706 | ixgbe_down(adapter); |
| 5707 | ixgbe_free_irq(adapter); |
| 5708 | ixgbe_free_all_tx_resources(adapter); |
| 5709 | ixgbe_free_all_rx_resources(adapter); |
| 5710 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5711 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5712 | ixgbe_clear_interrupt_scheme(adapter); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 5713 | #ifdef CONFIG_DCB |
| 5714 | kfree(adapter->ixgbe_ieee_pfc); |
| 5715 | kfree(adapter->ixgbe_ieee_ets); |
| 5716 | #endif |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5717 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5718 | #ifdef CONFIG_PM |
| 5719 | retval = pci_save_state(pdev); |
| 5720 | if (retval) |
| 5721 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5722 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5723 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5724 | if (wufc) { |
| 5725 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5726 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5727 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5728 | if (wufc & IXGBE_WUFC_MC) { |
| 5729 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5730 | fctrl |= IXGBE_FCTRL_MPE; |
| 5731 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5732 | } |
| 5733 | |
| 5734 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5735 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5736 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5737 | |
| 5738 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5739 | } else { |
| 5740 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5741 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5742 | } |
| 5743 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5744 | switch (hw->mac.type) { |
| 5745 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5746 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5747 | break; |
| 5748 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5749 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5750 | pci_wake_from_d3(pdev, !!wufc); |
| 5751 | break; |
| 5752 | default: |
| 5753 | break; |
| 5754 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5755 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5756 | *enable_wake = !!wufc; |
| 5757 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5758 | ixgbe_release_hw_control(adapter); |
| 5759 | |
| 5760 | pci_disable_device(pdev); |
| 5761 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5762 | return 0; |
| 5763 | } |
| 5764 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5765 | #ifdef CONFIG_PM |
| 5766 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5767 | { |
| 5768 | int retval; |
| 5769 | bool wake; |
| 5770 | |
| 5771 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5772 | if (retval) |
| 5773 | return retval; |
| 5774 | |
| 5775 | if (wake) { |
| 5776 | pci_prepare_to_sleep(pdev); |
| 5777 | } else { |
| 5778 | pci_wake_from_d3(pdev, false); |
| 5779 | pci_set_power_state(pdev, PCI_D3hot); |
| 5780 | } |
| 5781 | |
| 5782 | return 0; |
| 5783 | } |
| 5784 | #endif /* CONFIG_PM */ |
| 5785 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5786 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5787 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5788 | bool wake; |
| 5789 | |
| 5790 | __ixgbe_shutdown(pdev, &wake); |
| 5791 | |
| 5792 | if (system_state == SYSTEM_POWER_OFF) { |
| 5793 | pci_wake_from_d3(pdev, wake); |
| 5794 | pci_set_power_state(pdev, PCI_D3hot); |
| 5795 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5799 | * ixgbe_update_stats - Update the board statistics counters. |
| 5800 | * @adapter: board private structure |
| 5801 | **/ |
| 5802 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5803 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5804 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5805 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5806 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5807 | u64 total_mpc = 0; |
| 5808 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5809 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5810 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
| 5811 | u64 bytes = 0, packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5812 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5813 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5814 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5815 | return; |
| 5816 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5817 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5818 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5819 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5820 | for (i = 0; i < 16; i++) |
| 5821 | adapter->hw_rx_no_dma_resources += |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5822 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5823 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5824 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5825 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5826 | } |
| 5827 | adapter->rsc_total_count = rsc_count; |
| 5828 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5829 | } |
| 5830 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5831 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5832 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5833 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5834 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5835 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
| 5836 | bytes += rx_ring->stats.bytes; |
| 5837 | packets += rx_ring->stats.packets; |
| 5838 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5839 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5840 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5841 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
| 5842 | netdev->stats.rx_bytes = bytes; |
| 5843 | netdev->stats.rx_packets = packets; |
| 5844 | |
| 5845 | bytes = 0; |
| 5846 | packets = 0; |
| 5847 | /* gather some stats to the adapter struct that are per queue */ |
| 5848 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5849 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5850 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5851 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5852 | bytes += tx_ring->stats.bytes; |
| 5853 | packets += tx_ring->stats.packets; |
| 5854 | } |
| 5855 | adapter->restart_queue = restart_queue; |
| 5856 | adapter->tx_busy = tx_busy; |
| 5857 | netdev->stats.tx_bytes = bytes; |
| 5858 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5859 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5860 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5861 | for (i = 0; i < 8; i++) { |
| 5862 | /* for packet buffers not used, the register should read 0 */ |
| 5863 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5864 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5865 | hwstats->mpc[i] += mpc; |
| 5866 | total_mpc += hwstats->mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5867 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5868 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5869 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5870 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5871 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5872 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5873 | switch (hw->mac.type) { |
| 5874 | case ixgbe_mac_82598EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5875 | hwstats->pxonrxc[i] += |
| 5876 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5877 | break; |
| 5878 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5879 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5880 | hwstats->pxonrxc[i] += |
| 5881 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5882 | break; |
| 5883 | default: |
| 5884 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5885 | } |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5886 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5887 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5888 | } |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5889 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5890 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5891 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5892 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5893 | ixgbe_update_xoff_received(adapter); |
| 5894 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5895 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5896 | switch (hw->mac.type) { |
| 5897 | case ixgbe_mac_82598EB: |
| 5898 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5899 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5900 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5901 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5902 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5903 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5904 | /* OS2BMC stats are X540 only*/ |
| 5905 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5906 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5907 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5908 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5909 | case ixgbe_mac_82599EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5910 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5911 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5912 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5913 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5914 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5915 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5916 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5917 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5918 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5919 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5920 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5921 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5922 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5923 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5924 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5925 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5926 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5927 | break; |
| 5928 | default: |
| 5929 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5930 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5931 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5932 | hwstats->bprc += bprc; |
| 5933 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5934 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5935 | hwstats->mprc -= bprc; |
| 5936 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5937 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5938 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5939 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5940 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5941 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5942 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5943 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5944 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5945 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5946 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5947 | hwstats->lxofftxc += lxoff; |
| 5948 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5949 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5950 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5951 | /* |
| 5952 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5953 | */ |
| 5954 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5955 | hwstats->gptc -= xon_off_tot; |
| 5956 | hwstats->mptc -= xon_off_tot; |
| 5957 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5958 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5959 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 5960 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 5961 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 5962 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 5963 | hwstats->ptc64 -= xon_off_tot; |
| 5964 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 5965 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 5966 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 5967 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 5968 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 5969 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5970 | |
| 5971 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5972 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5973 | |
| 5974 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5975 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5976 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5977 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 5978 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5979 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5980 | } |
| 5981 | |
| 5982 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5983 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
| 5984 | * @adapter - pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5985 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5986 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5987 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5988 | struct ixgbe_hw *hw = &adapter->hw; |
| 5989 | int i; |
| 5990 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5991 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 5992 | return; |
| 5993 | |
| 5994 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 5995 | |
| 5996 | /* if interface is down do nothing */ |
| 5997 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 5998 | return; |
| 5999 | |
| 6000 | /* do nothing if we are not using signature filters */ |
| 6001 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 6002 | return; |
| 6003 | |
| 6004 | adapter->fdir_overflow++; |
| 6005 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6006 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 6007 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 6008 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6009 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6010 | /* re-enable flow director interrupts */ |
| 6011 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6012 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6013 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6014 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6015 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6016 | } |
| 6017 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6018 | /** |
| 6019 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
| 6020 | * @adapter - pointer to the device adapter structure |
| 6021 | * |
| 6022 | * This function serves two purposes. First it strobes the interrupt lines |
| 6023 | * in order to make certain interrupts are occuring. Secondly it sets the |
| 6024 | * bits needed to check for TX hangs. As a result we should immediately |
| 6025 | * determine if a hang has occured. |
| 6026 | */ |
| 6027 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 6028 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6029 | struct ixgbe_hw *hw = &adapter->hw; |
| 6030 | u64 eics = 0; |
| 6031 | int i; |
| 6032 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6033 | /* If we're down or resetting, just bail */ |
| 6034 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6035 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6036 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6037 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6038 | /* Force detection of hung controller */ |
| 6039 | if (netif_carrier_ok(adapter->netdev)) { |
| 6040 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 6041 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 6042 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6043 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6044 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6045 | /* |
| 6046 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 6047 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6048 | * would set *both* EIMS and EICS for any bit in EIAM |
| 6049 | */ |
| 6050 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 6051 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6052 | } else { |
| 6053 | /* get one bit for every active tx/rx interrupt vector */ |
| 6054 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 6055 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 6056 | if (qv->rxr_count || qv->txr_count) |
| 6057 | eics |= ((u64)1 << i); |
| 6058 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6059 | } |
| 6060 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6061 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6062 | ixgbe_irq_rearm_queues(adapter, eics); |
| 6063 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6067 | * ixgbe_watchdog_update_link - update the link status |
| 6068 | * @adapter - pointer to the device adapter structure |
| 6069 | * @link_speed - pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6070 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6071 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6072 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6073 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6074 | u32 link_speed = adapter->link_speed; |
| 6075 | bool link_up = adapter->link_up; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6076 | int i; |
| 6077 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6078 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6079 | return; |
| 6080 | |
| 6081 | if (hw->mac.ops.check_link) { |
| 6082 | 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] | 6083 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6084 | /* always assume link is up, if no check link function */ |
| 6085 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6086 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6087 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6088 | if (link_up) { |
| 6089 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 6090 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 6091 | hw->mac.ops.fc_enable(hw, i); |
| 6092 | } else { |
| 6093 | hw->mac.ops.fc_enable(hw, 0); |
| 6094 | } |
| 6095 | } |
| 6096 | |
| 6097 | if (link_up || |
| 6098 | time_after(jiffies, (adapter->link_check_timeout + |
| 6099 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 6100 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6101 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 6102 | IXGBE_WRITE_FLUSH(hw); |
| 6103 | } |
| 6104 | |
| 6105 | adapter->link_up = link_up; |
| 6106 | adapter->link_speed = link_speed; |
| 6107 | } |
| 6108 | |
| 6109 | /** |
| 6110 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 6111 | * print link up message |
| 6112 | * @adapter - pointer to the device adapter structure |
| 6113 | **/ |
| 6114 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 6115 | { |
| 6116 | struct net_device *netdev = adapter->netdev; |
| 6117 | struct ixgbe_hw *hw = &adapter->hw; |
| 6118 | u32 link_speed = adapter->link_speed; |
| 6119 | bool flow_rx, flow_tx; |
| 6120 | |
| 6121 | /* only continue if link was previously down */ |
| 6122 | if (netif_carrier_ok(netdev)) |
| 6123 | return; |
| 6124 | |
| 6125 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6126 | |
| 6127 | switch (hw->mac.type) { |
| 6128 | case ixgbe_mac_82598EB: { |
| 6129 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6130 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 6131 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 6132 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 6133 | } |
| 6134 | break; |
| 6135 | case ixgbe_mac_X540: |
| 6136 | case ixgbe_mac_82599EB: { |
| 6137 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 6138 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 6139 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 6140 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 6141 | } |
| 6142 | break; |
| 6143 | default: |
| 6144 | flow_tx = false; |
| 6145 | flow_rx = false; |
| 6146 | break; |
| 6147 | } |
| 6148 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 6149 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 6150 | "10 Gbps" : |
| 6151 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 6152 | "1 Gbps" : |
| 6153 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6154 | "100 Mbps" : |
| 6155 | "unknown speed"))), |
| 6156 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6157 | (flow_rx ? "RX" : |
| 6158 | (flow_tx ? "TX" : "None")))); |
| 6159 | |
| 6160 | netif_carrier_on(netdev); |
| 6161 | #ifdef HAVE_IPLINK_VF_CONFIG |
| 6162 | ixgbe_check_vf_rate_limit(adapter); |
| 6163 | #endif /* HAVE_IPLINK_VF_CONFIG */ |
| 6164 | } |
| 6165 | |
| 6166 | /** |
| 6167 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6168 | * print link down message |
| 6169 | * @adapter - pointer to the adapter structure |
| 6170 | **/ |
| 6171 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) |
| 6172 | { |
| 6173 | struct net_device *netdev = adapter->netdev; |
| 6174 | struct ixgbe_hw *hw = &adapter->hw; |
| 6175 | |
| 6176 | adapter->link_up = false; |
| 6177 | adapter->link_speed = 0; |
| 6178 | |
| 6179 | /* only continue if link was up previously */ |
| 6180 | if (!netif_carrier_ok(netdev)) |
| 6181 | return; |
| 6182 | |
| 6183 | /* poll for SFP+ cable when link is down */ |
| 6184 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6185 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6186 | |
| 6187 | e_info(drv, "NIC Link is Down\n"); |
| 6188 | netif_carrier_off(netdev); |
| 6189 | } |
| 6190 | |
| 6191 | /** |
| 6192 | * ixgbe_watchdog_flush_tx - flush queues on link down |
| 6193 | * @adapter - pointer to the device adapter structure |
| 6194 | **/ |
| 6195 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6196 | { |
| 6197 | int i; |
| 6198 | int some_tx_pending = 0; |
| 6199 | |
| 6200 | if (!netif_carrier_ok(adapter->netdev)) { |
| 6201 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6202 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6203 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 6204 | some_tx_pending = 1; |
| 6205 | break; |
| 6206 | } |
| 6207 | } |
| 6208 | |
| 6209 | if (some_tx_pending) { |
| 6210 | /* We've lost link, so the controller stops DMA, |
| 6211 | * but we've got queued Tx work that's never going |
| 6212 | * to get done, so reset controller to flush Tx. |
| 6213 | * (Do the reset outside of interrupt context). |
| 6214 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6215 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6216 | } |
| 6217 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6218 | } |
| 6219 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6220 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6221 | { |
| 6222 | u32 ssvpc; |
| 6223 | |
| 6224 | /* Do not perform spoof check for 82598 */ |
| 6225 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6226 | return; |
| 6227 | |
| 6228 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6229 | |
| 6230 | /* |
| 6231 | * ssvpc register is cleared on read, if zero then no |
| 6232 | * spoofed packets in the last interval. |
| 6233 | */ |
| 6234 | if (!ssvpc) |
| 6235 | return; |
| 6236 | |
| 6237 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); |
| 6238 | } |
| 6239 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6240 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6241 | * ixgbe_watchdog_subtask - check and bring link up |
| 6242 | * @adapter - pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6243 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6244 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6245 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6246 | /* if interface is down do nothing */ |
| 6247 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6248 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6249 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6250 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6251 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6252 | if (adapter->link_up) |
| 6253 | ixgbe_watchdog_link_is_up(adapter); |
| 6254 | else |
| 6255 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6256 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6257 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6258 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6259 | |
| 6260 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6261 | } |
| 6262 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6263 | /** |
| 6264 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
| 6265 | * @adapter - the ixgbe adapter structure |
| 6266 | **/ |
| 6267 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6268 | { |
| 6269 | struct ixgbe_hw *hw = &adapter->hw; |
| 6270 | s32 err; |
| 6271 | |
| 6272 | /* not searching for SFP so there is nothing to do here */ |
| 6273 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6274 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6275 | return; |
| 6276 | |
| 6277 | /* someone else is in init, wait until next service event */ |
| 6278 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6279 | return; |
| 6280 | |
| 6281 | err = hw->phy.ops.identify_sfp(hw); |
| 6282 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6283 | goto sfp_out; |
| 6284 | |
| 6285 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6286 | /* If no cable is present, then we need to reset |
| 6287 | * the next time we find a good cable. */ |
| 6288 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6289 | } |
| 6290 | |
| 6291 | /* exit on error */ |
| 6292 | if (err) |
| 6293 | goto sfp_out; |
| 6294 | |
| 6295 | /* exit if reset not needed */ |
| 6296 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6297 | goto sfp_out; |
| 6298 | |
| 6299 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6300 | |
| 6301 | /* |
| 6302 | * A module may be identified correctly, but the EEPROM may not have |
| 6303 | * support for that module. setup_sfp() will fail in that case, so |
| 6304 | * we should not allow that module to load. |
| 6305 | */ |
| 6306 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6307 | err = hw->phy.ops.reset(hw); |
| 6308 | else |
| 6309 | err = hw->mac.ops.setup_sfp(hw); |
| 6310 | |
| 6311 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6312 | goto sfp_out; |
| 6313 | |
| 6314 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6315 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6316 | |
| 6317 | sfp_out: |
| 6318 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6319 | |
| 6320 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6321 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6322 | e_dev_err("failed to initialize because an unsupported " |
| 6323 | "SFP+ module type was detected.\n"); |
| 6324 | e_dev_err("Reload the driver after installing a " |
| 6325 | "supported module.\n"); |
| 6326 | unregister_netdev(adapter->netdev); |
| 6327 | } |
| 6328 | } |
| 6329 | |
| 6330 | /** |
| 6331 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
| 6332 | * @adapter - the ixgbe adapter structure |
| 6333 | **/ |
| 6334 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6335 | { |
| 6336 | struct ixgbe_hw *hw = &adapter->hw; |
| 6337 | u32 autoneg; |
| 6338 | bool negotiation; |
| 6339 | |
| 6340 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6341 | return; |
| 6342 | |
| 6343 | /* someone else is in init, wait until next service event */ |
| 6344 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6345 | return; |
| 6346 | |
| 6347 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6348 | |
| 6349 | autoneg = hw->phy.autoneg_advertised; |
| 6350 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 6351 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 6352 | hw->mac.autotry_restart = false; |
| 6353 | if (hw->mac.ops.setup_link) |
| 6354 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 6355 | |
| 6356 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6357 | adapter->link_check_timeout = jiffies; |
| 6358 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6359 | } |
| 6360 | |
| 6361 | /** |
| 6362 | * ixgbe_service_timer - Timer Call-back |
| 6363 | * @data: pointer to adapter cast into an unsigned long |
| 6364 | **/ |
| 6365 | static void ixgbe_service_timer(unsigned long data) |
| 6366 | { |
| 6367 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6368 | unsigned long next_event_offset; |
| 6369 | |
| 6370 | /* poll faster when waiting for link */ |
| 6371 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6372 | next_event_offset = HZ / 10; |
| 6373 | else |
| 6374 | next_event_offset = HZ * 2; |
| 6375 | |
| 6376 | /* Reset the timer */ |
| 6377 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6378 | |
| 6379 | ixgbe_service_event_schedule(adapter); |
| 6380 | } |
| 6381 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6382 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6383 | { |
| 6384 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6385 | return; |
| 6386 | |
| 6387 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6388 | |
| 6389 | /* If we're already down or resetting, just bail */ |
| 6390 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6391 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6392 | return; |
| 6393 | |
| 6394 | ixgbe_dump(adapter); |
| 6395 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6396 | adapter->tx_timeout_count++; |
| 6397 | |
| 6398 | ixgbe_reinit_locked(adapter); |
| 6399 | } |
| 6400 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6401 | /** |
| 6402 | * ixgbe_service_task - manages and runs subtasks |
| 6403 | * @work: pointer to work_struct containing our data |
| 6404 | **/ |
| 6405 | static void ixgbe_service_task(struct work_struct *work) |
| 6406 | { |
| 6407 | struct ixgbe_adapter *adapter = container_of(work, |
| 6408 | struct ixgbe_adapter, |
| 6409 | service_task); |
| 6410 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6411 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6412 | ixgbe_sfp_detection_subtask(adapter); |
| 6413 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6414 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6415 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6416 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6417 | ixgbe_check_hang_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6418 | |
| 6419 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6420 | } |
| 6421 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6422 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6423 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6424 | u32 tx_flags, u8 *hdr_len, __be16 protocol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6425 | { |
| 6426 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 6427 | unsigned int i; |
| 6428 | int err; |
| 6429 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6430 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 6431 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6432 | |
| 6433 | if (skb_is_gso(skb)) { |
| 6434 | if (skb_header_cloned(skb)) { |
| 6435 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 6436 | if (err) |
| 6437 | return err; |
| 6438 | } |
| 6439 | l4len = tcp_hdrlen(skb); |
| 6440 | *hdr_len += l4len; |
| 6441 | |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6442 | if (protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6443 | struct iphdr *iph = ip_hdr(skb); |
| 6444 | iph->tot_len = 0; |
| 6445 | iph->check = 0; |
| 6446 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6447 | iph->daddr, 0, |
| 6448 | IPPROTO_TCP, |
| 6449 | 0); |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 6450 | } else if (skb_is_gso_v6(skb)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6451 | ipv6_hdr(skb)->payload_len = 0; |
| 6452 | tcp_hdr(skb)->check = |
| 6453 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6454 | &ipv6_hdr(skb)->daddr, |
| 6455 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6456 | } |
| 6457 | |
| 6458 | i = tx_ring->next_to_use; |
| 6459 | |
| 6460 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 6461 | context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6462 | |
| 6463 | /* VLAN MACLEN IPLEN */ |
| 6464 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 6465 | vlan_macip_lens |= |
| 6466 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 6467 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6468 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6469 | *hdr_len += skb_network_offset(skb); |
| 6470 | vlan_macip_lens |= |
| 6471 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 6472 | *hdr_len += |
| 6473 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 6474 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6475 | context_desc->seqnum_seed = 0; |
| 6476 | |
| 6477 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6478 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6479 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6480 | |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6481 | if (protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6482 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6483 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6484 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 6485 | |
| 6486 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6487 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6488 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 6489 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 6490 | /* use index 1 for TSO */ |
| 6491 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6492 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 6493 | |
| 6494 | tx_buffer_info->time_stamp = jiffies; |
| 6495 | tx_buffer_info->next_to_watch = i; |
| 6496 | |
| 6497 | i++; |
| 6498 | if (i == tx_ring->count) |
| 6499 | i = 0; |
| 6500 | tx_ring->next_to_use = i; |
| 6501 | |
| 6502 | return true; |
| 6503 | } |
| 6504 | return false; |
| 6505 | } |
| 6506 | |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6507 | static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 6508 | __be16 protocol) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6509 | { |
| 6510 | u32 rtn = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6511 | |
| 6512 | switch (protocol) { |
| 6513 | case cpu_to_be16(ETH_P_IP): |
| 6514 | rtn |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6515 | switch (ip_hdr(skb)->protocol) { |
| 6516 | case IPPROTO_TCP: |
| 6517 | rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6518 | break; |
| 6519 | case IPPROTO_SCTP: |
| 6520 | rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6521 | break; |
| 6522 | } |
| 6523 | break; |
| 6524 | case cpu_to_be16(ETH_P_IPV6): |
| 6525 | /* XXX what about other V6 headers?? */ |
| 6526 | switch (ipv6_hdr(skb)->nexthdr) { |
| 6527 | case IPPROTO_TCP: |
| 6528 | rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6529 | break; |
| 6530 | case IPPROTO_SCTP: |
| 6531 | rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6532 | break; |
| 6533 | } |
| 6534 | break; |
| 6535 | default: |
| 6536 | if (unlikely(net_ratelimit())) |
| 6537 | e_warn(probe, "partial checksum but proto=%x!\n", |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6538 | protocol); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6539 | break; |
| 6540 | } |
| 6541 | |
| 6542 | return rtn; |
| 6543 | } |
| 6544 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6545 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6546 | struct ixgbe_ring *tx_ring, |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6547 | struct sk_buff *skb, u32 tx_flags, |
| 6548 | __be16 protocol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6549 | { |
| 6550 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 6551 | unsigned int i; |
| 6552 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 6553 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 6554 | |
| 6555 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 6556 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 6557 | i = tx_ring->next_to_use; |
| 6558 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 6559 | context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6560 | |
| 6561 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 6562 | vlan_macip_lens |= |
| 6563 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 6564 | vlan_macip_lens |= (skb_network_offset(skb) << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6565 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6566 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 6567 | vlan_macip_lens |= (skb_transport_header(skb) - |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6568 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6569 | |
| 6570 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6571 | context_desc->seqnum_seed = 0; |
| 6572 | |
| 6573 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6574 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6575 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6576 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6577 | type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6578 | |
| 6579 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 6580 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6581 | context_desc->mss_l4len_idx = 0; |
| 6582 | |
| 6583 | tx_buffer_info->time_stamp = jiffies; |
| 6584 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6585 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6586 | i++; |
| 6587 | if (i == tx_ring->count) |
| 6588 | i = 0; |
| 6589 | tx_ring->next_to_use = i; |
| 6590 | |
| 6591 | return true; |
| 6592 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6593 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6594 | return false; |
| 6595 | } |
| 6596 | |
| 6597 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6598 | struct ixgbe_ring *tx_ring, |
| 6599 | struct sk_buff *skb, u32 tx_flags, |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6600 | unsigned int first, const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6601 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6602 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6603 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6604 | unsigned int len; |
| 6605 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6606 | unsigned int offset = 0, size, count = 0, i; |
| 6607 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 6608 | unsigned int f; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6609 | unsigned int bytecount = skb->len; |
| 6610 | u16 gso_segs = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6611 | |
| 6612 | i = tx_ring->next_to_use; |
| 6613 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6614 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 6615 | /* excluding fcoe_crc_eof for FCoE */ |
| 6616 | total -= sizeof(struct fcoe_crc_eof); |
| 6617 | |
| 6618 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6619 | while (len) { |
| 6620 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6621 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 6622 | |
| 6623 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6624 | tx_buffer_info->mapped_as_page = false; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6625 | tx_buffer_info->dma = dma_map_single(dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6626 | skb->data + offset, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 6627 | size, DMA_TO_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6628 | if (dma_mapping_error(dev, tx_buffer_info->dma)) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6629 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6630 | tx_buffer_info->time_stamp = jiffies; |
| 6631 | tx_buffer_info->next_to_watch = i; |
| 6632 | |
| 6633 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6634 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6635 | offset += size; |
| 6636 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6637 | |
| 6638 | if (len) { |
| 6639 | i++; |
| 6640 | if (i == tx_ring->count) |
| 6641 | i = 0; |
| 6642 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6643 | } |
| 6644 | |
| 6645 | for (f = 0; f < nr_frags; f++) { |
| 6646 | struct skb_frag_struct *frag; |
| 6647 | |
| 6648 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6649 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6650 | offset = frag->page_offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6651 | |
| 6652 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6653 | i++; |
| 6654 | if (i == tx_ring->count) |
| 6655 | i = 0; |
| 6656 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6657 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6658 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 6659 | |
| 6660 | tx_buffer_info->length = size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6661 | tx_buffer_info->dma = dma_map_page(dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6662 | frag->page, |
| 6663 | offset, size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 6664 | DMA_TO_DEVICE); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6665 | tx_buffer_info->mapped_as_page = true; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6666 | if (dma_mapping_error(dev, tx_buffer_info->dma)) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6667 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6668 | tx_buffer_info->time_stamp = jiffies; |
| 6669 | tx_buffer_info->next_to_watch = i; |
| 6670 | |
| 6671 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6672 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6673 | offset += size; |
| 6674 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6675 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6676 | if (total == 0) |
| 6677 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6678 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6679 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6680 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6681 | gso_segs = skb_shinfo(skb)->gso_segs; |
| 6682 | #ifdef IXGBE_FCOE |
| 6683 | /* adjust for FCoE Sequence Offload */ |
| 6684 | else if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6685 | gso_segs = DIV_ROUND_UP(skb->len - hdr_len, |
| 6686 | skb_shinfo(skb)->gso_size); |
| 6687 | #endif /* IXGBE_FCOE */ |
| 6688 | bytecount += (gso_segs - 1) * hdr_len; |
| 6689 | |
| 6690 | /* multiply data chunks by size of headers */ |
| 6691 | tx_ring->tx_buffer_info[i].bytecount = bytecount; |
| 6692 | tx_ring->tx_buffer_info[i].gso_segs = gso_segs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6693 | tx_ring->tx_buffer_info[i].skb = skb; |
| 6694 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 6695 | |
| 6696 | return count; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6697 | |
| 6698 | dma_error: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6699 | e_dev_err("TX DMA map failed\n"); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6700 | |
| 6701 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 6702 | tx_buffer_info->dma = 0; |
| 6703 | tx_buffer_info->time_stamp = 0; |
| 6704 | tx_buffer_info->next_to_watch = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6705 | if (count) |
| 6706 | count--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6707 | |
| 6708 | /* clear timestamp and dma mappings for remaining portion of packet */ |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6709 | while (count--) { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6710 | if (i == 0) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6711 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6712 | i--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6713 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6714 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6715 | } |
| 6716 | |
Anton Blanchard | e44d38e | 2010-02-03 13:12:51 +0000 | [diff] [blame] | 6717 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6718 | } |
| 6719 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6720 | static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6721 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6722 | { |
| 6723 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 6724 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 6725 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 6726 | unsigned int i; |
| 6727 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 6728 | |
| 6729 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 6730 | |
| 6731 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 6732 | |
| 6733 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 6734 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 6735 | |
| 6736 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 6737 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 6738 | |
| 6739 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6740 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6741 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 6742 | /* use index 1 context for tso */ |
| 6743 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6744 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6745 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6746 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6747 | |
| 6748 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6749 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6750 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6751 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6752 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6753 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 6754 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 6755 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6756 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 6757 | } |
| 6758 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6759 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 6760 | |
| 6761 | i = tx_ring->next_to_use; |
| 6762 | while (count--) { |
| 6763 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 6764 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6765 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 6766 | tx_desc->read.cmd_type_len = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6767 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6768 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6769 | i++; |
| 6770 | if (i == tx_ring->count) |
| 6771 | i = 0; |
| 6772 | } |
| 6773 | |
| 6774 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 6775 | |
| 6776 | /* |
| 6777 | * Force memory writes to complete before letting h/w |
| 6778 | * know there are new descriptors to fetch. (Only |
| 6779 | * applicable for weak-ordered memory model archs, |
| 6780 | * such as IA-64). |
| 6781 | */ |
| 6782 | wmb(); |
| 6783 | |
| 6784 | tx_ring->next_to_use = i; |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6785 | writel(i, tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6786 | } |
| 6787 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6788 | static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb, |
| 6789 | u32 tx_flags, __be16 protocol) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6790 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6791 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6792 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6793 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6794 | union { |
| 6795 | unsigned char *network; |
| 6796 | struct iphdr *ipv4; |
| 6797 | struct ipv6hdr *ipv6; |
| 6798 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6799 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6800 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6801 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6802 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6803 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6804 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6805 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6806 | /* do nothing if sampling is disabled */ |
| 6807 | if (!ring->atr_sample_rate) |
| 6808 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6809 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6810 | ring->atr_count++; |
| 6811 | |
| 6812 | /* snag network header to get L4 type and address */ |
| 6813 | hdr.network = skb_network_header(skb); |
| 6814 | |
| 6815 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 6816 | if ((protocol != __constant_htons(ETH_P_IPV6) || |
| 6817 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
| 6818 | (protocol != __constant_htons(ETH_P_IP) || |
| 6819 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6820 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6821 | |
| 6822 | th = tcp_hdr(skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6823 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6824 | /* skip this packet since the socket is closing */ |
| 6825 | if (th->fin) |
| 6826 | return; |
| 6827 | |
| 6828 | /* sample on all syn packets or once every atr sample count */ |
| 6829 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6830 | return; |
| 6831 | |
| 6832 | /* reset sample count */ |
| 6833 | ring->atr_count = 0; |
| 6834 | |
| 6835 | vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6836 | |
| 6837 | /* |
| 6838 | * src and dst are inverted, think how the receiver sees them |
| 6839 | * |
| 6840 | * The input is broken into two sections, a non-compressed section |
| 6841 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6842 | * is XORed together and stored in the compressed dword. |
| 6843 | */ |
| 6844 | input.formatted.vlan_id = vlan_id; |
| 6845 | |
| 6846 | /* |
| 6847 | * since src port and flex bytes occupy the same word XOR them together |
| 6848 | * and write the value to source port portion of compressed dword |
| 6849 | */ |
| 6850 | if (vlan_id) |
| 6851 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6852 | else |
| 6853 | common.port.src ^= th->dest ^ protocol; |
| 6854 | common.port.dst ^= th->source; |
| 6855 | |
| 6856 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6857 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6858 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6859 | } else { |
| 6860 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6861 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6862 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6863 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6864 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6865 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6866 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6867 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6868 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6869 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6870 | |
| 6871 | /* 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] | 6872 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6873 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6874 | } |
| 6875 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6876 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6877 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6878 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6879 | /* Herbert's original patch had: |
| 6880 | * smp_mb__after_netif_stop_queue(); |
| 6881 | * but since that doesn't exist yet, just open code it. */ |
| 6882 | smp_mb(); |
| 6883 | |
| 6884 | /* We need to check again in a case another CPU has just |
| 6885 | * made room available. */ |
| 6886 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 6887 | return -EBUSY; |
| 6888 | |
| 6889 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6890 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6891 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6892 | return 0; |
| 6893 | } |
| 6894 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6895 | static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6896 | { |
| 6897 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 6898 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6899 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6900 | } |
| 6901 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6902 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 6903 | { |
| 6904 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6905 | int txq = smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6906 | #ifdef IXGBE_FCOE |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6907 | __be16 protocol; |
| 6908 | |
| 6909 | protocol = vlan_get_protocol(skb); |
| 6910 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6911 | if (((protocol == htons(ETH_P_FCOE)) || |
| 6912 | (protocol == htons(ETH_P_FIP))) && |
| 6913 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
| 6914 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 6915 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 6916 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6917 | } |
| 6918 | #endif |
| 6919 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6920 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 6921 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 6922 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6923 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6924 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6925 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6926 | return skb_tx_hash(dev, skb); |
| 6927 | } |
| 6928 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6929 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6930 | struct ixgbe_adapter *adapter, |
| 6931 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6932 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6933 | unsigned int first; |
| 6934 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 6935 | u8 hdr_len = 0; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6936 | int tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6937 | int count = 0; |
| 6938 | unsigned int f; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6939 | __be16 protocol; |
| 6940 | |
| 6941 | protocol = vlan_get_protocol(skb); |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6942 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 6943 | if (vlan_tx_tag_present(skb)) { |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6944 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6945 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 6946 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6947 | tx_flags |= tx_ring->dcb_tc << 13; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6948 | } |
| 6949 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6950 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
John Fastabend | 33c66bd | 2010-05-18 16:00:11 +0000 | [diff] [blame] | 6951 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED && |
| 6952 | skb->priority != TC_PRIO_CONTROL) { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6953 | tx_flags |= tx_ring->dcb_tc << 13; |
John Fastabend | 2ea186a | 2010-02-27 03:28:24 -0800 | [diff] [blame] | 6954 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6955 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6956 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6957 | |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 6958 | #ifdef IXGBE_FCOE |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6959 | /* for FCoE with DCB, we force the priority to what |
| 6960 | * was specified by the switch */ |
| 6961 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED && |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6962 | (protocol == htons(ETH_P_FCOE))) |
| 6963 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Robert Love | ca77cd5 | 2010-03-24 12:45:00 +0000 | [diff] [blame] | 6964 | #endif |
| 6965 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6966 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6967 | if (skb_is_gso(skb) || |
| 6968 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6969 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 6970 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6971 | count++; |
| 6972 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6973 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 6974 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6975 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 6976 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6977 | if (ixgbe_maybe_stop_tx(tx_ring, count)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6978 | tx_ring->tx_stats.tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6979 | return NETDEV_TX_BUSY; |
| 6980 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6981 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6982 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6983 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6984 | #ifdef IXGBE_FCOE |
| 6985 | /* setup tx offload for FCoE */ |
| 6986 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 6987 | if (tso < 0) { |
| 6988 | dev_kfree_skb_any(skb); |
| 6989 | return NETDEV_TX_OK; |
| 6990 | } |
| 6991 | if (tso) |
| 6992 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 6993 | #endif /* IXGBE_FCOE */ |
| 6994 | } else { |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6995 | if (protocol == htons(ETH_P_IP)) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6996 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6997 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len, |
| 6998 | protocol); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6999 | if (tso < 0) { |
| 7000 | dev_kfree_skb_any(skb); |
| 7001 | return NETDEV_TX_OK; |
| 7002 | } |
| 7003 | |
| 7004 | if (tso) |
| 7005 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 7006 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags, |
| 7007 | protocol) && |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7008 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 7009 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7010 | } |
| 7011 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 7012 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7013 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7014 | /* add the ATR filter if ATR is on */ |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 7015 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
| 7016 | ixgbe_atr(tx_ring, skb, tx_flags, protocol); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 7017 | ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7018 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7019 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7020 | } else { |
| 7021 | dev_kfree_skb_any(skb); |
| 7022 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 7023 | tx_ring->next_to_use = first; |
| 7024 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7025 | |
| 7026 | return NETDEV_TX_OK; |
| 7027 | } |
| 7028 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7029 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 7030 | { |
| 7031 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7032 | struct ixgbe_ring *tx_ring; |
| 7033 | |
| 7034 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 7035 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 7036 | } |
| 7037 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7038 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7039 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 7040 | * @netdev: network interface device structure |
| 7041 | * @p: pointer to an address structure |
| 7042 | * |
| 7043 | * Returns 0 on success, negative on failure |
| 7044 | **/ |
| 7045 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7046 | { |
| 7047 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7048 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7049 | struct sockaddr *addr = p; |
| 7050 | |
| 7051 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7052 | return -EADDRNOTAVAIL; |
| 7053 | |
| 7054 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7055 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7056 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7057 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 7058 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7059 | |
| 7060 | return 0; |
| 7061 | } |
| 7062 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7063 | static int |
| 7064 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7065 | { |
| 7066 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7067 | struct ixgbe_hw *hw = &adapter->hw; |
| 7068 | u16 value; |
| 7069 | int rc; |
| 7070 | |
| 7071 | if (prtad != hw->phy.mdio.prtad) |
| 7072 | return -EINVAL; |
| 7073 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7074 | if (!rc) |
| 7075 | rc = value; |
| 7076 | return rc; |
| 7077 | } |
| 7078 | |
| 7079 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7080 | u16 addr, u16 value) |
| 7081 | { |
| 7082 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7083 | struct ixgbe_hw *hw = &adapter->hw; |
| 7084 | |
| 7085 | if (prtad != hw->phy.mdio.prtad) |
| 7086 | return -EINVAL; |
| 7087 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7088 | } |
| 7089 | |
| 7090 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7091 | { |
| 7092 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7093 | |
| 7094 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 7095 | } |
| 7096 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7097 | /** |
| 7098 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7099 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7100 | * @netdev: network interface device structure |
| 7101 | * |
| 7102 | * Returns non-zero on failure |
| 7103 | **/ |
| 7104 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 7105 | { |
| 7106 | int err = 0; |
| 7107 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7108 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7109 | |
| 7110 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7111 | rtnl_lock(); |
| 7112 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7113 | rtnl_unlock(); |
| 7114 | } |
| 7115 | return err; |
| 7116 | } |
| 7117 | |
| 7118 | /** |
| 7119 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7120 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7121 | * @netdev: network interface device structure |
| 7122 | * |
| 7123 | * Returns non-zero on failure |
| 7124 | **/ |
| 7125 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 7126 | { |
| 7127 | int err = 0; |
| 7128 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7129 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7130 | |
| 7131 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7132 | rtnl_lock(); |
| 7133 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7134 | rtnl_unlock(); |
| 7135 | } |
| 7136 | return err; |
| 7137 | } |
| 7138 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7139 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7140 | /* |
| 7141 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7142 | * without having to re-enable interrupts. It's not called while |
| 7143 | * the interrupt routine is executing. |
| 7144 | */ |
| 7145 | static void ixgbe_netpoll(struct net_device *netdev) |
| 7146 | { |
| 7147 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7148 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7149 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 7150 | /* if interface is down do nothing */ |
| 7151 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 7152 | return; |
| 7153 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7154 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7155 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 7156 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 7157 | for (i = 0; i < num_q_vectors; i++) { |
| 7158 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 7159 | ixgbe_msix_clean_many(0, q_vector); |
| 7160 | } |
| 7161 | } else { |
| 7162 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 7163 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7164 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7165 | } |
| 7166 | #endif |
| 7167 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7168 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 7169 | struct rtnl_link_stats64 *stats) |
| 7170 | { |
| 7171 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7172 | int i; |
| 7173 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7174 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7175 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7176 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7177 | u64 bytes, packets; |
| 7178 | unsigned int start; |
| 7179 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7180 | if (ring) { |
| 7181 | do { |
| 7182 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7183 | packets = ring->stats.packets; |
| 7184 | bytes = ring->stats.bytes; |
| 7185 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7186 | stats->rx_packets += packets; |
| 7187 | stats->rx_bytes += bytes; |
| 7188 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7189 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7190 | |
| 7191 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7192 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7193 | u64 bytes, packets; |
| 7194 | unsigned int start; |
| 7195 | |
| 7196 | if (ring) { |
| 7197 | do { |
| 7198 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7199 | packets = ring->stats.packets; |
| 7200 | bytes = ring->stats.bytes; |
| 7201 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7202 | stats->tx_packets += packets; |
| 7203 | stats->tx_bytes += bytes; |
| 7204 | } |
| 7205 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7206 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7207 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7208 | stats->multicast = netdev->stats.multicast; |
| 7209 | stats->rx_errors = netdev->stats.rx_errors; |
| 7210 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7211 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7212 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7213 | return stats; |
| 7214 | } |
| 7215 | |
| 7216 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7217 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7218 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7219 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7220 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7221 | .ndo_select_queue = ixgbe_select_queue, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 7222 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7223 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 7224 | .ndo_validate_addr = eth_validate_addr, |
| 7225 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7226 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7227 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7228 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7229 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7230 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7231 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7232 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7233 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
| 7234 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7235 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7236 | #ifdef CONFIG_IXGBE_DCB |
| 7237 | .ndo_setup_tc = ixgbe_setup_tc, |
| 7238 | #endif |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7239 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7240 | .ndo_poll_controller = ixgbe_netpoll, |
| 7241 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7242 | #ifdef IXGBE_FCOE |
| 7243 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7244 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7245 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7246 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7247 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7248 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7249 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7250 | }; |
| 7251 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7252 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 7253 | const struct ixgbe_info *ii) |
| 7254 | { |
| 7255 | #ifdef CONFIG_PCI_IOV |
| 7256 | struct ixgbe_hw *hw = &adapter->hw; |
| 7257 | int err; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 7258 | int num_vf_macvlans, i; |
| 7259 | struct vf_macvlans *mv_list; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7260 | |
Greg Rose | 3377eba79 | 2010-12-07 08:16:45 +0000 | [diff] [blame] | 7261 | if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs) |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7262 | return; |
| 7263 | |
| 7264 | /* The 82599 supports up to 64 VFs per physical function |
| 7265 | * but this implementation limits allocation to 63 so that |
| 7266 | * basic networking resources are still available to the |
| 7267 | * physical function |
| 7268 | */ |
| 7269 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
| 7270 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
| 7271 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 7272 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7273 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7274 | goto err_novfs; |
| 7275 | } |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 7276 | |
| 7277 | num_vf_macvlans = hw->mac.num_rar_entries - |
| 7278 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); |
| 7279 | |
| 7280 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, |
| 7281 | sizeof(struct vf_macvlans), |
| 7282 | GFP_KERNEL); |
| 7283 | if (mv_list) { |
| 7284 | /* Initialize list of VF macvlans */ |
| 7285 | INIT_LIST_HEAD(&adapter->vf_mvs.l); |
| 7286 | for (i = 0; i < num_vf_macvlans; i++) { |
| 7287 | mv_list->vf = -1; |
| 7288 | mv_list->free = true; |
| 7289 | mv_list->rar_entry = hw->mac.num_rar_entries - |
| 7290 | (i + adapter->num_vfs + 1); |
| 7291 | list_add(&mv_list->l, &adapter->vf_mvs.l); |
| 7292 | mv_list++; |
| 7293 | } |
| 7294 | } |
| 7295 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7296 | /* If call to enable VFs succeeded then allocate memory |
| 7297 | * for per VF control structures. |
| 7298 | */ |
| 7299 | adapter->vfinfo = |
| 7300 | kcalloc(adapter->num_vfs, |
| 7301 | sizeof(struct vf_data_storage), GFP_KERNEL); |
| 7302 | if (adapter->vfinfo) { |
| 7303 | /* Now that we're sure SR-IOV is enabled |
| 7304 | * and memory allocated set up the mailbox parameters |
| 7305 | */ |
| 7306 | ixgbe_init_mbx_params_pf(hw); |
| 7307 | memcpy(&hw->mbx.ops, ii->mbx_ops, |
| 7308 | sizeof(hw->mbx.ops)); |
| 7309 | |
| 7310 | /* Disable RSC when in SR-IOV mode */ |
| 7311 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | |
| 7312 | IXGBE_FLAG2_RSC_ENABLED); |
| 7313 | return; |
| 7314 | } |
| 7315 | |
| 7316 | /* Oh oh */ |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7317 | e_err(probe, "Unable to allocate memory for VF Data Storage - " |
| 7318 | "SRIOV disabled\n"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7319 | pci_disable_sriov(adapter->pdev); |
| 7320 | |
| 7321 | err_novfs: |
| 7322 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 7323 | adapter->num_vfs = 0; |
| 7324 | #endif /* CONFIG_PCI_IOV */ |
| 7325 | } |
| 7326 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7327 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7328 | * ixgbe_probe - Device Initialization Routine |
| 7329 | * @pdev: PCI device information struct |
| 7330 | * @ent: entry in ixgbe_pci_tbl |
| 7331 | * |
| 7332 | * Returns 0 on success, negative on failure |
| 7333 | * |
| 7334 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7335 | * The OS initialization, configuring of the adapter private structure, |
| 7336 | * and a hardware reset occur. |
| 7337 | **/ |
| 7338 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7339 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7340 | { |
| 7341 | struct net_device *netdev; |
| 7342 | struct ixgbe_adapter *adapter = NULL; |
| 7343 | struct ixgbe_hw *hw; |
| 7344 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7345 | static int cards_found; |
| 7346 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7347 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7348 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7349 | #ifdef IXGBE_FCOE |
| 7350 | u16 device_caps; |
| 7351 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7352 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7353 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7354 | /* Catch broken hardware that put the wrong VF device ID in |
| 7355 | * the PCIe SR-IOV capability. |
| 7356 | */ |
| 7357 | if (pdev->is_virtfn) { |
| 7358 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7359 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7360 | return -EINVAL; |
| 7361 | } |
| 7362 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7363 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7364 | if (err) |
| 7365 | return err; |
| 7366 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7367 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7368 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7369 | pci_using_dac = 1; |
| 7370 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7371 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7372 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7373 | err = dma_set_coherent_mask(&pdev->dev, |
| 7374 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7375 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7376 | dev_err(&pdev->dev, |
| 7377 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7378 | goto err_dma; |
| 7379 | } |
| 7380 | } |
| 7381 | pci_using_dac = 0; |
| 7382 | } |
| 7383 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7384 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7385 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7386 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7387 | dev_err(&pdev->dev, |
| 7388 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7389 | goto err_pci_reg; |
| 7390 | } |
| 7391 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7392 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7393 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7394 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7395 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7396 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7397 | if (ii->mac == ixgbe_mac_82598EB) |
| 7398 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7399 | else |
| 7400 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7401 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 7402 | #if defined(CONFIG_DCB) |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7403 | indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 7404 | #elif defined(IXGBE_FCOE) |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7405 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7406 | IXGBE_MAX_FCOE_INDICES); |
| 7407 | #endif |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7408 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7409 | if (!netdev) { |
| 7410 | err = -ENOMEM; |
| 7411 | goto err_alloc_etherdev; |
| 7412 | } |
| 7413 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7414 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7415 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7416 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7417 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7418 | |
| 7419 | adapter->netdev = netdev; |
| 7420 | adapter->pdev = pdev; |
| 7421 | hw = &adapter->hw; |
| 7422 | hw->back = adapter; |
| 7423 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 7424 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7425 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7426 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7427 | if (!hw->hw_addr) { |
| 7428 | err = -EIO; |
| 7429 | goto err_ioremap; |
| 7430 | } |
| 7431 | |
| 7432 | for (i = 1; i <= 5; i++) { |
| 7433 | if (pci_resource_len(pdev, i) == 0) |
| 7434 | continue; |
| 7435 | } |
| 7436 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7437 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7438 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7439 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7440 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7441 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7442 | adapter->bd_number = cards_found; |
| 7443 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7444 | /* Setup hw api */ |
| 7445 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7446 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7447 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7448 | /* EEPROM */ |
| 7449 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7450 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7451 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7452 | if (!(eec & (1 << 8))) |
| 7453 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7454 | |
| 7455 | /* PHY */ |
| 7456 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7457 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7458 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7459 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7460 | hw->phy.mdio.mmds = 0; |
| 7461 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7462 | hw->phy.mdio.dev = netdev; |
| 7463 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7464 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7465 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7466 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7467 | |
| 7468 | /* setup the private structure */ |
| 7469 | err = ixgbe_sw_init(adapter); |
| 7470 | if (err) |
| 7471 | goto err_sw_init; |
| 7472 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7473 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7474 | switch (adapter->hw.mac.type) { |
| 7475 | case ixgbe_mac_82599EB: |
| 7476 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7477 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7478 | break; |
| 7479 | default: |
| 7480 | break; |
| 7481 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7482 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7483 | /* |
| 7484 | * If there is a fan on this device and it has failed log the |
| 7485 | * failure. |
| 7486 | */ |
| 7487 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7488 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7489 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7490 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7491 | } |
| 7492 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7493 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7494 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7495 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7496 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7497 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7498 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7499 | err = 0; |
| 7500 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7501 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7502 | "module type was detected.\n"); |
| 7503 | e_dev_err("Reload the driver after installing a supported " |
| 7504 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7505 | goto err_sw_init; |
| 7506 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7507 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7508 | goto err_sw_init; |
| 7509 | } |
| 7510 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7511 | ixgbe_probe_vf(adapter, ii); |
| 7512 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7513 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7514 | NETIF_F_IP_CSUM | |
| 7515 | NETIF_F_HW_VLAN_TX | |
| 7516 | NETIF_F_HW_VLAN_RX | |
| 7517 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7518 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 7519 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7520 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7521 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 7522 | netdev->features |= NETIF_F_GRO; |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7523 | netdev->features |= NETIF_F_RXHASH; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7524 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7525 | switch (adapter->hw.mac.type) { |
| 7526 | case ixgbe_mac_82599EB: |
| 7527 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7528 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7529 | break; |
| 7530 | default: |
| 7531 | break; |
| 7532 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7533 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7534 | netdev->vlan_features |= NETIF_F_TSO; |
| 7535 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7536 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7537 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7538 | netdev->vlan_features |= NETIF_F_SG; |
| 7539 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7540 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7541 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 7542 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7543 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7544 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7545 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7546 | #endif |
| 7547 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7548 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7549 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7550 | if (hw->mac.ops.get_device_caps) { |
| 7551 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7552 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7553 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7554 | } |
| 7555 | } |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7556 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
| 7557 | netdev->vlan_features |= NETIF_F_FCOE_CRC; |
| 7558 | netdev->vlan_features |= NETIF_F_FSO; |
| 7559 | netdev->vlan_features |= NETIF_F_FCOE_MTU; |
| 7560 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7561 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7562 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7563 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7564 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7565 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7566 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7567 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7568 | netdev->features |= NETIF_F_LRO; |
| 7569 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7570 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7571 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7572 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7573 | err = -EIO; |
| 7574 | goto err_eeprom; |
| 7575 | } |
| 7576 | |
| 7577 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7578 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7579 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7580 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7581 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7582 | err = -EIO; |
| 7583 | goto err_eeprom; |
| 7584 | } |
| 7585 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 7586 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 7587 | if (hw->mac.ops.disable_tx_laser && |
| 7588 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 7589 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 7590 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 7591 | hw->mac.ops.disable_tx_laser(hw); |
| 7592 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7593 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
| 7594 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7595 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7596 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7597 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7598 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7599 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7600 | if (err) |
| 7601 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7602 | |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7603 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 7604 | netdev->features &= ~NETIF_F_RXHASH; |
| 7605 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7606 | switch (pdev->device) { |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7607 | case IXGBE_DEV_ID_82599_SFP: |
| 7608 | /* Only this subdevice supports WOL */ |
| 7609 | if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP) |
| 7610 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 7611 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
| 7612 | break; |
Alexander Duyck | 50d6c68 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 7613 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7614 | /* All except this subdevice support WOL */ |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7615 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
| 7616 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 7617 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
| 7618 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7619 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 7620 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7621 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7622 | break; |
| 7623 | default: |
| 7624 | adapter->wol = 0; |
| 7625 | break; |
| 7626 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7627 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7628 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7629 | /* pick up the PCI bus settings for reporting later */ |
| 7630 | hw->mac.ops.get_bus_info(hw); |
| 7631 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7632 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7633 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7634 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7635 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7636 | "Unknown"), |
| 7637 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7638 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7639 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7640 | "Unknown"), |
| 7641 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7642 | |
| 7643 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7644 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7645 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7646 | 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] | 7647 | 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] | 7648 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7649 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7650 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7651 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7652 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7653 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7654 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7655 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7656 | "not sufficient for optimal performance.\n"); |
| 7657 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7658 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7659 | } |
| 7660 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 7661 | /* save off EEPROM version number */ |
| 7662 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 7663 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7664 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7665 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7666 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7667 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7668 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7669 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7670 | "Please be aware there may be issues associated " |
| 7671 | "with your hardware. If you are experiencing " |
| 7672 | "problems please contact your Intel or hardware " |
| 7673 | "representative who provided you with this " |
| 7674 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7675 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7676 | strcpy(netdev->name, "eth%d"); |
| 7677 | err = register_netdev(netdev); |
| 7678 | if (err) |
| 7679 | goto err_register; |
| 7680 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 7681 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7682 | netif_carrier_off(netdev); |
| 7683 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7684 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 7685 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7686 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7687 | ixgbe_setup_dca(adapter); |
| 7688 | } |
| 7689 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7690 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7691 | 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] | 7692 | for (i = 0; i < adapter->num_vfs; i++) |
| 7693 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 7694 | } |
| 7695 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7696 | /* add san mac addr to netdev */ |
| 7697 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7698 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7699 | e_dev_info("Intel(R) 10 Gigabit Network Connection\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7700 | cards_found++; |
| 7701 | return 0; |
| 7702 | |
| 7703 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7704 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7705 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7706 | err_sw_init: |
| 7707 | err_eeprom: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7708 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7709 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7710 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7711 | iounmap(hw->hw_addr); |
| 7712 | err_ioremap: |
| 7713 | free_netdev(netdev); |
| 7714 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7715 | pci_release_selected_regions(pdev, |
| 7716 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7717 | err_pci_reg: |
| 7718 | err_dma: |
| 7719 | pci_disable_device(pdev); |
| 7720 | return err; |
| 7721 | } |
| 7722 | |
| 7723 | /** |
| 7724 | * ixgbe_remove - Device Removal Routine |
| 7725 | * @pdev: PCI device information struct |
| 7726 | * |
| 7727 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 7728 | * that it should release a PCI device. The could be caused by a |
| 7729 | * Hot-Plug event, or because the driver is going to be removed from |
| 7730 | * memory. |
| 7731 | **/ |
| 7732 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 7733 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7734 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7735 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7736 | |
| 7737 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7738 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7739 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7740 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7741 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 7742 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 7743 | dca_remove_requester(&pdev->dev); |
| 7744 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 7745 | } |
| 7746 | |
| 7747 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7748 | #ifdef IXGBE_FCOE |
| 7749 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7750 | ixgbe_cleanup_fcoe(adapter); |
| 7751 | |
| 7752 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7753 | |
| 7754 | /* remove the added san mac */ |
| 7755 | ixgbe_del_sanmac_netdev(netdev); |
| 7756 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7757 | if (netdev->reg_state == NETREG_REGISTERED) |
| 7758 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7759 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7760 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7761 | ixgbe_disable_sriov(adapter); |
| 7762 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7763 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7764 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7765 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7766 | |
| 7767 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7768 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7769 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7770 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7771 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7772 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7773 | free_netdev(netdev); |
| 7774 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7775 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7776 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7777 | pci_disable_device(pdev); |
| 7778 | } |
| 7779 | |
| 7780 | /** |
| 7781 | * ixgbe_io_error_detected - called when PCI error is detected |
| 7782 | * @pdev: Pointer to PCI device |
| 7783 | * @state: The current pci connection state |
| 7784 | * |
| 7785 | * This function is called after a PCI bus error affecting |
| 7786 | * this device has been detected. |
| 7787 | */ |
| 7788 | 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] | 7789 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7790 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7791 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7792 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7793 | |
| 7794 | netif_device_detach(netdev); |
| 7795 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 7796 | if (state == pci_channel_io_perm_failure) |
| 7797 | return PCI_ERS_RESULT_DISCONNECT; |
| 7798 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7799 | if (netif_running(netdev)) |
| 7800 | ixgbe_down(adapter); |
| 7801 | pci_disable_device(pdev); |
| 7802 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7803 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7804 | return PCI_ERS_RESULT_NEED_RESET; |
| 7805 | } |
| 7806 | |
| 7807 | /** |
| 7808 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 7809 | * @pdev: Pointer to PCI device |
| 7810 | * |
| 7811 | * Restart the card from scratch, as if from a cold-boot. |
| 7812 | */ |
| 7813 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 7814 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7815 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7816 | pci_ers_result_t result; |
| 7817 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7818 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7819 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7820 | 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] | 7821 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7822 | } else { |
| 7823 | pci_set_master(pdev); |
| 7824 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 7825 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7826 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 7827 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7828 | |
| 7829 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 7830 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7831 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7832 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7833 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7834 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7835 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7836 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 7837 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7838 | /* non-fatal, continue */ |
| 7839 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7840 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7841 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7842 | } |
| 7843 | |
| 7844 | /** |
| 7845 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 7846 | * @pdev: Pointer to PCI device |
| 7847 | * |
| 7848 | * This callback is called when the error recovery driver tells us that |
| 7849 | * its OK to resume normal operation. |
| 7850 | */ |
| 7851 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 7852 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7853 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7854 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7855 | |
| 7856 | if (netif_running(netdev)) { |
| 7857 | if (ixgbe_up(adapter)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7858 | e_info(probe, "ixgbe_up failed after reset\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7859 | return; |
| 7860 | } |
| 7861 | } |
| 7862 | |
| 7863 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7864 | } |
| 7865 | |
| 7866 | static struct pci_error_handlers ixgbe_err_handler = { |
| 7867 | .error_detected = ixgbe_io_error_detected, |
| 7868 | .slot_reset = ixgbe_io_slot_reset, |
| 7869 | .resume = ixgbe_io_resume, |
| 7870 | }; |
| 7871 | |
| 7872 | static struct pci_driver ixgbe_driver = { |
| 7873 | .name = ixgbe_driver_name, |
| 7874 | .id_table = ixgbe_pci_tbl, |
| 7875 | .probe = ixgbe_probe, |
| 7876 | .remove = __devexit_p(ixgbe_remove), |
| 7877 | #ifdef CONFIG_PM |
| 7878 | .suspend = ixgbe_suspend, |
| 7879 | .resume = ixgbe_resume, |
| 7880 | #endif |
| 7881 | .shutdown = ixgbe_shutdown, |
| 7882 | .err_handler = &ixgbe_err_handler |
| 7883 | }; |
| 7884 | |
| 7885 | /** |
| 7886 | * ixgbe_init_module - Driver Registration Routine |
| 7887 | * |
| 7888 | * ixgbe_init_module is the first routine called when the driver is |
| 7889 | * loaded. All it does is register with the PCI subsystem. |
| 7890 | **/ |
| 7891 | static int __init ixgbe_init_module(void) |
| 7892 | { |
| 7893 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 7894 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7895 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7896 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7897 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7898 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7899 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7900 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7901 | ret = pci_register_driver(&ixgbe_driver); |
| 7902 | return ret; |
| 7903 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7904 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7905 | module_init(ixgbe_init_module); |
| 7906 | |
| 7907 | /** |
| 7908 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 7909 | * |
| 7910 | * ixgbe_exit_module is called just before the driver is removed |
| 7911 | * from memory. |
| 7912 | **/ |
| 7913 | static void __exit ixgbe_exit_module(void) |
| 7914 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7915 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7916 | dca_unregister_notify(&dca_notifier); |
| 7917 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7918 | pci_unregister_driver(&ixgbe_driver); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7919 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7920 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7921 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7922 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7923 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7924 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7925 | { |
| 7926 | int ret_val; |
| 7927 | |
| 7928 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7929 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7930 | |
| 7931 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 7932 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7933 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 7934 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7935 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7936 | module_exit(ixgbe_exit_module); |
| 7937 | |
| 7938 | /* ixgbe_main.c */ |