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> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 38 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 39 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 40 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 42 | #include <net/checksum.h> |
| 43 | #include <net/ip6_checksum.h> |
| 44 | #include <linux/ethtool.h> |
| 45 | #include <linux/if_vlan.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 46 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 47 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 48 | |
| 49 | #include "ixgbe.h" |
| 50 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 51 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 52 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 53 | |
| 54 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 55 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 56 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 57 | #define MAJ 3 |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 58 | #define MIN 4 |
Don Skidmore | c89c711 | 2011-04-14 07:40:11 +0000 | [diff] [blame] | 59 | #define BUILD 8 |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 60 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 61 | __stringify(BUILD) "-k" |
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 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 668 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 669 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 670 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 671 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 672 | u32 data = 0; |
| 673 | u32 xoff[8] = {0}; |
| 674 | int i; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 675 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 676 | if ((hw->fc.current_mode == ixgbe_fc_full) || |
| 677 | (hw->fc.current_mode == ixgbe_fc_rx_pause)) { |
| 678 | switch (hw->mac.type) { |
| 679 | case ixgbe_mac_82598EB: |
| 680 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 681 | break; |
| 682 | default: |
| 683 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 684 | } |
| 685 | hwstats->lxoffrxc += data; |
| 686 | |
| 687 | /* refill credits (no tx hang) if we received xoff */ |
| 688 | if (!data) |
| 689 | return; |
| 690 | |
| 691 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 692 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 693 | &adapter->tx_ring[i]->state); |
| 694 | return; |
| 695 | } else if (!(adapter->dcb_cfg.pfc_mode_enable)) |
| 696 | return; |
| 697 | |
| 698 | /* update stats for each tc, only valid with PFC enabled */ |
| 699 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
| 700 | switch (hw->mac.type) { |
| 701 | case ixgbe_mac_82598EB: |
| 702 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 703 | break; |
| 704 | default: |
| 705 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 706 | } |
| 707 | hwstats->pxoffrxc[i] += xoff[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 708 | } |
| 709 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 710 | /* disarm tx queues that have received xoff frames */ |
| 711 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 712 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | fb5475f | 2011-04-26 07:26:36 +0000 | [diff] [blame] | 713 | u8 tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 714 | |
| 715 | if (xoff[tc]) |
| 716 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 721 | { |
| 722 | return ring->tx_stats.completed; |
| 723 | } |
| 724 | |
| 725 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 726 | { |
| 727 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); |
| 728 | struct ixgbe_hw *hw = &adapter->hw; |
| 729 | |
| 730 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 731 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
| 732 | |
| 733 | if (head != tail) |
| 734 | return (head < tail) ? |
| 735 | tail - head : (tail + ring->count - head); |
| 736 | |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 741 | { |
| 742 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 743 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 744 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 745 | bool ret = false; |
| 746 | |
| 747 | clear_check_for_tx_hang(tx_ring); |
| 748 | |
| 749 | /* |
| 750 | * Check for a hung queue, but be thorough. This verifies |
| 751 | * that a transmit has been completed since the previous |
| 752 | * check AND there is at least one packet pending. The |
| 753 | * ARMED bit is set to indicate a potential hang. The |
| 754 | * bit is cleared if a pause frame is received to remove |
| 755 | * false hang detection due to PFC or 802.3x frames. By |
| 756 | * requiring this to fail twice we avoid races with |
| 757 | * pfc clearing the ARMED bit and conditions where we |
| 758 | * run the check_tx_hang logic with a transmit completion |
| 759 | * pending but without time to complete it yet. |
| 760 | */ |
| 761 | if ((tx_done_old == tx_done) && tx_pending) { |
| 762 | /* make sure it is true for two checks in a row */ |
| 763 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 764 | &tx_ring->state); |
| 765 | } else { |
| 766 | /* update completed stats and continue */ |
| 767 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 768 | /* reset the countdown */ |
| 769 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 770 | } |
| 771 | |
| 772 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 775 | /** |
| 776 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 777 | * @adapter: driver private struct |
| 778 | **/ |
| 779 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 780 | { |
| 781 | |
| 782 | /* Do the reset outside of interrupt context */ |
| 783 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 784 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 785 | ixgbe_service_event_schedule(adapter); |
| 786 | } |
| 787 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 788 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 789 | /** |
| 790 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 791 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 792 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 793 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 794 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 795 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 796 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 797 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 798 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 799 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 800 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 801 | u16 i, eop, count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 802 | |
| 803 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 804 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 805 | eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 806 | |
| 807 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 808 | (count < q_vector->tx.work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 809 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 810 | rmb(); /* read buffer_info after eop_desc */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 811 | for ( ; !cleaned; count++) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 812 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 813 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 814 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 815 | tx_desc->wb.status = 0; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 816 | cleaned = (i == eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 817 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 818 | i++; |
| 819 | if (i == tx_ring->count) |
| 820 | i = 0; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 821 | |
| 822 | if (cleaned && tx_buffer_info->skb) { |
| 823 | total_bytes += tx_buffer_info->bytecount; |
| 824 | total_packets += tx_buffer_info->gso_segs; |
| 825 | } |
| 826 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 827 | ixgbe_unmap_and_free_tx_resource(tx_ring, |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 828 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 829 | } |
| 830 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 831 | tx_ring->tx_stats.completed++; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 832 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 833 | eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 834 | } |
| 835 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 836 | tx_ring->next_to_clean = i; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 837 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 838 | tx_ring->stats.packets += total_packets; |
| 839 | u64_stats_update_begin(&tx_ring->syncp); |
| 840 | q_vector->tx.total_bytes += total_bytes; |
| 841 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 842 | u64_stats_update_end(&tx_ring->syncp); |
| 843 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 844 | 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] | 845 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 846 | struct ixgbe_hw *hw = &adapter->hw; |
| 847 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
| 848 | e_err(drv, "Detected Tx Unit Hang\n" |
| 849 | " Tx Queue <%d>\n" |
| 850 | " TDH, TDT <%x>, <%x>\n" |
| 851 | " next_to_use <%x>\n" |
| 852 | " next_to_clean <%x>\n" |
| 853 | "tx_buffer_info[next_to_clean]\n" |
| 854 | " time_stamp <%lx>\n" |
| 855 | " jiffies <%lx>\n", |
| 856 | tx_ring->queue_index, |
| 857 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 858 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
| 859 | tx_ring->next_to_use, eop, |
| 860 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
| 861 | |
| 862 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 863 | |
| 864 | e_info(probe, |
| 865 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 866 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 867 | |
| 868 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 869 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 870 | |
| 871 | /* the adapter is about to reset, no point in enabling stuff */ |
| 872 | return true; |
| 873 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 874 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 875 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 876 | if (unlikely(count && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 877 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 878 | /* Make sure that anybody stopping the queue after this |
| 879 | * sees the new next_to_clean. |
| 880 | */ |
| 881 | smp_mb(); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 882 | if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) && |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 883 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 884 | netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 885 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 886 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 887 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 888 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 889 | return count < q_vector->tx.work_limit; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 892 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 893 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 894 | struct ixgbe_ring *rx_ring, |
| 895 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 896 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 897 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 898 | u32 rxctrl; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 899 | u8 reg_idx = rx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 900 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 901 | rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx)); |
| 902 | switch (hw->mac.type) { |
| 903 | case ixgbe_mac_82598EB: |
| 904 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 905 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 906 | break; |
| 907 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 908 | case ixgbe_mac_X540: |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 909 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 910 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 911 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 912 | break; |
| 913 | default: |
| 914 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 915 | } |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 916 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 917 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
| 918 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 919 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 923 | struct ixgbe_ring *tx_ring, |
| 924 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 925 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 926 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 927 | u32 txctrl; |
| 928 | u8 reg_idx = tx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 929 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 930 | switch (hw->mac.type) { |
| 931 | case ixgbe_mac_82598EB: |
| 932 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx)); |
| 933 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 934 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 935 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 936 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl); |
| 937 | break; |
| 938 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 939 | case ixgbe_mac_X540: |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 940 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx)); |
| 941 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 942 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 943 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 944 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 945 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl); |
| 946 | break; |
| 947 | default: |
| 948 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 949 | } |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 953 | { |
| 954 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 955 | int cpu = get_cpu(); |
| 956 | long r_idx; |
| 957 | int i; |
| 958 | |
| 959 | if (q_vector->cpu == cpu) |
| 960 | goto out_no_update; |
| 961 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 962 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
| 963 | for (i = 0; i < q_vector->tx.count; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 964 | ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 965 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 966 | r_idx + 1); |
| 967 | } |
| 968 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 969 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
| 970 | for (i = 0; i < q_vector->rx.count; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 971 | ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 972 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 973 | r_idx + 1); |
| 974 | } |
| 975 | |
| 976 | q_vector->cpu = cpu; |
| 977 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 978 | put_cpu(); |
| 979 | } |
| 980 | |
| 981 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 982 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 983 | int num_q_vectors; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 984 | int i; |
| 985 | |
| 986 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 987 | return; |
| 988 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 989 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 990 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 991 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 992 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 993 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 994 | else |
| 995 | num_q_vectors = 1; |
| 996 | |
| 997 | for (i = 0; i < num_q_vectors; i++) { |
| 998 | adapter->q_vector[i]->cpu = -1; |
| 999 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1004 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1005 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1006 | unsigned long event = *(unsigned long *)data; |
| 1007 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1008 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 1009 | return 0; |
| 1010 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1011 | switch (event) { |
| 1012 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1013 | /* if we're already enabled, don't do it again */ |
| 1014 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1015 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1016 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1017 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1018 | ixgbe_setup_dca(adapter); |
| 1019 | break; |
| 1020 | } |
| 1021 | /* Fall Through since DCA is disabled. */ |
| 1022 | case DCA_PROVIDER_REMOVE: |
| 1023 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1024 | dca_remove_requester(dev); |
| 1025 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 1026 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 1027 | } |
| 1028 | break; |
| 1029 | } |
| 1030 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1031 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1032 | } |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1033 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1034 | |
| 1035 | static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc, |
| 1036 | struct sk_buff *skb) |
| 1037 | { |
| 1038 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
| 1039 | } |
| 1040 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1041 | /** |
| 1042 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 1043 | * @adapter: board private structure |
| 1044 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1045 | * @status: hardware indication of status of receive |
| 1046 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 1047 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1048 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1049 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1050 | struct sk_buff *skb, u8 status, |
| 1051 | struct ixgbe_ring *ring, |
| 1052 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1053 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1054 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1055 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1056 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 1057 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1058 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 1059 | if (is_vlan && (tag & VLAN_VID_MASK)) |
| 1060 | __vlan_hwaccel_put_tag(skb, tag); |
| 1061 | |
| 1062 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1063 | napi_gro_receive(napi, skb); |
| 1064 | else |
| 1065 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1068 | /** |
| 1069 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 1070 | * @adapter: address of board private structure |
| 1071 | * @status_err: hardware indication of status of receive |
| 1072 | * @skb: skb currently being received and modified |
| 1073 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1074 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1075 | union ixgbe_adv_rx_desc *rx_desc, |
| 1076 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1077 | { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1078 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1079 | |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1080 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1081 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1082 | /* Rx csum disabled */ |
| 1083 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1084 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1085 | |
| 1086 | /* if IP and error */ |
| 1087 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 1088 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1089 | adapter->hw_csum_rx_error++; |
| 1090 | return; |
| 1091 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1092 | |
| 1093 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 1094 | return; |
| 1095 | |
| 1096 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1097 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1098 | |
| 1099 | /* |
| 1100 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1101 | * checksum errors. |
| 1102 | */ |
| 1103 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 1104 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 1105 | return; |
| 1106 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1107 | adapter->hw_csum_rx_error++; |
| 1108 | return; |
| 1109 | } |
| 1110 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1111 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1112 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1115 | 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] | 1116 | { |
| 1117 | /* |
| 1118 | * Force memory writes to complete before letting h/w |
| 1119 | * know there are new descriptors to fetch. (Only |
| 1120 | * applicable for weak-ordered memory model archs, |
| 1121 | * such as IA-64). |
| 1122 | */ |
| 1123 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1124 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1127 | /** |
| 1128 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1129 | * @rx_ring: ring to place buffers on |
| 1130 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1131 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1132 | 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] | 1133 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1134 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1135 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1136 | struct sk_buff *skb; |
| 1137 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1138 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1139 | /* do nothing if no valid netdev defined */ |
| 1140 | if (!rx_ring->netdev) |
| 1141 | return; |
| 1142 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1143 | while (cleaned_count--) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1144 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1145 | bi = &rx_ring->rx_buffer_info[i]; |
| 1146 | skb = bi->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1147 | |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1148 | if (!skb) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1149 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1150 | rx_ring->rx_buf_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1151 | if (!skb) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1152 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1153 | goto no_buffers; |
| 1154 | } |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1155 | /* initialize queue mapping */ |
| 1156 | skb_record_rx_queue(skb, rx_ring->queue_index); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1157 | bi->skb = skb; |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1158 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1159 | |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1160 | if (!bi->dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1161 | bi->dma = dma_map_single(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1162 | skb->data, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1163 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 1164 | DMA_FROM_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1165 | if (dma_mapping_error(rx_ring->dev, bi->dma)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1166 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1167 | bi->dma = 0; |
| 1168 | goto no_buffers; |
| 1169 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1170 | } |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1171 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1172 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1173 | if (!bi->page) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1174 | bi->page = netdev_alloc_page(rx_ring->netdev); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1175 | if (!bi->page) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1176 | rx_ring->rx_stats.alloc_rx_page_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1177 | goto no_buffers; |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | if (!bi->page_dma) { |
| 1182 | /* use a half page if we're re-using */ |
| 1183 | bi->page_offset ^= PAGE_SIZE / 2; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1184 | bi->page_dma = dma_map_page(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1185 | bi->page, |
| 1186 | bi->page_offset, |
| 1187 | PAGE_SIZE / 2, |
| 1188 | DMA_FROM_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1189 | if (dma_mapping_error(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1190 | bi->page_dma)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1191 | rx_ring->rx_stats.alloc_rx_page_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1192 | bi->page_dma = 0; |
| 1193 | goto no_buffers; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | /* Refresh the desc even if buffer_addrs didn't change |
| 1198 | * because each write-back erases this info. */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1199 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 1200 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1201 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1202 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1203 | rx_desc->read.hdr_addr = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | i++; |
| 1207 | if (i == rx_ring->count) |
| 1208 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1209 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1210 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1211 | no_buffers: |
| 1212 | if (rx_ring->next_to_use != i) { |
| 1213 | rx_ring->next_to_use = i; |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1214 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1218 | 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] | 1219 | { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1220 | /* HW will not DMA in data larger than the given buffer, even if it |
| 1221 | * parses the (NFS, of course) header to be larger. In that case, it |
| 1222 | * fills the header buffer and spills the rest into the page. |
| 1223 | */ |
| 1224 | u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info); |
| 1225 | u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
| 1226 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
| 1227 | if (hlen > IXGBE_RX_HDR_SIZE) |
| 1228 | hlen = IXGBE_RX_HDR_SIZE; |
| 1229 | return hlen; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1232 | /** |
| 1233 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 1234 | * @skb: pointer to the last skb in the rsc queue |
| 1235 | * |
| 1236 | * This function changes a queue full of hw rsc buffers into a completed |
| 1237 | * packet. It uses the ->prev pointers to find the first packet and then |
| 1238 | * turns it into the frag list owner. |
| 1239 | **/ |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1240 | 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] | 1241 | { |
| 1242 | unsigned int frag_list_size = 0; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1243 | unsigned int skb_cnt = 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1244 | |
| 1245 | while (skb->prev) { |
| 1246 | struct sk_buff *prev = skb->prev; |
| 1247 | frag_list_size += skb->len; |
| 1248 | skb->prev = NULL; |
| 1249 | skb = prev; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1250 | skb_cnt++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | skb_shinfo(skb)->frag_list = skb->next; |
| 1254 | skb->next = NULL; |
| 1255 | skb->len += frag_list_size; |
| 1256 | skb->data_len += frag_list_size; |
| 1257 | skb->truesize += frag_list_size; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1258 | IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt; |
| 1259 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1260 | return skb; |
| 1261 | } |
| 1262 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1263 | static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc) |
| 1264 | { |
| 1265 | return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 1266 | IXGBE_RXDADV_RSCCNT_MASK); |
| 1267 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1268 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1269 | static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1270 | struct ixgbe_ring *rx_ring, |
| 1271 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1272 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1273 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1274 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 1275 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 1276 | struct sk_buff *skb; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1277 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1278 | const int current_node = numa_node_id(); |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1279 | #ifdef IXGBE_FCOE |
| 1280 | int ddp_bytes = 0; |
| 1281 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1282 | u32 staterr; |
| 1283 | u16 i; |
| 1284 | u16 cleaned_count = 0; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1285 | bool pkt_is_rsc = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1286 | |
| 1287 | i = rx_ring->next_to_clean; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1288 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1289 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1290 | |
| 1291 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1292 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1293 | |
Milton Miller | 3c945e5 | 2010-02-19 17:44:42 +0000 | [diff] [blame] | 1294 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1295 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1296 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 1297 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1298 | skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1299 | rx_buffer_info->skb = NULL; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1300 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1301 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1302 | if (ring_is_rsc_enabled(rx_ring)) |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1303 | pkt_is_rsc = ixgbe_get_rsc_state(rx_desc); |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1304 | |
| 1305 | /* if this is a skb from previous receive DMA will be 0 */ |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 1306 | if (rx_buffer_info->dma) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1307 | u16 hlen; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1308 | if (pkt_is_rsc && |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1309 | !(staterr & IXGBE_RXD_STAT_EOP) && |
| 1310 | !skb->prev) { |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1311 | /* |
| 1312 | * When HWRSC is enabled, delay unmapping |
| 1313 | * of the first packet. It carries the |
| 1314 | * header information, HW may still |
| 1315 | * access the header after the writeback. |
| 1316 | * Only unmap it when EOP is reached |
| 1317 | */ |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1318 | IXGBE_RSC_CB(skb)->delay_unmap = true; |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1319 | IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1320 | } else { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1321 | dma_unmap_single(rx_ring->dev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1322 | rx_buffer_info->dma, |
| 1323 | rx_ring->rx_buf_len, |
| 1324 | DMA_FROM_DEVICE); |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1325 | } |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 1326 | rx_buffer_info->dma = 0; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1327 | |
| 1328 | if (ring_is_ps_enabled(rx_ring)) { |
| 1329 | hlen = ixgbe_get_hlen(rx_desc); |
| 1330 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
| 1331 | } else { |
| 1332 | hlen = le16_to_cpu(rx_desc->wb.upper.length); |
| 1333 | } |
| 1334 | |
| 1335 | skb_put(skb, hlen); |
| 1336 | } else { |
| 1337 | /* assume packet split since header is unmapped */ |
| 1338 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | if (upper_len) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1342 | dma_unmap_page(rx_ring->dev, |
| 1343 | rx_buffer_info->page_dma, |
| 1344 | PAGE_SIZE / 2, |
| 1345 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1346 | rx_buffer_info->page_dma = 0; |
| 1347 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1348 | rx_buffer_info->page, |
| 1349 | rx_buffer_info->page_offset, |
| 1350 | upper_len); |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1351 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1352 | if ((page_count(rx_buffer_info->page) == 1) && |
| 1353 | (page_to_nid(rx_buffer_info->page) == current_node)) |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1354 | get_page(rx_buffer_info->page); |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1355 | else |
| 1356 | rx_buffer_info->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1357 | |
| 1358 | skb->len += upper_len; |
| 1359 | skb->data_len += upper_len; |
| 1360 | skb->truesize += upper_len; |
| 1361 | } |
| 1362 | |
| 1363 | i++; |
| 1364 | if (i == rx_ring->count) |
| 1365 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1366 | |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1367 | next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1368 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1369 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1370 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1371 | if (pkt_is_rsc) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1372 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 1373 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 1374 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1375 | } else { |
| 1376 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 1377 | } |
| 1378 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1379 | if (!(staterr & IXGBE_RXD_STAT_EOP)) { |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1380 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1381 | rx_buffer_info->skb = next_buffer->skb; |
| 1382 | rx_buffer_info->dma = next_buffer->dma; |
| 1383 | next_buffer->skb = skb; |
| 1384 | next_buffer->dma = 0; |
| 1385 | } else { |
| 1386 | skb->next = next_buffer->skb; |
| 1387 | skb->next->prev = skb; |
| 1388 | } |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1389 | rx_ring->rx_stats.non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1390 | goto next_desc; |
| 1391 | } |
| 1392 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1393 | if (skb->prev) { |
| 1394 | skb = ixgbe_transform_rsc_queue(skb); |
| 1395 | /* if we got here without RSC the packet is invalid */ |
| 1396 | if (!pkt_is_rsc) { |
| 1397 | __pskb_trim(skb, 0); |
| 1398 | rx_buffer_info->skb = skb; |
| 1399 | goto next_desc; |
| 1400 | } |
| 1401 | } |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1402 | |
| 1403 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1404 | if (IXGBE_RSC_CB(skb)->delay_unmap) { |
| 1405 | dma_unmap_single(rx_ring->dev, |
| 1406 | IXGBE_RSC_CB(skb)->dma, |
| 1407 | rx_ring->rx_buf_len, |
| 1408 | DMA_FROM_DEVICE); |
| 1409 | IXGBE_RSC_CB(skb)->dma = 0; |
| 1410 | IXGBE_RSC_CB(skb)->delay_unmap = false; |
| 1411 | } |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1412 | } |
| 1413 | if (pkt_is_rsc) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1414 | if (ring_is_ps_enabled(rx_ring)) |
| 1415 | rx_ring->rx_stats.rsc_count += |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1416 | skb_shinfo(skb)->nr_frags; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1417 | else |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1418 | rx_ring->rx_stats.rsc_count += |
| 1419 | IXGBE_RSC_CB(skb)->skb_cnt; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1420 | rx_ring->rx_stats.rsc_flush++; |
| 1421 | } |
| 1422 | |
| 1423 | /* ERR_MASK will only have valid bits if EOP set */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1424 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1425 | /* trim packet back to size 0 and recycle it */ |
| 1426 | __pskb_trim(skb, 0); |
| 1427 | rx_buffer_info->skb = skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1428 | goto next_desc; |
| 1429 | } |
| 1430 | |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1431 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1432 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 1433 | ixgbe_rx_hash(rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1434 | |
| 1435 | /* probably a little skewed due to removing CRC */ |
| 1436 | total_rx_bytes += skb->len; |
| 1437 | total_rx_packets++; |
| 1438 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1439 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1440 | #ifdef IXGBE_FCOE |
| 1441 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1442 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 1443 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 1444 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1445 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1446 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1447 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 1448 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1449 | |
| 1450 | next_desc: |
| 1451 | rx_desc->wb.upper.status_error = 0; |
| 1452 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1453 | (*work_done)++; |
| 1454 | if (*work_done >= work_to_do) |
| 1455 | break; |
| 1456 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1457 | /* return some buffers to hardware, one at a time is too slow */ |
| 1458 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1459 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1460 | cleaned_count = 0; |
| 1461 | } |
| 1462 | |
| 1463 | /* use prefetched values */ |
| 1464 | rx_desc = next_rxd; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1465 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1468 | rx_ring->next_to_clean = i; |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1469 | cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1470 | |
| 1471 | if (cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1472 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1473 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1474 | #ifdef IXGBE_FCOE |
| 1475 | /* include DDPed FCoE data */ |
| 1476 | if (ddp_bytes > 0) { |
| 1477 | unsigned int mss; |
| 1478 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1479 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1480 | sizeof(struct fc_frame_header) - |
| 1481 | sizeof(struct fcoe_crc_eof); |
| 1482 | if (mss > 512) |
| 1483 | mss &= ~511; |
| 1484 | total_rx_bytes += ddp_bytes; |
| 1485 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1486 | } |
| 1487 | #endif /* IXGBE_FCOE */ |
| 1488 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1489 | u64_stats_update_begin(&rx_ring->syncp); |
| 1490 | rx_ring->stats.packets += total_rx_packets; |
| 1491 | rx_ring->stats.bytes += total_rx_bytes; |
| 1492 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1493 | q_vector->rx.total_packets += total_rx_packets; |
| 1494 | q_vector->rx.total_bytes += total_rx_bytes; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1497 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1498 | /** |
| 1499 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1500 | * @adapter: board private structure |
| 1501 | * |
| 1502 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1503 | * interrupts. |
| 1504 | **/ |
| 1505 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1506 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1507 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1508 | int i, q_vectors, v_idx, r_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1509 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1510 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1511 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1512 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1513 | /* |
| 1514 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1515 | * corresponding register. |
| 1516 | */ |
| 1517 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1518 | q_vector = adapter->q_vector[v_idx]; |
Akinobu Mita | 984b3f5 | 2010-03-05 13:41:37 -0800 | [diff] [blame] | 1519 | /* XXX for_each_set_bit(...) */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1520 | r_idx = find_first_bit(q_vector->rx.idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1521 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1522 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1523 | for (i = 0; i < q_vector->rx.count; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1524 | u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx; |
| 1525 | ixgbe_set_ivar(adapter, 0, reg_idx, v_idx); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1526 | r_idx = find_next_bit(q_vector->rx.idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1527 | adapter->num_rx_queues, |
| 1528 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1529 | } |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1530 | r_idx = find_first_bit(q_vector->tx.idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1531 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1532 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1533 | for (i = 0; i < q_vector->tx.count; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1534 | u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx; |
| 1535 | ixgbe_set_ivar(adapter, 1, reg_idx, v_idx); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1536 | r_idx = find_next_bit(q_vector->tx.idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1537 | adapter->num_tx_queues, |
| 1538 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1539 | } |
| 1540 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1541 | if (q_vector->tx.count && !q_vector->rx.count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1542 | /* tx only */ |
| 1543 | q_vector->eitr = adapter->tx_eitr_param; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1544 | else if (q_vector->rx.count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1545 | /* rx or mixed */ |
| 1546 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1547 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1548 | ixgbe_write_eitr(q_vector); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 1549 | /* If ATR is enabled, set interrupt affinity */ |
| 1550 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 1551 | /* |
| 1552 | * Allocate the affinity_hint cpumask, assign the mask |
| 1553 | * for this vector, and set our affinity_hint for |
| 1554 | * this irq. |
| 1555 | */ |
| 1556 | if (!alloc_cpumask_var(&q_vector->affinity_mask, |
| 1557 | GFP_KERNEL)) |
| 1558 | return; |
| 1559 | cpumask_set_cpu(v_idx, q_vector->affinity_mask); |
| 1560 | irq_set_affinity_hint(adapter->msix_entries[v_idx].vector, |
| 1561 | q_vector->affinity_mask); |
| 1562 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1565 | switch (adapter->hw.mac.type) { |
| 1566 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1567 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1568 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1569 | break; |
| 1570 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1571 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1572 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1573 | break; |
| 1574 | |
| 1575 | default: |
| 1576 | break; |
| 1577 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1578 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1579 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1580 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1581 | mask = IXGBE_EIMS_ENABLE_MASK; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1582 | if (adapter->num_vfs) |
| 1583 | mask &= ~(IXGBE_EIMS_OTHER | |
| 1584 | IXGBE_EIMS_MAILBOX | |
| 1585 | IXGBE_EIMS_LSC); |
| 1586 | else |
| 1587 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1588 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1591 | enum latency_range { |
| 1592 | lowest_latency = 0, |
| 1593 | low_latency = 1, |
| 1594 | bulk_latency = 2, |
| 1595 | latency_invalid = 255 |
| 1596 | }; |
| 1597 | |
| 1598 | /** |
| 1599 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1600 | * @q_vector: structure containing interrupt and ring information |
| 1601 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1602 | * |
| 1603 | * Stores a new ITR value based on packets and byte |
| 1604 | * counts during the last interrupt. The advantage of per interrupt |
| 1605 | * computation is faster updates and more accurate ITR for the current |
| 1606 | * traffic pattern. Constants in this function were computed |
| 1607 | * based on theoretical maximum wire speed and thresholds were set based |
| 1608 | * on testing data as well as attempting to minimize response time |
| 1609 | * while increasing bulk throughput. |
| 1610 | * this functionality is controlled by the InterruptThrottleRate module |
| 1611 | * parameter (see ixgbe_param.c) |
| 1612 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1613 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 1614 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1615 | { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1616 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1617 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1618 | int bytes = ring_container->total_bytes; |
| 1619 | int packets = ring_container->total_packets; |
| 1620 | u32 timepassed_us; |
| 1621 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1622 | |
| 1623 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1624 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1625 | |
| 1626 | /* simple throttlerate management |
| 1627 | * 0-20MB/s lowest (100000 ints/s) |
| 1628 | * 20-100MB/s low (20000 ints/s) |
| 1629 | * 100-1249MB/s bulk (8000 ints/s) |
| 1630 | */ |
| 1631 | /* what was last interrupt timeslice? */ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1632 | timepassed_us = 1000000/q_vector->eitr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1633 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1634 | |
| 1635 | switch (itr_setting) { |
| 1636 | case lowest_latency: |
| 1637 | if (bytes_perint > adapter->eitr_low) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1638 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1639 | break; |
| 1640 | case low_latency: |
| 1641 | if (bytes_perint > adapter->eitr_high) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1642 | itr_setting = bulk_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1643 | else if (bytes_perint <= adapter->eitr_low) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1644 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1645 | break; |
| 1646 | case bulk_latency: |
| 1647 | if (bytes_perint <= adapter->eitr_high) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1648 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1649 | break; |
| 1650 | } |
| 1651 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1652 | /* clear work counters since we have the values we need */ |
| 1653 | ring_container->total_bytes = 0; |
| 1654 | ring_container->total_packets = 0; |
| 1655 | |
| 1656 | /* write updated itr to ring container */ |
| 1657 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1658 | } |
| 1659 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1660 | /** |
| 1661 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1662 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1663 | * |
| 1664 | * This function is made to be called by ethtool and by the driver |
| 1665 | * when it needs to update EITR registers at runtime. Hardware |
| 1666 | * specific quirks/differences are taken care of here. |
| 1667 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1668 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1669 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1670 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1671 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1672 | int v_idx = q_vector->v_idx; |
| 1673 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1674 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1675 | switch (adapter->hw.mac.type) { |
| 1676 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1677 | /* must write high and low 16 bits to reset counter */ |
| 1678 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1679 | break; |
| 1680 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1681 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1682 | /* |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1683 | * 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] | 1684 | * max interrupt rate, but there is an errata where it can |
| 1685 | * not be zero with RSC |
| 1686 | */ |
| 1687 | if (itr_reg == 8 && |
| 1688 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 1689 | itr_reg = 0; |
| 1690 | |
| 1691 | /* |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1692 | * set the WDIS bit to not clear the timer bits and cause an |
| 1693 | * immediate assertion of the interrupt |
| 1694 | */ |
| 1695 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1696 | break; |
| 1697 | default: |
| 1698 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1699 | } |
| 1700 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1701 | } |
| 1702 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1703 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1704 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1705 | u32 new_itr = q_vector->eitr; |
| 1706 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1707 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1708 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 1709 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1710 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1711 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1712 | |
| 1713 | switch (current_itr) { |
| 1714 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1715 | case lowest_latency: |
| 1716 | new_itr = 100000; |
| 1717 | break; |
| 1718 | case low_latency: |
| 1719 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1720 | break; |
| 1721 | case bulk_latency: |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1722 | new_itr = 8000; |
| 1723 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1724 | default: |
| 1725 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1729 | /* do an exponential smoothing */ |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 1730 | new_itr = ((q_vector->eitr * 9) + new_itr)/10; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1731 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 1732 | /* save the algorithm value here */ |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1733 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1734 | |
| 1735 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1736 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1737 | } |
| 1738 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1739 | /** |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1740 | * ixgbe_check_overtemp_subtask - check for over tempurature |
| 1741 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1742 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1743 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1744 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1745 | struct ixgbe_hw *hw = &adapter->hw; |
| 1746 | u32 eicr = adapter->interrupt_event; |
| 1747 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1748 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1749 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1750 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1751 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1752 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 1753 | return; |
| 1754 | |
| 1755 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1756 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1757 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1758 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 1759 | /* |
| 1760 | * Since the warning interrupt is for both ports |
| 1761 | * we don't have to check if: |
| 1762 | * - This interrupt wasn't for our port. |
| 1763 | * - We may have missed the interrupt so always have to |
| 1764 | * check if we got a LSC |
| 1765 | */ |
| 1766 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 1767 | !(eicr & IXGBE_EICR_LSC)) |
| 1768 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1769 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1770 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
| 1771 | u32 autoneg; |
| 1772 | bool link_up = false; |
| 1773 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1774 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 1775 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1776 | if (link_up) |
| 1777 | return; |
| 1778 | } |
| 1779 | |
| 1780 | /* Check if this is not due to overtemp */ |
| 1781 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 1782 | return; |
| 1783 | |
| 1784 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1785 | default: |
| 1786 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 1787 | return; |
| 1788 | break; |
| 1789 | } |
| 1790 | e_crit(drv, |
| 1791 | "Network adapter has been stopped because it has over heated. " |
| 1792 | "Restart the computer. If the problem persists, " |
| 1793 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1794 | |
| 1795 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1798 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1799 | { |
| 1800 | struct ixgbe_hw *hw = &adapter->hw; |
| 1801 | |
| 1802 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1803 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 1804 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1805 | /* write to clear the interrupt */ |
| 1806 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1807 | } |
| 1808 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1809 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1810 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1811 | { |
| 1812 | struct ixgbe_hw *hw = &adapter->hw; |
| 1813 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 1814 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1815 | /* Clear the interrupt */ |
| 1816 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1817 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1818 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 1819 | ixgbe_service_event_schedule(adapter); |
| 1820 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 1821 | } |
| 1822 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1823 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1824 | /* Clear the interrupt */ |
| 1825 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1826 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1827 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 1828 | ixgbe_service_event_schedule(adapter); |
| 1829 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1830 | } |
| 1831 | } |
| 1832 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1833 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1834 | { |
| 1835 | struct ixgbe_hw *hw = &adapter->hw; |
| 1836 | |
| 1837 | adapter->lsc_int++; |
| 1838 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1839 | adapter->link_check_timeout = jiffies; |
| 1840 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1841 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 1842 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 1843 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1844 | } |
| 1845 | } |
| 1846 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1847 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1848 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 1849 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1850 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1851 | u32 eicr; |
| 1852 | |
| 1853 | /* |
| 1854 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1855 | * of clear-by-read. Reading with EICS will return the |
| 1856 | * interrupt causes without clearing, which later be done |
| 1857 | * with the write to EICR. |
| 1858 | */ |
| 1859 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1860 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1861 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1862 | if (eicr & IXGBE_EICR_LSC) |
| 1863 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1864 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1865 | if (eicr & IXGBE_EICR_MAILBOX) |
| 1866 | ixgbe_msg_task(adapter); |
| 1867 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1868 | switch (hw->mac.type) { |
| 1869 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1870 | case ixgbe_mac_X540: |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1871 | /* Handle Flow Director Full threshold interrupt */ |
| 1872 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1873 | int reinit_count = 0; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1874 | int i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1875 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1876 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1877 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1878 | &ring->state)) |
| 1879 | reinit_count++; |
| 1880 | } |
| 1881 | if (reinit_count) { |
| 1882 | /* no more flow director interrupts until after init */ |
| 1883 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 1884 | eicr &= ~IXGBE_EICR_FLOW_DIR; |
| 1885 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 1886 | ixgbe_service_event_schedule(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1887 | } |
| 1888 | } |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1889 | ixgbe_check_sfp_event(adapter, eicr); |
| 1890 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1891 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { |
| 1892 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1893 | adapter->interrupt_event = eicr; |
| 1894 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1895 | ixgbe_service_event_schedule(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1896 | } |
| 1897 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1898 | break; |
| 1899 | default: |
| 1900 | break; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1901 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1902 | |
| 1903 | ixgbe_check_fan_failure(adapter, eicr); |
| 1904 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1905 | /* re-enable the original interrupt state, no lsc, no queues */ |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1906 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1907 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr & |
| 1908 | ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1909 | |
| 1910 | return IRQ_HANDLED; |
| 1911 | } |
| 1912 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1913 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1914 | u64 qmask) |
| 1915 | { |
| 1916 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1917 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1918 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1919 | switch (hw->mac.type) { |
| 1920 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1921 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1922 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 1923 | break; |
| 1924 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1925 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1926 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1927 | if (mask) |
| 1928 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1929 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1930 | if (mask) |
| 1931 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 1932 | break; |
| 1933 | default: |
| 1934 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1935 | } |
| 1936 | /* skip the flush */ |
| 1937 | } |
| 1938 | |
| 1939 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1940 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1941 | { |
| 1942 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1943 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1944 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1945 | switch (hw->mac.type) { |
| 1946 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1947 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1948 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 1949 | break; |
| 1950 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1951 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1952 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1953 | if (mask) |
| 1954 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1955 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1956 | if (mask) |
| 1957 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 1958 | break; |
| 1959 | default: |
| 1960 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1961 | } |
| 1962 | /* skip the flush */ |
| 1963 | } |
| 1964 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1965 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1966 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1967 | struct ixgbe_q_vector *q_vector = data; |
| 1968 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1969 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1970 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1971 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1972 | if (!q_vector->tx.count) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1973 | return IRQ_HANDLED; |
| 1974 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1975 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
| 1976 | for (i = 0; i < q_vector->tx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1977 | tx_ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1978 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1979 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1980 | } |
| 1981 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1982 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1983 | napi_schedule(&q_vector->napi); |
| 1984 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1985 | return IRQ_HANDLED; |
| 1986 | } |
| 1987 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1988 | /** |
| 1989 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1990 | * @irq: unused |
| 1991 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1992 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1993 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1994 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1995 | struct ixgbe_q_vector *q_vector = data; |
| 1996 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1997 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1998 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1999 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2000 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2001 | #ifdef CONFIG_IXGBE_DCA |
| 2002 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2003 | ixgbe_update_dca(q_vector); |
| 2004 | #endif |
| 2005 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2006 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
| 2007 | for (i = 0; i < q_vector->rx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2008 | rx_ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2009 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2010 | r_idx + 1); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2013 | if (!q_vector->rx.count) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2014 | return IRQ_HANDLED; |
| 2015 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2016 | /* EIAM disabled interrupts (on this vector) for us */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2017 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2018 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2019 | return IRQ_HANDLED; |
| 2020 | } |
| 2021 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2022 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 2023 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2024 | struct ixgbe_q_vector *q_vector = data; |
| 2025 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2026 | struct ixgbe_ring *ring; |
| 2027 | int r_idx; |
| 2028 | int i; |
| 2029 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2030 | if (!q_vector->tx.count && !q_vector->rx.count) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2031 | return IRQ_HANDLED; |
| 2032 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2033 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
| 2034 | for (i = 0; i < q_vector->tx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2035 | ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2036 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2037 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2040 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
| 2041 | for (i = 0; i < q_vector->rx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2042 | ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2043 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2044 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2047 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2048 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2049 | |
| 2050 | return IRQ_HANDLED; |
| 2051 | } |
| 2052 | |
| 2053 | /** |
| 2054 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 2055 | * @napi: napi struct with our devices info in it |
| 2056 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2057 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2058 | * This function is optimized for cleaning one queue only on a single |
| 2059 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2060 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2061 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 2062 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2063 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2064 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2065 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2066 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2067 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2068 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2069 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2070 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2071 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2072 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2073 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2074 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2075 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2076 | rx_ring = adapter->rx_ring[r_idx]; |
| 2077 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 2078 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2079 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2080 | /* If all Rx work done, exit the polling mode */ |
| 2081 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2082 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2083 | if (adapter->rx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 2084 | ixgbe_set_itr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2085 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2086 | ixgbe_irq_enable_queues(adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2087 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | return work_done; |
| 2091 | } |
| 2092 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2093 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2094 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2095 | * @napi: napi struct with our devices info in it |
| 2096 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2097 | * |
| 2098 | * This function will clean more than one rx queue associated with a |
| 2099 | * q_vector. |
| 2100 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2101 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2102 | { |
| 2103 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2104 | container_of(napi, struct ixgbe_q_vector, napi); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2105 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2106 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2107 | int work_done = 0, i; |
| 2108 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2109 | bool tx_clean_complete = true; |
| 2110 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2111 | #ifdef CONFIG_IXGBE_DCA |
| 2112 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2113 | ixgbe_update_dca(q_vector); |
| 2114 | #endif |
| 2115 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2116 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
| 2117 | for (i = 0; i < q_vector->tx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2118 | ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2119 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2120 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2121 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2122 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2123 | |
| 2124 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2125 | * the budget to go below 1 because we'll exit polling */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2126 | budget /= (q_vector->rx.count ?: 1); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2127 | budget = max(budget, 1); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2128 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
| 2129 | for (i = 0; i < q_vector->rx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2130 | ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2131 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2132 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2133 | r_idx + 1); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2136 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2137 | ring = adapter->rx_ring[r_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2138 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2139 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2140 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2141 | if (adapter->rx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 2142 | ixgbe_set_itr(q_vector); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2143 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2144 | ixgbe_irq_enable_queues(adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2145 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2146 | return 0; |
| 2147 | } |
| 2148 | |
| 2149 | return work_done; |
| 2150 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2151 | |
| 2152 | /** |
| 2153 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 2154 | * @napi: napi struct with our devices info in it |
| 2155 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2156 | * |
| 2157 | * This function is optimized for cleaning one queue only on a single |
| 2158 | * q_vector!!! |
| 2159 | **/ |
| 2160 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 2161 | { |
| 2162 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2163 | container_of(napi, struct ixgbe_q_vector, napi); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2164 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2165 | struct ixgbe_ring *tx_ring = NULL; |
| 2166 | int work_done = 0; |
| 2167 | long r_idx; |
| 2168 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2169 | #ifdef CONFIG_IXGBE_DCA |
| 2170 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2171 | ixgbe_update_dca(q_vector); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2172 | #endif |
| 2173 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2174 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2175 | tx_ring = adapter->tx_ring[r_idx]; |
| 2176 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2177 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 2178 | work_done = budget; |
| 2179 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2180 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2181 | if (work_done < budget) { |
| 2182 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2183 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 2184 | ixgbe_set_itr(q_vector); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2185 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2186 | ixgbe_irq_enable_queues(adapter, |
| 2187 | ((u64)1 << q_vector->v_idx)); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | return work_done; |
| 2191 | } |
| 2192 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2193 | 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] | 2194 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2195 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2196 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2197 | struct ixgbe_ring *rx_ring = a->rx_ring[r_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2198 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2199 | set_bit(r_idx, q_vector->rx.idx); |
| 2200 | q_vector->rx.count++; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2201 | rx_ring->q_vector = q_vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2202 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2203 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2204 | 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] | 2205 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2206 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2207 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2208 | struct ixgbe_ring *tx_ring = a->tx_ring[t_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2209 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2210 | set_bit(t_idx, q_vector->tx.idx); |
| 2211 | q_vector->tx.count++; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2212 | tx_ring->q_vector = q_vector; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 2213 | q_vector->tx.work_limit = a->tx_work_limit; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2214 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2215 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2216 | /** |
| 2217 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 2218 | * @adapter: board private structure to initialize |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2219 | * |
| 2220 | * This function maps descriptor rings to the queue-specific vectors |
| 2221 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 2222 | * one vector per ring/queue, but on a constrained vector budget, we |
| 2223 | * group the rings as "efficiently" as possible. You would add new |
| 2224 | * mapping configurations in here. |
| 2225 | **/ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2226 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2227 | { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2228 | int q_vectors; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2229 | int v_start = 0; |
| 2230 | int rxr_idx = 0, txr_idx = 0; |
| 2231 | int rxr_remaining = adapter->num_rx_queues; |
| 2232 | int txr_remaining = adapter->num_tx_queues; |
| 2233 | int i, j; |
| 2234 | int rqpv, tqpv; |
| 2235 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2236 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2237 | /* No mapping required if MSI-X is disabled. */ |
| 2238 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2239 | goto out; |
| 2240 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2241 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2242 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2243 | /* |
| 2244 | * The ideal configuration... |
| 2245 | * We have enough vectors to map one per queue. |
| 2246 | */ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2247 | if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2248 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 2249 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 2250 | |
| 2251 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 2252 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 2253 | |
| 2254 | goto out; |
| 2255 | } |
| 2256 | |
| 2257 | /* |
| 2258 | * If we don't have enough vectors for a 1-to-1 |
| 2259 | * mapping, we'll have to group them so there are |
| 2260 | * multiple queues per vector. |
| 2261 | */ |
| 2262 | /* Re-adjusting *qpv takes care of the remainder. */ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2263 | for (i = v_start; i < q_vectors; i++) { |
| 2264 | rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2265 | for (j = 0; j < rqpv; j++) { |
| 2266 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 2267 | rxr_idx++; |
| 2268 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2269 | } |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2270 | tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2271 | for (j = 0; j < tqpv; j++) { |
| 2272 | map_vector_to_txq(adapter, i, txr_idx); |
| 2273 | txr_idx++; |
| 2274 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2275 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2276 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2277 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2278 | return err; |
| 2279 | } |
| 2280 | |
| 2281 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2282 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2283 | * @adapter: board private structure |
| 2284 | * |
| 2285 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2286 | * interrupts from the kernel. |
| 2287 | **/ |
| 2288 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2289 | { |
| 2290 | struct net_device *netdev = adapter->netdev; |
| 2291 | irqreturn_t (*handler)(int, void *); |
| 2292 | int i, vector, q_vectors, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2293 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2294 | |
| 2295 | /* Decrement for Other and TCP Timer vectors */ |
| 2296 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2297 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2298 | err = ixgbe_map_rings_to_vectors(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2299 | if (err) |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2300 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2301 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2302 | #define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2303 | ? &ixgbe_msix_clean_many : \ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2304 | (_v)->rx.count ? &ixgbe_msix_clean_rx : \ |
| 2305 | (_v)->tx.count ? &ixgbe_msix_clean_tx : \ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2306 | NULL) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2307 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2308 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 2309 | handler = SET_HANDLER(q_vector); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2310 | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2311 | if (handler == &ixgbe_msix_clean_rx) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2312 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2313 | "%s-%s-%d", netdev->name, "rx", ri++); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2314 | } else if (handler == &ixgbe_msix_clean_tx) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2315 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2316 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2317 | } else if (handler == &ixgbe_msix_clean_many) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2318 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2319 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2320 | ti++; |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2321 | } else { |
| 2322 | /* skip this unused q_vector */ |
| 2323 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2324 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2325 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2326 | handler, 0, q_vector->name, |
| 2327 | q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2328 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2329 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2330 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2331 | goto free_queue_irqs; |
| 2332 | } |
| 2333 | } |
| 2334 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2335 | sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2336 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2337 | ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2338 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2339 | e_err(probe, "request_irq for msix_lsc failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2340 | goto free_queue_irqs; |
| 2341 | } |
| 2342 | |
| 2343 | return 0; |
| 2344 | |
| 2345 | free_queue_irqs: |
| 2346 | for (i = vector - 1; i >= 0; i--) |
| 2347 | free_irq(adapter->msix_entries[--vector].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2348 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2349 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2350 | pci_disable_msix(adapter->pdev); |
| 2351 | kfree(adapter->msix_entries); |
| 2352 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2353 | return err; |
| 2354 | } |
| 2355 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2356 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2357 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2358 | * @adapter: board private structure |
| 2359 | **/ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2360 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2361 | bool flush) |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2362 | { |
| 2363 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2364 | |
| 2365 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2366 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
| 2367 | mask |= IXGBE_EIMS_GPI_SDP0; |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 2368 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2369 | mask |= IXGBE_EIMS_GPI_SDP1; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2370 | switch (adapter->hw.mac.type) { |
| 2371 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2372 | case ixgbe_mac_X540: |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2373 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2374 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2375 | mask |= IXGBE_EIMS_GPI_SDP2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2376 | if (adapter->num_vfs) |
| 2377 | mask |= IXGBE_EIMS_MAILBOX; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2378 | break; |
| 2379 | default: |
| 2380 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2381 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 2382 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2383 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2384 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2385 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2386 | if (queues) |
| 2387 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2388 | if (flush) |
| 2389 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2390 | |
| 2391 | if (adapter->num_vfs > 32) { |
| 2392 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 2393 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2394 | } |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2395 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2396 | |
| 2397 | /** |
| 2398 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2399 | * @irq: interrupt number |
| 2400 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2401 | **/ |
| 2402 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2403 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2404 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2405 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2406 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2407 | u32 eicr; |
| 2408 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2409 | /* |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2410 | * Workaround for silicon errata on 82598. Mask the interrupts |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2411 | * before the read of EICR. |
| 2412 | */ |
| 2413 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2414 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2415 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 2416 | * therefore no explict interrupt disable is necessary */ |
| 2417 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2418 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2419 | /* |
| 2420 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2421 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2422 | * have disabled interrupts due to EIAM |
| 2423 | * finish the workaround of silicon errata on 82598. Unmask |
| 2424 | * the interrupt that we masked before the EICR read. |
| 2425 | */ |
| 2426 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2427 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2428 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2429 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2430 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2431 | if (eicr & IXGBE_EICR_LSC) |
| 2432 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2433 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2434 | switch (hw->mac.type) { |
| 2435 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2436 | ixgbe_check_sfp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2437 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2438 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2439 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2440 | adapter->interrupt_event = eicr; |
| 2441 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2442 | ixgbe_service_event_schedule(adapter); |
| 2443 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2444 | } |
| 2445 | break; |
| 2446 | default: |
| 2447 | break; |
| 2448 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2449 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2450 | ixgbe_check_fan_failure(adapter, eicr); |
| 2451 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2452 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2453 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2454 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2457 | /* |
| 2458 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2459 | * ixgbe_poll will re-enable the queue interrupts |
| 2460 | */ |
| 2461 | |
| 2462 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2463 | ixgbe_irq_enable(adapter, false, false); |
| 2464 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2465 | return IRQ_HANDLED; |
| 2466 | } |
| 2467 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2468 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 2469 | { |
| 2470 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2471 | |
| 2472 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2473 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2474 | bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES); |
| 2475 | bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES); |
| 2476 | q_vector->rx.count = 0; |
| 2477 | q_vector->tx.count = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2481 | /** |
| 2482 | * ixgbe_request_irq - initialize interrupts |
| 2483 | * @adapter: board private structure |
| 2484 | * |
| 2485 | * Attempts to configure interrupts using the best available |
| 2486 | * capabilities of the hardware and kernel. |
| 2487 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2488 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2489 | { |
| 2490 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2491 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2492 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2493 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2494 | err = ixgbe_request_msix_irqs(adapter); |
| 2495 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2496 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2497 | netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2498 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2499 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2500 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2503 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2504 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2505 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2506 | return err; |
| 2507 | } |
| 2508 | |
| 2509 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2510 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2511 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2512 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2513 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2514 | q_vectors = adapter->num_msix_vectors; |
| 2515 | |
| 2516 | i = q_vectors - 1; |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2517 | free_irq(adapter->msix_entries[i].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2518 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2519 | i--; |
| 2520 | for (; i >= 0; i--) { |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2521 | /* free only the irqs that were actually requested */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2522 | if (!adapter->q_vector[i]->rx.count && |
| 2523 | !adapter->q_vector[i]->tx.count) |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2524 | continue; |
| 2525 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2526 | free_irq(adapter->msix_entries[i].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2527 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | ixgbe_reset_q_vectors(adapter); |
| 2531 | } else { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2532 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2537 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2538 | * @adapter: board private structure |
| 2539 | **/ |
| 2540 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2541 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2542 | switch (adapter->hw.mac.type) { |
| 2543 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2544 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2545 | break; |
| 2546 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2547 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2548 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2549 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2550 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2551 | if (adapter->num_vfs > 32) |
| 2552 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2553 | break; |
| 2554 | default: |
| 2555 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2556 | } |
| 2557 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2558 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2559 | int i; |
| 2560 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 2561 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2562 | } else { |
| 2563 | synchronize_irq(adapter->pdev->irq); |
| 2564 | } |
| 2565 | } |
| 2566 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2567 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2568 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2569 | * |
| 2570 | **/ |
| 2571 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2572 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2573 | struct ixgbe_hw *hw = &adapter->hw; |
| 2574 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2575 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2576 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2577 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2578 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2579 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2580 | |
| 2581 | map_vector_to_rxq(adapter, 0, 0); |
| 2582 | map_vector_to_txq(adapter, 0, 0); |
| 2583 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2584 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2587 | /** |
| 2588 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2589 | * @adapter: board private structure |
| 2590 | * @ring: structure containing ring specific data |
| 2591 | * |
| 2592 | * Configure the Tx descriptor ring after a reset. |
| 2593 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2594 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2595 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2596 | { |
| 2597 | struct ixgbe_hw *hw = &adapter->hw; |
| 2598 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2599 | int wait_loop = 10; |
| 2600 | u32 txdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2601 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2602 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2603 | /* disable queue to avoid issues while updating state */ |
| 2604 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2605 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), |
| 2606 | txdctl & ~IXGBE_TXDCTL_ENABLE); |
| 2607 | IXGBE_WRITE_FLUSH(hw); |
| 2608 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2609 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2610 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2611 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2612 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2613 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2614 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2615 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2616 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2617 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2618 | /* configure fetching thresholds */ |
| 2619 | if (adapter->rx_itr_setting == 0) { |
| 2620 | /* cannot set wthresh when itr==0 */ |
| 2621 | txdctl &= ~0x007F0000; |
| 2622 | } else { |
| 2623 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2624 | txdctl |= (8 << 16); |
| 2625 | } |
| 2626 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2627 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2628 | txdctl |= 32; |
| 2629 | } |
| 2630 | |
| 2631 | /* reinitialize flowdirector state */ |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2632 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2633 | adapter->atr_sample_rate) { |
| 2634 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2635 | ring->atr_count = 0; |
| 2636 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2637 | } else { |
| 2638 | ring->atr_sample_rate = 0; |
| 2639 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2640 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2641 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2642 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2643 | /* enable queue */ |
| 2644 | txdctl |= IXGBE_TXDCTL_ENABLE; |
| 2645 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2646 | |
| 2647 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2648 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2649 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2650 | return; |
| 2651 | |
| 2652 | /* poll to verify queue is enabled */ |
| 2653 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2654 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2655 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2656 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2657 | if (!wait_loop) |
| 2658 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2661 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2662 | { |
| 2663 | struct ixgbe_hw *hw = &adapter->hw; |
| 2664 | u32 rttdcs; |
John Fastabend | 72a32f1 | 2011-04-26 07:25:58 +0000 | [diff] [blame] | 2665 | u32 reg; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2666 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2667 | |
| 2668 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2669 | return; |
| 2670 | |
| 2671 | /* disable the arbiter while setting MTQC */ |
| 2672 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2673 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2674 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2675 | |
| 2676 | /* set transmit pool layout */ |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2677 | switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2678 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2679 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2680 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2681 | break; |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2682 | default: |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2683 | if (!tcs) |
| 2684 | reg = IXGBE_MTQC_64Q_1PB; |
| 2685 | else if (tcs <= 4) |
| 2686 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2687 | else |
| 2688 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2689 | |
| 2690 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg); |
| 2691 | |
| 2692 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 2693 | if (tcs) { |
| 2694 | reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 2695 | reg |= IXGBE_SECTX_DCB; |
| 2696 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg); |
| 2697 | } |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2698 | break; |
| 2699 | } |
| 2700 | |
| 2701 | /* re-enable the arbiter */ |
| 2702 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2703 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2704 | } |
| 2705 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2706 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2707 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2708 | * @adapter: board private structure |
| 2709 | * |
| 2710 | * Configure the Tx unit of the MAC after a reset. |
| 2711 | **/ |
| 2712 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2713 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2714 | struct ixgbe_hw *hw = &adapter->hw; |
| 2715 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2716 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2717 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2718 | ixgbe_setup_mtqc(adapter); |
| 2719 | |
| 2720 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2721 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2722 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2723 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2724 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2725 | } |
| 2726 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2727 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2728 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2729 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2732 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2733 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2734 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2735 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2736 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2737 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2738 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2739 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2740 | switch (adapter->hw.mac.type) { |
| 2741 | case ixgbe_mac_82598EB: { |
| 2742 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
| 2743 | const int mask = feature[RING_F_RSS].mask; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2744 | reg_idx = reg_idx & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2745 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2746 | break; |
| 2747 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2748 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2749 | default: |
| 2750 | break; |
| 2751 | } |
| 2752 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2753 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2754 | |
| 2755 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2756 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2757 | if (adapter->num_vfs) |
| 2758 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2759 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2760 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2761 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2762 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2763 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2764 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2765 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2766 | #else |
| 2767 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2768 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2769 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2770 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2771 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2772 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2773 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2774 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2775 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2776 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2779 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2780 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2781 | struct ixgbe_hw *hw = &adapter->hw; |
| 2782 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2783 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2784 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2785 | u32 mrqc = 0, reta = 0; |
| 2786 | u32 rxcsum; |
| 2787 | int i, j; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2788 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2789 | int maxq = adapter->ring_feature[RING_F_RSS].indices; |
| 2790 | |
| 2791 | if (tcs) |
| 2792 | maxq = min(maxq, adapter->num_tx_queues / tcs); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2793 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2794 | /* Fill out hash function seeds */ |
| 2795 | for (i = 0; i < 10; i++) |
| 2796 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2797 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2798 | /* Fill out redirection table */ |
| 2799 | for (i = 0, j = 0; i < 128; i++, j++) { |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2800 | if (j == maxq) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2801 | j = 0; |
| 2802 | /* reta = 4-byte sliding window of |
| 2803 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2804 | reta = (reta << 8) | (j * 0x11); |
| 2805 | if ((i & 3) == 3) |
| 2806 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 2807 | } |
| 2808 | |
| 2809 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 2810 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2811 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2812 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 2813 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2814 | if (adapter->hw.mac.type == ixgbe_mac_82598EB && |
| 2815 | (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2816 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2817 | } else { |
| 2818 | int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2819 | | IXGBE_FLAG_SRIOV_ENABLED); |
| 2820 | |
| 2821 | switch (mask) { |
| 2822 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2823 | if (!tcs) |
| 2824 | mrqc = IXGBE_MRQC_RSSEN; |
| 2825 | else if (tcs <= 4) |
| 2826 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 2827 | else |
| 2828 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 2829 | break; |
| 2830 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2831 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2832 | break; |
| 2833 | default: |
| 2834 | break; |
| 2835 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2838 | /* Perform hash on these packet types */ |
| 2839 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2840 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2841 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2842 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2843 | |
| 2844 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2845 | } |
| 2846 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2847 | /** |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2848 | * ixgbe_clear_rscctl - disable RSC for the indicated ring |
| 2849 | * @adapter: address of board private structure |
| 2850 | * @ring: structure containing ring specific data |
| 2851 | **/ |
| 2852 | void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter, |
| 2853 | struct ixgbe_ring *ring) |
| 2854 | { |
| 2855 | struct ixgbe_hw *hw = &adapter->hw; |
| 2856 | u32 rscctrl; |
| 2857 | u8 reg_idx = ring->reg_idx; |
| 2858 | |
| 2859 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
| 2860 | rscctrl &= ~IXGBE_RSCCTL_RSCEN; |
| 2861 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
| 2862 | } |
| 2863 | |
| 2864 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2865 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2866 | * @adapter: address of board private structure |
| 2867 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2868 | **/ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2869 | void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2870 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2871 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2872 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2873 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2874 | int rx_buf_len; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2875 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2876 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2877 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2878 | return; |
| 2879 | |
| 2880 | rx_buf_len = ring->rx_buf_len; |
| 2881 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2882 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2883 | /* |
| 2884 | * we must limit the number of descriptors so that the |
| 2885 | * total size of max desc * buf_len is not greater |
| 2886 | * than 65535 |
| 2887 | */ |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2888 | if (ring_is_ps_enabled(ring)) { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2889 | #if (MAX_SKB_FRAGS > 16) |
| 2890 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2891 | #elif (MAX_SKB_FRAGS > 8) |
| 2892 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2893 | #elif (MAX_SKB_FRAGS > 4) |
| 2894 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2895 | #else |
| 2896 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2897 | #endif |
| 2898 | } else { |
| 2899 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2900 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2901 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2902 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2903 | else |
| 2904 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2905 | } |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2906 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2909 | /** |
| 2910 | * ixgbe_set_uta - Set unicast filter table address |
| 2911 | * @adapter: board private structure |
| 2912 | * |
| 2913 | * The unicast table address is a register array of 32-bit registers. |
| 2914 | * The table is meant to be used in a way similar to how the MTA is used |
| 2915 | * however due to certain limitations in the hardware it is necessary to |
| 2916 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 2917 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
| 2918 | **/ |
| 2919 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) |
| 2920 | { |
| 2921 | struct ixgbe_hw *hw = &adapter->hw; |
| 2922 | int i; |
| 2923 | |
| 2924 | /* The UTA table only exists on 82599 hardware and newer */ |
| 2925 | if (hw->mac.type < ixgbe_mac_82599EB) |
| 2926 | return; |
| 2927 | |
| 2928 | /* we only need to do this if VMDq is enabled */ |
| 2929 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2930 | return; |
| 2931 | |
| 2932 | for (i = 0; i < 128; i++) |
| 2933 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); |
| 2934 | } |
| 2935 | |
| 2936 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2937 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2938 | struct ixgbe_ring *ring) |
| 2939 | { |
| 2940 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2941 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2942 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2943 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2944 | |
| 2945 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2946 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2947 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2948 | return; |
| 2949 | |
| 2950 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2951 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2952 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2953 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2954 | |
| 2955 | if (!wait_loop) { |
| 2956 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 2957 | "the polling period\n", reg_idx); |
| 2958 | } |
| 2959 | } |
| 2960 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2961 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 2962 | struct ixgbe_ring *ring) |
| 2963 | { |
| 2964 | struct ixgbe_hw *hw = &adapter->hw; |
| 2965 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2966 | u32 rxdctl; |
| 2967 | u8 reg_idx = ring->reg_idx; |
| 2968 | |
| 2969 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2970 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 2971 | |
| 2972 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 2973 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2974 | |
| 2975 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2976 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2977 | return; |
| 2978 | |
| 2979 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 2980 | do { |
| 2981 | udelay(10); |
| 2982 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2983 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2984 | |
| 2985 | if (!wait_loop) { |
| 2986 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 2987 | "the polling period\n", reg_idx); |
| 2988 | } |
| 2989 | } |
| 2990 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2991 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 2992 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2993 | { |
| 2994 | struct ixgbe_hw *hw = &adapter->hw; |
| 2995 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2996 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2997 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2998 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2999 | /* disable queue to avoid issues while updating state */ |
| 3000 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3001 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3002 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3003 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3004 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3005 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3006 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 3007 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3008 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3009 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3010 | |
| 3011 | ixgbe_configure_srrctl(adapter, ring); |
| 3012 | ixgbe_configure_rscctl(adapter, ring); |
| 3013 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 3014 | /* If operating in IOV mode set RLPML for X540 */ |
| 3015 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 3016 | hw->mac.type == ixgbe_mac_X540) { |
| 3017 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 3018 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 3019 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 3020 | } |
| 3021 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3022 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3023 | /* |
| 3024 | * enable cache line friendly hardware writes: |
| 3025 | * PTHRESH=32 descriptors (half the internal cache), |
| 3026 | * this also removes ugly rx_no_buffer_count increment |
| 3027 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3028 | * WTHRESH=8 burst writeback up to two cache lines |
| 3029 | */ |
| 3030 | rxdctl &= ~0x3FFFFF; |
| 3031 | rxdctl |= 0x080420; |
| 3032 | } |
| 3033 | |
| 3034 | /* enable receive descriptor ring */ |
| 3035 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3036 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3037 | |
| 3038 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3039 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3040 | } |
| 3041 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3042 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3043 | { |
| 3044 | struct ixgbe_hw *hw = &adapter->hw; |
| 3045 | int p; |
| 3046 | |
| 3047 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3048 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3049 | IXGBE_PSRTYPE_UDPHDR | |
| 3050 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3051 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3052 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3053 | |
| 3054 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3055 | return; |
| 3056 | |
| 3057 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) |
| 3058 | psrtype |= (adapter->num_rx_queues_per_pool << 29); |
| 3059 | |
| 3060 | for (p = 0; p < adapter->num_rx_pools; p++) |
| 3061 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), |
| 3062 | psrtype); |
| 3063 | } |
| 3064 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3065 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3066 | { |
| 3067 | struct ixgbe_hw *hw = &adapter->hw; |
| 3068 | u32 gcr_ext; |
| 3069 | u32 vt_reg_bits; |
| 3070 | u32 reg_offset, vf_shift; |
| 3071 | u32 vmdctl; |
| 3072 | |
| 3073 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3074 | return; |
| 3075 | |
| 3076 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 3077 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; |
| 3078 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); |
| 3079 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 3080 | |
| 3081 | vf_shift = adapter->num_vfs % 32; |
| 3082 | reg_offset = (adapter->num_vfs > 32) ? 1 : 0; |
| 3083 | |
| 3084 | /* Enable only the PF's pool for Tx/Rx */ |
| 3085 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 3086 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); |
| 3087 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 3088 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); |
| 3089 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 3090 | |
| 3091 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
| 3092 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 3093 | |
| 3094 | /* |
| 3095 | * Set up VF register offsets for selected VT Mode, |
| 3096 | * i.e. 32 or 64 VFs for SR-IOV |
| 3097 | */ |
| 3098 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3099 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; |
| 3100 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; |
| 3101 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3102 | |
| 3103 | /* enable Tx loopback for VF/PF communication */ |
| 3104 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3105 | /* Enable MAC Anti-Spoofing */ |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3106 | hw->mac.ops.set_mac_anti_spoofing(hw, |
| 3107 | (adapter->antispoofing_enabled = |
| 3108 | (adapter->num_vfs != 0)), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3109 | adapter->num_vfs); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3112 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3113 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3114 | struct ixgbe_hw *hw = &adapter->hw; |
| 3115 | struct net_device *netdev = adapter->netdev; |
| 3116 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3117 | int rx_buf_len; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3118 | struct ixgbe_ring *rx_ring; |
| 3119 | int i; |
| 3120 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3121 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3122 | /* Decide whether to use packet split mode or not */ |
Don Skidmore | a124339 | 2011-01-18 22:53:47 +0000 | [diff] [blame] | 3123 | /* On by default */ |
| 3124 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
| 3125 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3126 | /* Do not use packet split if we're in SR-IOV Mode */ |
Don Skidmore | a124339 | 2011-01-18 22:53:47 +0000 | [diff] [blame] | 3127 | if (adapter->num_vfs) |
| 3128 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
| 3129 | |
| 3130 | /* Disable packet split due to 82599 erratum #45 */ |
| 3131 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3132 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3133 | |
| 3134 | /* Set the RX buffer length according to the mode */ |
| 3135 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3136 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3137 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3138 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3139 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3140 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3141 | else |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3142 | rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024); |
| 3143 | } |
| 3144 | |
| 3145 | #ifdef IXGBE_FCOE |
| 3146 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3147 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3148 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3149 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3150 | |
| 3151 | #endif /* IXGBE_FCOE */ |
| 3152 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3153 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3154 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3155 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3156 | |
| 3157 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3158 | } |
| 3159 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3160 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3161 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3162 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3163 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3164 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3165 | /* |
| 3166 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3167 | * the Base and Length of the Rx Descriptor Ring |
| 3168 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3169 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3170 | rx_ring = adapter->rx_ring[i]; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3171 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3172 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3173 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3174 | set_ring_ps_enabled(rx_ring); |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 3175 | else |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3176 | clear_ring_ps_enabled(rx_ring); |
| 3177 | |
| 3178 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3179 | set_ring_rsc_enabled(rx_ring); |
| 3180 | else |
| 3181 | clear_ring_rsc_enabled(rx_ring); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3182 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3183 | #ifdef IXGBE_FCOE |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3184 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3185 | struct ixgbe_ring_feature *f; |
| 3186 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3187 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3188 | clear_ring_ps_enabled(rx_ring); |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3189 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 3190 | rx_ring->rx_buf_len = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3191 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3192 | } else if (!ring_is_rsc_enabled(rx_ring) && |
| 3193 | !ring_is_ps_enabled(rx_ring)) { |
| 3194 | rx_ring->rx_buf_len = |
| 3195 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3196 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3197 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3198 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3199 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3202 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3203 | { |
| 3204 | struct ixgbe_hw *hw = &adapter->hw; |
| 3205 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3206 | |
| 3207 | switch (hw->mac.type) { |
| 3208 | case ixgbe_mac_82598EB: |
| 3209 | /* |
| 3210 | * For VMDq support of different descriptor types or |
| 3211 | * buffer sizes through the use of multiple SRRCTL |
| 3212 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3213 | * |
| 3214 | * also, the manual doesn't mention it clearly but DCA hints |
| 3215 | * will only use queue 0's tags unless this bit is set. Side |
| 3216 | * effects of setting this bit are only that SRRCTL must be |
| 3217 | * fully programmed [0..15] |
| 3218 | */ |
| 3219 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3220 | break; |
| 3221 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3222 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3223 | /* Disable RSC for ACK packets */ |
| 3224 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3225 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3226 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3227 | /* hardware requires some bits to be set by default */ |
| 3228 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3229 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3230 | break; |
| 3231 | default: |
| 3232 | /* We should do nothing since we don't know this hardware */ |
| 3233 | return; |
| 3234 | } |
| 3235 | |
| 3236 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3237 | } |
| 3238 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3239 | /** |
| 3240 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3241 | * @adapter: board private structure |
| 3242 | * |
| 3243 | * Configure the Rx unit of the MAC after a reset. |
| 3244 | **/ |
| 3245 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3246 | { |
| 3247 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3248 | int i; |
| 3249 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3250 | |
| 3251 | /* disable receives while setting up the descriptors */ |
| 3252 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3253 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3254 | |
| 3255 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3256 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3257 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3258 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3259 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3260 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3261 | ixgbe_set_uta(adapter); |
| 3262 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3263 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3264 | ixgbe_set_rx_buffer_len(adapter); |
| 3265 | |
| 3266 | /* |
| 3267 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3268 | * the Base and Length of the Rx Descriptor Ring |
| 3269 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3270 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3271 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3272 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3273 | /* disable drop enable for 82598 parts */ |
| 3274 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3275 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3276 | |
| 3277 | /* enable all receives */ |
| 3278 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3279 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3282 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 3283 | { |
| 3284 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3285 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3286 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3287 | |
| 3288 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3289 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3290 | set_bit(vid, adapter->active_vlans); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 3294 | { |
| 3295 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3296 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3297 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3298 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3299 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3300 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3301 | clear_bit(vid, adapter->active_vlans); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3302 | } |
| 3303 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3304 | /** |
| 3305 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3306 | * @adapter: driver data |
| 3307 | */ |
| 3308 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3309 | { |
| 3310 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3311 | u32 vlnctrl; |
| 3312 | |
| 3313 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3314 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3315 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3316 | } |
| 3317 | |
| 3318 | /** |
| 3319 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3320 | * @adapter: driver data |
| 3321 | */ |
| 3322 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3323 | { |
| 3324 | struct ixgbe_hw *hw = &adapter->hw; |
| 3325 | u32 vlnctrl; |
| 3326 | |
| 3327 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3328 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3329 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3330 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3331 | } |
| 3332 | |
| 3333 | /** |
| 3334 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3335 | * @adapter: driver data |
| 3336 | */ |
| 3337 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3338 | { |
| 3339 | struct ixgbe_hw *hw = &adapter->hw; |
| 3340 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3341 | int i, j; |
| 3342 | |
| 3343 | switch (hw->mac.type) { |
| 3344 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3345 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3346 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3347 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3348 | break; |
| 3349 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3350 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3351 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3352 | j = adapter->rx_ring[i]->reg_idx; |
| 3353 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3354 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3355 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3356 | } |
| 3357 | break; |
| 3358 | default: |
| 3359 | break; |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3364 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3365 | * @adapter: driver data |
| 3366 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3367 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3368 | { |
| 3369 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3370 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3371 | int i, j; |
| 3372 | |
| 3373 | switch (hw->mac.type) { |
| 3374 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3375 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3376 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3377 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3378 | break; |
| 3379 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3380 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3381 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3382 | j = adapter->rx_ring[i]->reg_idx; |
| 3383 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3384 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3385 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3386 | } |
| 3387 | break; |
| 3388 | default: |
| 3389 | break; |
| 3390 | } |
| 3391 | } |
| 3392 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3393 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3394 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3395 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3396 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3397 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3398 | |
| 3399 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3400 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3404 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3405 | * @netdev: network interface device structure |
| 3406 | * |
| 3407 | * Writes unicast address list to the RAR table. |
| 3408 | * Returns: -ENOMEM on failure/insufficient address space |
| 3409 | * 0 on no addresses written |
| 3410 | * X on writing X addresses to the RAR table |
| 3411 | **/ |
| 3412 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3413 | { |
| 3414 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3415 | struct ixgbe_hw *hw = &adapter->hw; |
| 3416 | unsigned int vfn = adapter->num_vfs; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3417 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3418 | int count = 0; |
| 3419 | |
| 3420 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3421 | if (netdev_uc_count(netdev) > rar_entries) |
| 3422 | return -ENOMEM; |
| 3423 | |
| 3424 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3425 | struct netdev_hw_addr *ha; |
| 3426 | /* return error if we do not support writing to RAR table */ |
| 3427 | if (!hw->mac.ops.set_rar) |
| 3428 | return -ENOMEM; |
| 3429 | |
| 3430 | netdev_for_each_uc_addr(ha, netdev) { |
| 3431 | if (!rar_entries) |
| 3432 | break; |
| 3433 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
| 3434 | vfn, IXGBE_RAH_AV); |
| 3435 | count++; |
| 3436 | } |
| 3437 | } |
| 3438 | /* write the addresses in reverse order to avoid write combining */ |
| 3439 | for (; rar_entries > 0 ; rar_entries--) |
| 3440 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3441 | |
| 3442 | return count; |
| 3443 | } |
| 3444 | |
| 3445 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3446 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3447 | * @netdev: network interface device structure |
| 3448 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3449 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3450 | * address list or the network interface flags are updated. This routine is |
| 3451 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3452 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3453 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3454 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3455 | { |
| 3456 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3457 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3458 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3459 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3460 | |
| 3461 | /* Check for Promiscuous and All Multicast modes */ |
| 3462 | |
| 3463 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3464 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3465 | /* set all bits that we expect to always be set */ |
| 3466 | fctrl |= IXGBE_FCTRL_BAM; |
| 3467 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3468 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3469 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3470 | /* clear the bits we are changing the status of */ |
| 3471 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3472 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3473 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3474 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3475 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3476 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3477 | /* don't hardware filter vlans in promisc mode */ |
| 3478 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3479 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3480 | if (netdev->flags & IFF_ALLMULTI) { |
| 3481 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3482 | vmolr |= IXGBE_VMOLR_MPE; |
| 3483 | } else { |
| 3484 | /* |
| 3485 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3486 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3487 | * that we can at least receive multicast traffic |
| 3488 | */ |
| 3489 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3490 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3491 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3492 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3493 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3494 | /* |
| 3495 | * Write addresses to available RAR registers, if there is not |
| 3496 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3497 | * unicast promiscuous mode |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3498 | */ |
| 3499 | count = ixgbe_write_uc_addr_list(netdev); |
| 3500 | if (count < 0) { |
| 3501 | fctrl |= IXGBE_FCTRL_UPE; |
| 3502 | vmolr |= IXGBE_VMOLR_ROPE; |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | if (adapter->num_vfs) { |
| 3507 | ixgbe_restore_vf_multicasts(adapter); |
| 3508 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & |
| 3509 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3510 | IXGBE_VMOLR_ROPE); |
| 3511 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3515 | |
| 3516 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3517 | ixgbe_vlan_strip_enable(adapter); |
| 3518 | else |
| 3519 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3522 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3523 | { |
| 3524 | int q_idx; |
| 3525 | struct ixgbe_q_vector *q_vector; |
| 3526 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3527 | |
| 3528 | /* legacy and MSI only use one vector */ |
| 3529 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3530 | q_vectors = 1; |
| 3531 | |
| 3532 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3533 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3534 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3535 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3536 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 3537 | if (!q_vector->rx.count || !q_vector->tx.count) { |
| 3538 | if (q_vector->tx.count == 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3539 | napi->poll = &ixgbe_clean_txonly; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 3540 | else if (q_vector->rx.count == 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3541 | napi->poll = &ixgbe_clean_rxonly; |
| 3542 | } |
| 3543 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3544 | |
| 3545 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3550 | { |
| 3551 | int q_idx; |
| 3552 | struct ixgbe_q_vector *q_vector; |
| 3553 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3554 | |
| 3555 | /* legacy and MSI only use one vector */ |
| 3556 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3557 | q_vectors = 1; |
| 3558 | |
| 3559 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3560 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3561 | napi_disable(&q_vector->napi); |
| 3562 | } |
| 3563 | } |
| 3564 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3565 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3566 | /* |
| 3567 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3568 | * @adapter: ixgbe adapter struct |
| 3569 | * |
| 3570 | * This is called by the driver on open to configure the DCB hardware. |
| 3571 | * This is also called by the gennetlink interface when reconfiguring |
| 3572 | * the DCB state. |
| 3573 | */ |
| 3574 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3575 | { |
| 3576 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3577 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3578 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3579 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3580 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3581 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3582 | return; |
| 3583 | } |
| 3584 | |
| 3585 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3586 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3587 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3588 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3589 | /* Enable VLAN tag insert/strip */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3590 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3591 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3592 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3593 | |
| 3594 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3595 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3596 | #ifdef CONFIG_FCOE |
| 3597 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3598 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3599 | #endif |
| 3600 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3601 | DCB_TX_CONFIG); |
| 3602 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3603 | DCB_RX_CONFIG); |
| 3604 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
| 3605 | } else { |
| 3606 | struct net_device *dev = adapter->netdev; |
| 3607 | |
| 3608 | if (adapter->ixgbe_ieee_ets) |
| 3609 | dev->dcbnl_ops->ieee_setets(dev, |
| 3610 | adapter->ixgbe_ieee_ets); |
| 3611 | if (adapter->ixgbe_ieee_pfc) |
| 3612 | dev->dcbnl_ops->ieee_setpfc(dev, |
| 3613 | adapter->ixgbe_ieee_pfc); |
| 3614 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3615 | |
| 3616 | /* Enable RSS Hash per TC */ |
| 3617 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3618 | int i; |
| 3619 | u32 reg = 0; |
| 3620 | |
| 3621 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 3622 | u8 msb = 0; |
| 3623 | u8 cnt = adapter->netdev->tc_to_txq[i].count; |
| 3624 | |
| 3625 | while (cnt >>= 1) |
| 3626 | msb++; |
| 3627 | |
| 3628 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); |
| 3629 | } |
| 3630 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); |
| 3631 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | #endif |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3635 | |
| 3636 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3637 | { |
| 3638 | int hdrm = 0; |
| 3639 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3640 | struct ixgbe_hw *hw = &adapter->hw; |
| 3641 | |
| 3642 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3643 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3644 | hdrm = 64 << adapter->fdir_pballoc; |
| 3645 | |
| 3646 | hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL); |
| 3647 | } |
| 3648 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3649 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 3650 | { |
| 3651 | struct ixgbe_hw *hw = &adapter->hw; |
| 3652 | struct hlist_node *node, *node2; |
| 3653 | struct ixgbe_fdir_filter *filter; |
| 3654 | |
| 3655 | spin_lock(&adapter->fdir_perfect_lock); |
| 3656 | |
| 3657 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 3658 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 3659 | |
| 3660 | hlist_for_each_entry_safe(filter, node, node2, |
| 3661 | &adapter->fdir_filter_list, fdir_node) { |
| 3662 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 3663 | &filter->filter, |
| 3664 | filter->sw_idx, |
| 3665 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 3666 | IXGBE_FDIR_DROP_QUEUE : |
| 3667 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | spin_unlock(&adapter->fdir_perfect_lock); |
| 3671 | } |
| 3672 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3673 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3674 | { |
| 3675 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3676 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3677 | int i; |
| 3678 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3679 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3680 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3681 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3682 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3683 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3684 | ixgbe_set_rx_mode(netdev); |
| 3685 | ixgbe_restore_vlan(adapter); |
| 3686 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3687 | #ifdef IXGBE_FCOE |
| 3688 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 3689 | ixgbe_configure_fcoe(adapter); |
| 3690 | |
| 3691 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3692 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 3693 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3694 | adapter->tx_ring[i]->atr_sample_rate = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3695 | adapter->atr_sample_rate; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3696 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3697 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3698 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 3699 | adapter->fdir_pballoc); |
| 3700 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3701 | } |
Alexander Duyck | 933d41f | 2010-09-07 21:34:29 +0000 | [diff] [blame] | 3702 | ixgbe_configure_virtualization(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3703 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3704 | ixgbe_configure_tx(adapter); |
| 3705 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3706 | } |
| 3707 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3708 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3709 | { |
| 3710 | switch (hw->phy.type) { |
| 3711 | case ixgbe_phy_sfp_avago: |
| 3712 | case ixgbe_phy_sfp_ftl: |
| 3713 | case ixgbe_phy_sfp_intel: |
| 3714 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3715 | case ixgbe_phy_sfp_passive_tyco: |
| 3716 | case ixgbe_phy_sfp_passive_unknown: |
| 3717 | case ixgbe_phy_sfp_active_unknown: |
| 3718 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3719 | return true; |
| 3720 | default: |
| 3721 | return false; |
| 3722 | } |
| 3723 | } |
| 3724 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3725 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3726 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3727 | * @adapter: pointer to private adapter struct |
| 3728 | **/ |
| 3729 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3730 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3731 | /* |
| 3732 | * We are assuming the worst case scenerio here, and that |
| 3733 | * is that an SFP was inserted/removed after the reset |
| 3734 | * but before SFP detection was enabled. As such the best |
| 3735 | * solution is to just start searching as soon as we start |
| 3736 | */ |
| 3737 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3738 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3739 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3740 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | /** |
| 3744 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3745 | * @hw: pointer to private hardware struct |
| 3746 | * |
| 3747 | * Returns 0 on success, negative on failure |
| 3748 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3749 | 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] | 3750 | { |
| 3751 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3752 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3753 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 3754 | |
| 3755 | if (hw->mac.ops.check_link) |
| 3756 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 3757 | |
| 3758 | if (ret) |
| 3759 | goto link_cfg_out; |
| 3760 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 3761 | autoneg = hw->phy.autoneg_advertised; |
| 3762 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3763 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3764 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3765 | if (ret) |
| 3766 | goto link_cfg_out; |
| 3767 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3768 | if (hw->mac.ops.setup_link) |
| 3769 | 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] | 3770 | link_cfg_out: |
| 3771 | return ret; |
| 3772 | } |
| 3773 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3774 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3775 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3776 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3777 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3778 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3779 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3780 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 3781 | IXGBE_GPIE_OCD; |
| 3782 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3783 | /* |
| 3784 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 3785 | * this saves a register write for every interrupt |
| 3786 | */ |
| 3787 | switch (hw->mac.type) { |
| 3788 | case ixgbe_mac_82598EB: |
| 3789 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 3790 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3791 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3792 | case ixgbe_mac_X540: |
| 3793 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3794 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 3795 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 3796 | break; |
| 3797 | } |
| 3798 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3799 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 3800 | * specifically only auto mask tx and rx interrupts */ |
| 3801 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3804 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 3805 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 3806 | |
| 3807 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3808 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 3809 | gpie |= IXGBE_GPIE_VTMODE_64; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3812 | /* Enable fan failure interrupt */ |
| 3813 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3814 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3815 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3816 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3817 | gpie |= IXGBE_SDP1_GPIEN; |
| 3818 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3819 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3820 | |
| 3821 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 3822 | } |
| 3823 | |
| 3824 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 3825 | { |
| 3826 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3827 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3828 | u32 ctrl_ext; |
| 3829 | |
| 3830 | ixgbe_get_hw_control(adapter); |
| 3831 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3832 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3833 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3834 | ixgbe_configure_msix(adapter); |
| 3835 | else |
| 3836 | ixgbe_configure_msi_and_legacy(adapter); |
| 3837 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3838 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ |
| 3839 | if (hw->mac.ops.enable_tx_laser && |
| 3840 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 3841 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3842 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 3843 | hw->mac.ops.enable_tx_laser(hw); |
| 3844 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3845 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3846 | ixgbe_napi_enable_all(adapter); |
| 3847 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 3848 | if (ixgbe_is_sfp(hw)) { |
| 3849 | ixgbe_sfp_link_config(adapter); |
| 3850 | } else { |
| 3851 | err = ixgbe_non_sfp_link_config(hw); |
| 3852 | if (err) |
| 3853 | e_err(probe, "link_config FAILED %d\n", err); |
| 3854 | } |
| 3855 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3856 | /* clear any pending interrupts, may auto mask */ |
| 3857 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3858 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3859 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3860 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3861 | * If this adapter has a fan, check to see if we had a failure |
| 3862 | * before we enabled the interrupt. |
| 3863 | */ |
| 3864 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 3865 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 3866 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3867 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3870 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3871 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3872 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3873 | /* bring the link up in the watchdog, this could race with our first |
| 3874 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3875 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3876 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3877 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 3878 | |
| 3879 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 3880 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 3881 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 3882 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
| 3883 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3884 | return 0; |
| 3885 | } |
| 3886 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3887 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 3888 | { |
| 3889 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3890 | /* put off any impending NetWatchDogTimeout */ |
| 3891 | adapter->netdev->trans_start = jiffies; |
| 3892 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3893 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3894 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3895 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 3896 | /* |
| 3897 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 3898 | * back up to give the VFs time to respond to the reset. The |
| 3899 | * two second wait is based upon the watchdog timer cycle in |
| 3900 | * the VF driver. |
| 3901 | */ |
| 3902 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3903 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3904 | ixgbe_up(adapter); |
| 3905 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 3906 | } |
| 3907 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3908 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 3909 | { |
| 3910 | /* hardware has been reset, we need to reload some things */ |
| 3911 | ixgbe_configure(adapter); |
| 3912 | |
| 3913 | return ixgbe_up_complete(adapter); |
| 3914 | } |
| 3915 | |
| 3916 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 3917 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3918 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3919 | int err; |
| 3920 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3921 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 3922 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 3923 | usleep_range(1000, 2000); |
| 3924 | |
| 3925 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 3926 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 3927 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 3928 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 3929 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3930 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3931 | switch (err) { |
| 3932 | case 0: |
| 3933 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3934 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3935 | break; |
| 3936 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3937 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3938 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3939 | case IXGBE_ERR_EEPROM_VERSION: |
| 3940 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3941 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 3942 | "Please be aware there may be issuesassociated with " |
| 3943 | "your hardware. If you are experiencing problems " |
| 3944 | "please contact your Intel or hardware " |
| 3945 | "representative who provided you with this " |
| 3946 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3947 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3948 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3949 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3950 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3951 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3952 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 3953 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3954 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3955 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 3956 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3959 | /** |
| 3960 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3961 | * @rx_ring: ring to free buffers from |
| 3962 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3963 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3964 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3965 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3966 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3967 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3968 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3969 | /* ring already cleared, nothing to do */ |
| 3970 | if (!rx_ring->rx_buffer_info) |
| 3971 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3972 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3973 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3974 | for (i = 0; i < rx_ring->count; i++) { |
| 3975 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 3976 | |
| 3977 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 3978 | if (rx_buffer_info->dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3979 | dma_unmap_single(rx_ring->dev, rx_buffer_info->dma, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3980 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3981 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3982 | rx_buffer_info->dma = 0; |
| 3983 | } |
| 3984 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3985 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3986 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3987 | do { |
| 3988 | struct sk_buff *this = skb; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 3989 | if (IXGBE_RSC_CB(this)->delay_unmap) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3990 | dma_unmap_single(dev, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3991 | IXGBE_RSC_CB(this)->dma, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3992 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3993 | DMA_FROM_DEVICE); |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 3994 | IXGBE_RSC_CB(this)->dma = 0; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 3995 | IXGBE_RSC_CB(skb)->delay_unmap = false; |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 3996 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3997 | skb = skb->prev; |
| 3998 | dev_kfree_skb(this); |
| 3999 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4000 | } |
| 4001 | if (!rx_buffer_info->page) |
| 4002 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 4003 | if (rx_buffer_info->page_dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4004 | dma_unmap_page(dev, rx_buffer_info->page_dma, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 4005 | PAGE_SIZE / 2, DMA_FROM_DEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 4006 | rx_buffer_info->page_dma = 0; |
| 4007 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4008 | put_page(rx_buffer_info->page); |
| 4009 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 4010 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4011 | } |
| 4012 | |
| 4013 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4014 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4015 | |
| 4016 | /* Zero out the descriptor ring */ |
| 4017 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4018 | |
| 4019 | rx_ring->next_to_clean = 0; |
| 4020 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4025 | * @tx_ring: ring to be cleaned |
| 4026 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4027 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4028 | { |
| 4029 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4030 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4031 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4032 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4033 | /* ring already cleared, nothing to do */ |
| 4034 | if (!tx_ring->tx_buffer_info) |
| 4035 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4036 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4037 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4038 | for (i = 0; i < tx_ring->count; i++) { |
| 4039 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4040 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4044 | memset(tx_ring->tx_buffer_info, 0, size); |
| 4045 | |
| 4046 | /* Zero out the descriptor ring */ |
| 4047 | memset(tx_ring->desc, 0, tx_ring->size); |
| 4048 | |
| 4049 | tx_ring->next_to_use = 0; |
| 4050 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4054 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4055 | * @adapter: board private structure |
| 4056 | **/ |
| 4057 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4058 | { |
| 4059 | int i; |
| 4060 | |
| 4061 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4062 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4063 | } |
| 4064 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4065 | /** |
| 4066 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4067 | * @adapter: board private structure |
| 4068 | **/ |
| 4069 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4070 | { |
| 4071 | int i; |
| 4072 | |
| 4073 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4074 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4075 | } |
| 4076 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4077 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4078 | { |
| 4079 | struct hlist_node *node, *node2; |
| 4080 | struct ixgbe_fdir_filter *filter; |
| 4081 | |
| 4082 | spin_lock(&adapter->fdir_perfect_lock); |
| 4083 | |
| 4084 | hlist_for_each_entry_safe(filter, node, node2, |
| 4085 | &adapter->fdir_filter_list, fdir_node) { |
| 4086 | hlist_del(&filter->fdir_node); |
| 4087 | kfree(filter); |
| 4088 | } |
| 4089 | adapter->fdir_filter_count = 0; |
| 4090 | |
| 4091 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4092 | } |
| 4093 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4094 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4095 | { |
| 4096 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4097 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4098 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4099 | int i; |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4100 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4101 | |
| 4102 | /* signal that we are down to the interrupt handler */ |
| 4103 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4104 | |
| 4105 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4106 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4107 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4108 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4109 | /* disable all enabled rx queues */ |
| 4110 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4111 | /* this call also flushes the previous write */ |
| 4112 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4113 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4114 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4115 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4116 | netif_tx_stop_all_queues(netdev); |
| 4117 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4118 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4119 | netif_carrier_off(netdev); |
| 4120 | netif_tx_disable(netdev); |
| 4121 | |
| 4122 | ixgbe_irq_disable(adapter); |
| 4123 | |
| 4124 | ixgbe_napi_disable_all(adapter); |
| 4125 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4126 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4127 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4128 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4129 | |
| 4130 | del_timer_sync(&adapter->service_timer); |
| 4131 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4132 | /* disable receive for all VFs and wait one second */ |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4133 | if (adapter->num_vfs) { |
| 4134 | /* 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] | 4135 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4136 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4137 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4138 | ixgbe_disable_tx_rx(adapter); |
| 4139 | |
| 4140 | /* Mark all the VFs as inactive */ |
| 4141 | for (i = 0 ; i < adapter->num_vfs; i++) |
| 4142 | adapter->vfinfo[i].clear_to_send = 0; |
| 4143 | } |
| 4144 | |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4145 | /* Cleanup the affinity_hint CPU mask memory and callback */ |
| 4146 | for (i = 0; i < num_q_vectors; i++) { |
| 4147 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 4148 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4149 | irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL); |
| 4150 | /* release the CPU mask memory */ |
| 4151 | free_cpumask_var(q_vector->affinity_mask); |
| 4152 | } |
| 4153 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4154 | /* disable transmits in the hardware now that interrupts are off */ |
| 4155 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4156 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4157 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4158 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4159 | |
| 4160 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4161 | switch (hw->mac.type) { |
| 4162 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4163 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4164 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4165 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4166 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4167 | break; |
| 4168 | default: |
| 4169 | break; |
| 4170 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4171 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4172 | if (!pci_channel_offline(adapter->pdev)) |
| 4173 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4174 | |
| 4175 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 4176 | if (hw->mac.ops.disable_tx_laser && |
| 4177 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 4178 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4179 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 4180 | hw->mac.ops.disable_tx_laser(hw); |
| 4181 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4182 | ixgbe_clean_all_tx_rings(adapter); |
| 4183 | ixgbe_clean_all_rx_rings(adapter); |
| 4184 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4185 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4186 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4187 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4188 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4191 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4192 | * ixgbe_poll - NAPI Rx polling callback |
| 4193 | * @napi: structure for representing this polling device |
| 4194 | * @budget: how many packets driver is allowed to clean |
| 4195 | * |
| 4196 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4197 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4198 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4199 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4200 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4201 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4202 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4203 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4204 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4205 | #ifdef CONFIG_IXGBE_DCA |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 4206 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 4207 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4208 | #endif |
| 4209 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4210 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]); |
| 4211 | 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] | 4212 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4213 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4214 | work_done = budget; |
| 4215 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 4216 | /* If budget not fully consumed, exit the polling mode */ |
| 4217 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 4218 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4219 | if (adapter->rx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 4220 | ixgbe_set_itr(q_vector); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4221 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 4222 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4223 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4224 | return work_done; |
| 4225 | } |
| 4226 | |
| 4227 | /** |
| 4228 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4229 | * @netdev: network interface device structure |
| 4230 | **/ |
| 4231 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4232 | { |
| 4233 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4234 | |
| 4235 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4236 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4237 | } |
| 4238 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4239 | /** |
| 4240 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 4241 | * @adapter: board private structure to initialize |
| 4242 | * |
| 4243 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 4244 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 4245 | * |
| 4246 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4247 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 4248 | { |
| 4249 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4250 | 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] | 4251 | |
| 4252 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4253 | f->mask = 0xF; |
| 4254 | adapter->num_rx_queues = f->indices; |
| 4255 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4256 | ret = true; |
| 4257 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4258 | ret = false; |
| 4259 | } |
| 4260 | |
| 4261 | return ret; |
| 4262 | } |
| 4263 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4264 | /** |
| 4265 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 4266 | * @adapter: board private structure to initialize |
| 4267 | * |
| 4268 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 4269 | * to the original CPU that initiated the Tx session. This runs in addition |
| 4270 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 4271 | * Rx load across CPUs using RSS. |
| 4272 | * |
| 4273 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4274 | 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] | 4275 | { |
| 4276 | bool ret = false; |
| 4277 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 4278 | |
| 4279 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 4280 | f_fdir->mask = 0; |
| 4281 | |
| 4282 | /* Flow Director must have RSS enabled */ |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4283 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4284 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4285 | adapter->num_tx_queues = f_fdir->indices; |
| 4286 | adapter->num_rx_queues = f_fdir->indices; |
| 4287 | ret = true; |
| 4288 | } else { |
| 4289 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4290 | } |
| 4291 | return ret; |
| 4292 | } |
| 4293 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4294 | #ifdef IXGBE_FCOE |
| 4295 | /** |
| 4296 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 4297 | * @adapter: board private structure to initialize |
| 4298 | * |
| 4299 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 4300 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 4301 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 4302 | * index of the first rx queue used by FCoE. |
| 4303 | * |
| 4304 | **/ |
| 4305 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 4306 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4307 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 4308 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4309 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4310 | return false; |
| 4311 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4312 | f->indices = min((int)num_online_cpus(), f->indices); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4313 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4314 | adapter->num_rx_queues = 1; |
| 4315 | adapter->num_tx_queues = 1; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4316 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4317 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 4318 | e_info(probe, "FCoE enabled with RSS\n"); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4319 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4320 | ixgbe_set_fdir_queues(adapter); |
| 4321 | else |
| 4322 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4323 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4324 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4325 | /* adding FCoE rx rings to the end */ |
| 4326 | f->mask = adapter->num_rx_queues; |
| 4327 | adapter->num_rx_queues += f->indices; |
| 4328 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4329 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4330 | return true; |
| 4331 | } |
| 4332 | #endif /* IXGBE_FCOE */ |
| 4333 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4334 | /* Artificial max queue cap per traffic class in DCB mode */ |
| 4335 | #define DCB_QUEUE_CAP 8 |
| 4336 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4337 | #ifdef CONFIG_IXGBE_DCB |
| 4338 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
| 4339 | { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4340 | int per_tc_q, q, i, offset = 0; |
| 4341 | struct net_device *dev = adapter->netdev; |
| 4342 | int tcs = netdev_get_num_tc(dev); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4343 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4344 | if (!tcs) |
| 4345 | return false; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4346 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4347 | /* Map queue offset and counts onto allocated tx queues */ |
| 4348 | per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP); |
| 4349 | q = min((int)num_online_cpus(), per_tc_q); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4350 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4351 | for (i = 0; i < tcs; i++) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4352 | netdev_set_prio_tc_map(dev, i, i); |
| 4353 | netdev_set_tc_queue(dev, i, q, offset); |
| 4354 | offset += q; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4357 | adapter->num_tx_queues = q * tcs; |
| 4358 | adapter->num_rx_queues = q * tcs; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4359 | |
| 4360 | #ifdef IXGBE_FCOE |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4361 | /* FCoE enabled queues require special configuration indexed |
| 4362 | * by feature specific indices and mask. Here we map FCoE |
| 4363 | * indices onto the DCB queue pairs allowing FCoE to own |
| 4364 | * configuration later. |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4365 | */ |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4366 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 4367 | int tc; |
| 4368 | struct ixgbe_ring_feature *f = |
| 4369 | &adapter->ring_feature[RING_F_FCOE]; |
| 4370 | |
| 4371 | tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up); |
| 4372 | f->indices = dev->tc_to_txq[tc].count; |
| 4373 | f->mask = dev->tc_to_txq[tc].offset; |
| 4374 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4375 | #endif |
| 4376 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4377 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4378 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4379 | #endif |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4380 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4381 | /** |
| 4382 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 4383 | * @adapter: board private structure to initialize |
| 4384 | * |
| 4385 | * IOV doesn't actually use anything, so just NAK the |
| 4386 | * request for now and let the other queue routines |
| 4387 | * figure out what to do. |
| 4388 | */ |
| 4389 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 4390 | { |
| 4391 | return false; |
| 4392 | } |
| 4393 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4394 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4395 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4396 | * @adapter: board private structure to initialize |
| 4397 | * |
| 4398 | * This is the top level queue allocation routine. The order here is very |
| 4399 | * important, starting with the "most" number of features turned on at once, |
| 4400 | * and ending with the smallest set of features. This way large combinations |
| 4401 | * can be allocated if they're turned on, and smaller combinations are the |
| 4402 | * fallthrough conditions. |
| 4403 | * |
| 4404 | **/ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4405 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4406 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4407 | /* Start with base case */ |
| 4408 | adapter->num_rx_queues = 1; |
| 4409 | adapter->num_tx_queues = 1; |
| 4410 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 4411 | adapter->num_rx_queues_per_pool = 1; |
| 4412 | |
| 4413 | if (ixgbe_set_sriov_queues(adapter)) |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4414 | goto done; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4415 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4416 | #ifdef CONFIG_IXGBE_DCB |
| 4417 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4418 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4419 | |
| 4420 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4421 | #ifdef IXGBE_FCOE |
| 4422 | if (ixgbe_set_fcoe_queues(adapter)) |
| 4423 | goto done; |
| 4424 | |
| 4425 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4426 | if (ixgbe_set_fdir_queues(adapter)) |
| 4427 | goto done; |
| 4428 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4429 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4430 | goto done; |
| 4431 | |
| 4432 | /* fallback to base case */ |
| 4433 | adapter->num_rx_queues = 1; |
| 4434 | adapter->num_tx_queues = 1; |
| 4435 | |
| 4436 | done: |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4437 | /* Notify the stack of the (possibly) reduced queue counts. */ |
John Fastabend | f0796d5 | 2010-07-01 13:21:57 +0000 | [diff] [blame] | 4438 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4439 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 4440 | adapter->num_rx_queues); |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4441 | } |
| 4442 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4443 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4444 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4445 | { |
| 4446 | int err, vector_threshold; |
| 4447 | |
| 4448 | /* We'll want at least 3 (vector_threshold): |
| 4449 | * 1) TxQ[0] Cleanup |
| 4450 | * 2) RxQ[0] Cleanup |
| 4451 | * 3) Other (Link Status Change, etc.) |
| 4452 | * 4) TCP Timer (optional) |
| 4453 | */ |
| 4454 | vector_threshold = MIN_MSIX_COUNT; |
| 4455 | |
| 4456 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 4457 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 4458 | * Right now, we simply care about how many we'll get; we'll |
| 4459 | * set them up later while requesting irq's. |
| 4460 | */ |
| 4461 | while (vectors >= vector_threshold) { |
| 4462 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4463 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4464 | if (!err) /* Success in acquiring all requested vectors. */ |
| 4465 | break; |
| 4466 | else if (err < 0) |
| 4467 | vectors = 0; /* Nasty failure, quit now */ |
| 4468 | else /* err == number of vectors we should try again with */ |
| 4469 | vectors = err; |
| 4470 | } |
| 4471 | |
| 4472 | if (vectors < vector_threshold) { |
| 4473 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 4474 | * This just means we'll go with either a single MSI |
| 4475 | * vector or fall back to legacy interrupts. |
| 4476 | */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4477 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4478 | "Unable to allocate MSI-X interrupts\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4479 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4480 | kfree(adapter->msix_entries); |
| 4481 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4482 | } else { |
| 4483 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 4484 | /* |
| 4485 | * Adjust for only the vectors we'll use, which is minimum |
| 4486 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 4487 | * vectors we were allocated. |
| 4488 | */ |
| 4489 | adapter->num_msix_vectors = min(vectors, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4490 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4491 | } |
| 4492 | } |
| 4493 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4494 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4495 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4496 | * @adapter: board private structure to initialize |
| 4497 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4498 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 4499 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4500 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4501 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4502 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4503 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4504 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4505 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 4506 | return false; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4507 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4508 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4509 | adapter->rx_ring[i]->reg_idx = i; |
| 4510 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4511 | adapter->tx_ring[i]->reg_idx = i; |
| 4512 | |
| 4513 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4517 | |
| 4518 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 4519 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, |
| 4520 | unsigned int *tx, unsigned int *rx) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4521 | { |
| 4522 | struct net_device *dev = adapter->netdev; |
| 4523 | struct ixgbe_hw *hw = &adapter->hw; |
| 4524 | u8 num_tcs = netdev_get_num_tc(dev); |
| 4525 | |
| 4526 | *tx = 0; |
| 4527 | *rx = 0; |
| 4528 | |
| 4529 | switch (hw->mac.type) { |
| 4530 | case ixgbe_mac_82598EB: |
John Fastabend | aba70d5 | 2011-04-26 07:26:14 +0000 | [diff] [blame] | 4531 | *tx = tc << 2; |
| 4532 | *rx = tc << 3; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4533 | break; |
| 4534 | case ixgbe_mac_82599EB: |
| 4535 | case ixgbe_mac_X540: |
| 4536 | if (num_tcs == 8) { |
| 4537 | if (tc < 3) { |
| 4538 | *tx = tc << 5; |
| 4539 | *rx = tc << 4; |
| 4540 | } else if (tc < 5) { |
| 4541 | *tx = ((tc + 2) << 4); |
| 4542 | *rx = tc << 4; |
| 4543 | } else if (tc < num_tcs) { |
| 4544 | *tx = ((tc + 8) << 3); |
| 4545 | *rx = tc << 4; |
| 4546 | } |
| 4547 | } else if (num_tcs == 4) { |
| 4548 | *rx = tc << 5; |
| 4549 | switch (tc) { |
| 4550 | case 0: |
| 4551 | *tx = 0; |
| 4552 | break; |
| 4553 | case 1: |
| 4554 | *tx = 64; |
| 4555 | break; |
| 4556 | case 2: |
| 4557 | *tx = 96; |
| 4558 | break; |
| 4559 | case 3: |
| 4560 | *tx = 112; |
| 4561 | break; |
| 4562 | default: |
| 4563 | break; |
| 4564 | } |
| 4565 | } |
| 4566 | break; |
| 4567 | default: |
| 4568 | break; |
| 4569 | } |
| 4570 | } |
| 4571 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4572 | /** |
| 4573 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 4574 | * @adapter: board private structure to initialize |
| 4575 | * |
| 4576 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 4577 | * |
| 4578 | **/ |
| 4579 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 4580 | { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4581 | struct net_device *dev = adapter->netdev; |
| 4582 | int i, j, k; |
| 4583 | u8 num_tcs = netdev_get_num_tc(dev); |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4584 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4585 | if (!num_tcs) |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4586 | return false; |
| 4587 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4588 | for (i = 0, k = 0; i < num_tcs; i++) { |
| 4589 | unsigned int tx_s, rx_s; |
| 4590 | u16 count = dev->tc_to_txq[i].count; |
| 4591 | |
| 4592 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); |
| 4593 | for (j = 0; j < count; j++, k++) { |
| 4594 | adapter->tx_ring[k]->reg_idx = tx_s + j; |
| 4595 | adapter->rx_ring[k]->reg_idx = rx_s + j; |
| 4596 | adapter->tx_ring[k]->dcb_tc = i; |
| 4597 | adapter->rx_ring[k]->dcb_tc = i; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4598 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4599 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4600 | |
| 4601 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4602 | } |
| 4603 | #endif |
| 4604 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4605 | /** |
| 4606 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 4607 | * @adapter: board private structure to initialize |
| 4608 | * |
| 4609 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 4610 | * |
| 4611 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4612 | 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] | 4613 | { |
| 4614 | int i; |
| 4615 | bool ret = false; |
| 4616 | |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4617 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4618 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4619 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4620 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4621 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4622 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4623 | ret = true; |
| 4624 | } |
| 4625 | |
| 4626 | return ret; |
| 4627 | } |
| 4628 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4629 | #ifdef IXGBE_FCOE |
| 4630 | /** |
| 4631 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 4632 | * @adapter: board private structure to initialize |
| 4633 | * |
| 4634 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 4635 | * |
| 4636 | */ |
| 4637 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 4638 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4639 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4640 | int i; |
| 4641 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4642 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4643 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4644 | return false; |
| 4645 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4646 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4647 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4648 | ixgbe_cache_ring_fdir(adapter); |
| 4649 | else |
| 4650 | ixgbe_cache_ring_rss(adapter); |
| 4651 | |
| 4652 | fcoe_rx_i = f->mask; |
| 4653 | fcoe_tx_i = f->mask; |
| 4654 | } |
| 4655 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 4656 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 4657 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
| 4658 | } |
| 4659 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4663 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4664 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 4665 | * @adapter: board private structure to initialize |
| 4666 | * |
| 4667 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 4668 | * no other mapping is used. |
| 4669 | * |
| 4670 | */ |
| 4671 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 4672 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4673 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 4674 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4675 | if (adapter->num_vfs) |
| 4676 | return true; |
| 4677 | else |
| 4678 | return false; |
| 4679 | } |
| 4680 | |
| 4681 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4682 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 4683 | * @adapter: board private structure to initialize |
| 4684 | * |
| 4685 | * Once we know the feature-set enabled for the device, we'll cache |
| 4686 | * the register offset the descriptor ring is assigned to. |
| 4687 | * |
| 4688 | * Note, the order the various feature calls is important. It must start with |
| 4689 | * the "most" features enabled at the same time, then trickle down to the |
| 4690 | * least amount of features turned on at once. |
| 4691 | **/ |
| 4692 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 4693 | { |
| 4694 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4695 | adapter->rx_ring[0]->reg_idx = 0; |
| 4696 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4697 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4698 | if (ixgbe_cache_ring_sriov(adapter)) |
| 4699 | return; |
| 4700 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4701 | #ifdef CONFIG_IXGBE_DCB |
| 4702 | if (ixgbe_cache_ring_dcb(adapter)) |
| 4703 | return; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4704 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4705 | |
| 4706 | #ifdef IXGBE_FCOE |
| 4707 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 4708 | return; |
| 4709 | #endif /* IXGBE_FCOE */ |
| 4710 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4711 | if (ixgbe_cache_ring_fdir(adapter)) |
| 4712 | return; |
| 4713 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4714 | if (ixgbe_cache_ring_rss(adapter)) |
| 4715 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4716 | } |
| 4717 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4718 | /** |
| 4719 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 4720 | * @adapter: board private structure to initialize |
| 4721 | * |
| 4722 | * 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] | 4723 | * number of queues at compile-time. The polling_netdev array is |
| 4724 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4725 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4726 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4727 | { |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4728 | int rx = 0, tx = 0, nid = adapter->node; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4729 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4730 | if (nid < 0 || !node_online(nid)) |
| 4731 | nid = first_online_node; |
| 4732 | |
| 4733 | for (; tx < adapter->num_tx_queues; tx++) { |
| 4734 | struct ixgbe_ring *ring; |
| 4735 | |
| 4736 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4737 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4738 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4739 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4740 | goto err_allocation; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4741 | ring->count = adapter->tx_ring_count; |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4742 | ring->queue_index = tx; |
| 4743 | ring->numa_node = nid; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4744 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 4745 | ring->netdev = adapter->netdev; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4746 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4747 | adapter->tx_ring[tx] = ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4748 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4749 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4750 | for (; rx < adapter->num_rx_queues; rx++) { |
| 4751 | struct ixgbe_ring *ring; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4752 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4753 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4754 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4755 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4756 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4757 | goto err_allocation; |
| 4758 | ring->count = adapter->rx_ring_count; |
| 4759 | ring->queue_index = rx; |
| 4760 | ring->numa_node = nid; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4761 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 4762 | ring->netdev = adapter->netdev; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4763 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4764 | adapter->rx_ring[rx] = ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4765 | } |
| 4766 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4767 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4768 | |
| 4769 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4770 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4771 | err_allocation: |
| 4772 | while (tx) |
| 4773 | kfree(adapter->tx_ring[--tx]); |
| 4774 | |
| 4775 | while (rx) |
| 4776 | kfree(adapter->rx_ring[--rx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4777 | return -ENOMEM; |
| 4778 | } |
| 4779 | |
| 4780 | /** |
| 4781 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 4782 | * @adapter: board private structure to initialize |
| 4783 | * |
| 4784 | * Attempt to configure the interrupts using the best available |
| 4785 | * capabilities of the hardware and the kernel. |
| 4786 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 4787 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4788 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4789 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4790 | int err = 0; |
| 4791 | int vector, v_budget; |
| 4792 | |
| 4793 | /* |
| 4794 | * It's easy to be greedy for MSI-X vectors, but it really |
| 4795 | * doesn't do us much good if we have a lot more vectors |
| 4796 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 4797 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4798 | */ |
| 4799 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4800 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4801 | |
| 4802 | /* |
| 4803 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4804 | * hw.mac->max_msix_vectors vectors. With features |
| 4805 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 4806 | * descriptor queues supported by our device. Thus, we cap it off in |
| 4807 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4808 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4809 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4810 | |
| 4811 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 4812 | * mean we disable MSI-X capabilities of the adapter. */ |
| 4813 | adapter->msix_entries = kcalloc(v_budget, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4814 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4815 | if (adapter->msix_entries) { |
| 4816 | for (vector = 0; vector < v_budget; vector++) |
| 4817 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4818 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4819 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 4820 | |
| 4821 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4822 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4823 | } |
David S. Miller | 26d2784 | 2010-05-03 15:18:22 -0700 | [diff] [blame] | 4824 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4825 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 4826 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4827 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4828 | e_err(probe, |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4829 | "ATR is not supported while multiple " |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4830 | "queues are disabled. Disabling Flow Director\n"); |
| 4831 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4832 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4833 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4834 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4835 | ixgbe_disable_sriov(adapter); |
| 4836 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4837 | err = ixgbe_set_num_queues(adapter); |
| 4838 | if (err) |
| 4839 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4840 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4841 | err = pci_enable_msi(adapter->pdev); |
| 4842 | if (!err) { |
| 4843 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 4844 | } else { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4845 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4846 | "Unable to allocate MSI interrupt, " |
| 4847 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4848 | /* reset err */ |
| 4849 | err = 0; |
| 4850 | } |
| 4851 | |
| 4852 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4853 | return err; |
| 4854 | } |
| 4855 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4856 | /** |
| 4857 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 4858 | * @adapter: board private structure to initialize |
| 4859 | * |
| 4860 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 4861 | * return -ENOMEM. |
| 4862 | **/ |
| 4863 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 4864 | { |
| 4865 | int q_idx, num_q_vectors; |
| 4866 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4867 | int (*poll)(struct napi_struct *, int); |
| 4868 | |
| 4869 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 4870 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4871 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4872 | } else { |
| 4873 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4874 | poll = &ixgbe_poll; |
| 4875 | } |
| 4876 | |
| 4877 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4878 | q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4879 | GFP_KERNEL, adapter->node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4880 | if (!q_vector) |
| 4881 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4882 | GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4883 | if (!q_vector) |
| 4884 | goto err_out; |
| 4885 | q_vector->adapter = adapter; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 4886 | if (q_vector->tx.count && !q_vector->rx.count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4887 | q_vector->eitr = adapter->tx_eitr_param; |
| 4888 | else |
| 4889 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4890 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4891 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4892 | adapter->q_vector[q_idx] = q_vector; |
| 4893 | } |
| 4894 | |
| 4895 | return 0; |
| 4896 | |
| 4897 | err_out: |
| 4898 | while (q_idx) { |
| 4899 | q_idx--; |
| 4900 | q_vector = adapter->q_vector[q_idx]; |
| 4901 | netif_napi_del(&q_vector->napi); |
| 4902 | kfree(q_vector); |
| 4903 | adapter->q_vector[q_idx] = NULL; |
| 4904 | } |
| 4905 | return -ENOMEM; |
| 4906 | } |
| 4907 | |
| 4908 | /** |
| 4909 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 4910 | * @adapter: board private structure to initialize |
| 4911 | * |
| 4912 | * This function frees the memory allocated to the q_vectors. In addition if |
| 4913 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4914 | * to freeing the q_vector. |
| 4915 | **/ |
| 4916 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 4917 | { |
| 4918 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4919 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4920 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4921 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4922 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4923 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4924 | |
| 4925 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 4926 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4927 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4928 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4929 | kfree(q_vector); |
| 4930 | } |
| 4931 | } |
| 4932 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 4933 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4934 | { |
| 4935 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 4936 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4937 | pci_disable_msix(adapter->pdev); |
| 4938 | kfree(adapter->msix_entries); |
| 4939 | adapter->msix_entries = NULL; |
| 4940 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 4941 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 4942 | pci_disable_msi(adapter->pdev); |
| 4943 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | /** |
| 4947 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 4948 | * @adapter: board private structure to initialize |
| 4949 | * |
| 4950 | * We determine which interrupt scheme to use based on... |
| 4951 | * - Kernel support (MSI, MSI-X) |
| 4952 | * - which can be user-defined (via MODULE_PARAM) |
| 4953 | * - Hardware queue count (num_*_queues) |
| 4954 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 4955 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4956 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4957 | { |
| 4958 | int err; |
| 4959 | |
| 4960 | /* Number of supported queues */ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4961 | err = ixgbe_set_num_queues(adapter); |
| 4962 | if (err) |
| 4963 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4964 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4965 | err = ixgbe_set_interrupt_capability(adapter); |
| 4966 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4967 | e_dev_err("Unable to setup interrupt capabilities\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4968 | goto err_set_interrupt; |
| 4969 | } |
| 4970 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4971 | err = ixgbe_alloc_q_vectors(adapter); |
| 4972 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4973 | e_dev_err("Unable to allocate memory for queue vectors\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4974 | goto err_alloc_q_vectors; |
| 4975 | } |
| 4976 | |
| 4977 | err = ixgbe_alloc_queues(adapter); |
| 4978 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4979 | e_dev_err("Unable to allocate memory for queues\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4980 | goto err_alloc_queues; |
| 4981 | } |
| 4982 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4983 | 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] | 4984 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 4985 | adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4986 | |
| 4987 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4988 | |
| 4989 | return 0; |
| 4990 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4991 | err_alloc_queues: |
| 4992 | ixgbe_free_q_vectors(adapter); |
| 4993 | err_alloc_q_vectors: |
| 4994 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4995 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4996 | return err; |
| 4997 | } |
| 4998 | |
| 4999 | /** |
| 5000 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 5001 | * @adapter: board private structure to clear interrupt scheme on |
| 5002 | * |
| 5003 | * We go through and clear interrupt specific resources and reset the structure |
| 5004 | * to pre-load conditions |
| 5005 | **/ |
| 5006 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 5007 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5008 | int i; |
| 5009 | |
| 5010 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5011 | kfree(adapter->tx_ring[i]); |
| 5012 | adapter->tx_ring[i] = NULL; |
| 5013 | } |
| 5014 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 5015 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 5016 | |
| 5017 | /* ixgbe_get_stats64() might access this ring, we must wait |
| 5018 | * a grace period before freeing it. |
| 5019 | */ |
Lai Jiangshan | bcec8b6 | 2011-03-18 11:57:21 +0800 | [diff] [blame] | 5020 | kfree_rcu(ring, rcu); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5021 | adapter->rx_ring[i] = NULL; |
| 5022 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5023 | |
Don Skidmore | b8eb3a1 | 2010-12-01 20:54:53 +0000 | [diff] [blame] | 5024 | adapter->num_tx_queues = 0; |
| 5025 | adapter->num_rx_queues = 0; |
| 5026 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5027 | ixgbe_free_q_vectors(adapter); |
| 5028 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | /** |
| 5032 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5033 | * @adapter: board private structure to initialize |
| 5034 | * |
| 5035 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5036 | * Fields are initialized based on PCI device information and |
| 5037 | * OS network device settings (MTU size). |
| 5038 | **/ |
| 5039 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 5040 | { |
| 5041 | struct ixgbe_hw *hw = &adapter->hw; |
| 5042 | struct pci_dev *pdev = adapter->pdev; |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 5043 | struct net_device *dev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5044 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5045 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5046 | int j; |
| 5047 | struct tc_configuration *tc; |
| 5048 | #endif |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5049 | int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5050 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5051 | /* PCI config space info */ |
| 5052 | |
| 5053 | hw->vendor_id = pdev->vendor; |
| 5054 | hw->device_id = pdev->device; |
| 5055 | hw->revision_id = pdev->revision; |
| 5056 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5057 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5058 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5059 | /* Set capability flags */ |
| 5060 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 5061 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 5062 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5063 | switch (hw->mac.type) { |
| 5064 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5065 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5066 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5067 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5068 | break; |
| 5069 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5070 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5071 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5072 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5073 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5074 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5075 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 5076 | /* Flow Director hash filters enabled */ |
| 5077 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5078 | adapter->atr_sample_rate = 20; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5079 | adapter->ring_feature[RING_F_FDIR].indices = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5080 | IXGBE_MAX_FDIR_INDICES; |
Alexander Duyck | c04f6ca | 2011-05-11 07:18:36 +0000 | [diff] [blame] | 5081 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5082 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5083 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5084 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5085 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5086 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 5087 | /* Default traffic class to use for FCoE */ |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 5088 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5089 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5090 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5091 | break; |
| 5092 | default: |
| 5093 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5094 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5095 | |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5096 | /* n-tuple support exists, always init our spinlock */ |
| 5097 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5098 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5099 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5100 | /* Configure DCB traffic classes */ |
| 5101 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5102 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5103 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5104 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5105 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5106 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5107 | tc->dcb_pfc = pfc_disabled; |
| 5108 | } |
| 5109 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5110 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5111 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5112 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5113 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5114 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 5115 | MAX_TRAFFIC_CLASS); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5116 | |
| 5117 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5118 | |
| 5119 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5120 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5121 | 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] | 5122 | #ifdef CONFIG_DCB |
| 5123 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 5124 | #endif |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5125 | hw->fc.high_water = FC_HIGH_WATER(max_frame); |
| 5126 | hw->fc.low_water = FC_LOW_WATER(max_frame); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5127 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5128 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5129 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5130 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5131 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5132 | adapter->rx_itr_setting = 1; |
| 5133 | adapter->rx_eitr_param = 20000; |
| 5134 | adapter->tx_itr_setting = 1; |
| 5135 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5136 | |
| 5137 | /* set defaults for eitr in MegaBytes */ |
| 5138 | adapter->eitr_low = 10; |
| 5139 | adapter->eitr_high = 20; |
| 5140 | |
| 5141 | /* set default ring sizes */ |
| 5142 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5143 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5144 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame^] | 5145 | /* set default work limits */ |
| 5146 | adapter->tx_work_limit = adapter->tx_ring_count; |
| 5147 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5148 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5149 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5150 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5151 | return -EIO; |
| 5152 | } |
| 5153 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5154 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5155 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 5156 | |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5157 | /* get assigned NUMA node */ |
| 5158 | adapter->node = dev_to_node(&pdev->dev); |
| 5159 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5160 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5161 | |
| 5162 | return 0; |
| 5163 | } |
| 5164 | |
| 5165 | /** |
| 5166 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5167 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5168 | * |
| 5169 | * Return 0 on success, negative on failure |
| 5170 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5171 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5172 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5173 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5174 | int size; |
| 5175 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5176 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5177 | tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5178 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5179 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5180 | if (!tx_ring->tx_buffer_info) |
| 5181 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5182 | |
| 5183 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5184 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5185 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5186 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5187 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 5188 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5189 | if (!tx_ring->desc) |
| 5190 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5191 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5192 | tx_ring->next_to_use = 0; |
| 5193 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5194 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5195 | |
| 5196 | err: |
| 5197 | vfree(tx_ring->tx_buffer_info); |
| 5198 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5199 | 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] | 5200 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5204 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5205 | * @adapter: board private structure |
| 5206 | * |
| 5207 | * If this function returns with an error, then it's possible one or |
| 5208 | * more of the rings is populated (while the rest are not). It is the |
| 5209 | * callers duty to clean those orphaned rings. |
| 5210 | * |
| 5211 | * Return 0 on success, negative on failure |
| 5212 | **/ |
| 5213 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5214 | { |
| 5215 | int i, err = 0; |
| 5216 | |
| 5217 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5218 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5219 | if (!err) |
| 5220 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5221 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5222 | break; |
| 5223 | } |
| 5224 | |
| 5225 | return err; |
| 5226 | } |
| 5227 | |
| 5228 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5229 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5230 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5231 | * |
| 5232 | * Returns 0 on success, negative on failure |
| 5233 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5234 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5235 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5236 | struct device *dev = rx_ring->dev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5237 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5238 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5239 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5240 | rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5241 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5242 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5243 | if (!rx_ring->rx_buffer_info) |
| 5244 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5245 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5246 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5247 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5248 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5249 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5250 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 5251 | &rx_ring->dma, GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5252 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5253 | if (!rx_ring->desc) |
| 5254 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5255 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5256 | rx_ring->next_to_clean = 0; |
| 5257 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5258 | |
| 5259 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5260 | err: |
| 5261 | vfree(rx_ring->rx_buffer_info); |
| 5262 | rx_ring->rx_buffer_info = NULL; |
| 5263 | 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] | 5264 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5265 | } |
| 5266 | |
| 5267 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5268 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5269 | * @adapter: board private structure |
| 5270 | * |
| 5271 | * If this function returns with an error, then it's possible one or |
| 5272 | * more of the rings is populated (while the rest are not). It is the |
| 5273 | * callers duty to clean those orphaned rings. |
| 5274 | * |
| 5275 | * Return 0 on success, negative on failure |
| 5276 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5277 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5278 | { |
| 5279 | int i, err = 0; |
| 5280 | |
| 5281 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5282 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5283 | if (!err) |
| 5284 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5285 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5286 | break; |
| 5287 | } |
| 5288 | |
| 5289 | return err; |
| 5290 | } |
| 5291 | |
| 5292 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5293 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5294 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5295 | * |
| 5296 | * Free all transmit software resources |
| 5297 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5298 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5299 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5300 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5301 | |
| 5302 | vfree(tx_ring->tx_buffer_info); |
| 5303 | tx_ring->tx_buffer_info = NULL; |
| 5304 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5305 | /* if not set, then don't free */ |
| 5306 | if (!tx_ring->desc) |
| 5307 | return; |
| 5308 | |
| 5309 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5310 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5311 | |
| 5312 | tx_ring->desc = NULL; |
| 5313 | } |
| 5314 | |
| 5315 | /** |
| 5316 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5317 | * @adapter: board private structure |
| 5318 | * |
| 5319 | * Free all transmit software resources |
| 5320 | **/ |
| 5321 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5322 | { |
| 5323 | int i; |
| 5324 | |
| 5325 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5326 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5327 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5331 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5332 | * @rx_ring: ring to clean the resources from |
| 5333 | * |
| 5334 | * Free all receive software resources |
| 5335 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5336 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5337 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5338 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5339 | |
| 5340 | vfree(rx_ring->rx_buffer_info); |
| 5341 | rx_ring->rx_buffer_info = NULL; |
| 5342 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5343 | /* if not set, then don't free */ |
| 5344 | if (!rx_ring->desc) |
| 5345 | return; |
| 5346 | |
| 5347 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5348 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5349 | |
| 5350 | rx_ring->desc = NULL; |
| 5351 | } |
| 5352 | |
| 5353 | /** |
| 5354 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5355 | * @adapter: board private structure |
| 5356 | * |
| 5357 | * Free all receive software resources |
| 5358 | **/ |
| 5359 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5360 | { |
| 5361 | int i; |
| 5362 | |
| 5363 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5364 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5365 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5369 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5370 | * @netdev: network interface device structure |
| 5371 | * @new_mtu: new value for maximum frame size |
| 5372 | * |
| 5373 | * Returns 0 on success, negative on failure |
| 5374 | **/ |
| 5375 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5376 | { |
| 5377 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5378 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5379 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5380 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5381 | /* MTU < 68 is an error and causes problems on some kernels */ |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 5382 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED && |
| 5383 | hw->mac.type != ixgbe_mac_X540) { |
| 5384 | if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
| 5385 | return -EINVAL; |
| 5386 | } else { |
| 5387 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5388 | return -EINVAL; |
| 5389 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5390 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5391 | 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] | 5392 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5393 | netdev->mtu = new_mtu; |
| 5394 | |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5395 | hw->fc.high_water = FC_HIGH_WATER(max_frame); |
| 5396 | hw->fc.low_water = FC_LOW_WATER(max_frame); |
| 5397 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5398 | if (netif_running(netdev)) |
| 5399 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5400 | |
| 5401 | return 0; |
| 5402 | } |
| 5403 | |
| 5404 | /** |
| 5405 | * ixgbe_open - Called when a network interface is made active |
| 5406 | * @netdev: network interface device structure |
| 5407 | * |
| 5408 | * Returns 0 on success, negative value on failure |
| 5409 | * |
| 5410 | * The open entry point is called when a network interface is made |
| 5411 | * active by the system (IFF_UP). At this point all resources needed |
| 5412 | * for transmit and receive operations are allocated, the interrupt |
| 5413 | * handler is registered with the OS, the watchdog timer is started, |
| 5414 | * and the stack is notified that the interface is ready. |
| 5415 | **/ |
| 5416 | static int ixgbe_open(struct net_device *netdev) |
| 5417 | { |
| 5418 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5419 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5420 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5421 | /* disallow open during test */ |
| 5422 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5423 | return -EBUSY; |
| 5424 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5425 | netif_carrier_off(netdev); |
| 5426 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5427 | /* allocate transmit descriptors */ |
| 5428 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5429 | if (err) |
| 5430 | goto err_setup_tx; |
| 5431 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5432 | /* allocate receive descriptors */ |
| 5433 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5434 | if (err) |
| 5435 | goto err_setup_rx; |
| 5436 | |
| 5437 | ixgbe_configure(adapter); |
| 5438 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5439 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5440 | if (err) |
| 5441 | goto err_req_irq; |
| 5442 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5443 | err = ixgbe_up_complete(adapter); |
| 5444 | if (err) |
| 5445 | goto err_up; |
| 5446 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 5447 | netif_tx_start_all_queues(netdev); |
| 5448 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5449 | return 0; |
| 5450 | |
| 5451 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5452 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5453 | ixgbe_free_irq(adapter); |
| 5454 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5455 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5456 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5457 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5458 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5459 | ixgbe_reset(adapter); |
| 5460 | |
| 5461 | return err; |
| 5462 | } |
| 5463 | |
| 5464 | /** |
| 5465 | * ixgbe_close - Disables a network interface |
| 5466 | * @netdev: network interface device structure |
| 5467 | * |
| 5468 | * Returns 0, this is not allowed to fail |
| 5469 | * |
| 5470 | * The close entry point is called when an interface is de-activated |
| 5471 | * by the OS. The hardware is still under the drivers control, but |
| 5472 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5473 | * hardware, and all transmit and receive resources are freed. |
| 5474 | **/ |
| 5475 | static int ixgbe_close(struct net_device *netdev) |
| 5476 | { |
| 5477 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5478 | |
| 5479 | ixgbe_down(adapter); |
| 5480 | ixgbe_free_irq(adapter); |
| 5481 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5482 | ixgbe_fdir_filter_exit(adapter); |
| 5483 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5484 | ixgbe_free_all_tx_resources(adapter); |
| 5485 | ixgbe_free_all_rx_resources(adapter); |
| 5486 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5487 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5488 | |
| 5489 | return 0; |
| 5490 | } |
| 5491 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5492 | #ifdef CONFIG_PM |
| 5493 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5494 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5495 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5496 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5497 | u32 err; |
| 5498 | |
| 5499 | pci_set_power_state(pdev, PCI_D0); |
| 5500 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5501 | /* |
| 5502 | * pci_restore_state clears dev->state_saved so call |
| 5503 | * pci_save_state to restore it. |
| 5504 | */ |
| 5505 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5506 | |
| 5507 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5508 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5509 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5510 | return err; |
| 5511 | } |
| 5512 | pci_set_master(pdev); |
| 5513 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5514 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5515 | |
| 5516 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5517 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5518 | e_dev_err("Cannot initialize interrupts for device\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5519 | return err; |
| 5520 | } |
| 5521 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5522 | ixgbe_reset(adapter); |
| 5523 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5524 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5525 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5526 | if (netif_running(netdev)) { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5527 | err = ixgbe_open(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5528 | if (err) |
| 5529 | return err; |
| 5530 | } |
| 5531 | |
| 5532 | netif_device_attach(netdev); |
| 5533 | |
| 5534 | return 0; |
| 5535 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5536 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5537 | |
| 5538 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5539 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5540 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5541 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5542 | struct ixgbe_hw *hw = &adapter->hw; |
| 5543 | u32 ctrl, fctrl; |
| 5544 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5545 | #ifdef CONFIG_PM |
| 5546 | int retval = 0; |
| 5547 | #endif |
| 5548 | |
| 5549 | netif_device_detach(netdev); |
| 5550 | |
| 5551 | if (netif_running(netdev)) { |
| 5552 | ixgbe_down(adapter); |
| 5553 | ixgbe_free_irq(adapter); |
| 5554 | ixgbe_free_all_tx_resources(adapter); |
| 5555 | ixgbe_free_all_rx_resources(adapter); |
| 5556 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5557 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5558 | ixgbe_clear_interrupt_scheme(adapter); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 5559 | #ifdef CONFIG_DCB |
| 5560 | kfree(adapter->ixgbe_ieee_pfc); |
| 5561 | kfree(adapter->ixgbe_ieee_ets); |
| 5562 | #endif |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5563 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5564 | #ifdef CONFIG_PM |
| 5565 | retval = pci_save_state(pdev); |
| 5566 | if (retval) |
| 5567 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5568 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5569 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5570 | if (wufc) { |
| 5571 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5572 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5573 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5574 | if (wufc & IXGBE_WUFC_MC) { |
| 5575 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5576 | fctrl |= IXGBE_FCTRL_MPE; |
| 5577 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5578 | } |
| 5579 | |
| 5580 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5581 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5582 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5583 | |
| 5584 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5585 | } else { |
| 5586 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5587 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5588 | } |
| 5589 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5590 | switch (hw->mac.type) { |
| 5591 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5592 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5593 | break; |
| 5594 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5595 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5596 | pci_wake_from_d3(pdev, !!wufc); |
| 5597 | break; |
| 5598 | default: |
| 5599 | break; |
| 5600 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5601 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5602 | *enable_wake = !!wufc; |
| 5603 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5604 | ixgbe_release_hw_control(adapter); |
| 5605 | |
| 5606 | pci_disable_device(pdev); |
| 5607 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5608 | return 0; |
| 5609 | } |
| 5610 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5611 | #ifdef CONFIG_PM |
| 5612 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5613 | { |
| 5614 | int retval; |
| 5615 | bool wake; |
| 5616 | |
| 5617 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5618 | if (retval) |
| 5619 | return retval; |
| 5620 | |
| 5621 | if (wake) { |
| 5622 | pci_prepare_to_sleep(pdev); |
| 5623 | } else { |
| 5624 | pci_wake_from_d3(pdev, false); |
| 5625 | pci_set_power_state(pdev, PCI_D3hot); |
| 5626 | } |
| 5627 | |
| 5628 | return 0; |
| 5629 | } |
| 5630 | #endif /* CONFIG_PM */ |
| 5631 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5632 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5633 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5634 | bool wake; |
| 5635 | |
| 5636 | __ixgbe_shutdown(pdev, &wake); |
| 5637 | |
| 5638 | if (system_state == SYSTEM_POWER_OFF) { |
| 5639 | pci_wake_from_d3(pdev, wake); |
| 5640 | pci_set_power_state(pdev, PCI_D3hot); |
| 5641 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5645 | * ixgbe_update_stats - Update the board statistics counters. |
| 5646 | * @adapter: board private structure |
| 5647 | **/ |
| 5648 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5649 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5650 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5651 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5652 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5653 | u64 total_mpc = 0; |
| 5654 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5655 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5656 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
| 5657 | u64 bytes = 0, packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5658 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5659 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5660 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5661 | return; |
| 5662 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5663 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5664 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5665 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5666 | for (i = 0; i < 16; i++) |
| 5667 | adapter->hw_rx_no_dma_resources += |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5668 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5669 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5670 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5671 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5672 | } |
| 5673 | adapter->rsc_total_count = rsc_count; |
| 5674 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5675 | } |
| 5676 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5677 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5678 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5679 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5680 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5681 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
| 5682 | bytes += rx_ring->stats.bytes; |
| 5683 | packets += rx_ring->stats.packets; |
| 5684 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5685 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5686 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5687 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
| 5688 | netdev->stats.rx_bytes = bytes; |
| 5689 | netdev->stats.rx_packets = packets; |
| 5690 | |
| 5691 | bytes = 0; |
| 5692 | packets = 0; |
| 5693 | /* gather some stats to the adapter struct that are per queue */ |
| 5694 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5695 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5696 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5697 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5698 | bytes += tx_ring->stats.bytes; |
| 5699 | packets += tx_ring->stats.packets; |
| 5700 | } |
| 5701 | adapter->restart_queue = restart_queue; |
| 5702 | adapter->tx_busy = tx_busy; |
| 5703 | netdev->stats.tx_bytes = bytes; |
| 5704 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5705 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5706 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5707 | for (i = 0; i < 8; i++) { |
| 5708 | /* for packet buffers not used, the register should read 0 */ |
| 5709 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5710 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5711 | hwstats->mpc[i] += mpc; |
| 5712 | total_mpc += hwstats->mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5713 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5714 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5715 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5716 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5717 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5718 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5719 | switch (hw->mac.type) { |
| 5720 | case ixgbe_mac_82598EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5721 | hwstats->pxonrxc[i] += |
| 5722 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5723 | break; |
| 5724 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5725 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5726 | hwstats->pxonrxc[i] += |
| 5727 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5728 | break; |
| 5729 | default: |
| 5730 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5731 | } |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5732 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5733 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5734 | } |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5735 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5736 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5737 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5738 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5739 | ixgbe_update_xoff_received(adapter); |
| 5740 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5741 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5742 | switch (hw->mac.type) { |
| 5743 | case ixgbe_mac_82598EB: |
| 5744 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5745 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5746 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5747 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5748 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5749 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5750 | /* OS2BMC stats are X540 only*/ |
| 5751 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5752 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5753 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5754 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5755 | case ixgbe_mac_82599EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5756 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5757 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5758 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5759 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5760 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5761 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5762 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5763 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5764 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5765 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5766 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5767 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5768 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5769 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5770 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5771 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5772 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5773 | break; |
| 5774 | default: |
| 5775 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5776 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5777 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5778 | hwstats->bprc += bprc; |
| 5779 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5780 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5781 | hwstats->mprc -= bprc; |
| 5782 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5783 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5784 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5785 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5786 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5787 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5788 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5789 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5790 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5791 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5792 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5793 | hwstats->lxofftxc += lxoff; |
| 5794 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5795 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5796 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5797 | /* |
| 5798 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5799 | */ |
| 5800 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5801 | hwstats->gptc -= xon_off_tot; |
| 5802 | hwstats->mptc -= xon_off_tot; |
| 5803 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5804 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5805 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 5806 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 5807 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 5808 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 5809 | hwstats->ptc64 -= xon_off_tot; |
| 5810 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 5811 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 5812 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 5813 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 5814 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 5815 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5816 | |
| 5817 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5818 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5819 | |
| 5820 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5821 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5822 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5823 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 5824 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5825 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5829 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
| 5830 | * @adapter - pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5831 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5832 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5833 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5834 | struct ixgbe_hw *hw = &adapter->hw; |
| 5835 | int i; |
| 5836 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5837 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 5838 | return; |
| 5839 | |
| 5840 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 5841 | |
| 5842 | /* if interface is down do nothing */ |
| 5843 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 5844 | return; |
| 5845 | |
| 5846 | /* do nothing if we are not using signature filters */ |
| 5847 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 5848 | return; |
| 5849 | |
| 5850 | adapter->fdir_overflow++; |
| 5851 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5852 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 5853 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 5854 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 5855 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5856 | /* re-enable flow director interrupts */ |
| 5857 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5858 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5859 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5860 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5861 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5862 | } |
| 5863 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5864 | /** |
| 5865 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
| 5866 | * @adapter - pointer to the device adapter structure |
| 5867 | * |
| 5868 | * This function serves two purposes. First it strobes the interrupt lines |
| 5869 | * in order to make certain interrupts are occuring. Secondly it sets the |
| 5870 | * bits needed to check for TX hangs. As a result we should immediately |
| 5871 | * determine if a hang has occured. |
| 5872 | */ |
| 5873 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 5874 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5875 | struct ixgbe_hw *hw = &adapter->hw; |
| 5876 | u64 eics = 0; |
| 5877 | int i; |
| 5878 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5879 | /* If we're down or resetting, just bail */ |
| 5880 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5881 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5882 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5883 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5884 | /* Force detection of hung controller */ |
| 5885 | if (netif_carrier_ok(adapter->netdev)) { |
| 5886 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 5887 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 5888 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5889 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5890 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5891 | /* |
| 5892 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5893 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5894 | * would set *both* EIMS and EICS for any bit in EIAM |
| 5895 | */ |
| 5896 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 5897 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5898 | } else { |
| 5899 | /* get one bit for every active tx/rx interrupt vector */ |
| 5900 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 5901 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 5902 | if (qv->rx.count || qv->tx.count) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5903 | eics |= ((u64)1 << i); |
| 5904 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5905 | } |
| 5906 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5907 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5908 | ixgbe_irq_rearm_queues(adapter, eics); |
| 5909 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5913 | * ixgbe_watchdog_update_link - update the link status |
| 5914 | * @adapter - pointer to the device adapter structure |
| 5915 | * @link_speed - pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5916 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5917 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5918 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5919 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5920 | u32 link_speed = adapter->link_speed; |
| 5921 | bool link_up = adapter->link_up; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5922 | int i; |
| 5923 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5924 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 5925 | return; |
| 5926 | |
| 5927 | if (hw->mac.ops.check_link) { |
| 5928 | 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] | 5929 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5930 | /* always assume link is up, if no check link function */ |
| 5931 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 5932 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5933 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5934 | if (link_up) { |
| 5935 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5936 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 5937 | hw->mac.ops.fc_enable(hw, i); |
| 5938 | } else { |
| 5939 | hw->mac.ops.fc_enable(hw, 0); |
| 5940 | } |
| 5941 | } |
| 5942 | |
| 5943 | if (link_up || |
| 5944 | time_after(jiffies, (adapter->link_check_timeout + |
| 5945 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 5946 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5947 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 5948 | IXGBE_WRITE_FLUSH(hw); |
| 5949 | } |
| 5950 | |
| 5951 | adapter->link_up = link_up; |
| 5952 | adapter->link_speed = link_speed; |
| 5953 | } |
| 5954 | |
| 5955 | /** |
| 5956 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 5957 | * print link up message |
| 5958 | * @adapter - pointer to the device adapter structure |
| 5959 | **/ |
| 5960 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 5961 | { |
| 5962 | struct net_device *netdev = adapter->netdev; |
| 5963 | struct ixgbe_hw *hw = &adapter->hw; |
| 5964 | u32 link_speed = adapter->link_speed; |
| 5965 | bool flow_rx, flow_tx; |
| 5966 | |
| 5967 | /* only continue if link was previously down */ |
| 5968 | if (netif_carrier_ok(netdev)) |
| 5969 | return; |
| 5970 | |
| 5971 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 5972 | |
| 5973 | switch (hw->mac.type) { |
| 5974 | case ixgbe_mac_82598EB: { |
| 5975 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5976 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 5977 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 5978 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 5979 | } |
| 5980 | break; |
| 5981 | case ixgbe_mac_X540: |
| 5982 | case ixgbe_mac_82599EB: { |
| 5983 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 5984 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 5985 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 5986 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 5987 | } |
| 5988 | break; |
| 5989 | default: |
| 5990 | flow_tx = false; |
| 5991 | flow_rx = false; |
| 5992 | break; |
| 5993 | } |
| 5994 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 5995 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 5996 | "10 Gbps" : |
| 5997 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 5998 | "1 Gbps" : |
| 5999 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6000 | "100 Mbps" : |
| 6001 | "unknown speed"))), |
| 6002 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6003 | (flow_rx ? "RX" : |
| 6004 | (flow_tx ? "TX" : "None")))); |
| 6005 | |
| 6006 | netif_carrier_on(netdev); |
| 6007 | #ifdef HAVE_IPLINK_VF_CONFIG |
| 6008 | ixgbe_check_vf_rate_limit(adapter); |
| 6009 | #endif /* HAVE_IPLINK_VF_CONFIG */ |
| 6010 | } |
| 6011 | |
| 6012 | /** |
| 6013 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6014 | * print link down message |
| 6015 | * @adapter - pointer to the adapter structure |
| 6016 | **/ |
| 6017 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) |
| 6018 | { |
| 6019 | struct net_device *netdev = adapter->netdev; |
| 6020 | struct ixgbe_hw *hw = &adapter->hw; |
| 6021 | |
| 6022 | adapter->link_up = false; |
| 6023 | adapter->link_speed = 0; |
| 6024 | |
| 6025 | /* only continue if link was up previously */ |
| 6026 | if (!netif_carrier_ok(netdev)) |
| 6027 | return; |
| 6028 | |
| 6029 | /* poll for SFP+ cable when link is down */ |
| 6030 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6031 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6032 | |
| 6033 | e_info(drv, "NIC Link is Down\n"); |
| 6034 | netif_carrier_off(netdev); |
| 6035 | } |
| 6036 | |
| 6037 | /** |
| 6038 | * ixgbe_watchdog_flush_tx - flush queues on link down |
| 6039 | * @adapter - pointer to the device adapter structure |
| 6040 | **/ |
| 6041 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6042 | { |
| 6043 | int i; |
| 6044 | int some_tx_pending = 0; |
| 6045 | |
| 6046 | if (!netif_carrier_ok(adapter->netdev)) { |
| 6047 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6048 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6049 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 6050 | some_tx_pending = 1; |
| 6051 | break; |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | if (some_tx_pending) { |
| 6056 | /* We've lost link, so the controller stops DMA, |
| 6057 | * but we've got queued Tx work that's never going |
| 6058 | * to get done, so reset controller to flush Tx. |
| 6059 | * (Do the reset outside of interrupt context). |
| 6060 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6061 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6062 | } |
| 6063 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6064 | } |
| 6065 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6066 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6067 | { |
| 6068 | u32 ssvpc; |
| 6069 | |
| 6070 | /* Do not perform spoof check for 82598 */ |
| 6071 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6072 | return; |
| 6073 | |
| 6074 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6075 | |
| 6076 | /* |
| 6077 | * ssvpc register is cleared on read, if zero then no |
| 6078 | * spoofed packets in the last interval. |
| 6079 | */ |
| 6080 | if (!ssvpc) |
| 6081 | return; |
| 6082 | |
| 6083 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); |
| 6084 | } |
| 6085 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6086 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6087 | * ixgbe_watchdog_subtask - check and bring link up |
| 6088 | * @adapter - pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6089 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6090 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6091 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6092 | /* if interface is down do nothing */ |
| 6093 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6094 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6095 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6096 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6097 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6098 | if (adapter->link_up) |
| 6099 | ixgbe_watchdog_link_is_up(adapter); |
| 6100 | else |
| 6101 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6102 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6103 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6104 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6105 | |
| 6106 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6107 | } |
| 6108 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6109 | /** |
| 6110 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
| 6111 | * @adapter - the ixgbe adapter structure |
| 6112 | **/ |
| 6113 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6114 | { |
| 6115 | struct ixgbe_hw *hw = &adapter->hw; |
| 6116 | s32 err; |
| 6117 | |
| 6118 | /* not searching for SFP so there is nothing to do here */ |
| 6119 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6120 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6121 | return; |
| 6122 | |
| 6123 | /* someone else is in init, wait until next service event */ |
| 6124 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6125 | return; |
| 6126 | |
| 6127 | err = hw->phy.ops.identify_sfp(hw); |
| 6128 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6129 | goto sfp_out; |
| 6130 | |
| 6131 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6132 | /* If no cable is present, then we need to reset |
| 6133 | * the next time we find a good cable. */ |
| 6134 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6135 | } |
| 6136 | |
| 6137 | /* exit on error */ |
| 6138 | if (err) |
| 6139 | goto sfp_out; |
| 6140 | |
| 6141 | /* exit if reset not needed */ |
| 6142 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6143 | goto sfp_out; |
| 6144 | |
| 6145 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6146 | |
| 6147 | /* |
| 6148 | * A module may be identified correctly, but the EEPROM may not have |
| 6149 | * support for that module. setup_sfp() will fail in that case, so |
| 6150 | * we should not allow that module to load. |
| 6151 | */ |
| 6152 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6153 | err = hw->phy.ops.reset(hw); |
| 6154 | else |
| 6155 | err = hw->mac.ops.setup_sfp(hw); |
| 6156 | |
| 6157 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6158 | goto sfp_out; |
| 6159 | |
| 6160 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6161 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6162 | |
| 6163 | sfp_out: |
| 6164 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6165 | |
| 6166 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6167 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6168 | e_dev_err("failed to initialize because an unsupported " |
| 6169 | "SFP+ module type was detected.\n"); |
| 6170 | e_dev_err("Reload the driver after installing a " |
| 6171 | "supported module.\n"); |
| 6172 | unregister_netdev(adapter->netdev); |
| 6173 | } |
| 6174 | } |
| 6175 | |
| 6176 | /** |
| 6177 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
| 6178 | * @adapter - the ixgbe adapter structure |
| 6179 | **/ |
| 6180 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6181 | { |
| 6182 | struct ixgbe_hw *hw = &adapter->hw; |
| 6183 | u32 autoneg; |
| 6184 | bool negotiation; |
| 6185 | |
| 6186 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6187 | return; |
| 6188 | |
| 6189 | /* someone else is in init, wait until next service event */ |
| 6190 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6191 | return; |
| 6192 | |
| 6193 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6194 | |
| 6195 | autoneg = hw->phy.autoneg_advertised; |
| 6196 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 6197 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 6198 | hw->mac.autotry_restart = false; |
| 6199 | if (hw->mac.ops.setup_link) |
| 6200 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 6201 | |
| 6202 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6203 | adapter->link_check_timeout = jiffies; |
| 6204 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6205 | } |
| 6206 | |
| 6207 | /** |
| 6208 | * ixgbe_service_timer - Timer Call-back |
| 6209 | * @data: pointer to adapter cast into an unsigned long |
| 6210 | **/ |
| 6211 | static void ixgbe_service_timer(unsigned long data) |
| 6212 | { |
| 6213 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6214 | unsigned long next_event_offset; |
| 6215 | |
| 6216 | /* poll faster when waiting for link */ |
| 6217 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6218 | next_event_offset = HZ / 10; |
| 6219 | else |
| 6220 | next_event_offset = HZ * 2; |
| 6221 | |
| 6222 | /* Reset the timer */ |
| 6223 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6224 | |
| 6225 | ixgbe_service_event_schedule(adapter); |
| 6226 | } |
| 6227 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6228 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6229 | { |
| 6230 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6231 | return; |
| 6232 | |
| 6233 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6234 | |
| 6235 | /* If we're already down or resetting, just bail */ |
| 6236 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6237 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6238 | return; |
| 6239 | |
| 6240 | ixgbe_dump(adapter); |
| 6241 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6242 | adapter->tx_timeout_count++; |
| 6243 | |
| 6244 | ixgbe_reinit_locked(adapter); |
| 6245 | } |
| 6246 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6247 | /** |
| 6248 | * ixgbe_service_task - manages and runs subtasks |
| 6249 | * @work: pointer to work_struct containing our data |
| 6250 | **/ |
| 6251 | static void ixgbe_service_task(struct work_struct *work) |
| 6252 | { |
| 6253 | struct ixgbe_adapter *adapter = container_of(work, |
| 6254 | struct ixgbe_adapter, |
| 6255 | service_task); |
| 6256 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6257 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6258 | ixgbe_sfp_detection_subtask(adapter); |
| 6259 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6260 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6261 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6262 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6263 | ixgbe_check_hang_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6264 | |
| 6265 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6266 | } |
| 6267 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6268 | void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens, |
| 6269 | u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6270 | { |
| 6271 | struct ixgbe_adv_tx_context_desc *context_desc; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6272 | u16 i = tx_ring->next_to_use; |
| 6273 | |
| 6274 | context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i); |
| 6275 | |
| 6276 | i++; |
| 6277 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 6278 | |
| 6279 | /* set bits to identify this as an advanced context descriptor */ |
| 6280 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 6281 | |
| 6282 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6283 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); |
| 6284 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 6285 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 6286 | } |
| 6287 | |
| 6288 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 6289 | u32 tx_flags, __be16 protocol, u8 *hdr_len) |
| 6290 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6291 | int err; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6292 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6293 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6294 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6295 | if (!skb_is_gso(skb)) |
| 6296 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6297 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6298 | if (skb_header_cloned(skb)) { |
| 6299 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 6300 | if (err) |
| 6301 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6302 | } |
| 6303 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6304 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6305 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6306 | |
| 6307 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6308 | struct iphdr *iph = ip_hdr(skb); |
| 6309 | iph->tot_len = 0; |
| 6310 | iph->check = 0; |
| 6311 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6312 | iph->daddr, 0, |
| 6313 | IPPROTO_TCP, |
| 6314 | 0); |
| 6315 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6316 | } else if (skb_is_gso_v6(skb)) { |
| 6317 | ipv6_hdr(skb)->payload_len = 0; |
| 6318 | tcp_hdr(skb)->check = |
| 6319 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6320 | &ipv6_hdr(skb)->daddr, |
| 6321 | 0, IPPROTO_TCP, 0); |
| 6322 | } |
| 6323 | |
| 6324 | l4len = tcp_hdrlen(skb); |
| 6325 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6326 | |
| 6327 | /* mss_l4len_id: use 1 as index for TSO */ |
| 6328 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6329 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 6330 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 6331 | |
| 6332 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6333 | vlan_macip_lens = skb_network_header_len(skb); |
| 6334 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6335 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6336 | |
| 6337 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
| 6338 | mss_l4len_idx); |
| 6339 | |
| 6340 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6341 | } |
| 6342 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6343 | static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6344 | struct sk_buff *skb, u32 tx_flags, |
| 6345 | __be16 protocol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6346 | { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6347 | u32 vlan_macip_lens = 0; |
| 6348 | u32 mss_l4len_idx = 0; |
| 6349 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6350 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6351 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
| 6352 | if (!(tx_flags & IXGBE_TX_FLAGS_VLAN)) |
| 6353 | return false; |
| 6354 | } else { |
| 6355 | u8 l4_hdr = 0; |
| 6356 | switch (protocol) { |
| 6357 | case __constant_htons(ETH_P_IP): |
| 6358 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6359 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6360 | l4_hdr = ip_hdr(skb)->protocol; |
| 6361 | break; |
| 6362 | case __constant_htons(ETH_P_IPV6): |
| 6363 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6364 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6365 | break; |
| 6366 | default: |
| 6367 | if (unlikely(net_ratelimit())) { |
| 6368 | dev_warn(tx_ring->dev, |
| 6369 | "partial checksum but proto=%x!\n", |
| 6370 | skb->protocol); |
| 6371 | } |
| 6372 | break; |
| 6373 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6374 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6375 | switch (l4_hdr) { |
| 6376 | case IPPROTO_TCP: |
| 6377 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6378 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6379 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6380 | break; |
| 6381 | case IPPROTO_SCTP: |
| 6382 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6383 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6384 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6385 | break; |
| 6386 | case IPPROTO_UDP: |
| 6387 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6388 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6389 | break; |
| 6390 | default: |
| 6391 | if (unlikely(net_ratelimit())) { |
| 6392 | dev_warn(tx_ring->dev, |
| 6393 | "partial checksum but l4 proto=%x!\n", |
| 6394 | skb->protocol); |
| 6395 | } |
| 6396 | break; |
| 6397 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6398 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6399 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6400 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6401 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6402 | |
| 6403 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6404 | type_tucmd, mss_l4len_idx); |
| 6405 | |
| 6406 | return (skb->ip_summed == CHECKSUM_PARTIAL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6407 | } |
| 6408 | |
| 6409 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6410 | struct ixgbe_ring *tx_ring, |
| 6411 | struct sk_buff *skb, u32 tx_flags, |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6412 | unsigned int first, const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6413 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6414 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6415 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6416 | unsigned int len; |
| 6417 | unsigned int total = skb->len; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6418 | unsigned int offset = 0, size, count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6419 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 6420 | unsigned int f; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6421 | unsigned int bytecount = skb->len; |
| 6422 | u16 gso_segs = 1; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6423 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6424 | |
| 6425 | i = tx_ring->next_to_use; |
| 6426 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6427 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 6428 | /* excluding fcoe_crc_eof for FCoE */ |
| 6429 | total -= sizeof(struct fcoe_crc_eof); |
| 6430 | |
| 6431 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6432 | while (len) { |
| 6433 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6434 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 6435 | |
| 6436 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6437 | tx_buffer_info->mapped_as_page = false; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6438 | tx_buffer_info->dma = dma_map_single(dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6439 | skb->data + offset, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 6440 | size, DMA_TO_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6441 | if (dma_mapping_error(dev, tx_buffer_info->dma)) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6442 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6443 | tx_buffer_info->time_stamp = jiffies; |
| 6444 | tx_buffer_info->next_to_watch = i; |
| 6445 | |
| 6446 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6447 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6448 | offset += size; |
| 6449 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6450 | |
| 6451 | if (len) { |
| 6452 | i++; |
| 6453 | if (i == tx_ring->count) |
| 6454 | i = 0; |
| 6455 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6456 | } |
| 6457 | |
| 6458 | for (f = 0; f < nr_frags; f++) { |
| 6459 | struct skb_frag_struct *frag; |
| 6460 | |
| 6461 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6462 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6463 | offset = frag->page_offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6464 | |
| 6465 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6466 | i++; |
| 6467 | if (i == tx_ring->count) |
| 6468 | i = 0; |
| 6469 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6470 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6471 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 6472 | |
| 6473 | tx_buffer_info->length = size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6474 | tx_buffer_info->dma = dma_map_page(dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6475 | frag->page, |
| 6476 | offset, size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 6477 | DMA_TO_DEVICE); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6478 | tx_buffer_info->mapped_as_page = true; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6479 | if (dma_mapping_error(dev, tx_buffer_info->dma)) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6480 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6481 | tx_buffer_info->time_stamp = jiffies; |
| 6482 | tx_buffer_info->next_to_watch = i; |
| 6483 | |
| 6484 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6485 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6486 | offset += size; |
| 6487 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6488 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6489 | if (total == 0) |
| 6490 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6491 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6492 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6493 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6494 | gso_segs = skb_shinfo(skb)->gso_segs; |
| 6495 | #ifdef IXGBE_FCOE |
| 6496 | /* adjust for FCoE Sequence Offload */ |
| 6497 | else if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6498 | gso_segs = DIV_ROUND_UP(skb->len - hdr_len, |
| 6499 | skb_shinfo(skb)->gso_size); |
| 6500 | #endif /* IXGBE_FCOE */ |
| 6501 | bytecount += (gso_segs - 1) * hdr_len; |
| 6502 | |
| 6503 | /* multiply data chunks by size of headers */ |
| 6504 | tx_ring->tx_buffer_info[i].bytecount = bytecount; |
| 6505 | tx_ring->tx_buffer_info[i].gso_segs = gso_segs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6506 | tx_ring->tx_buffer_info[i].skb = skb; |
| 6507 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 6508 | |
| 6509 | return count; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6510 | |
| 6511 | dma_error: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6512 | e_dev_err("TX DMA map failed\n"); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6513 | |
| 6514 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 6515 | tx_buffer_info->dma = 0; |
| 6516 | tx_buffer_info->time_stamp = 0; |
| 6517 | tx_buffer_info->next_to_watch = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6518 | if (count) |
| 6519 | count--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6520 | |
| 6521 | /* clear timestamp and dma mappings for remaining portion of packet */ |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6522 | while (count--) { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6523 | if (i == 0) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6524 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6525 | i--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6526 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6527 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6528 | } |
| 6529 | |
Anton Blanchard | e44d38e | 2010-02-03 13:12:51 +0000 | [diff] [blame] | 6530 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6531 | } |
| 6532 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6533 | static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6534 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6535 | { |
| 6536 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 6537 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 6538 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 6539 | unsigned int i; |
| 6540 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 6541 | |
| 6542 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 6543 | |
| 6544 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 6545 | |
| 6546 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 6547 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 6548 | |
| 6549 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 6550 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 6551 | |
| 6552 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6553 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6554 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 6555 | /* use index 1 context for tso */ |
| 6556 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6557 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6558 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6559 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6560 | |
| 6561 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6562 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6563 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6564 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6565 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6566 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 6567 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 6568 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6569 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 6570 | } |
| 6571 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6572 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 6573 | |
| 6574 | i = tx_ring->next_to_use; |
| 6575 | while (count--) { |
| 6576 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 6577 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6578 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 6579 | tx_desc->read.cmd_type_len = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6580 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6581 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6582 | i++; |
| 6583 | if (i == tx_ring->count) |
| 6584 | i = 0; |
| 6585 | } |
| 6586 | |
| 6587 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 6588 | |
| 6589 | /* |
| 6590 | * Force memory writes to complete before letting h/w |
| 6591 | * know there are new descriptors to fetch. (Only |
| 6592 | * applicable for weak-ordered memory model archs, |
| 6593 | * such as IA-64). |
| 6594 | */ |
| 6595 | wmb(); |
| 6596 | |
| 6597 | tx_ring->next_to_use = i; |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6598 | writel(i, tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6599 | } |
| 6600 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6601 | static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb, |
| 6602 | u32 tx_flags, __be16 protocol) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6603 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6604 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6605 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6606 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6607 | union { |
| 6608 | unsigned char *network; |
| 6609 | struct iphdr *ipv4; |
| 6610 | struct ipv6hdr *ipv6; |
| 6611 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6612 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6613 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6614 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6615 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6616 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6617 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6618 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6619 | /* do nothing if sampling is disabled */ |
| 6620 | if (!ring->atr_sample_rate) |
| 6621 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6622 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6623 | ring->atr_count++; |
| 6624 | |
| 6625 | /* snag network header to get L4 type and address */ |
| 6626 | hdr.network = skb_network_header(skb); |
| 6627 | |
| 6628 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 6629 | if ((protocol != __constant_htons(ETH_P_IPV6) || |
| 6630 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
| 6631 | (protocol != __constant_htons(ETH_P_IP) || |
| 6632 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6633 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6634 | |
| 6635 | th = tcp_hdr(skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6636 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6637 | /* skip this packet since the socket is closing */ |
| 6638 | if (th->fin) |
| 6639 | return; |
| 6640 | |
| 6641 | /* sample on all syn packets or once every atr sample count */ |
| 6642 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6643 | return; |
| 6644 | |
| 6645 | /* reset sample count */ |
| 6646 | ring->atr_count = 0; |
| 6647 | |
| 6648 | vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6649 | |
| 6650 | /* |
| 6651 | * src and dst are inverted, think how the receiver sees them |
| 6652 | * |
| 6653 | * The input is broken into two sections, a non-compressed section |
| 6654 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6655 | * is XORed together and stored in the compressed dword. |
| 6656 | */ |
| 6657 | input.formatted.vlan_id = vlan_id; |
| 6658 | |
| 6659 | /* |
| 6660 | * since src port and flex bytes occupy the same word XOR them together |
| 6661 | * and write the value to source port portion of compressed dword |
| 6662 | */ |
| 6663 | if (vlan_id) |
| 6664 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6665 | else |
| 6666 | common.port.src ^= th->dest ^ protocol; |
| 6667 | common.port.dst ^= th->source; |
| 6668 | |
| 6669 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6670 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6671 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6672 | } else { |
| 6673 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6674 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6675 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6676 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6677 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6678 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6679 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6680 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6681 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6682 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6683 | |
| 6684 | /* 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] | 6685 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6686 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6687 | } |
| 6688 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6689 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6690 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6691 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6692 | /* Herbert's original patch had: |
| 6693 | * smp_mb__after_netif_stop_queue(); |
| 6694 | * but since that doesn't exist yet, just open code it. */ |
| 6695 | smp_mb(); |
| 6696 | |
| 6697 | /* We need to check again in a case another CPU has just |
| 6698 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6699 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6700 | return -EBUSY; |
| 6701 | |
| 6702 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6703 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6704 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6705 | return 0; |
| 6706 | } |
| 6707 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 6708 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6709 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6710 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6711 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6712 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6713 | } |
| 6714 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6715 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 6716 | { |
| 6717 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 6718 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 6719 | smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6720 | #ifdef IXGBE_FCOE |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 6721 | __be16 protocol = vlan_get_protocol(skb); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6722 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6723 | if (((protocol == htons(ETH_P_FCOE)) || |
| 6724 | (protocol == htons(ETH_P_FIP))) && |
| 6725 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
| 6726 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 6727 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 6728 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6729 | } |
| 6730 | #endif |
| 6731 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6732 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 6733 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 6734 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6735 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6736 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6737 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6738 | return skb_tx_hash(dev, skb); |
| 6739 | } |
| 6740 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6741 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6742 | struct ixgbe_adapter *adapter, |
| 6743 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6744 | { |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6745 | int tso; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6746 | u32 tx_flags = 0; |
| 6747 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 6748 | unsigned short f; |
| 6749 | #endif |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6750 | u16 first; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6751 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6752 | __be16 protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6753 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6754 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6755 | /* |
| 6756 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
| 6757 | * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD, |
| 6758 | * + 2 desc gap to keep tail from touching head, |
| 6759 | * + 1 desc for context descriptor, |
| 6760 | * otherwise try next time |
| 6761 | */ |
| 6762 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 6763 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 6764 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 6765 | #else |
| 6766 | count += skb_shinfo(skb)->nr_frags; |
| 6767 | #endif |
| 6768 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 6769 | tx_ring->tx_stats.tx_busy++; |
| 6770 | return NETDEV_TX_BUSY; |
| 6771 | } |
| 6772 | |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6773 | protocol = vlan_get_protocol(skb); |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6774 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 6775 | if (vlan_tx_tag_present(skb)) { |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6776 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6777 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 6778 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6779 | tx_flags |= tx_ring->dcb_tc << 13; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6780 | } |
| 6781 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6782 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
John Fastabend | 33c66bd | 2010-05-18 16:00:11 +0000 | [diff] [blame] | 6783 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED && |
| 6784 | skb->priority != TC_PRIO_CONTROL) { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6785 | tx_flags |= tx_ring->dcb_tc << 13; |
John Fastabend | 2ea186a | 2010-02-27 03:28:24 -0800 | [diff] [blame] | 6786 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6787 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6788 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6789 | |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 6790 | #ifdef IXGBE_FCOE |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6791 | /* for FCoE with DCB, we force the priority to what |
| 6792 | * was specified by the switch */ |
| 6793 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED && |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6794 | (protocol == htons(ETH_P_FCOE))) |
| 6795 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6796 | |
Robert Love | ca77cd5 | 2010-03-24 12:45:00 +0000 | [diff] [blame] | 6797 | #endif |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6798 | /* record the location of the first descriptor for this packet */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6799 | first = tx_ring->next_to_use; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6800 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6801 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6802 | #ifdef IXGBE_FCOE |
| 6803 | /* setup tx offload for FCoE */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6804 | tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len); |
| 6805 | if (tso < 0) |
| 6806 | goto out_drop; |
| 6807 | else if (tso) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6808 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 6809 | #endif /* IXGBE_FCOE */ |
| 6810 | } else { |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6811 | if (protocol == htons(ETH_P_IP)) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6812 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6813 | tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len); |
| 6814 | if (tso < 0) |
| 6815 | goto out_drop; |
| 6816 | else if (tso) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6817 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6818 | else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol)) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6819 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6820 | } |
| 6821 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6822 | 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] | 6823 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6824 | /* add the ATR filter if ATR is on */ |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6825 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
| 6826 | ixgbe_atr(tx_ring, skb, tx_flags, protocol); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6827 | ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6828 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6829 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6830 | } else { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6831 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 6832 | tx_ring->next_to_use = first; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6833 | goto out_drop; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6834 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6835 | |
| 6836 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6837 | |
| 6838 | out_drop: |
| 6839 | dev_kfree_skb_any(skb); |
| 6840 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6841 | } |
| 6842 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6843 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 6844 | { |
| 6845 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6846 | struct ixgbe_ring *tx_ring; |
| 6847 | |
| 6848 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6849 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6850 | } |
| 6851 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6852 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6853 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 6854 | * @netdev: network interface device structure |
| 6855 | * @p: pointer to an address structure |
| 6856 | * |
| 6857 | * Returns 0 on success, negative on failure |
| 6858 | **/ |
| 6859 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 6860 | { |
| 6861 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6862 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6863 | struct sockaddr *addr = p; |
| 6864 | |
| 6865 | if (!is_valid_ether_addr(addr->sa_data)) |
| 6866 | return -EADDRNOTAVAIL; |
| 6867 | |
| 6868 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6869 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6870 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6871 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 6872 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6873 | |
| 6874 | return 0; |
| 6875 | } |
| 6876 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 6877 | static int |
| 6878 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 6879 | { |
| 6880 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6881 | struct ixgbe_hw *hw = &adapter->hw; |
| 6882 | u16 value; |
| 6883 | int rc; |
| 6884 | |
| 6885 | if (prtad != hw->phy.mdio.prtad) |
| 6886 | return -EINVAL; |
| 6887 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 6888 | if (!rc) |
| 6889 | rc = value; |
| 6890 | return rc; |
| 6891 | } |
| 6892 | |
| 6893 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 6894 | u16 addr, u16 value) |
| 6895 | { |
| 6896 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6897 | struct ixgbe_hw *hw = &adapter->hw; |
| 6898 | |
| 6899 | if (prtad != hw->phy.mdio.prtad) |
| 6900 | return -EINVAL; |
| 6901 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 6902 | } |
| 6903 | |
| 6904 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 6905 | { |
| 6906 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6907 | |
| 6908 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 6909 | } |
| 6910 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6911 | /** |
| 6912 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 6913 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6914 | * @netdev: network interface device structure |
| 6915 | * |
| 6916 | * Returns non-zero on failure |
| 6917 | **/ |
| 6918 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 6919 | { |
| 6920 | int err = 0; |
| 6921 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6922 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 6923 | |
| 6924 | if (is_valid_ether_addr(mac->san_addr)) { |
| 6925 | rtnl_lock(); |
| 6926 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 6927 | rtnl_unlock(); |
| 6928 | } |
| 6929 | return err; |
| 6930 | } |
| 6931 | |
| 6932 | /** |
| 6933 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 6934 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6935 | * @netdev: network interface device structure |
| 6936 | * |
| 6937 | * Returns non-zero on failure |
| 6938 | **/ |
| 6939 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 6940 | { |
| 6941 | int err = 0; |
| 6942 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6943 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 6944 | |
| 6945 | if (is_valid_ether_addr(mac->san_addr)) { |
| 6946 | rtnl_lock(); |
| 6947 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 6948 | rtnl_unlock(); |
| 6949 | } |
| 6950 | return err; |
| 6951 | } |
| 6952 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6953 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6954 | /* |
| 6955 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 6956 | * without having to re-enable interrupts. It's not called while |
| 6957 | * the interrupt routine is executing. |
| 6958 | */ |
| 6959 | static void ixgbe_netpoll(struct net_device *netdev) |
| 6960 | { |
| 6961 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6962 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6963 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 6964 | /* if interface is down do nothing */ |
| 6965 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6966 | return; |
| 6967 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6968 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6969 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 6970 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 6971 | for (i = 0; i < num_q_vectors; i++) { |
| 6972 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 6973 | ixgbe_msix_clean_many(0, q_vector); |
| 6974 | } |
| 6975 | } else { |
| 6976 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 6977 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6978 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6979 | } |
| 6980 | #endif |
| 6981 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6982 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 6983 | struct rtnl_link_stats64 *stats) |
| 6984 | { |
| 6985 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6986 | int i; |
| 6987 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6988 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6989 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6990 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6991 | u64 bytes, packets; |
| 6992 | unsigned int start; |
| 6993 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6994 | if (ring) { |
| 6995 | do { |
| 6996 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 6997 | packets = ring->stats.packets; |
| 6998 | bytes = ring->stats.bytes; |
| 6999 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7000 | stats->rx_packets += packets; |
| 7001 | stats->rx_bytes += bytes; |
| 7002 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7003 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7004 | |
| 7005 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7006 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7007 | u64 bytes, packets; |
| 7008 | unsigned int start; |
| 7009 | |
| 7010 | if (ring) { |
| 7011 | do { |
| 7012 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7013 | packets = ring->stats.packets; |
| 7014 | bytes = ring->stats.bytes; |
| 7015 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7016 | stats->tx_packets += packets; |
| 7017 | stats->tx_bytes += bytes; |
| 7018 | } |
| 7019 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7020 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7021 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7022 | stats->multicast = netdev->stats.multicast; |
| 7023 | stats->rx_errors = netdev->stats.rx_errors; |
| 7024 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7025 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7026 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7027 | return stats; |
| 7028 | } |
| 7029 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7030 | /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7031 | * #adapter: pointer to ixgbe_adapter |
| 7032 | * @tc: number of traffic classes currently enabled |
| 7033 | * |
| 7034 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7035 | * 802.1Q priority maps to a packet buffer that exists. |
| 7036 | */ |
| 7037 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7038 | { |
| 7039 | struct ixgbe_hw *hw = &adapter->hw; |
| 7040 | u32 reg, rsave; |
| 7041 | int i; |
| 7042 | |
| 7043 | /* 82598 have a static priority to TC mapping that can not |
| 7044 | * be changed so no validation is needed. |
| 7045 | */ |
| 7046 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7047 | return; |
| 7048 | |
| 7049 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7050 | rsave = reg; |
| 7051 | |
| 7052 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7053 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7054 | |
| 7055 | /* If up2tc is out of bounds default to zero */ |
| 7056 | if (up2tc > tc) |
| 7057 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7058 | } |
| 7059 | |
| 7060 | if (reg != rsave) |
| 7061 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7062 | |
| 7063 | return; |
| 7064 | } |
| 7065 | |
| 7066 | |
| 7067 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic |
| 7068 | * classes. |
| 7069 | * |
| 7070 | * @netdev: net device to configure |
| 7071 | * @tc: number of traffic classes to enable |
| 7072 | */ |
| 7073 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7074 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7075 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7076 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7077 | |
| 7078 | /* If DCB is anabled do not remove traffic classes, multiple |
| 7079 | * traffic classes are required to implement DCB |
| 7080 | */ |
| 7081 | if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 7082 | return 0; |
| 7083 | |
| 7084 | /* Hardware supports up to 8 traffic classes */ |
| 7085 | if (tc > MAX_TRAFFIC_CLASS || |
| 7086 | (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS)) |
| 7087 | return -EINVAL; |
| 7088 | |
| 7089 | /* Hardware has to reinitialize queues and interrupts to |
| 7090 | * match packet buffer alignment. Unfortunantly, the |
| 7091 | * hardware is not flexible enough to do this dynamically. |
| 7092 | */ |
| 7093 | if (netif_running(dev)) |
| 7094 | ixgbe_close(dev); |
| 7095 | ixgbe_clear_interrupt_scheme(adapter); |
| 7096 | |
| 7097 | if (tc) |
| 7098 | netdev_set_num_tc(dev, tc); |
| 7099 | else |
| 7100 | netdev_reset_tc(dev); |
| 7101 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7102 | ixgbe_init_interrupt_scheme(adapter); |
| 7103 | ixgbe_validate_rtr(adapter, tc); |
| 7104 | if (netif_running(dev)) |
| 7105 | ixgbe_open(dev); |
| 7106 | |
| 7107 | return 0; |
| 7108 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7109 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7110 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7111 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7112 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7113 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7114 | .ndo_select_queue = ixgbe_select_queue, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 7115 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7116 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 7117 | .ndo_validate_addr = eth_validate_addr, |
| 7118 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7119 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7120 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7121 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7122 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7123 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7124 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7125 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7126 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
| 7127 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7128 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7129 | .ndo_setup_tc = ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7130 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7131 | .ndo_poll_controller = ixgbe_netpoll, |
| 7132 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7133 | #ifdef IXGBE_FCOE |
| 7134 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7135 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7136 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7137 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7138 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7139 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7140 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7141 | }; |
| 7142 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7143 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 7144 | const struct ixgbe_info *ii) |
| 7145 | { |
| 7146 | #ifdef CONFIG_PCI_IOV |
| 7147 | struct ixgbe_hw *hw = &adapter->hw; |
| 7148 | int err; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 7149 | int num_vf_macvlans, i; |
| 7150 | struct vf_macvlans *mv_list; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7151 | |
Greg Rose | 3377eba79 | 2010-12-07 08:16:45 +0000 | [diff] [blame] | 7152 | if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs) |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7153 | return; |
| 7154 | |
| 7155 | /* The 82599 supports up to 64 VFs per physical function |
| 7156 | * but this implementation limits allocation to 63 so that |
| 7157 | * basic networking resources are still available to the |
| 7158 | * physical function |
| 7159 | */ |
| 7160 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
| 7161 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
| 7162 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 7163 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7164 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7165 | goto err_novfs; |
| 7166 | } |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 7167 | |
| 7168 | num_vf_macvlans = hw->mac.num_rar_entries - |
| 7169 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); |
| 7170 | |
| 7171 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, |
| 7172 | sizeof(struct vf_macvlans), |
| 7173 | GFP_KERNEL); |
| 7174 | if (mv_list) { |
| 7175 | /* Initialize list of VF macvlans */ |
| 7176 | INIT_LIST_HEAD(&adapter->vf_mvs.l); |
| 7177 | for (i = 0; i < num_vf_macvlans; i++) { |
| 7178 | mv_list->vf = -1; |
| 7179 | mv_list->free = true; |
| 7180 | mv_list->rar_entry = hw->mac.num_rar_entries - |
| 7181 | (i + adapter->num_vfs + 1); |
| 7182 | list_add(&mv_list->l, &adapter->vf_mvs.l); |
| 7183 | mv_list++; |
| 7184 | } |
| 7185 | } |
| 7186 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7187 | /* If call to enable VFs succeeded then allocate memory |
| 7188 | * for per VF control structures. |
| 7189 | */ |
| 7190 | adapter->vfinfo = |
| 7191 | kcalloc(adapter->num_vfs, |
| 7192 | sizeof(struct vf_data_storage), GFP_KERNEL); |
| 7193 | if (adapter->vfinfo) { |
| 7194 | /* Now that we're sure SR-IOV is enabled |
| 7195 | * and memory allocated set up the mailbox parameters |
| 7196 | */ |
| 7197 | ixgbe_init_mbx_params_pf(hw); |
| 7198 | memcpy(&hw->mbx.ops, ii->mbx_ops, |
| 7199 | sizeof(hw->mbx.ops)); |
| 7200 | |
| 7201 | /* Disable RSC when in SR-IOV mode */ |
| 7202 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | |
| 7203 | IXGBE_FLAG2_RSC_ENABLED); |
| 7204 | return; |
| 7205 | } |
| 7206 | |
| 7207 | /* Oh oh */ |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7208 | e_err(probe, "Unable to allocate memory for VF Data Storage - " |
| 7209 | "SRIOV disabled\n"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7210 | pci_disable_sriov(adapter->pdev); |
| 7211 | |
| 7212 | err_novfs: |
| 7213 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 7214 | adapter->num_vfs = 0; |
| 7215 | #endif /* CONFIG_PCI_IOV */ |
| 7216 | } |
| 7217 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7218 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7219 | * ixgbe_probe - Device Initialization Routine |
| 7220 | * @pdev: PCI device information struct |
| 7221 | * @ent: entry in ixgbe_pci_tbl |
| 7222 | * |
| 7223 | * Returns 0 on success, negative on failure |
| 7224 | * |
| 7225 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7226 | * The OS initialization, configuring of the adapter private structure, |
| 7227 | * and a hardware reset occur. |
| 7228 | **/ |
| 7229 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7230 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7231 | { |
| 7232 | struct net_device *netdev; |
| 7233 | struct ixgbe_adapter *adapter = NULL; |
| 7234 | struct ixgbe_hw *hw; |
| 7235 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7236 | static int cards_found; |
| 7237 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7238 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7239 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7240 | #ifdef IXGBE_FCOE |
| 7241 | u16 device_caps; |
| 7242 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7243 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7244 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7245 | /* Catch broken hardware that put the wrong VF device ID in |
| 7246 | * the PCIe SR-IOV capability. |
| 7247 | */ |
| 7248 | if (pdev->is_virtfn) { |
| 7249 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7250 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7251 | return -EINVAL; |
| 7252 | } |
| 7253 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7254 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7255 | if (err) |
| 7256 | return err; |
| 7257 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7258 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7259 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7260 | pci_using_dac = 1; |
| 7261 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7262 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7263 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7264 | err = dma_set_coherent_mask(&pdev->dev, |
| 7265 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7266 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7267 | dev_err(&pdev->dev, |
| 7268 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7269 | goto err_dma; |
| 7270 | } |
| 7271 | } |
| 7272 | pci_using_dac = 0; |
| 7273 | } |
| 7274 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7275 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7276 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7277 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7278 | dev_err(&pdev->dev, |
| 7279 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7280 | goto err_pci_reg; |
| 7281 | } |
| 7282 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7283 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7284 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7285 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7286 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7287 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7288 | #ifdef CONFIG_IXGBE_DCB |
| 7289 | indices *= MAX_TRAFFIC_CLASS; |
| 7290 | #endif |
| 7291 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7292 | if (ii->mac == ixgbe_mac_82598EB) |
| 7293 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7294 | else |
| 7295 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7296 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7297 | #ifdef IXGBE_FCOE |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7298 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7299 | IXGBE_MAX_FCOE_INDICES); |
| 7300 | #endif |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7301 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7302 | if (!netdev) { |
| 7303 | err = -ENOMEM; |
| 7304 | goto err_alloc_etherdev; |
| 7305 | } |
| 7306 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7307 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7308 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7309 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7310 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7311 | |
| 7312 | adapter->netdev = netdev; |
| 7313 | adapter->pdev = pdev; |
| 7314 | hw = &adapter->hw; |
| 7315 | hw->back = adapter; |
| 7316 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 7317 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7318 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7319 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7320 | if (!hw->hw_addr) { |
| 7321 | err = -EIO; |
| 7322 | goto err_ioremap; |
| 7323 | } |
| 7324 | |
| 7325 | for (i = 1; i <= 5; i++) { |
| 7326 | if (pci_resource_len(pdev, i) == 0) |
| 7327 | continue; |
| 7328 | } |
| 7329 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7330 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7331 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7332 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7333 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7334 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7335 | adapter->bd_number = cards_found; |
| 7336 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7337 | /* Setup hw api */ |
| 7338 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7339 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7340 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7341 | /* EEPROM */ |
| 7342 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7343 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7344 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7345 | if (!(eec & (1 << 8))) |
| 7346 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7347 | |
| 7348 | /* PHY */ |
| 7349 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7350 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7351 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7352 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7353 | hw->phy.mdio.mmds = 0; |
| 7354 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7355 | hw->phy.mdio.dev = netdev; |
| 7356 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7357 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7358 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7359 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7360 | |
| 7361 | /* setup the private structure */ |
| 7362 | err = ixgbe_sw_init(adapter); |
| 7363 | if (err) |
| 7364 | goto err_sw_init; |
| 7365 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7366 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7367 | switch (adapter->hw.mac.type) { |
| 7368 | case ixgbe_mac_82599EB: |
| 7369 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7370 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7371 | break; |
| 7372 | default: |
| 7373 | break; |
| 7374 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7375 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7376 | /* |
| 7377 | * If there is a fan on this device and it has failed log the |
| 7378 | * failure. |
| 7379 | */ |
| 7380 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7381 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7382 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7383 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7384 | } |
| 7385 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7386 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7387 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7388 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7389 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7390 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7391 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7392 | err = 0; |
| 7393 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7394 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7395 | "module type was detected.\n"); |
| 7396 | e_dev_err("Reload the driver after installing a supported " |
| 7397 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7398 | goto err_sw_init; |
| 7399 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7400 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7401 | goto err_sw_init; |
| 7402 | } |
| 7403 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7404 | ixgbe_probe_vf(adapter, ii); |
| 7405 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7406 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7407 | NETIF_F_IP_CSUM | |
| 7408 | NETIF_F_HW_VLAN_TX | |
| 7409 | NETIF_F_HW_VLAN_RX | |
| 7410 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7411 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 7412 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7413 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7414 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 7415 | netdev->features |= NETIF_F_GRO; |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7416 | netdev->features |= NETIF_F_RXHASH; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7417 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7418 | switch (adapter->hw.mac.type) { |
| 7419 | case ixgbe_mac_82599EB: |
| 7420 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7421 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7422 | break; |
| 7423 | default: |
| 7424 | break; |
| 7425 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7426 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7427 | netdev->vlan_features |= NETIF_F_TSO; |
| 7428 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7429 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7430 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7431 | netdev->vlan_features |= NETIF_F_SG; |
| 7432 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7433 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7434 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 7435 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7436 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7437 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7438 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7439 | #endif |
| 7440 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7441 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7442 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7443 | if (hw->mac.ops.get_device_caps) { |
| 7444 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7445 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7446 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7447 | } |
| 7448 | } |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7449 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
| 7450 | netdev->vlan_features |= NETIF_F_FCOE_CRC; |
| 7451 | netdev->vlan_features |= NETIF_F_FSO; |
| 7452 | netdev->vlan_features |= NETIF_F_FCOE_MTU; |
| 7453 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7454 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7455 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7456 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7457 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7458 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7459 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7460 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7461 | netdev->features |= NETIF_F_LRO; |
| 7462 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7463 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7464 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7465 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7466 | err = -EIO; |
| 7467 | goto err_eeprom; |
| 7468 | } |
| 7469 | |
| 7470 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7471 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7472 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7473 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7474 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7475 | err = -EIO; |
| 7476 | goto err_eeprom; |
| 7477 | } |
| 7478 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 7479 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 7480 | if (hw->mac.ops.disable_tx_laser && |
| 7481 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 7482 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 7483 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 7484 | hw->mac.ops.disable_tx_laser(hw); |
| 7485 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7486 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
| 7487 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7488 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7489 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7490 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7491 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7492 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7493 | if (err) |
| 7494 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7495 | |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7496 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 7497 | netdev->features &= ~NETIF_F_RXHASH; |
| 7498 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7499 | switch (pdev->device) { |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7500 | case IXGBE_DEV_ID_82599_SFP: |
| 7501 | /* Only this subdevice supports WOL */ |
| 7502 | if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP) |
| 7503 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 7504 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
| 7505 | break; |
Alexander Duyck | 50d6c68 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 7506 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7507 | /* All except this subdevice support WOL */ |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7508 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
| 7509 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 7510 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
| 7511 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7512 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 7513 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7514 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7515 | break; |
| 7516 | default: |
| 7517 | adapter->wol = 0; |
| 7518 | break; |
| 7519 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7520 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7521 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7522 | /* pick up the PCI bus settings for reporting later */ |
| 7523 | hw->mac.ops.get_bus_info(hw); |
| 7524 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7525 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7526 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7527 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7528 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7529 | "Unknown"), |
| 7530 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7531 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7532 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7533 | "Unknown"), |
| 7534 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7535 | |
| 7536 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7537 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7538 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7539 | 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] | 7540 | 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] | 7541 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7542 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7543 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7544 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7545 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7546 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7547 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7548 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7549 | "not sufficient for optimal performance.\n"); |
| 7550 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7551 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7552 | } |
| 7553 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 7554 | /* save off EEPROM version number */ |
| 7555 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 7556 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7557 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7558 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7559 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7560 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7561 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7562 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7563 | "Please be aware there may be issues associated " |
| 7564 | "with your hardware. If you are experiencing " |
| 7565 | "problems please contact your Intel or hardware " |
| 7566 | "representative who provided you with this " |
| 7567 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7568 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7569 | strcpy(netdev->name, "eth%d"); |
| 7570 | err = register_netdev(netdev); |
| 7571 | if (err) |
| 7572 | goto err_register; |
| 7573 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 7574 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7575 | netif_carrier_off(netdev); |
| 7576 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7577 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 7578 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7579 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7580 | ixgbe_setup_dca(adapter); |
| 7581 | } |
| 7582 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7583 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7584 | 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] | 7585 | for (i = 0; i < adapter->num_vfs; i++) |
| 7586 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 7587 | } |
| 7588 | |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 7589 | /* Inform firmware of driver version */ |
| 7590 | if (hw->mac.ops.set_fw_drv_ver) |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 7591 | hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD, |
| 7592 | FW_CEM_UNUSED_VER); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 7593 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7594 | /* add san mac addr to netdev */ |
| 7595 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7596 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7597 | e_dev_info("Intel(R) 10 Gigabit Network Connection\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7598 | cards_found++; |
| 7599 | return 0; |
| 7600 | |
| 7601 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7602 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7603 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7604 | err_sw_init: |
| 7605 | err_eeprom: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7606 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7607 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7608 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7609 | iounmap(hw->hw_addr); |
| 7610 | err_ioremap: |
| 7611 | free_netdev(netdev); |
| 7612 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7613 | pci_release_selected_regions(pdev, |
| 7614 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7615 | err_pci_reg: |
| 7616 | err_dma: |
| 7617 | pci_disable_device(pdev); |
| 7618 | return err; |
| 7619 | } |
| 7620 | |
| 7621 | /** |
| 7622 | * ixgbe_remove - Device Removal Routine |
| 7623 | * @pdev: PCI device information struct |
| 7624 | * |
| 7625 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 7626 | * that it should release a PCI device. The could be caused by a |
| 7627 | * Hot-Plug event, or because the driver is going to be removed from |
| 7628 | * memory. |
| 7629 | **/ |
| 7630 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 7631 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7632 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7633 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7634 | |
| 7635 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7636 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7637 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7638 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7639 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 7640 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 7641 | dca_remove_requester(&pdev->dev); |
| 7642 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 7643 | } |
| 7644 | |
| 7645 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7646 | #ifdef IXGBE_FCOE |
| 7647 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7648 | ixgbe_cleanup_fcoe(adapter); |
| 7649 | |
| 7650 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7651 | |
| 7652 | /* remove the added san mac */ |
| 7653 | ixgbe_del_sanmac_netdev(netdev); |
| 7654 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7655 | if (netdev->reg_state == NETREG_REGISTERED) |
| 7656 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7657 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7658 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7659 | ixgbe_disable_sriov(adapter); |
| 7660 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7661 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7662 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7663 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7664 | |
| 7665 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7666 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7667 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7668 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7669 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7670 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7671 | free_netdev(netdev); |
| 7672 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7673 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7674 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7675 | pci_disable_device(pdev); |
| 7676 | } |
| 7677 | |
| 7678 | /** |
| 7679 | * ixgbe_io_error_detected - called when PCI error is detected |
| 7680 | * @pdev: Pointer to PCI device |
| 7681 | * @state: The current pci connection state |
| 7682 | * |
| 7683 | * This function is called after a PCI bus error affecting |
| 7684 | * this device has been detected. |
| 7685 | */ |
| 7686 | 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] | 7687 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7688 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7689 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7690 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7691 | |
| 7692 | netif_device_detach(netdev); |
| 7693 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 7694 | if (state == pci_channel_io_perm_failure) |
| 7695 | return PCI_ERS_RESULT_DISCONNECT; |
| 7696 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7697 | if (netif_running(netdev)) |
| 7698 | ixgbe_down(adapter); |
| 7699 | pci_disable_device(pdev); |
| 7700 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7701 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7702 | return PCI_ERS_RESULT_NEED_RESET; |
| 7703 | } |
| 7704 | |
| 7705 | /** |
| 7706 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 7707 | * @pdev: Pointer to PCI device |
| 7708 | * |
| 7709 | * Restart the card from scratch, as if from a cold-boot. |
| 7710 | */ |
| 7711 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 7712 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7713 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7714 | pci_ers_result_t result; |
| 7715 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7716 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7717 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7718 | 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] | 7719 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7720 | } else { |
| 7721 | pci_set_master(pdev); |
| 7722 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 7723 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7724 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 7725 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7726 | |
| 7727 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 7728 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7729 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7730 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7731 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7732 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7733 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7734 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 7735 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7736 | /* non-fatal, continue */ |
| 7737 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7738 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7739 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7740 | } |
| 7741 | |
| 7742 | /** |
| 7743 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 7744 | * @pdev: Pointer to PCI device |
| 7745 | * |
| 7746 | * This callback is called when the error recovery driver tells us that |
| 7747 | * its OK to resume normal operation. |
| 7748 | */ |
| 7749 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 7750 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7751 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7752 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7753 | |
| 7754 | if (netif_running(netdev)) { |
| 7755 | if (ixgbe_up(adapter)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7756 | e_info(probe, "ixgbe_up failed after reset\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7757 | return; |
| 7758 | } |
| 7759 | } |
| 7760 | |
| 7761 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7762 | } |
| 7763 | |
| 7764 | static struct pci_error_handlers ixgbe_err_handler = { |
| 7765 | .error_detected = ixgbe_io_error_detected, |
| 7766 | .slot_reset = ixgbe_io_slot_reset, |
| 7767 | .resume = ixgbe_io_resume, |
| 7768 | }; |
| 7769 | |
| 7770 | static struct pci_driver ixgbe_driver = { |
| 7771 | .name = ixgbe_driver_name, |
| 7772 | .id_table = ixgbe_pci_tbl, |
| 7773 | .probe = ixgbe_probe, |
| 7774 | .remove = __devexit_p(ixgbe_remove), |
| 7775 | #ifdef CONFIG_PM |
| 7776 | .suspend = ixgbe_suspend, |
| 7777 | .resume = ixgbe_resume, |
| 7778 | #endif |
| 7779 | .shutdown = ixgbe_shutdown, |
| 7780 | .err_handler = &ixgbe_err_handler |
| 7781 | }; |
| 7782 | |
| 7783 | /** |
| 7784 | * ixgbe_init_module - Driver Registration Routine |
| 7785 | * |
| 7786 | * ixgbe_init_module is the first routine called when the driver is |
| 7787 | * loaded. All it does is register with the PCI subsystem. |
| 7788 | **/ |
| 7789 | static int __init ixgbe_init_module(void) |
| 7790 | { |
| 7791 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 7792 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7793 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7794 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7795 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7796 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7797 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7798 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7799 | ret = pci_register_driver(&ixgbe_driver); |
| 7800 | return ret; |
| 7801 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7802 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7803 | module_init(ixgbe_init_module); |
| 7804 | |
| 7805 | /** |
| 7806 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 7807 | * |
| 7808 | * ixgbe_exit_module is called just before the driver is removed |
| 7809 | * from memory. |
| 7810 | **/ |
| 7811 | static void __exit ixgbe_exit_module(void) |
| 7812 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7813 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7814 | dca_unregister_notify(&dca_notifier); |
| 7815 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7816 | pci_unregister_driver(&ixgbe_driver); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7817 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7818 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7819 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7820 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7821 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7822 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7823 | { |
| 7824 | int ret_val; |
| 7825 | |
| 7826 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7827 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7828 | |
| 7829 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 7830 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7831 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 7832 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7833 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7834 | module_exit(ixgbe_exit_module); |
| 7835 | |
| 7836 | /* ixgbe_main.c */ |