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> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 45 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 46 | #include <linux/if_vlan.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 47 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 48 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | |
| 50 | #include "ixgbe.h" |
| 51 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 52 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 53 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 54 | |
| 55 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 56 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 57 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 58 | #define MAJ 3 |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 59 | #define MIN 4 |
Don Skidmore | c89c711 | 2011-04-14 07:40:11 +0000 | [diff] [blame] | 60 | #define BUILD 8 |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 61 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 62 | __stringify(BUILD) "-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 63 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 64 | static const char ixgbe_copyright[] = |
| 65 | "Copyright (c) 1999-2011 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 66 | |
| 67 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 68 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 69 | [board_82599] = &ixgbe_82599_info, |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 70 | [board_X540] = &ixgbe_X540_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 74 | * |
| 75 | * Wildcard entries (PCI_ANY_ID) should come last |
| 76 | * Last entry must be all 0s |
| 77 | * |
| 78 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 79 | * Class, Class Mask, private data (not used) } |
| 80 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 81 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 83 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 84 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 85 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 87 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 89 | board_82598 }, |
Peter P Waskiewicz Jr | 3845bec | 2009-07-16 15:50:52 +0000 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), |
| 91 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 93 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 95 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 97 | board_82598 }, |
| 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 99 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 101 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 103 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 105 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 107 | board_82599 }, |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
| 109 | board_82599 }, |
Don Skidmore | 74757d4 | 2009-12-08 07:22:23 +0000 | [diff] [blame] | 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), |
| 111 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 113 | board_82599 }, |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame] | 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
| 115 | board_82599 }, |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
| 117 | board_82599 }, |
Peter P Waskiewicz Jr | 8911184 | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
| 119 | board_82599 }, |
Don Skidmore | dbffcb2 | 2010-12-03 03:32:34 +0000 | [diff] [blame] | 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), |
| 121 | board_82599 }, |
| 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), |
| 123 | board_82599 }, |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), |
| 125 | board_82599 }, |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 126 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
| 127 | board_82599 }, |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 128 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), |
Don Skidmore | d994653 | 2010-12-09 06:55:19 +0000 | [diff] [blame] | 129 | board_X540 }, |
Emil Tantilov | 4c40ef0 | 2011-03-24 07:06:02 +0000 | [diff] [blame] | 130 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), |
| 131 | board_82599 }, |
Don Skidmore | 4f6290c | 2011-05-14 06:36:35 +0000 | [diff] [blame] | 132 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), |
| 133 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 134 | |
| 135 | /* required last entry */ |
| 136 | {0, } |
| 137 | }; |
| 138 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 139 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 140 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 141 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 142 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 143 | static struct notifier_block dca_notifier = { |
| 144 | .notifier_call = ixgbe_notify_dca, |
| 145 | .next = NULL, |
| 146 | .priority = 0 |
| 147 | }; |
| 148 | #endif |
| 149 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 150 | #ifdef CONFIG_PCI_IOV |
| 151 | static unsigned int max_vfs; |
| 152 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 153 | MODULE_PARM_DESC(max_vfs, |
| 154 | "Maximum number of virtual functions to allocate per physical function"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 155 | #endif /* CONFIG_PCI_IOV */ |
| 156 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 157 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 158 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 159 | MODULE_LICENSE("GPL"); |
| 160 | MODULE_VERSION(DRV_VERSION); |
| 161 | |
| 162 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 163 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 164 | static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) |
| 165 | { |
| 166 | struct ixgbe_hw *hw = &adapter->hw; |
| 167 | u32 gcr; |
| 168 | u32 gpie; |
| 169 | u32 vmdctl; |
| 170 | |
| 171 | #ifdef CONFIG_PCI_IOV |
| 172 | /* disable iov and allow time for transactions to clear */ |
| 173 | pci_disable_sriov(adapter->pdev); |
| 174 | #endif |
| 175 | |
| 176 | /* turn off device IOV mode */ |
| 177 | gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 178 | gcr &= ~(IXGBE_GCR_EXT_SRIOV); |
| 179 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr); |
| 180 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 181 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 182 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 183 | |
| 184 | /* set default pool back to 0 */ |
| 185 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 186 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
| 187 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 188 | IXGBE_WRITE_FLUSH(hw); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 189 | |
| 190 | /* take a breather then clean up driver data */ |
| 191 | msleep(100); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 192 | |
| 193 | kfree(adapter->vfinfo); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 194 | adapter->vfinfo = NULL; |
| 195 | |
| 196 | adapter->num_vfs = 0; |
| 197 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 198 | } |
| 199 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 200 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 201 | { |
| 202 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
| 203 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
| 204 | schedule_work(&adapter->service_task); |
| 205 | } |
| 206 | |
| 207 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 208 | { |
| 209 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 210 | |
| 211 | /* flush memory to make sure state is correct before next watchog */ |
| 212 | smp_mb__before_clear_bit(); |
| 213 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 214 | } |
| 215 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 216 | struct ixgbe_reg_info { |
| 217 | u32 ofs; |
| 218 | char *name; |
| 219 | }; |
| 220 | |
| 221 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 222 | |
| 223 | /* General Registers */ |
| 224 | {IXGBE_CTRL, "CTRL"}, |
| 225 | {IXGBE_STATUS, "STATUS"}, |
| 226 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 227 | |
| 228 | /* Interrupt Registers */ |
| 229 | {IXGBE_EICR, "EICR"}, |
| 230 | |
| 231 | /* RX Registers */ |
| 232 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 233 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 234 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 235 | {IXGBE_RDH(0), "RDH"}, |
| 236 | {IXGBE_RDT(0), "RDT"}, |
| 237 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 238 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 239 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 240 | |
| 241 | /* TX Registers */ |
| 242 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 243 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 244 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 245 | {IXGBE_TDH(0), "TDH"}, |
| 246 | {IXGBE_TDT(0), "TDT"}, |
| 247 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 248 | |
| 249 | /* List Terminator */ |
| 250 | {} |
| 251 | }; |
| 252 | |
| 253 | |
| 254 | /* |
| 255 | * ixgbe_regdump - register printout routine |
| 256 | */ |
| 257 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 258 | { |
| 259 | int i = 0, j = 0; |
| 260 | char rname[16]; |
| 261 | u32 regs[64]; |
| 262 | |
| 263 | switch (reginfo->ofs) { |
| 264 | case IXGBE_SRRCTL(0): |
| 265 | for (i = 0; i < 64; i++) |
| 266 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 267 | break; |
| 268 | case IXGBE_DCA_RXCTRL(0): |
| 269 | for (i = 0; i < 64; i++) |
| 270 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 271 | break; |
| 272 | case IXGBE_RDLEN(0): |
| 273 | for (i = 0; i < 64; i++) |
| 274 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 275 | break; |
| 276 | case IXGBE_RDH(0): |
| 277 | for (i = 0; i < 64; i++) |
| 278 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 279 | break; |
| 280 | case IXGBE_RDT(0): |
| 281 | for (i = 0; i < 64; i++) |
| 282 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 283 | break; |
| 284 | case IXGBE_RXDCTL(0): |
| 285 | for (i = 0; i < 64; i++) |
| 286 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 287 | break; |
| 288 | case IXGBE_RDBAL(0): |
| 289 | for (i = 0; i < 64; i++) |
| 290 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 291 | break; |
| 292 | case IXGBE_RDBAH(0): |
| 293 | for (i = 0; i < 64; i++) |
| 294 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 295 | break; |
| 296 | case IXGBE_TDBAL(0): |
| 297 | for (i = 0; i < 64; i++) |
| 298 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 299 | break; |
| 300 | case IXGBE_TDBAH(0): |
| 301 | for (i = 0; i < 64; i++) |
| 302 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 303 | break; |
| 304 | case IXGBE_TDLEN(0): |
| 305 | for (i = 0; i < 64; i++) |
| 306 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 307 | break; |
| 308 | case IXGBE_TDH(0): |
| 309 | for (i = 0; i < 64; i++) |
| 310 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 311 | break; |
| 312 | case IXGBE_TDT(0): |
| 313 | for (i = 0; i < 64; i++) |
| 314 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 315 | break; |
| 316 | case IXGBE_TXDCTL(0): |
| 317 | for (i = 0; i < 64; i++) |
| 318 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 319 | break; |
| 320 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 321 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 322 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | for (i = 0; i < 8; i++) { |
| 327 | 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] | 328 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 329 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 330 | pr_cont(" %08x", regs[i*8+j]); |
| 331 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 338 | */ |
| 339 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 340 | { |
| 341 | struct net_device *netdev = adapter->netdev; |
| 342 | struct ixgbe_hw *hw = &adapter->hw; |
| 343 | struct ixgbe_reg_info *reginfo; |
| 344 | int n = 0; |
| 345 | struct ixgbe_ring *tx_ring; |
| 346 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 347 | union ixgbe_adv_tx_desc *tx_desc; |
| 348 | struct my_u0 { u64 a; u64 b; } *u0; |
| 349 | struct ixgbe_ring *rx_ring; |
| 350 | union ixgbe_adv_rx_desc *rx_desc; |
| 351 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 352 | u32 staterr; |
| 353 | int i = 0; |
| 354 | |
| 355 | if (!netif_msg_hw(adapter)) |
| 356 | return; |
| 357 | |
| 358 | /* Print netdevice Info */ |
| 359 | if (netdev) { |
| 360 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 361 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 362 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 363 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 364 | netdev->name, |
| 365 | netdev->state, |
| 366 | netdev->trans_start, |
| 367 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /* Print Registers */ |
| 371 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 372 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 373 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 374 | reginfo->name; reginfo++) { |
| 375 | ixgbe_regdump(hw, reginfo); |
| 376 | } |
| 377 | |
| 378 | /* Print TX Ring Summary */ |
| 379 | if (!netdev || !netif_running(netdev)) |
| 380 | goto exit; |
| 381 | |
| 382 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 383 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 384 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 385 | tx_ring = adapter->tx_ring[n]; |
| 386 | tx_buffer_info = |
| 387 | &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 388 | pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 389 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 390 | (u64)tx_buffer_info->dma, |
| 391 | tx_buffer_info->length, |
| 392 | tx_buffer_info->next_to_watch, |
| 393 | (u64)tx_buffer_info->time_stamp); |
| 394 | } |
| 395 | |
| 396 | /* Print TX Rings */ |
| 397 | if (!netif_msg_tx_done(adapter)) |
| 398 | goto rx_ring_summary; |
| 399 | |
| 400 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 401 | |
| 402 | /* Transmit Descriptor Formats |
| 403 | * |
| 404 | * Advanced Transmit Descriptor |
| 405 | * +--------------------------------------------------------------+ |
| 406 | * 0 | Buffer Address [63:0] | |
| 407 | * +--------------------------------------------------------------+ |
| 408 | * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
| 409 | * +--------------------------------------------------------------+ |
| 410 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 |
| 411 | */ |
| 412 | |
| 413 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 414 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 415 | pr_info("------------------------------------\n"); |
| 416 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 417 | pr_info("------------------------------------\n"); |
| 418 | pr_info("T [desc] [address 63:0 ] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 419 | "[PlPOIdStDDt Ln] [bi->dma ] " |
| 420 | "leng ntw timestamp bi->skb\n"); |
| 421 | |
| 422 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 423 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 424 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 425 | u0 = (struct my_u0 *)tx_desc; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 426 | pr_info("T [0x%03X] %016llX %016llX %016llX" |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 427 | " %04X %p %016llX %p", i, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 428 | le64_to_cpu(u0->a), |
| 429 | le64_to_cpu(u0->b), |
| 430 | (u64)tx_buffer_info->dma, |
| 431 | tx_buffer_info->length, |
| 432 | tx_buffer_info->next_to_watch, |
| 433 | (u64)tx_buffer_info->time_stamp, |
| 434 | tx_buffer_info->skb); |
| 435 | if (i == tx_ring->next_to_use && |
| 436 | i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 437 | pr_cont(" NTC/U\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 438 | else if (i == tx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 439 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 440 | else if (i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 441 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 442 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 443 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 444 | |
| 445 | if (netif_msg_pktdata(adapter) && |
| 446 | tx_buffer_info->dma != 0) |
| 447 | print_hex_dump(KERN_INFO, "", |
| 448 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 449 | phys_to_virt(tx_buffer_info->dma), |
| 450 | tx_buffer_info->length, true); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /* Print RX Rings Summary */ |
| 455 | rx_ring_summary: |
| 456 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 457 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 458 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 459 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 460 | pr_info("%5d %5X %5X\n", |
| 461 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /* Print RX Rings */ |
| 465 | if (!netif_msg_rx_status(adapter)) |
| 466 | goto exit; |
| 467 | |
| 468 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 469 | |
| 470 | /* Advanced Receive Descriptor (Read) Format |
| 471 | * 63 1 0 |
| 472 | * +-----------------------------------------------------+ |
| 473 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 474 | * +----------------------------------------------+------+ |
| 475 | * 8 | Header Buffer Address [63:1] | DD | |
| 476 | * +-----------------------------------------------------+ |
| 477 | * |
| 478 | * |
| 479 | * Advanced Receive Descriptor (Write-Back) Format |
| 480 | * |
| 481 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 482 | * +------------------------------------------------------+ |
| 483 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | |
| 484 | * | Checksum Ident | | | | Type | Type | |
| 485 | * +------------------------------------------------------+ |
| 486 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 487 | * +------------------------------------------------------+ |
| 488 | * 63 48 47 32 31 20 19 0 |
| 489 | */ |
| 490 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 491 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 492 | pr_info("------------------------------------\n"); |
| 493 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 494 | pr_info("------------------------------------\n"); |
| 495 | pr_info("R [desc] [ PktBuf A0] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 496 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " |
| 497 | "<-- Adv Rx Read format\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 498 | pr_info("RWB[desc] [PcsmIpSHl PtRs] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 499 | "[vl er S cks ln] ---------------- [bi->skb] " |
| 500 | "<-- Adv Rx Write-Back format\n"); |
| 501 | |
| 502 | for (i = 0; i < rx_ring->count; i++) { |
| 503 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 504 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 505 | u0 = (struct my_u0 *)rx_desc; |
| 506 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 507 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 508 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 509 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 510 | "%016llX ---------------- %p", i, |
| 511 | le64_to_cpu(u0->a), |
| 512 | le64_to_cpu(u0->b), |
| 513 | rx_buffer_info->skb); |
| 514 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 515 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 516 | "%016llX %016llX %p", i, |
| 517 | le64_to_cpu(u0->a), |
| 518 | le64_to_cpu(u0->b), |
| 519 | (u64)rx_buffer_info->dma, |
| 520 | rx_buffer_info->skb); |
| 521 | |
| 522 | if (netif_msg_pktdata(adapter)) { |
| 523 | print_hex_dump(KERN_INFO, "", |
| 524 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 525 | phys_to_virt(rx_buffer_info->dma), |
| 526 | rx_ring->rx_buf_len, true); |
| 527 | |
| 528 | if (rx_ring->rx_buf_len |
| 529 | < IXGBE_RXBUFFER_2048) |
| 530 | print_hex_dump(KERN_INFO, "", |
| 531 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 532 | phys_to_virt( |
| 533 | rx_buffer_info->page_dma + |
| 534 | rx_buffer_info->page_offset |
| 535 | ), |
| 536 | PAGE_SIZE/2, true); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 541 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 542 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 543 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 544 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 545 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 546 | |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | exit: |
| 551 | return; |
| 552 | } |
| 553 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 554 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 555 | { |
| 556 | u32 ctrl_ext; |
| 557 | |
| 558 | /* Let firmware take over control of h/w */ |
| 559 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 560 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 561 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 565 | { |
| 566 | u32 ctrl_ext; |
| 567 | |
| 568 | /* Let firmware know the driver has taken over */ |
| 569 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 570 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 571 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 572 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 573 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 574 | /* |
| 575 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 576 | * @adapter: pointer to adapter struct |
| 577 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 578 | * @queue: queue to map the corresponding interrupt to |
| 579 | * @msix_vector: the vector to map to the corresponding queue |
| 580 | * |
| 581 | */ |
| 582 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 583 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 584 | { |
| 585 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 586 | struct ixgbe_hw *hw = &adapter->hw; |
| 587 | switch (hw->mac.type) { |
| 588 | case ixgbe_mac_82598EB: |
| 589 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 590 | if (direction == -1) |
| 591 | direction = 0; |
| 592 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 593 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 594 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 595 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 596 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 597 | break; |
| 598 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 599 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 600 | if (direction == -1) { |
| 601 | /* other causes */ |
| 602 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 603 | index = ((queue & 1) * 8); |
| 604 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 605 | ivar &= ~(0xFF << index); |
| 606 | ivar |= (msix_vector << index); |
| 607 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 608 | break; |
| 609 | } else { |
| 610 | /* tx or rx causes */ |
| 611 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 612 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 613 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 614 | ivar &= ~(0xFF << index); |
| 615 | ivar |= (msix_vector << index); |
| 616 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 617 | break; |
| 618 | } |
| 619 | default: |
| 620 | break; |
| 621 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 624 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 625 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 626 | { |
| 627 | u32 mask; |
| 628 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 629 | switch (adapter->hw.mac.type) { |
| 630 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 631 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 632 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 633 | break; |
| 634 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 635 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 636 | mask = (qmask & 0xFFFFFFFF); |
| 637 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 638 | mask = (qmask >> 32); |
| 639 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 640 | break; |
| 641 | default: |
| 642 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 646 | static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring, |
| 647 | struct ixgbe_tx_buffer *tx_buffer) |
| 648 | { |
| 649 | if (tx_buffer->dma) { |
| 650 | if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE) |
| 651 | dma_unmap_page(ring->dev, |
| 652 | tx_buffer->dma, |
| 653 | tx_buffer->length, |
| 654 | DMA_TO_DEVICE); |
| 655 | else |
| 656 | dma_unmap_single(ring->dev, |
| 657 | tx_buffer->dma, |
| 658 | tx_buffer->length, |
| 659 | DMA_TO_DEVICE); |
| 660 | } |
| 661 | tx_buffer->dma = 0; |
| 662 | } |
| 663 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 664 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring, |
| 665 | struct ixgbe_tx_buffer *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 666 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 667 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info); |
| 668 | if (tx_buffer_info->skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 669 | dev_kfree_skb_any(tx_buffer_info->skb); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 670 | tx_buffer_info->skb = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 671 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 672 | } |
| 673 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 674 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 675 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 676 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 677 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 678 | u32 data = 0; |
| 679 | u32 xoff[8] = {0}; |
| 680 | int i; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 681 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 682 | if ((hw->fc.current_mode == ixgbe_fc_full) || |
| 683 | (hw->fc.current_mode == ixgbe_fc_rx_pause)) { |
| 684 | switch (hw->mac.type) { |
| 685 | case ixgbe_mac_82598EB: |
| 686 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 687 | break; |
| 688 | default: |
| 689 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 690 | } |
| 691 | hwstats->lxoffrxc += data; |
| 692 | |
| 693 | /* refill credits (no tx hang) if we received xoff */ |
| 694 | if (!data) |
| 695 | return; |
| 696 | |
| 697 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 698 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 699 | &adapter->tx_ring[i]->state); |
| 700 | return; |
| 701 | } else if (!(adapter->dcb_cfg.pfc_mode_enable)) |
| 702 | return; |
| 703 | |
| 704 | /* update stats for each tc, only valid with PFC enabled */ |
| 705 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
| 706 | switch (hw->mac.type) { |
| 707 | case ixgbe_mac_82598EB: |
| 708 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 709 | break; |
| 710 | default: |
| 711 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 712 | } |
| 713 | hwstats->pxoffrxc[i] += xoff[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 714 | } |
| 715 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 716 | /* disarm tx queues that have received xoff frames */ |
| 717 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 718 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | fb5475f | 2011-04-26 07:26:36 +0000 | [diff] [blame] | 719 | u8 tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 720 | |
| 721 | if (xoff[tc]) |
| 722 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 727 | { |
| 728 | return ring->tx_stats.completed; |
| 729 | } |
| 730 | |
| 731 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 732 | { |
| 733 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); |
| 734 | struct ixgbe_hw *hw = &adapter->hw; |
| 735 | |
| 736 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 737 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
| 738 | |
| 739 | if (head != tail) |
| 740 | return (head < tail) ? |
| 741 | tail - head : (tail + ring->count - head); |
| 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 747 | { |
| 748 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 749 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 750 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 751 | bool ret = false; |
| 752 | |
| 753 | clear_check_for_tx_hang(tx_ring); |
| 754 | |
| 755 | /* |
| 756 | * Check for a hung queue, but be thorough. This verifies |
| 757 | * that a transmit has been completed since the previous |
| 758 | * check AND there is at least one packet pending. The |
| 759 | * ARMED bit is set to indicate a potential hang. The |
| 760 | * bit is cleared if a pause frame is received to remove |
| 761 | * false hang detection due to PFC or 802.3x frames. By |
| 762 | * requiring this to fail twice we avoid races with |
| 763 | * pfc clearing the ARMED bit and conditions where we |
| 764 | * run the check_tx_hang logic with a transmit completion |
| 765 | * pending but without time to complete it yet. |
| 766 | */ |
| 767 | if ((tx_done_old == tx_done) && tx_pending) { |
| 768 | /* make sure it is true for two checks in a row */ |
| 769 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 770 | &tx_ring->state); |
| 771 | } else { |
| 772 | /* update completed stats and continue */ |
| 773 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 774 | /* reset the countdown */ |
| 775 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 776 | } |
| 777 | |
| 778 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 781 | /** |
| 782 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 783 | * @adapter: driver private struct |
| 784 | **/ |
| 785 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 786 | { |
| 787 | |
| 788 | /* Do the reset outside of interrupt context */ |
| 789 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 790 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 791 | ixgbe_service_event_schedule(adapter); |
| 792 | } |
| 793 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 794 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 795 | /** |
| 796 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 797 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 798 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 799 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 800 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 801 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 802 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 803 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 804 | struct ixgbe_tx_buffer *tx_buffer; |
| 805 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 806 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 807 | u16 budget = q_vector->tx.work_limit; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 808 | u16 i = tx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 809 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 810 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 811 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 812 | |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 813 | for (; budget; budget--) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 814 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 815 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 816 | /* if next_to_watch is not set then there is no work pending */ |
| 817 | if (!eop_desc) |
| 818 | break; |
| 819 | |
| 820 | /* if DD is not set pending work has not been completed */ |
| 821 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 822 | break; |
| 823 | |
| 824 | /* count the packet as being completed */ |
| 825 | tx_ring->tx_stats.completed++; |
| 826 | |
| 827 | /* clear next_to_watch to prevent false hangs */ |
| 828 | tx_buffer->next_to_watch = NULL; |
| 829 | |
| 830 | /* prevent any other reads prior to eop_desc being verified */ |
| 831 | rmb(); |
| 832 | |
| 833 | do { |
| 834 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 835 | tx_desc->wb.status = 0; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 836 | if (likely(tx_desc == eop_desc)) { |
| 837 | eop_desc = NULL; |
| 838 | dev_kfree_skb_any(tx_buffer->skb); |
| 839 | tx_buffer->skb = NULL; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 840 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 841 | total_bytes += tx_buffer->bytecount; |
| 842 | total_packets += tx_buffer->gso_segs; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 843 | } |
| 844 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 845 | tx_buffer++; |
| 846 | tx_desc++; |
| 847 | i++; |
| 848 | if (unlikely(i == tx_ring->count)) { |
| 849 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 850 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 851 | tx_buffer = tx_ring->tx_buffer_info; |
| 852 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0); |
| 853 | } |
| 854 | |
| 855 | } while (eop_desc); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 856 | } |
| 857 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 858 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 859 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 860 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 861 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 862 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 863 | q_vector->tx.total_bytes += total_bytes; |
| 864 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 865 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 866 | 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] | 867 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 868 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 869 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 870 | e_err(drv, "Detected Tx Unit Hang\n" |
| 871 | " Tx Queue <%d>\n" |
| 872 | " TDH, TDT <%x>, <%x>\n" |
| 873 | " next_to_use <%x>\n" |
| 874 | " next_to_clean <%x>\n" |
| 875 | "tx_buffer_info[next_to_clean]\n" |
| 876 | " time_stamp <%lx>\n" |
| 877 | " jiffies <%lx>\n", |
| 878 | tx_ring->queue_index, |
| 879 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 880 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 881 | tx_ring->next_to_use, i, |
| 882 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 883 | |
| 884 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 885 | |
| 886 | e_info(probe, |
| 887 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 888 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 889 | |
| 890 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 891 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 892 | |
| 893 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 894 | return budget; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 895 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 896 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 897 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 898 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 899 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 900 | /* Make sure that anybody stopping the queue after this |
| 901 | * sees the new next_to_clean. |
| 902 | */ |
| 903 | smp_mb(); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 904 | if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) && |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 905 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 906 | netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 907 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 908 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 909 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 910 | |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 911 | return budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 914 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 915 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 916 | struct ixgbe_ring *rx_ring, |
| 917 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 918 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 919 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 920 | u32 rxctrl; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 921 | u8 reg_idx = rx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 922 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 923 | rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx)); |
| 924 | switch (hw->mac.type) { |
| 925 | case ixgbe_mac_82598EB: |
| 926 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 927 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 928 | break; |
| 929 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 930 | case ixgbe_mac_X540: |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 931 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 932 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 933 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 934 | break; |
| 935 | default: |
| 936 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 937 | } |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 938 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 939 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
| 940 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 941 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 945 | struct ixgbe_ring *tx_ring, |
| 946 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 947 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 948 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 949 | u32 txctrl; |
| 950 | u8 reg_idx = tx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 951 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 952 | switch (hw->mac.type) { |
| 953 | case ixgbe_mac_82598EB: |
| 954 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx)); |
| 955 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 956 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 957 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 958 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl); |
| 959 | break; |
| 960 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 961 | case ixgbe_mac_X540: |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 962 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx)); |
| 963 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 964 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 965 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 966 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 967 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl); |
| 968 | break; |
| 969 | default: |
| 970 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 971 | } |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 975 | { |
| 976 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 977 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 978 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 979 | |
| 980 | if (q_vector->cpu == cpu) |
| 981 | goto out_no_update; |
| 982 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 983 | for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next) |
| 984 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 985 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 986 | for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next) |
| 987 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 988 | |
| 989 | q_vector->cpu = cpu; |
| 990 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 991 | put_cpu(); |
| 992 | } |
| 993 | |
| 994 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 995 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 996 | int num_q_vectors; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 997 | int i; |
| 998 | |
| 999 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 1000 | return; |
| 1001 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1002 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 1003 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 1004 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1005 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 1006 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1007 | else |
| 1008 | num_q_vectors = 1; |
| 1009 | |
| 1010 | for (i = 0; i < num_q_vectors; i++) { |
| 1011 | adapter->q_vector[i]->cpu = -1; |
| 1012 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1017 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1018 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1019 | unsigned long event = *(unsigned long *)data; |
| 1020 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1021 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1022 | return 0; |
| 1023 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1024 | switch (event) { |
| 1025 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1026 | /* if we're already enabled, don't do it again */ |
| 1027 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1028 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1029 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1030 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1031 | ixgbe_setup_dca(adapter); |
| 1032 | break; |
| 1033 | } |
| 1034 | /* Fall Through since DCA is disabled. */ |
| 1035 | case DCA_PROVIDER_REMOVE: |
| 1036 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1037 | dca_remove_requester(dev); |
| 1038 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 1039 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 1040 | } |
| 1041 | break; |
| 1042 | } |
| 1043 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1044 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1045 | } |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1046 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1047 | |
| 1048 | static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc, |
| 1049 | struct sk_buff *skb) |
| 1050 | { |
| 1051 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
| 1052 | } |
| 1053 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1054 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1055 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
| 1056 | * @adapter: address of board private structure |
| 1057 | * @rx_desc: advanced rx descriptor |
| 1058 | * |
| 1059 | * Returns : true if it is FCoE pkt |
| 1060 | */ |
| 1061 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter, |
| 1062 | union ixgbe_adv_rx_desc *rx_desc) |
| 1063 | { |
| 1064 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1065 | |
| 1066 | return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 1067 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1068 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1069 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1070 | } |
| 1071 | |
| 1072 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1073 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 1074 | * @adapter: board private structure |
| 1075 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1076 | * @status: hardware indication of status of receive |
| 1077 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 1078 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1079 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1080 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1081 | struct sk_buff *skb, u8 status, |
| 1082 | struct ixgbe_ring *ring, |
| 1083 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1084 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1085 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1086 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1087 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 1088 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1089 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 1090 | if (is_vlan && (tag & VLAN_VID_MASK)) |
| 1091 | __vlan_hwaccel_put_tag(skb, tag); |
| 1092 | |
| 1093 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1094 | napi_gro_receive(napi, skb); |
| 1095 | else |
| 1096 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1099 | /** |
| 1100 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 1101 | * @adapter: address of board private structure |
| 1102 | * @status_err: hardware indication of status of receive |
| 1103 | * @skb: skb currently being received and modified |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1104 | * @status_err: status error value of last descriptor in packet |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1105 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1106 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1107 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1108 | struct sk_buff *skb, |
| 1109 | u32 status_err) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1110 | { |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1111 | skb->ip_summed = CHECKSUM_NONE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1112 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1113 | /* Rx csum disabled */ |
| 1114 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1115 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1116 | |
| 1117 | /* if IP and error */ |
| 1118 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 1119 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1120 | adapter->hw_csum_rx_error++; |
| 1121 | return; |
| 1122 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1123 | |
| 1124 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 1125 | return; |
| 1126 | |
| 1127 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1128 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1129 | |
| 1130 | /* |
| 1131 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1132 | * checksum errors. |
| 1133 | */ |
| 1134 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 1135 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 1136 | return; |
| 1137 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1138 | adapter->hw_csum_rx_error++; |
| 1139 | return; |
| 1140 | } |
| 1141 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1142 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1143 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1146 | 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] | 1147 | { |
| 1148 | /* |
| 1149 | * Force memory writes to complete before letting h/w |
| 1150 | * know there are new descriptors to fetch. (Only |
| 1151 | * applicable for weak-ordered memory model archs, |
| 1152 | * such as IA-64). |
| 1153 | */ |
| 1154 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1155 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1158 | /** |
| 1159 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1160 | * @rx_ring: ring to place buffers on |
| 1161 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1162 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1163 | 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] | 1164 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1165 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1166 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1167 | struct sk_buff *skb; |
| 1168 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1169 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1170 | /* do nothing if no valid netdev defined */ |
| 1171 | if (!rx_ring->netdev) |
| 1172 | return; |
| 1173 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1174 | while (cleaned_count--) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1175 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1176 | bi = &rx_ring->rx_buffer_info[i]; |
| 1177 | skb = bi->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1178 | |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1179 | if (!skb) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1180 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1181 | rx_ring->rx_buf_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1182 | if (!skb) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1183 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1184 | goto no_buffers; |
| 1185 | } |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1186 | /* initialize queue mapping */ |
| 1187 | skb_record_rx_queue(skb, rx_ring->queue_index); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1188 | bi->skb = skb; |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1189 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1190 | |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1191 | if (!bi->dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1192 | bi->dma = dma_map_single(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1193 | skb->data, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1194 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 1195 | DMA_FROM_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1196 | if (dma_mapping_error(rx_ring->dev, bi->dma)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1197 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1198 | bi->dma = 0; |
| 1199 | goto no_buffers; |
| 1200 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1201 | } |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1202 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1203 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1204 | if (!bi->page) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1205 | bi->page = netdev_alloc_page(rx_ring->netdev); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1206 | if (!bi->page) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1207 | rx_ring->rx_stats.alloc_rx_page_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1208 | goto no_buffers; |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | if (!bi->page_dma) { |
| 1213 | /* use a half page if we're re-using */ |
| 1214 | bi->page_offset ^= PAGE_SIZE / 2; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1215 | bi->page_dma = dma_map_page(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1216 | bi->page, |
| 1217 | bi->page_offset, |
| 1218 | PAGE_SIZE / 2, |
| 1219 | DMA_FROM_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1220 | if (dma_mapping_error(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1221 | bi->page_dma)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1222 | rx_ring->rx_stats.alloc_rx_page_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1223 | bi->page_dma = 0; |
| 1224 | goto no_buffers; |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | /* Refresh the desc even if buffer_addrs didn't change |
| 1229 | * because each write-back erases this info. */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1230 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 1231 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1232 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1233 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1234 | rx_desc->read.hdr_addr = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | i++; |
| 1238 | if (i == rx_ring->count) |
| 1239 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1240 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1241 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1242 | no_buffers: |
| 1243 | if (rx_ring->next_to_use != i) { |
| 1244 | rx_ring->next_to_use = i; |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1245 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1249 | 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] | 1250 | { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1251 | /* HW will not DMA in data larger than the given buffer, even if it |
| 1252 | * parses the (NFS, of course) header to be larger. In that case, it |
| 1253 | * fills the header buffer and spills the rest into the page. |
| 1254 | */ |
| 1255 | u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info); |
| 1256 | u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
| 1257 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
| 1258 | if (hlen > IXGBE_RX_HDR_SIZE) |
| 1259 | hlen = IXGBE_RX_HDR_SIZE; |
| 1260 | return hlen; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1263 | /** |
| 1264 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 1265 | * @skb: pointer to the last skb in the rsc queue |
| 1266 | * |
| 1267 | * This function changes a queue full of hw rsc buffers into a completed |
| 1268 | * packet. It uses the ->prev pointers to find the first packet and then |
| 1269 | * turns it into the frag list owner. |
| 1270 | **/ |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1271 | 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] | 1272 | { |
| 1273 | unsigned int frag_list_size = 0; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1274 | unsigned int skb_cnt = 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1275 | |
| 1276 | while (skb->prev) { |
| 1277 | struct sk_buff *prev = skb->prev; |
| 1278 | frag_list_size += skb->len; |
| 1279 | skb->prev = NULL; |
| 1280 | skb = prev; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1281 | skb_cnt++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | skb_shinfo(skb)->frag_list = skb->next; |
| 1285 | skb->next = NULL; |
| 1286 | skb->len += frag_list_size; |
| 1287 | skb->data_len += frag_list_size; |
| 1288 | skb->truesize += frag_list_size; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1289 | IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt; |
| 1290 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1291 | return skb; |
| 1292 | } |
| 1293 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1294 | static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc) |
| 1295 | { |
| 1296 | return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 1297 | IXGBE_RXDADV_RSCCNT_MASK); |
| 1298 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1299 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1300 | static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1301 | struct ixgbe_ring *rx_ring, |
| 1302 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1303 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1304 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1305 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 1306 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 1307 | struct sk_buff *skb; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1308 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1309 | const int current_node = numa_node_id(); |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1310 | #ifdef IXGBE_FCOE |
| 1311 | int ddp_bytes = 0; |
| 1312 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1313 | u32 staterr; |
| 1314 | u16 i; |
| 1315 | u16 cleaned_count = 0; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1316 | bool pkt_is_rsc = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1317 | |
| 1318 | i = rx_ring->next_to_clean; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1319 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1320 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1321 | |
| 1322 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1323 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1324 | |
Milton Miller | 3c945e5 | 2010-02-19 17:44:42 +0000 | [diff] [blame] | 1325 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1326 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1327 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 1328 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1329 | skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1330 | rx_buffer_info->skb = NULL; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1331 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1332 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1333 | if (ring_is_rsc_enabled(rx_ring)) |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1334 | pkt_is_rsc = ixgbe_get_rsc_state(rx_desc); |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1335 | |
| 1336 | /* if this is a skb from previous receive DMA will be 0 */ |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 1337 | if (rx_buffer_info->dma) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1338 | u16 hlen; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1339 | if (pkt_is_rsc && |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1340 | !(staterr & IXGBE_RXD_STAT_EOP) && |
| 1341 | !skb->prev) { |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1342 | /* |
| 1343 | * When HWRSC is enabled, delay unmapping |
| 1344 | * of the first packet. It carries the |
| 1345 | * header information, HW may still |
| 1346 | * access the header after the writeback. |
| 1347 | * Only unmap it when EOP is reached |
| 1348 | */ |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1349 | IXGBE_RSC_CB(skb)->delay_unmap = true; |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1350 | IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1351 | } else { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1352 | dma_unmap_single(rx_ring->dev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1353 | rx_buffer_info->dma, |
| 1354 | rx_ring->rx_buf_len, |
| 1355 | DMA_FROM_DEVICE); |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1356 | } |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 1357 | rx_buffer_info->dma = 0; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1358 | |
| 1359 | if (ring_is_ps_enabled(rx_ring)) { |
| 1360 | hlen = ixgbe_get_hlen(rx_desc); |
| 1361 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
| 1362 | } else { |
| 1363 | hlen = le16_to_cpu(rx_desc->wb.upper.length); |
| 1364 | } |
| 1365 | |
| 1366 | skb_put(skb, hlen); |
| 1367 | } else { |
| 1368 | /* assume packet split since header is unmapped */ |
| 1369 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | if (upper_len) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1373 | dma_unmap_page(rx_ring->dev, |
| 1374 | rx_buffer_info->page_dma, |
| 1375 | PAGE_SIZE / 2, |
| 1376 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1377 | rx_buffer_info->page_dma = 0; |
| 1378 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1379 | rx_buffer_info->page, |
| 1380 | rx_buffer_info->page_offset, |
| 1381 | upper_len); |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1382 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1383 | if ((page_count(rx_buffer_info->page) == 1) && |
| 1384 | (page_to_nid(rx_buffer_info->page) == current_node)) |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1385 | get_page(rx_buffer_info->page); |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1386 | else |
| 1387 | rx_buffer_info->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1388 | |
| 1389 | skb->len += upper_len; |
| 1390 | skb->data_len += upper_len; |
| 1391 | skb->truesize += upper_len; |
| 1392 | } |
| 1393 | |
| 1394 | i++; |
| 1395 | if (i == rx_ring->count) |
| 1396 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1397 | |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1398 | next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1399 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1400 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1401 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1402 | if (pkt_is_rsc) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1403 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 1404 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 1405 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1406 | } else { |
| 1407 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 1408 | } |
| 1409 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1410 | if (!(staterr & IXGBE_RXD_STAT_EOP)) { |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1411 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1412 | rx_buffer_info->skb = next_buffer->skb; |
| 1413 | rx_buffer_info->dma = next_buffer->dma; |
| 1414 | next_buffer->skb = skb; |
| 1415 | next_buffer->dma = 0; |
| 1416 | } else { |
| 1417 | skb->next = next_buffer->skb; |
| 1418 | skb->next->prev = skb; |
| 1419 | } |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1420 | rx_ring->rx_stats.non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1421 | goto next_desc; |
| 1422 | } |
| 1423 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1424 | if (skb->prev) { |
| 1425 | skb = ixgbe_transform_rsc_queue(skb); |
| 1426 | /* if we got here without RSC the packet is invalid */ |
| 1427 | if (!pkt_is_rsc) { |
| 1428 | __pskb_trim(skb, 0); |
| 1429 | rx_buffer_info->skb = skb; |
| 1430 | goto next_desc; |
| 1431 | } |
| 1432 | } |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1433 | |
| 1434 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1435 | if (IXGBE_RSC_CB(skb)->delay_unmap) { |
| 1436 | dma_unmap_single(rx_ring->dev, |
| 1437 | IXGBE_RSC_CB(skb)->dma, |
| 1438 | rx_ring->rx_buf_len, |
| 1439 | DMA_FROM_DEVICE); |
| 1440 | IXGBE_RSC_CB(skb)->dma = 0; |
| 1441 | IXGBE_RSC_CB(skb)->delay_unmap = false; |
| 1442 | } |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1443 | } |
| 1444 | if (pkt_is_rsc) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1445 | if (ring_is_ps_enabled(rx_ring)) |
| 1446 | rx_ring->rx_stats.rsc_count += |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1447 | skb_shinfo(skb)->nr_frags; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1448 | else |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1449 | rx_ring->rx_stats.rsc_count += |
| 1450 | IXGBE_RSC_CB(skb)->skb_cnt; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1451 | rx_ring->rx_stats.rsc_flush++; |
| 1452 | } |
| 1453 | |
| 1454 | /* ERR_MASK will only have valid bits if EOP set */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1455 | if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) { |
| 1456 | dev_kfree_skb_any(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1457 | goto next_desc; |
| 1458 | } |
| 1459 | |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1460 | ixgbe_rx_checksum(adapter, rx_desc, skb, staterr); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1461 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 1462 | ixgbe_rx_hash(rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1463 | |
| 1464 | /* probably a little skewed due to removing CRC */ |
| 1465 | total_rx_bytes += skb->len; |
| 1466 | total_rx_packets++; |
| 1467 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1468 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1469 | #ifdef IXGBE_FCOE |
| 1470 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1471 | if (ixgbe_rx_is_fcoe(adapter, rx_desc)) { |
| 1472 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb, |
| 1473 | staterr); |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1474 | if (!ddp_bytes) { |
| 1475 | dev_kfree_skb_any(skb); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1476 | goto next_desc; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 1477 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1478 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1479 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 1480 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1481 | |
| 1482 | next_desc: |
| 1483 | rx_desc->wb.upper.status_error = 0; |
| 1484 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1485 | (*work_done)++; |
| 1486 | if (*work_done >= work_to_do) |
| 1487 | break; |
| 1488 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1489 | /* return some buffers to hardware, one at a time is too slow */ |
| 1490 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1491 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1492 | cleaned_count = 0; |
| 1493 | } |
| 1494 | |
| 1495 | /* use prefetched values */ |
| 1496 | rx_desc = next_rxd; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1497 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1500 | rx_ring->next_to_clean = i; |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1501 | cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1502 | |
| 1503 | if (cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1504 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1505 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1506 | #ifdef IXGBE_FCOE |
| 1507 | /* include DDPed FCoE data */ |
| 1508 | if (ddp_bytes > 0) { |
| 1509 | unsigned int mss; |
| 1510 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1511 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1512 | sizeof(struct fc_frame_header) - |
| 1513 | sizeof(struct fcoe_crc_eof); |
| 1514 | if (mss > 512) |
| 1515 | mss &= ~511; |
| 1516 | total_rx_bytes += ddp_bytes; |
| 1517 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1518 | } |
| 1519 | #endif /* IXGBE_FCOE */ |
| 1520 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1521 | u64_stats_update_begin(&rx_ring->syncp); |
| 1522 | rx_ring->stats.packets += total_rx_packets; |
| 1523 | rx_ring->stats.bytes += total_rx_bytes; |
| 1524 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1525 | q_vector->rx.total_packets += total_rx_packets; |
| 1526 | q_vector->rx.total_bytes += total_rx_bytes; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1529 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1530 | /** |
| 1531 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1532 | * @adapter: board private structure |
| 1533 | * |
| 1534 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1535 | * interrupts. |
| 1536 | **/ |
| 1537 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1538 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1539 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1540 | int q_vectors, v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1541 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1542 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1543 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1544 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1545 | /* |
| 1546 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1547 | * corresponding register. |
| 1548 | */ |
| 1549 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1550 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1551 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1552 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1553 | for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next) |
| 1554 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1555 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1556 | for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next) |
| 1557 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1558 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1559 | if (q_vector->tx.ring && !q_vector->rx.ring) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1560 | /* tx only */ |
| 1561 | q_vector->eitr = adapter->tx_eitr_param; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1562 | else if (q_vector->rx.ring) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1563 | /* rx or mixed */ |
| 1564 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1565 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1566 | ixgbe_write_eitr(q_vector); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 1567 | /* If ATR is enabled, set interrupt affinity */ |
| 1568 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 1569 | /* |
| 1570 | * Allocate the affinity_hint cpumask, assign the mask |
| 1571 | * for this vector, and set our affinity_hint for |
| 1572 | * this irq. |
| 1573 | */ |
| 1574 | if (!alloc_cpumask_var(&q_vector->affinity_mask, |
| 1575 | GFP_KERNEL)) |
| 1576 | return; |
| 1577 | cpumask_set_cpu(v_idx, q_vector->affinity_mask); |
| 1578 | irq_set_affinity_hint(adapter->msix_entries[v_idx].vector, |
| 1579 | q_vector->affinity_mask); |
| 1580 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1583 | switch (adapter->hw.mac.type) { |
| 1584 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1585 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1586 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1587 | break; |
| 1588 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1589 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1590 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1591 | break; |
| 1592 | |
| 1593 | default: |
| 1594 | break; |
| 1595 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1596 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1597 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1598 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1599 | mask = IXGBE_EIMS_ENABLE_MASK; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1600 | if (adapter->num_vfs) |
| 1601 | mask &= ~(IXGBE_EIMS_OTHER | |
| 1602 | IXGBE_EIMS_MAILBOX | |
| 1603 | IXGBE_EIMS_LSC); |
| 1604 | else |
| 1605 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1606 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1609 | enum latency_range { |
| 1610 | lowest_latency = 0, |
| 1611 | low_latency = 1, |
| 1612 | bulk_latency = 2, |
| 1613 | latency_invalid = 255 |
| 1614 | }; |
| 1615 | |
| 1616 | /** |
| 1617 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1618 | * @q_vector: structure containing interrupt and ring information |
| 1619 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1620 | * |
| 1621 | * Stores a new ITR value based on packets and byte |
| 1622 | * counts during the last interrupt. The advantage of per interrupt |
| 1623 | * computation is faster updates and more accurate ITR for the current |
| 1624 | * traffic pattern. Constants in this function were computed |
| 1625 | * based on theoretical maximum wire speed and thresholds were set based |
| 1626 | * on testing data as well as attempting to minimize response time |
| 1627 | * while increasing bulk throughput. |
| 1628 | * this functionality is controlled by the InterruptThrottleRate module |
| 1629 | * parameter (see ixgbe_param.c) |
| 1630 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1631 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 1632 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1633 | { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1634 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1635 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1636 | int bytes = ring_container->total_bytes; |
| 1637 | int packets = ring_container->total_packets; |
| 1638 | u32 timepassed_us; |
| 1639 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1640 | |
| 1641 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1642 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1643 | |
| 1644 | /* simple throttlerate management |
| 1645 | * 0-20MB/s lowest (100000 ints/s) |
| 1646 | * 20-100MB/s low (20000 ints/s) |
| 1647 | * 100-1249MB/s bulk (8000 ints/s) |
| 1648 | */ |
| 1649 | /* what was last interrupt timeslice? */ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1650 | timepassed_us = 1000000/q_vector->eitr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1651 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1652 | |
| 1653 | switch (itr_setting) { |
| 1654 | case lowest_latency: |
| 1655 | if (bytes_perint > adapter->eitr_low) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1656 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1657 | break; |
| 1658 | case low_latency: |
| 1659 | if (bytes_perint > adapter->eitr_high) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1660 | itr_setting = bulk_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1661 | else if (bytes_perint <= adapter->eitr_low) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1662 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1663 | break; |
| 1664 | case bulk_latency: |
| 1665 | if (bytes_perint <= adapter->eitr_high) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1666 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1667 | break; |
| 1668 | } |
| 1669 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1670 | /* clear work counters since we have the values we need */ |
| 1671 | ring_container->total_bytes = 0; |
| 1672 | ring_container->total_packets = 0; |
| 1673 | |
| 1674 | /* write updated itr to ring container */ |
| 1675 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1676 | } |
| 1677 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1678 | /** |
| 1679 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1680 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1681 | * |
| 1682 | * This function is made to be called by ethtool and by the driver |
| 1683 | * when it needs to update EITR registers at runtime. Hardware |
| 1684 | * specific quirks/differences are taken care of here. |
| 1685 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1686 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1687 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1688 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1689 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1690 | int v_idx = q_vector->v_idx; |
| 1691 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1692 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1693 | switch (adapter->hw.mac.type) { |
| 1694 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1695 | /* must write high and low 16 bits to reset counter */ |
| 1696 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1697 | break; |
| 1698 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1699 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1700 | /* |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1701 | * 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] | 1702 | * max interrupt rate, but there is an errata where it can |
| 1703 | * not be zero with RSC |
| 1704 | */ |
| 1705 | if (itr_reg == 8 && |
| 1706 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 1707 | itr_reg = 0; |
| 1708 | |
| 1709 | /* |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1710 | * set the WDIS bit to not clear the timer bits and cause an |
| 1711 | * immediate assertion of the interrupt |
| 1712 | */ |
| 1713 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1714 | break; |
| 1715 | default: |
| 1716 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1717 | } |
| 1718 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1719 | } |
| 1720 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1721 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1722 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1723 | u32 new_itr = q_vector->eitr; |
| 1724 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1725 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1726 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 1727 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1728 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1729 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1730 | |
| 1731 | switch (current_itr) { |
| 1732 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1733 | case lowest_latency: |
| 1734 | new_itr = 100000; |
| 1735 | break; |
| 1736 | case low_latency: |
| 1737 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1738 | break; |
| 1739 | case bulk_latency: |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1740 | new_itr = 8000; |
| 1741 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1742 | default: |
| 1743 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1747 | /* do an exponential smoothing */ |
Alexander Duyck | 125601b | 2010-11-16 19:27:08 -0800 | [diff] [blame] | 1748 | new_itr = ((q_vector->eitr * 9) + new_itr)/10; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1749 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1750 | /* save the algorithm value here */ |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1751 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1752 | |
| 1753 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1754 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1755 | } |
| 1756 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1757 | /** |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1758 | * ixgbe_check_overtemp_subtask - check for over tempurature |
| 1759 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1760 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1761 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1762 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1763 | struct ixgbe_hw *hw = &adapter->hw; |
| 1764 | u32 eicr = adapter->interrupt_event; |
| 1765 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1766 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1767 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1768 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1769 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1770 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 1771 | return; |
| 1772 | |
| 1773 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1774 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1775 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1776 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 1777 | /* |
| 1778 | * Since the warning interrupt is for both ports |
| 1779 | * we don't have to check if: |
| 1780 | * - This interrupt wasn't for our port. |
| 1781 | * - We may have missed the interrupt so always have to |
| 1782 | * check if we got a LSC |
| 1783 | */ |
| 1784 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 1785 | !(eicr & IXGBE_EICR_LSC)) |
| 1786 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1787 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1788 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
| 1789 | u32 autoneg; |
| 1790 | bool link_up = false; |
| 1791 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1792 | hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 1793 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1794 | if (link_up) |
| 1795 | return; |
| 1796 | } |
| 1797 | |
| 1798 | /* Check if this is not due to overtemp */ |
| 1799 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 1800 | return; |
| 1801 | |
| 1802 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 1803 | default: |
| 1804 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 1805 | return; |
| 1806 | break; |
| 1807 | } |
| 1808 | e_crit(drv, |
| 1809 | "Network adapter has been stopped because it has over heated. " |
| 1810 | "Restart the computer. If the problem persists, " |
| 1811 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1812 | |
| 1813 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1816 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1817 | { |
| 1818 | struct ixgbe_hw *hw = &adapter->hw; |
| 1819 | |
| 1820 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1821 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 1822 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1823 | /* write to clear the interrupt */ |
| 1824 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1825 | } |
| 1826 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1827 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1828 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1829 | { |
| 1830 | struct ixgbe_hw *hw = &adapter->hw; |
| 1831 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 1832 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1833 | /* Clear the interrupt */ |
| 1834 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1835 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1836 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 1837 | ixgbe_service_event_schedule(adapter); |
| 1838 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 1839 | } |
| 1840 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1841 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1842 | /* Clear the interrupt */ |
| 1843 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1844 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1845 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 1846 | ixgbe_service_event_schedule(adapter); |
| 1847 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1848 | } |
| 1849 | } |
| 1850 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1851 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1852 | { |
| 1853 | struct ixgbe_hw *hw = &adapter->hw; |
| 1854 | |
| 1855 | adapter->lsc_int++; |
| 1856 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1857 | adapter->link_check_timeout = jiffies; |
| 1858 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1859 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 1860 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 1861 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1865 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1866 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 1867 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1868 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1869 | u32 eicr; |
| 1870 | |
| 1871 | /* |
| 1872 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1873 | * of clear-by-read. Reading with EICS will return the |
| 1874 | * interrupt causes without clearing, which later be done |
| 1875 | * with the write to EICR. |
| 1876 | */ |
| 1877 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1878 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1879 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1880 | if (eicr & IXGBE_EICR_LSC) |
| 1881 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1882 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1883 | if (eicr & IXGBE_EICR_MAILBOX) |
| 1884 | ixgbe_msg_task(adapter); |
| 1885 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1886 | switch (hw->mac.type) { |
| 1887 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1888 | case ixgbe_mac_X540: |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1889 | /* Handle Flow Director Full threshold interrupt */ |
| 1890 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1891 | int reinit_count = 0; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1892 | int i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1893 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1894 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1895 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 1896 | &ring->state)) |
| 1897 | reinit_count++; |
| 1898 | } |
| 1899 | if (reinit_count) { |
| 1900 | /* no more flow director interrupts until after init */ |
| 1901 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 1902 | eicr &= ~IXGBE_EICR_FLOW_DIR; |
| 1903 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 1904 | ixgbe_service_event_schedule(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1905 | } |
| 1906 | } |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 1907 | ixgbe_check_sfp_event(adapter, eicr); |
| 1908 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 1909 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { |
| 1910 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1911 | adapter->interrupt_event = eicr; |
| 1912 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 1913 | ixgbe_service_event_schedule(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1914 | } |
| 1915 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1916 | break; |
| 1917 | default: |
| 1918 | break; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1919 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1920 | |
| 1921 | ixgbe_check_fan_failure(adapter, eicr); |
| 1922 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1923 | /* re-enable the original interrupt state, no lsc, no queues */ |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1924 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 1925 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr & |
| 1926 | ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1927 | |
| 1928 | return IRQ_HANDLED; |
| 1929 | } |
| 1930 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1931 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1932 | u64 qmask) |
| 1933 | { |
| 1934 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1935 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1936 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1937 | switch (hw->mac.type) { |
| 1938 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1939 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1940 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 1941 | break; |
| 1942 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1943 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1944 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1945 | if (mask) |
| 1946 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1947 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1948 | if (mask) |
| 1949 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 1950 | break; |
| 1951 | default: |
| 1952 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1953 | } |
| 1954 | /* skip the flush */ |
| 1955 | } |
| 1956 | |
| 1957 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1958 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1959 | { |
| 1960 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1961 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1962 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1963 | switch (hw->mac.type) { |
| 1964 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1965 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1966 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 1967 | break; |
| 1968 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1969 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1970 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1971 | if (mask) |
| 1972 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1973 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1974 | if (mask) |
| 1975 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 1976 | break; |
| 1977 | default: |
| 1978 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1979 | } |
| 1980 | /* skip the flush */ |
| 1981 | } |
| 1982 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1983 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1984 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1985 | struct ixgbe_q_vector *q_vector = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1986 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1987 | if (!q_vector->tx.count) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1988 | return IRQ_HANDLED; |
| 1989 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1990 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1991 | napi_schedule(&q_vector->napi); |
| 1992 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1993 | return IRQ_HANDLED; |
| 1994 | } |
| 1995 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1996 | /** |
| 1997 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1998 | * @irq: unused |
| 1999 | * @data: pointer to our q_vector struct for this interrupt vector |
| 2000 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2001 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 2002 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2003 | struct ixgbe_q_vector *q_vector = data; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2004 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2005 | if (!q_vector->rx.count) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2006 | return IRQ_HANDLED; |
| 2007 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2008 | /* EIAM disabled interrupts (on this vector) for us */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2009 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2010 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2011 | return IRQ_HANDLED; |
| 2012 | } |
| 2013 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2014 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 2015 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2016 | struct ixgbe_q_vector *q_vector = data; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2017 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2018 | if (!q_vector->tx.count && !q_vector->rx.count) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2019 | return IRQ_HANDLED; |
| 2020 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2021 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2022 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2023 | |
| 2024 | return IRQ_HANDLED; |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 2029 | * @napi: napi struct with our devices info in it |
| 2030 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2031 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2032 | * This function is optimized for cleaning one queue only on a single |
| 2033 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2034 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2035 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 2036 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2037 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2038 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2039 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2040 | int work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2041 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2042 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2043 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2044 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2045 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2046 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2047 | ixgbe_clean_rx_irq(q_vector, q_vector->rx.ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2048 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2049 | /* If all Rx work done, exit the polling mode */ |
| 2050 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2051 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2052 | if (adapter->rx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2053 | ixgbe_set_itr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2054 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2055 | ixgbe_irq_enable_queues(adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2056 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | return work_done; |
| 2060 | } |
| 2061 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2062 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2063 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2064 | * @napi: napi struct with our devices info in it |
| 2065 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2066 | * |
| 2067 | * This function will clean more than one rx queue associated with a |
| 2068 | * q_vector. |
| 2069 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2070 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2071 | { |
| 2072 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2073 | container_of(napi, struct ixgbe_q_vector, napi); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2074 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2075 | struct ixgbe_ring *ring; |
| 2076 | int work_done = 0; |
| 2077 | bool clean_complete = true; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2078 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2079 | #ifdef CONFIG_IXGBE_DCA |
| 2080 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2081 | ixgbe_update_dca(q_vector); |
| 2082 | #endif |
| 2083 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2084 | for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next) |
| 2085 | clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2086 | |
| 2087 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2088 | * the budget to go below 1 because we'll exit polling */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2089 | budget /= (q_vector->rx.count ?: 1); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2090 | budget = max(budget, 1); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2091 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2092 | for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next) |
| 2093 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
| 2094 | |
| 2095 | if (!clean_complete) |
| 2096 | work_done = budget; |
| 2097 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2098 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2099 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2100 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2101 | if (adapter->rx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2102 | ixgbe_set_itr(q_vector); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2103 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2104 | ixgbe_irq_enable_queues(adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2105 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2106 | return 0; |
| 2107 | } |
| 2108 | |
| 2109 | return work_done; |
| 2110 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2111 | |
| 2112 | /** |
| 2113 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 2114 | * @napi: napi struct with our devices info in it |
| 2115 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2116 | * |
| 2117 | * This function is optimized for cleaning one queue only on a single |
| 2118 | * q_vector!!! |
| 2119 | **/ |
| 2120 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 2121 | { |
| 2122 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2123 | container_of(napi, struct ixgbe_q_vector, napi); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2124 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2125 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2126 | #ifdef CONFIG_IXGBE_DCA |
| 2127 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2128 | ixgbe_update_dca(q_vector); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2129 | #endif |
| 2130 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2131 | if (!ixgbe_clean_tx_irq(q_vector, q_vector->tx.ring)) |
| 2132 | return budget; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2133 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2134 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2135 | napi_complete(napi); |
| 2136 | if (adapter->tx_itr_setting & 1) |
| 2137 | ixgbe_set_itr(q_vector); |
| 2138 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2139 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2140 | |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2141 | return 0; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2144 | 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] | 2145 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2146 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2147 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2148 | struct ixgbe_ring *rx_ring = a->rx_ring[r_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2149 | |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2150 | rx_ring->q_vector = q_vector; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2151 | rx_ring->next = q_vector->rx.ring; |
| 2152 | q_vector->rx.ring = rx_ring; |
| 2153 | q_vector->rx.count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2154 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2155 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2156 | 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] | 2157 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2158 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2159 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2160 | struct ixgbe_ring *tx_ring = a->tx_ring[t_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2161 | |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2162 | tx_ring->q_vector = q_vector; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2163 | tx_ring->next = q_vector->tx.ring; |
| 2164 | q_vector->tx.ring = tx_ring; |
| 2165 | q_vector->tx.count++; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2166 | q_vector->tx.work_limit = a->tx_work_limit; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2167 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2168 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2169 | /** |
| 2170 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 2171 | * @adapter: board private structure to initialize |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2172 | * |
| 2173 | * This function maps descriptor rings to the queue-specific vectors |
| 2174 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 2175 | * one vector per ring/queue, but on a constrained vector budget, we |
| 2176 | * group the rings as "efficiently" as possible. You would add new |
| 2177 | * mapping configurations in here. |
| 2178 | **/ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2179 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2180 | { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2181 | int q_vectors; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2182 | int v_start = 0; |
| 2183 | int rxr_idx = 0, txr_idx = 0; |
| 2184 | int rxr_remaining = adapter->num_rx_queues; |
| 2185 | int txr_remaining = adapter->num_tx_queues; |
| 2186 | int i, j; |
| 2187 | int rqpv, tqpv; |
| 2188 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2189 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2190 | /* No mapping required if MSI-X is disabled. */ |
| 2191 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2192 | goto out; |
| 2193 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2194 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2195 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2196 | /* |
| 2197 | * The ideal configuration... |
| 2198 | * We have enough vectors to map one per queue. |
| 2199 | */ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2200 | if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2201 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 2202 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 2203 | |
| 2204 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 2205 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 2206 | |
| 2207 | goto out; |
| 2208 | } |
| 2209 | |
| 2210 | /* |
| 2211 | * If we don't have enough vectors for a 1-to-1 |
| 2212 | * mapping, we'll have to group them so there are |
| 2213 | * multiple queues per vector. |
| 2214 | */ |
| 2215 | /* Re-adjusting *qpv takes care of the remainder. */ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2216 | for (i = v_start; i < q_vectors; i++) { |
| 2217 | rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2218 | for (j = 0; j < rqpv; j++) { |
| 2219 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 2220 | rxr_idx++; |
| 2221 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2222 | } |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2223 | tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2224 | for (j = 0; j < tqpv; j++) { |
| 2225 | map_vector_to_txq(adapter, i, txr_idx); |
| 2226 | txr_idx++; |
| 2227 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2228 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2229 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2230 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2231 | return err; |
| 2232 | } |
| 2233 | |
| 2234 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2235 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2236 | * @adapter: board private structure |
| 2237 | * |
| 2238 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2239 | * interrupts from the kernel. |
| 2240 | **/ |
| 2241 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2242 | { |
| 2243 | struct net_device *netdev = adapter->netdev; |
| 2244 | irqreturn_t (*handler)(int, void *); |
| 2245 | int i, vector, q_vectors, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2246 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2247 | |
| 2248 | /* Decrement for Other and TCP Timer vectors */ |
| 2249 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2250 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2251 | err = ixgbe_map_rings_to_vectors(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2252 | if (err) |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2253 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2254 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2255 | #define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2256 | ? &ixgbe_msix_clean_many : \ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2257 | (_v)->rx.count ? &ixgbe_msix_clean_rx : \ |
| 2258 | (_v)->tx.count ? &ixgbe_msix_clean_tx : \ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2259 | NULL) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2260 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2261 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 2262 | handler = SET_HANDLER(q_vector); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2263 | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2264 | if (handler == &ixgbe_msix_clean_rx) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2265 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2266 | "%s-%s-%d", netdev->name, "rx", ri++); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2267 | } else if (handler == &ixgbe_msix_clean_tx) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2268 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2269 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2270 | } else if (handler == &ixgbe_msix_clean_many) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2271 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2272 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2273 | ti++; |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2274 | } else { |
| 2275 | /* skip this unused q_vector */ |
| 2276 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2277 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2278 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2279 | handler, 0, q_vector->name, |
| 2280 | q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2281 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2282 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2283 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2284 | goto free_queue_irqs; |
| 2285 | } |
| 2286 | } |
| 2287 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2288 | sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2289 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2290 | ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2291 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2292 | e_err(probe, "request_irq for msix_lsc failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2293 | goto free_queue_irqs; |
| 2294 | } |
| 2295 | |
| 2296 | return 0; |
| 2297 | |
| 2298 | free_queue_irqs: |
| 2299 | for (i = vector - 1; i >= 0; i--) |
| 2300 | free_irq(adapter->msix_entries[--vector].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2301 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2302 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2303 | pci_disable_msix(adapter->pdev); |
| 2304 | kfree(adapter->msix_entries); |
| 2305 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2306 | return err; |
| 2307 | } |
| 2308 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2309 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2310 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2311 | * @adapter: board private structure |
| 2312 | **/ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2313 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2314 | bool flush) |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2315 | { |
| 2316 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2317 | |
| 2318 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2319 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
| 2320 | mask |= IXGBE_EIMS_GPI_SDP0; |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 2321 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2322 | mask |= IXGBE_EIMS_GPI_SDP1; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2323 | switch (adapter->hw.mac.type) { |
| 2324 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2325 | case ixgbe_mac_X540: |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2326 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2327 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2328 | mask |= IXGBE_EIMS_GPI_SDP2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2329 | if (adapter->num_vfs) |
| 2330 | mask |= IXGBE_EIMS_MAILBOX; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2331 | break; |
| 2332 | default: |
| 2333 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2334 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 2335 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2336 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2337 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2338 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2339 | if (queues) |
| 2340 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2341 | if (flush) |
| 2342 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2343 | |
| 2344 | if (adapter->num_vfs > 32) { |
| 2345 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 2346 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2347 | } |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2348 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2349 | |
| 2350 | /** |
| 2351 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2352 | * @irq: interrupt number |
| 2353 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2354 | **/ |
| 2355 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2356 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2357 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2358 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2359 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2360 | u32 eicr; |
| 2361 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2362 | /* |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2363 | * Workaround for silicon errata on 82598. Mask the interrupts |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2364 | * before the read of EICR. |
| 2365 | */ |
| 2366 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2367 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2368 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 2369 | * therefore no explict interrupt disable is necessary */ |
| 2370 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2371 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2372 | /* |
| 2373 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2374 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2375 | * have disabled interrupts due to EIAM |
| 2376 | * finish the workaround of silicon errata on 82598. Unmask |
| 2377 | * the interrupt that we masked before the EICR read. |
| 2378 | */ |
| 2379 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2380 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2381 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2382 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2383 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2384 | if (eicr & IXGBE_EICR_LSC) |
| 2385 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2386 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2387 | switch (hw->mac.type) { |
| 2388 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2389 | ixgbe_check_sfp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2390 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2391 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2392 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2393 | adapter->interrupt_event = eicr; |
| 2394 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2395 | ixgbe_service_event_schedule(adapter); |
| 2396 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2397 | } |
| 2398 | break; |
| 2399 | default: |
| 2400 | break; |
| 2401 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2402 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2403 | ixgbe_check_fan_failure(adapter, eicr); |
| 2404 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2405 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2406 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2407 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2410 | /* |
| 2411 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2412 | * ixgbe_poll will re-enable the queue interrupts |
| 2413 | */ |
| 2414 | |
| 2415 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2416 | ixgbe_irq_enable(adapter, false, false); |
| 2417 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2418 | return IRQ_HANDLED; |
| 2419 | } |
| 2420 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2421 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 2422 | { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2423 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2424 | int i; |
| 2425 | |
| 2426 | /* legacy and MSI only use one vector */ |
| 2427 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2428 | q_vectors = 1; |
| 2429 | |
| 2430 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2431 | adapter->rx_ring[i]->q_vector = NULL; |
| 2432 | adapter->rx_ring[i]->next = NULL; |
| 2433 | } |
| 2434 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2435 | adapter->tx_ring[i]->q_vector = NULL; |
| 2436 | adapter->tx_ring[i]->next = NULL; |
| 2437 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2438 | |
| 2439 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2440 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2441 | memset(&q_vector->rx, 0, sizeof(struct ixgbe_ring_container)); |
| 2442 | memset(&q_vector->tx, 0, sizeof(struct ixgbe_ring_container)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2443 | } |
| 2444 | } |
| 2445 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2446 | /** |
| 2447 | * ixgbe_request_irq - initialize interrupts |
| 2448 | * @adapter: board private structure |
| 2449 | * |
| 2450 | * Attempts to configure interrupts using the best available |
| 2451 | * capabilities of the hardware and kernel. |
| 2452 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2453 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2454 | { |
| 2455 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2456 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2457 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2458 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2459 | err = ixgbe_request_msix_irqs(adapter); |
| 2460 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2461 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2462 | netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2463 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2464 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2465 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2468 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2469 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2470 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2471 | return err; |
| 2472 | } |
| 2473 | |
| 2474 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2475 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2476 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2477 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2478 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2479 | q_vectors = adapter->num_msix_vectors; |
| 2480 | |
| 2481 | i = q_vectors - 1; |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2482 | free_irq(adapter->msix_entries[i].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2483 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2484 | i--; |
| 2485 | for (; i >= 0; i--) { |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2486 | /* free only the irqs that were actually requested */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2487 | if (!adapter->q_vector[i]->rx.count && |
| 2488 | !adapter->q_vector[i]->tx.count) |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2489 | continue; |
| 2490 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2491 | free_irq(adapter->msix_entries[i].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2492 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | ixgbe_reset_q_vectors(adapter); |
| 2496 | } else { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2497 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2502 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2503 | * @adapter: board private structure |
| 2504 | **/ |
| 2505 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2506 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2507 | switch (adapter->hw.mac.type) { |
| 2508 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2509 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2510 | break; |
| 2511 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2512 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2513 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2514 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2515 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2516 | if (adapter->num_vfs > 32) |
| 2517 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2518 | break; |
| 2519 | default: |
| 2520 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2521 | } |
| 2522 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2523 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2524 | int i; |
| 2525 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 2526 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2527 | } else { |
| 2528 | synchronize_irq(adapter->pdev->irq); |
| 2529 | } |
| 2530 | } |
| 2531 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2532 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2533 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2534 | * |
| 2535 | **/ |
| 2536 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2537 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2538 | struct ixgbe_hw *hw = &adapter->hw; |
| 2539 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2540 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2541 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2542 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2543 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2544 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2545 | |
| 2546 | map_vector_to_rxq(adapter, 0, 0); |
| 2547 | map_vector_to_txq(adapter, 0, 0); |
| 2548 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2549 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2552 | /** |
| 2553 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2554 | * @adapter: board private structure |
| 2555 | * @ring: structure containing ring specific data |
| 2556 | * |
| 2557 | * Configure the Tx descriptor ring after a reset. |
| 2558 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2559 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2560 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2561 | { |
| 2562 | struct ixgbe_hw *hw = &adapter->hw; |
| 2563 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2564 | int wait_loop = 10; |
| 2565 | u32 txdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2566 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2567 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2568 | /* disable queue to avoid issues while updating state */ |
| 2569 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2570 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), |
| 2571 | txdctl & ~IXGBE_TXDCTL_ENABLE); |
| 2572 | IXGBE_WRITE_FLUSH(hw); |
| 2573 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2574 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2575 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2576 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2577 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2578 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2579 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2580 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2581 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2582 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2583 | /* configure fetching thresholds */ |
| 2584 | if (adapter->rx_itr_setting == 0) { |
| 2585 | /* cannot set wthresh when itr==0 */ |
| 2586 | txdctl &= ~0x007F0000; |
| 2587 | } else { |
| 2588 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2589 | txdctl |= (8 << 16); |
| 2590 | } |
| 2591 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2592 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2593 | txdctl |= 32; |
| 2594 | } |
| 2595 | |
| 2596 | /* reinitialize flowdirector state */ |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2597 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2598 | adapter->atr_sample_rate) { |
| 2599 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2600 | ring->atr_count = 0; |
| 2601 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2602 | } else { |
| 2603 | ring->atr_sample_rate = 0; |
| 2604 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2605 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2606 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2607 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2608 | /* enable queue */ |
| 2609 | txdctl |= IXGBE_TXDCTL_ENABLE; |
| 2610 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2611 | |
| 2612 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2613 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2614 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2615 | return; |
| 2616 | |
| 2617 | /* poll to verify queue is enabled */ |
| 2618 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2619 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2620 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2621 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2622 | if (!wait_loop) |
| 2623 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2626 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2627 | { |
| 2628 | struct ixgbe_hw *hw = &adapter->hw; |
| 2629 | u32 rttdcs; |
John Fastabend | 72a32f1 | 2011-04-26 07:25:58 +0000 | [diff] [blame] | 2630 | u32 reg; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2631 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2632 | |
| 2633 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2634 | return; |
| 2635 | |
| 2636 | /* disable the arbiter while setting MTQC */ |
| 2637 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2638 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2639 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2640 | |
| 2641 | /* set transmit pool layout */ |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2642 | switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2643 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2644 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2645 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2646 | break; |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2647 | default: |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2648 | if (!tcs) |
| 2649 | reg = IXGBE_MTQC_64Q_1PB; |
| 2650 | else if (tcs <= 4) |
| 2651 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2652 | else |
| 2653 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2654 | |
| 2655 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg); |
| 2656 | |
| 2657 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 2658 | if (tcs) { |
| 2659 | reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 2660 | reg |= IXGBE_SECTX_DCB; |
| 2661 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg); |
| 2662 | } |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2663 | break; |
| 2664 | } |
| 2665 | |
| 2666 | /* re-enable the arbiter */ |
| 2667 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2668 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2669 | } |
| 2670 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2671 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2672 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2673 | * @adapter: board private structure |
| 2674 | * |
| 2675 | * Configure the Tx unit of the MAC after a reset. |
| 2676 | **/ |
| 2677 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2678 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2679 | struct ixgbe_hw *hw = &adapter->hw; |
| 2680 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2681 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2682 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2683 | ixgbe_setup_mtqc(adapter); |
| 2684 | |
| 2685 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2686 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2687 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2688 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2689 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2690 | } |
| 2691 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2692 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2693 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2694 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2697 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2698 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2699 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2700 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2701 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2702 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2703 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2704 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2705 | switch (adapter->hw.mac.type) { |
| 2706 | case ixgbe_mac_82598EB: { |
| 2707 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
| 2708 | const int mask = feature[RING_F_RSS].mask; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2709 | reg_idx = reg_idx & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2710 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2711 | break; |
| 2712 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2713 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2714 | default: |
| 2715 | break; |
| 2716 | } |
| 2717 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2718 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2719 | |
| 2720 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2721 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2722 | if (adapter->num_vfs) |
| 2723 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2724 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2725 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2726 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2727 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2728 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2729 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2730 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2731 | #else |
| 2732 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2733 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2734 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2735 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2736 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2737 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2738 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2739 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2740 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2741 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2744 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2745 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2746 | struct ixgbe_hw *hw = &adapter->hw; |
| 2747 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2748 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2749 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2750 | u32 mrqc = 0, reta = 0; |
| 2751 | u32 rxcsum; |
| 2752 | int i, j; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2753 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2754 | int maxq = adapter->ring_feature[RING_F_RSS].indices; |
| 2755 | |
| 2756 | if (tcs) |
| 2757 | maxq = min(maxq, adapter->num_tx_queues / tcs); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2758 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2759 | /* Fill out hash function seeds */ |
| 2760 | for (i = 0; i < 10; i++) |
| 2761 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2762 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2763 | /* Fill out redirection table */ |
| 2764 | for (i = 0, j = 0; i < 128; i++, j++) { |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2765 | if (j == maxq) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2766 | j = 0; |
| 2767 | /* reta = 4-byte sliding window of |
| 2768 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2769 | reta = (reta << 8) | (j * 0x11); |
| 2770 | if ((i & 3) == 3) |
| 2771 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 2772 | } |
| 2773 | |
| 2774 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 2775 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2776 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2777 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 2778 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2779 | if (adapter->hw.mac.type == ixgbe_mac_82598EB && |
| 2780 | (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2781 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2782 | } else { |
| 2783 | int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2784 | | IXGBE_FLAG_SRIOV_ENABLED); |
| 2785 | |
| 2786 | switch (mask) { |
| 2787 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2788 | if (!tcs) |
| 2789 | mrqc = IXGBE_MRQC_RSSEN; |
| 2790 | else if (tcs <= 4) |
| 2791 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 2792 | else |
| 2793 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 2794 | break; |
| 2795 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2796 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2797 | break; |
| 2798 | default: |
| 2799 | break; |
| 2800 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2803 | /* Perform hash on these packet types */ |
| 2804 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2805 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2806 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2807 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2808 | |
| 2809 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2810 | } |
| 2811 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2812 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2813 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2814 | * @adapter: address of board private structure |
| 2815 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2816 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 2817 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2818 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2819 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2820 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2821 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2822 | int rx_buf_len; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2823 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2824 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2825 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2826 | return; |
| 2827 | |
| 2828 | rx_buf_len = ring->rx_buf_len; |
| 2829 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2830 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2831 | /* |
| 2832 | * we must limit the number of descriptors so that the |
| 2833 | * total size of max desc * buf_len is not greater |
| 2834 | * than 65535 |
| 2835 | */ |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2836 | if (ring_is_ps_enabled(ring)) { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2837 | #if (MAX_SKB_FRAGS > 16) |
| 2838 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2839 | #elif (MAX_SKB_FRAGS > 8) |
| 2840 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2841 | #elif (MAX_SKB_FRAGS > 4) |
| 2842 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2843 | #else |
| 2844 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2845 | #endif |
| 2846 | } else { |
| 2847 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2848 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2849 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2850 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2851 | else |
| 2852 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2853 | } |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2854 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2855 | } |
| 2856 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2857 | /** |
| 2858 | * ixgbe_set_uta - Set unicast filter table address |
| 2859 | * @adapter: board private structure |
| 2860 | * |
| 2861 | * The unicast table address is a register array of 32-bit registers. |
| 2862 | * The table is meant to be used in a way similar to how the MTA is used |
| 2863 | * however due to certain limitations in the hardware it is necessary to |
| 2864 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 2865 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
| 2866 | **/ |
| 2867 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) |
| 2868 | { |
| 2869 | struct ixgbe_hw *hw = &adapter->hw; |
| 2870 | int i; |
| 2871 | |
| 2872 | /* The UTA table only exists on 82599 hardware and newer */ |
| 2873 | if (hw->mac.type < ixgbe_mac_82599EB) |
| 2874 | return; |
| 2875 | |
| 2876 | /* we only need to do this if VMDq is enabled */ |
| 2877 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2878 | return; |
| 2879 | |
| 2880 | for (i = 0; i < 128; i++) |
| 2881 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); |
| 2882 | } |
| 2883 | |
| 2884 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2885 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2886 | struct ixgbe_ring *ring) |
| 2887 | { |
| 2888 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2889 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2890 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2891 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2892 | |
| 2893 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2894 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2895 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2896 | return; |
| 2897 | |
| 2898 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2899 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2900 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2901 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2902 | |
| 2903 | if (!wait_loop) { |
| 2904 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 2905 | "the polling period\n", reg_idx); |
| 2906 | } |
| 2907 | } |
| 2908 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2909 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 2910 | struct ixgbe_ring *ring) |
| 2911 | { |
| 2912 | struct ixgbe_hw *hw = &adapter->hw; |
| 2913 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2914 | u32 rxdctl; |
| 2915 | u8 reg_idx = ring->reg_idx; |
| 2916 | |
| 2917 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2918 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 2919 | |
| 2920 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 2921 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2922 | |
| 2923 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2924 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2925 | return; |
| 2926 | |
| 2927 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 2928 | do { |
| 2929 | udelay(10); |
| 2930 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2931 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2932 | |
| 2933 | if (!wait_loop) { |
| 2934 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 2935 | "the polling period\n", reg_idx); |
| 2936 | } |
| 2937 | } |
| 2938 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2939 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 2940 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2941 | { |
| 2942 | struct ixgbe_hw *hw = &adapter->hw; |
| 2943 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2944 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2945 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2946 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2947 | /* disable queue to avoid issues while updating state */ |
| 2948 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2949 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2950 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2951 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 2952 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 2953 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 2954 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 2955 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 2956 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2957 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2958 | |
| 2959 | ixgbe_configure_srrctl(adapter, ring); |
| 2960 | ixgbe_configure_rscctl(adapter, ring); |
| 2961 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 2962 | /* If operating in IOV mode set RLPML for X540 */ |
| 2963 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 2964 | hw->mac.type == ixgbe_mac_X540) { |
| 2965 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 2966 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 2967 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 2968 | } |
| 2969 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2970 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2971 | /* |
| 2972 | * enable cache line friendly hardware writes: |
| 2973 | * PTHRESH=32 descriptors (half the internal cache), |
| 2974 | * this also removes ugly rx_no_buffer_count increment |
| 2975 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 2976 | * WTHRESH=8 burst writeback up to two cache lines |
| 2977 | */ |
| 2978 | rxdctl &= ~0x3FFFFF; |
| 2979 | rxdctl |= 0x080420; |
| 2980 | } |
| 2981 | |
| 2982 | /* enable receive descriptor ring */ |
| 2983 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 2984 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2985 | |
| 2986 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 2987 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2990 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 2991 | { |
| 2992 | struct ixgbe_hw *hw = &adapter->hw; |
| 2993 | int p; |
| 2994 | |
| 2995 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 2996 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2997 | IXGBE_PSRTYPE_UDPHDR | |
| 2998 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 2999 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3000 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3001 | |
| 3002 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3003 | return; |
| 3004 | |
| 3005 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) |
| 3006 | psrtype |= (adapter->num_rx_queues_per_pool << 29); |
| 3007 | |
| 3008 | for (p = 0; p < adapter->num_rx_pools; p++) |
| 3009 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), |
| 3010 | psrtype); |
| 3011 | } |
| 3012 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3013 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3014 | { |
| 3015 | struct ixgbe_hw *hw = &adapter->hw; |
| 3016 | u32 gcr_ext; |
| 3017 | u32 vt_reg_bits; |
| 3018 | u32 reg_offset, vf_shift; |
| 3019 | u32 vmdctl; |
| 3020 | |
| 3021 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3022 | return; |
| 3023 | |
| 3024 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 3025 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; |
| 3026 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); |
| 3027 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 3028 | |
| 3029 | vf_shift = adapter->num_vfs % 32; |
| 3030 | reg_offset = (adapter->num_vfs > 32) ? 1 : 0; |
| 3031 | |
| 3032 | /* Enable only the PF's pool for Tx/Rx */ |
| 3033 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 3034 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); |
| 3035 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 3036 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); |
| 3037 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 3038 | |
| 3039 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
| 3040 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 3041 | |
| 3042 | /* |
| 3043 | * Set up VF register offsets for selected VT Mode, |
| 3044 | * i.e. 32 or 64 VFs for SR-IOV |
| 3045 | */ |
| 3046 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3047 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; |
| 3048 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; |
| 3049 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3050 | |
| 3051 | /* enable Tx loopback for VF/PF communication */ |
| 3052 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3053 | /* Enable MAC Anti-Spoofing */ |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3054 | hw->mac.ops.set_mac_anti_spoofing(hw, |
| 3055 | (adapter->antispoofing_enabled = |
| 3056 | (adapter->num_vfs != 0)), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3057 | adapter->num_vfs); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3060 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3061 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3062 | struct ixgbe_hw *hw = &adapter->hw; |
| 3063 | struct net_device *netdev = adapter->netdev; |
| 3064 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3065 | int rx_buf_len; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3066 | struct ixgbe_ring *rx_ring; |
| 3067 | int i; |
| 3068 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3069 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3070 | /* Decide whether to use packet split mode or not */ |
Don Skidmore | a124339 | 2011-01-18 22:53:47 +0000 | [diff] [blame] | 3071 | /* On by default */ |
| 3072 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
| 3073 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3074 | /* Do not use packet split if we're in SR-IOV Mode */ |
Don Skidmore | a124339 | 2011-01-18 22:53:47 +0000 | [diff] [blame] | 3075 | if (adapter->num_vfs) |
| 3076 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
| 3077 | |
| 3078 | /* Disable packet split due to 82599 erratum #45 */ |
| 3079 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3080 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3081 | |
| 3082 | /* Set the RX buffer length according to the mode */ |
| 3083 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3084 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3085 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3086 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3087 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3088 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3089 | else |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3090 | rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024); |
| 3091 | } |
| 3092 | |
| 3093 | #ifdef IXGBE_FCOE |
| 3094 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3095 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3096 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3097 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3098 | |
| 3099 | #endif /* IXGBE_FCOE */ |
| 3100 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3101 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3102 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3103 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3104 | |
| 3105 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3108 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3109 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3110 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3111 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3112 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3113 | /* |
| 3114 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3115 | * the Base and Length of the Rx Descriptor Ring |
| 3116 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3117 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3118 | rx_ring = adapter->rx_ring[i]; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3119 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3120 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3121 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3122 | set_ring_ps_enabled(rx_ring); |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 3123 | else |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3124 | clear_ring_ps_enabled(rx_ring); |
| 3125 | |
| 3126 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3127 | set_ring_rsc_enabled(rx_ring); |
| 3128 | else |
| 3129 | clear_ring_rsc_enabled(rx_ring); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3130 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3131 | #ifdef IXGBE_FCOE |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3132 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3133 | struct ixgbe_ring_feature *f; |
| 3134 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3135 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3136 | clear_ring_ps_enabled(rx_ring); |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3137 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 3138 | rx_ring->rx_buf_len = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3139 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3140 | } else if (!ring_is_rsc_enabled(rx_ring) && |
| 3141 | !ring_is_ps_enabled(rx_ring)) { |
| 3142 | rx_ring->rx_buf_len = |
| 3143 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3144 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3145 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3146 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3147 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3148 | } |
| 3149 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3150 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3151 | { |
| 3152 | struct ixgbe_hw *hw = &adapter->hw; |
| 3153 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3154 | |
| 3155 | switch (hw->mac.type) { |
| 3156 | case ixgbe_mac_82598EB: |
| 3157 | /* |
| 3158 | * For VMDq support of different descriptor types or |
| 3159 | * buffer sizes through the use of multiple SRRCTL |
| 3160 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3161 | * |
| 3162 | * also, the manual doesn't mention it clearly but DCA hints |
| 3163 | * will only use queue 0's tags unless this bit is set. Side |
| 3164 | * effects of setting this bit are only that SRRCTL must be |
| 3165 | * fully programmed [0..15] |
| 3166 | */ |
| 3167 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3168 | break; |
| 3169 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3170 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3171 | /* Disable RSC for ACK packets */ |
| 3172 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3173 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3174 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3175 | /* hardware requires some bits to be set by default */ |
| 3176 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3177 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3178 | break; |
| 3179 | default: |
| 3180 | /* We should do nothing since we don't know this hardware */ |
| 3181 | return; |
| 3182 | } |
| 3183 | |
| 3184 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3185 | } |
| 3186 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3187 | /** |
| 3188 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3189 | * @adapter: board private structure |
| 3190 | * |
| 3191 | * Configure the Rx unit of the MAC after a reset. |
| 3192 | **/ |
| 3193 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3194 | { |
| 3195 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3196 | int i; |
| 3197 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3198 | |
| 3199 | /* disable receives while setting up the descriptors */ |
| 3200 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3201 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3202 | |
| 3203 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3204 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3205 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3206 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3207 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3208 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3209 | ixgbe_set_uta(adapter); |
| 3210 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3211 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3212 | ixgbe_set_rx_buffer_len(adapter); |
| 3213 | |
| 3214 | /* |
| 3215 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3216 | * the Base and Length of the Rx Descriptor Ring |
| 3217 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3218 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3219 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3220 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3221 | /* disable drop enable for 82598 parts */ |
| 3222 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3223 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3224 | |
| 3225 | /* enable all receives */ |
| 3226 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3227 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3230 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 3231 | { |
| 3232 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3233 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3234 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3235 | |
| 3236 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3237 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3238 | set_bit(vid, adapter->active_vlans); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 3242 | { |
| 3243 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3244 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3245 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3246 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3247 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3248 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3249 | clear_bit(vid, adapter->active_vlans); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3252 | /** |
| 3253 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3254 | * @adapter: driver data |
| 3255 | */ |
| 3256 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3257 | { |
| 3258 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3259 | u32 vlnctrl; |
| 3260 | |
| 3261 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3262 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3263 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3264 | } |
| 3265 | |
| 3266 | /** |
| 3267 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3268 | * @adapter: driver data |
| 3269 | */ |
| 3270 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3271 | { |
| 3272 | struct ixgbe_hw *hw = &adapter->hw; |
| 3273 | u32 vlnctrl; |
| 3274 | |
| 3275 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3276 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3277 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3278 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3279 | } |
| 3280 | |
| 3281 | /** |
| 3282 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3283 | * @adapter: driver data |
| 3284 | */ |
| 3285 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3286 | { |
| 3287 | struct ixgbe_hw *hw = &adapter->hw; |
| 3288 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3289 | int i, j; |
| 3290 | |
| 3291 | switch (hw->mac.type) { |
| 3292 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3293 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3294 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3295 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3296 | break; |
| 3297 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3298 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3299 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3300 | j = adapter->rx_ring[i]->reg_idx; |
| 3301 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3302 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3303 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3304 | } |
| 3305 | break; |
| 3306 | default: |
| 3307 | break; |
| 3308 | } |
| 3309 | } |
| 3310 | |
| 3311 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3312 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3313 | * @adapter: driver data |
| 3314 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3315 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3316 | { |
| 3317 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3318 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3319 | int i, j; |
| 3320 | |
| 3321 | switch (hw->mac.type) { |
| 3322 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3323 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3324 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3325 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3326 | break; |
| 3327 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3328 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3329 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3330 | j = adapter->rx_ring[i]->reg_idx; |
| 3331 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3332 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3333 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3334 | } |
| 3335 | break; |
| 3336 | default: |
| 3337 | break; |
| 3338 | } |
| 3339 | } |
| 3340 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3341 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3342 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3343 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3344 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3345 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3346 | |
| 3347 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3348 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3352 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3353 | * @netdev: network interface device structure |
| 3354 | * |
| 3355 | * Writes unicast address list to the RAR table. |
| 3356 | * Returns: -ENOMEM on failure/insufficient address space |
| 3357 | * 0 on no addresses written |
| 3358 | * X on writing X addresses to the RAR table |
| 3359 | **/ |
| 3360 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3361 | { |
| 3362 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3363 | struct ixgbe_hw *hw = &adapter->hw; |
| 3364 | unsigned int vfn = adapter->num_vfs; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3365 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3366 | int count = 0; |
| 3367 | |
| 3368 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3369 | if (netdev_uc_count(netdev) > rar_entries) |
| 3370 | return -ENOMEM; |
| 3371 | |
| 3372 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3373 | struct netdev_hw_addr *ha; |
| 3374 | /* return error if we do not support writing to RAR table */ |
| 3375 | if (!hw->mac.ops.set_rar) |
| 3376 | return -ENOMEM; |
| 3377 | |
| 3378 | netdev_for_each_uc_addr(ha, netdev) { |
| 3379 | if (!rar_entries) |
| 3380 | break; |
| 3381 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
| 3382 | vfn, IXGBE_RAH_AV); |
| 3383 | count++; |
| 3384 | } |
| 3385 | } |
| 3386 | /* write the addresses in reverse order to avoid write combining */ |
| 3387 | for (; rar_entries > 0 ; rar_entries--) |
| 3388 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3389 | |
| 3390 | return count; |
| 3391 | } |
| 3392 | |
| 3393 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3394 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3395 | * @netdev: network interface device structure |
| 3396 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3397 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3398 | * address list or the network interface flags are updated. This routine is |
| 3399 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3400 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3401 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3402 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3403 | { |
| 3404 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3405 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3406 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3407 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3408 | |
| 3409 | /* Check for Promiscuous and All Multicast modes */ |
| 3410 | |
| 3411 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3412 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3413 | /* set all bits that we expect to always be set */ |
| 3414 | fctrl |= IXGBE_FCTRL_BAM; |
| 3415 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3416 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3417 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3418 | /* clear the bits we are changing the status of */ |
| 3419 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3420 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3421 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3422 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3423 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3424 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3425 | /* don't hardware filter vlans in promisc mode */ |
| 3426 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3427 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3428 | if (netdev->flags & IFF_ALLMULTI) { |
| 3429 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3430 | vmolr |= IXGBE_VMOLR_MPE; |
| 3431 | } else { |
| 3432 | /* |
| 3433 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3434 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3435 | * that we can at least receive multicast traffic |
| 3436 | */ |
| 3437 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3438 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3439 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3440 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3441 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3442 | /* |
| 3443 | * Write addresses to available RAR registers, if there is not |
| 3444 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3445 | * unicast promiscuous mode |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3446 | */ |
| 3447 | count = ixgbe_write_uc_addr_list(netdev); |
| 3448 | if (count < 0) { |
| 3449 | fctrl |= IXGBE_FCTRL_UPE; |
| 3450 | vmolr |= IXGBE_VMOLR_ROPE; |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | if (adapter->num_vfs) { |
| 3455 | ixgbe_restore_vf_multicasts(adapter); |
| 3456 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & |
| 3457 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3458 | IXGBE_VMOLR_ROPE); |
| 3459 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3463 | |
| 3464 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3465 | ixgbe_vlan_strip_enable(adapter); |
| 3466 | else |
| 3467 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3468 | } |
| 3469 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3470 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3471 | { |
| 3472 | int q_idx; |
| 3473 | struct ixgbe_q_vector *q_vector; |
| 3474 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3475 | |
| 3476 | /* legacy and MSI only use one vector */ |
| 3477 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3478 | q_vectors = 1; |
| 3479 | |
| 3480 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3481 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3482 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3483 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3484 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 3485 | if (!q_vector->rx.count || !q_vector->tx.count) { |
| 3486 | if (q_vector->tx.count == 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3487 | napi->poll = &ixgbe_clean_txonly; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 3488 | else if (q_vector->rx.count == 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3489 | napi->poll = &ixgbe_clean_rxonly; |
| 3490 | } |
| 3491 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3492 | |
| 3493 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3498 | { |
| 3499 | int q_idx; |
| 3500 | struct ixgbe_q_vector *q_vector; |
| 3501 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3502 | |
| 3503 | /* legacy and MSI only use one vector */ |
| 3504 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3505 | q_vectors = 1; |
| 3506 | |
| 3507 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3508 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3509 | napi_disable(&q_vector->napi); |
| 3510 | } |
| 3511 | } |
| 3512 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3513 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3514 | /* |
| 3515 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3516 | * @adapter: ixgbe adapter struct |
| 3517 | * |
| 3518 | * This is called by the driver on open to configure the DCB hardware. |
| 3519 | * This is also called by the gennetlink interface when reconfiguring |
| 3520 | * the DCB state. |
| 3521 | */ |
| 3522 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3523 | { |
| 3524 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3525 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3526 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3527 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3528 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3529 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3530 | return; |
| 3531 | } |
| 3532 | |
| 3533 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3534 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3535 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3536 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3537 | /* Enable VLAN tag insert/strip */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3538 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3539 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3540 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3541 | |
| 3542 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3543 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
Alexander Duyck | 971060b | 2011-07-15 02:31:30 +0000 | [diff] [blame] | 3544 | #ifdef IXGBE_FCOE |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3545 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3546 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3547 | #endif |
| 3548 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3549 | DCB_TX_CONFIG); |
| 3550 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3551 | DCB_RX_CONFIG); |
| 3552 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
| 3553 | } else { |
| 3554 | struct net_device *dev = adapter->netdev; |
| 3555 | |
| 3556 | if (adapter->ixgbe_ieee_ets) |
| 3557 | dev->dcbnl_ops->ieee_setets(dev, |
| 3558 | adapter->ixgbe_ieee_ets); |
| 3559 | if (adapter->ixgbe_ieee_pfc) |
| 3560 | dev->dcbnl_ops->ieee_setpfc(dev, |
| 3561 | adapter->ixgbe_ieee_pfc); |
| 3562 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3563 | |
| 3564 | /* Enable RSS Hash per TC */ |
| 3565 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3566 | int i; |
| 3567 | u32 reg = 0; |
| 3568 | |
| 3569 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 3570 | u8 msb = 0; |
| 3571 | u8 cnt = adapter->netdev->tc_to_txq[i].count; |
| 3572 | |
| 3573 | while (cnt >>= 1) |
| 3574 | msb++; |
| 3575 | |
| 3576 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); |
| 3577 | } |
| 3578 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); |
| 3579 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | #endif |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3583 | |
| 3584 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3585 | { |
| 3586 | int hdrm = 0; |
| 3587 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3588 | struct ixgbe_hw *hw = &adapter->hw; |
| 3589 | |
| 3590 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3591 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3592 | hdrm = 64 << adapter->fdir_pballoc; |
| 3593 | |
| 3594 | hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL); |
| 3595 | } |
| 3596 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3597 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 3598 | { |
| 3599 | struct ixgbe_hw *hw = &adapter->hw; |
| 3600 | struct hlist_node *node, *node2; |
| 3601 | struct ixgbe_fdir_filter *filter; |
| 3602 | |
| 3603 | spin_lock(&adapter->fdir_perfect_lock); |
| 3604 | |
| 3605 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 3606 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 3607 | |
| 3608 | hlist_for_each_entry_safe(filter, node, node2, |
| 3609 | &adapter->fdir_filter_list, fdir_node) { |
| 3610 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 3611 | &filter->filter, |
| 3612 | filter->sw_idx, |
| 3613 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 3614 | IXGBE_FDIR_DROP_QUEUE : |
| 3615 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | spin_unlock(&adapter->fdir_perfect_lock); |
| 3619 | } |
| 3620 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3621 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3622 | { |
| 3623 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3624 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3625 | int i; |
| 3626 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3627 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3628 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3629 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3630 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3631 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3632 | ixgbe_set_rx_mode(netdev); |
| 3633 | ixgbe_restore_vlan(adapter); |
| 3634 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3635 | #ifdef IXGBE_FCOE |
| 3636 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 3637 | ixgbe_configure_fcoe(adapter); |
| 3638 | |
| 3639 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3640 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 3641 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3642 | adapter->tx_ring[i]->atr_sample_rate = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3643 | adapter->atr_sample_rate; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3644 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3645 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3646 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 3647 | adapter->fdir_pballoc); |
| 3648 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3649 | } |
Alexander Duyck | 933d41f | 2010-09-07 21:34:29 +0000 | [diff] [blame] | 3650 | ixgbe_configure_virtualization(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3651 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3652 | ixgbe_configure_tx(adapter); |
| 3653 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3654 | } |
| 3655 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3656 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3657 | { |
| 3658 | switch (hw->phy.type) { |
| 3659 | case ixgbe_phy_sfp_avago: |
| 3660 | case ixgbe_phy_sfp_ftl: |
| 3661 | case ixgbe_phy_sfp_intel: |
| 3662 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3663 | case ixgbe_phy_sfp_passive_tyco: |
| 3664 | case ixgbe_phy_sfp_passive_unknown: |
| 3665 | case ixgbe_phy_sfp_active_unknown: |
| 3666 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3667 | return true; |
| 3668 | default: |
| 3669 | return false; |
| 3670 | } |
| 3671 | } |
| 3672 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3673 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3674 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3675 | * @adapter: pointer to private adapter struct |
| 3676 | **/ |
| 3677 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3678 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3679 | /* |
| 3680 | * We are assuming the worst case scenerio here, and that |
| 3681 | * is that an SFP was inserted/removed after the reset |
| 3682 | * but before SFP detection was enabled. As such the best |
| 3683 | * solution is to just start searching as soon as we start |
| 3684 | */ |
| 3685 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3686 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3687 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3688 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | /** |
| 3692 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3693 | * @hw: pointer to private hardware struct |
| 3694 | * |
| 3695 | * Returns 0 on success, negative on failure |
| 3696 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3697 | 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] | 3698 | { |
| 3699 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3700 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3701 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 3702 | |
| 3703 | if (hw->mac.ops.check_link) |
| 3704 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 3705 | |
| 3706 | if (ret) |
| 3707 | goto link_cfg_out; |
| 3708 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 3709 | autoneg = hw->phy.autoneg_advertised; |
| 3710 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3711 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3712 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3713 | if (ret) |
| 3714 | goto link_cfg_out; |
| 3715 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3716 | if (hw->mac.ops.setup_link) |
| 3717 | 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] | 3718 | link_cfg_out: |
| 3719 | return ret; |
| 3720 | } |
| 3721 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3722 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3723 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3724 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3725 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3726 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3727 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3728 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 3729 | IXGBE_GPIE_OCD; |
| 3730 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3731 | /* |
| 3732 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 3733 | * this saves a register write for every interrupt |
| 3734 | */ |
| 3735 | switch (hw->mac.type) { |
| 3736 | case ixgbe_mac_82598EB: |
| 3737 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 3738 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3739 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3740 | case ixgbe_mac_X540: |
| 3741 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3742 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 3743 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 3744 | break; |
| 3745 | } |
| 3746 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3747 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 3748 | * specifically only auto mask tx and rx interrupts */ |
| 3749 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3750 | } |
| 3751 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3752 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 3753 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 3754 | |
| 3755 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3756 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 3757 | gpie |= IXGBE_GPIE_VTMODE_64; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3760 | /* Enable fan failure interrupt */ |
| 3761 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3762 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3763 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3764 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3765 | gpie |= IXGBE_SDP1_GPIEN; |
| 3766 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3767 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3768 | |
| 3769 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 3770 | } |
| 3771 | |
| 3772 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 3773 | { |
| 3774 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3775 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3776 | u32 ctrl_ext; |
| 3777 | |
| 3778 | ixgbe_get_hw_control(adapter); |
| 3779 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3780 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3781 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3782 | ixgbe_configure_msix(adapter); |
| 3783 | else |
| 3784 | ixgbe_configure_msi_and_legacy(adapter); |
| 3785 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3786 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ |
| 3787 | if (hw->mac.ops.enable_tx_laser && |
| 3788 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 3789 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3790 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 3791 | hw->mac.ops.enable_tx_laser(hw); |
| 3792 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3793 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3794 | ixgbe_napi_enable_all(adapter); |
| 3795 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 3796 | if (ixgbe_is_sfp(hw)) { |
| 3797 | ixgbe_sfp_link_config(adapter); |
| 3798 | } else { |
| 3799 | err = ixgbe_non_sfp_link_config(hw); |
| 3800 | if (err) |
| 3801 | e_err(probe, "link_config FAILED %d\n", err); |
| 3802 | } |
| 3803 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3804 | /* clear any pending interrupts, may auto mask */ |
| 3805 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3806 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3807 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3808 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3809 | * If this adapter has a fan, check to see if we had a failure |
| 3810 | * before we enabled the interrupt. |
| 3811 | */ |
| 3812 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 3813 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 3814 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3815 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3818 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3819 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3820 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3821 | /* bring the link up in the watchdog, this could race with our first |
| 3822 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3823 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3824 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3825 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 3826 | |
| 3827 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 3828 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 3829 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 3830 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
| 3831 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3832 | return 0; |
| 3833 | } |
| 3834 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3835 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 3836 | { |
| 3837 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3838 | /* put off any impending NetWatchDogTimeout */ |
| 3839 | adapter->netdev->trans_start = jiffies; |
| 3840 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3841 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3842 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3843 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 3844 | /* |
| 3845 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 3846 | * back up to give the VFs time to respond to the reset. The |
| 3847 | * two second wait is based upon the watchdog timer cycle in |
| 3848 | * the VF driver. |
| 3849 | */ |
| 3850 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3851 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3852 | ixgbe_up(adapter); |
| 3853 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 3854 | } |
| 3855 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3856 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 3857 | { |
| 3858 | /* hardware has been reset, we need to reload some things */ |
| 3859 | ixgbe_configure(adapter); |
| 3860 | |
| 3861 | return ixgbe_up_complete(adapter); |
| 3862 | } |
| 3863 | |
| 3864 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 3865 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3866 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3867 | int err; |
| 3868 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3869 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 3870 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 3871 | usleep_range(1000, 2000); |
| 3872 | |
| 3873 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 3874 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 3875 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 3876 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 3877 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3878 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3879 | switch (err) { |
| 3880 | case 0: |
| 3881 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3882 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3883 | break; |
| 3884 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3885 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3886 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3887 | case IXGBE_ERR_EEPROM_VERSION: |
| 3888 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3889 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 3890 | "Please be aware there may be issuesassociated with " |
| 3891 | "your hardware. If you are experiencing problems " |
| 3892 | "please contact your Intel or hardware " |
| 3893 | "representative who provided you with this " |
| 3894 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3895 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3896 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3897 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3898 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3899 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3900 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 3901 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3902 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3903 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 3904 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3905 | } |
| 3906 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3907 | /** |
| 3908 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3909 | * @rx_ring: ring to free buffers from |
| 3910 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3911 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3912 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3913 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3914 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3915 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3916 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3917 | /* ring already cleared, nothing to do */ |
| 3918 | if (!rx_ring->rx_buffer_info) |
| 3919 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3920 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3921 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3922 | for (i = 0; i < rx_ring->count; i++) { |
| 3923 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 3924 | |
| 3925 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 3926 | if (rx_buffer_info->dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3927 | dma_unmap_single(rx_ring->dev, rx_buffer_info->dma, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3928 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3929 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3930 | rx_buffer_info->dma = 0; |
| 3931 | } |
| 3932 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3933 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3934 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3935 | do { |
| 3936 | struct sk_buff *this = skb; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 3937 | if (IXGBE_RSC_CB(this)->delay_unmap) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3938 | dma_unmap_single(dev, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3939 | IXGBE_RSC_CB(this)->dma, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3940 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3941 | DMA_FROM_DEVICE); |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 3942 | IXGBE_RSC_CB(this)->dma = 0; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 3943 | IXGBE_RSC_CB(skb)->delay_unmap = false; |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 3944 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3945 | skb = skb->prev; |
| 3946 | dev_kfree_skb(this); |
| 3947 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3948 | } |
| 3949 | if (!rx_buffer_info->page) |
| 3950 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 3951 | if (rx_buffer_info->page_dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3952 | dma_unmap_page(dev, rx_buffer_info->page_dma, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3953 | PAGE_SIZE / 2, DMA_FROM_DEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 3954 | rx_buffer_info->page_dma = 0; |
| 3955 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3956 | put_page(rx_buffer_info->page); |
| 3957 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 3958 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 3962 | memset(rx_ring->rx_buffer_info, 0, size); |
| 3963 | |
| 3964 | /* Zero out the descriptor ring */ |
| 3965 | memset(rx_ring->desc, 0, rx_ring->size); |
| 3966 | |
| 3967 | rx_ring->next_to_clean = 0; |
| 3968 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | /** |
| 3972 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3973 | * @tx_ring: ring to be cleaned |
| 3974 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3975 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3976 | { |
| 3977 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 3978 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3979 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3980 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3981 | /* ring already cleared, nothing to do */ |
| 3982 | if (!tx_ring->tx_buffer_info) |
| 3983 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3984 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3985 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3986 | for (i = 0; i < tx_ring->count; i++) { |
| 3987 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3988 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3992 | memset(tx_ring->tx_buffer_info, 0, size); |
| 3993 | |
| 3994 | /* Zero out the descriptor ring */ |
| 3995 | memset(tx_ring->desc, 0, tx_ring->size); |
| 3996 | |
| 3997 | tx_ring->next_to_use = 0; |
| 3998 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4002 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4003 | * @adapter: board private structure |
| 4004 | **/ |
| 4005 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4006 | { |
| 4007 | int i; |
| 4008 | |
| 4009 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4010 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4011 | } |
| 4012 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4013 | /** |
| 4014 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4015 | * @adapter: board private structure |
| 4016 | **/ |
| 4017 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4018 | { |
| 4019 | int i; |
| 4020 | |
| 4021 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4022 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4023 | } |
| 4024 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4025 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4026 | { |
| 4027 | struct hlist_node *node, *node2; |
| 4028 | struct ixgbe_fdir_filter *filter; |
| 4029 | |
| 4030 | spin_lock(&adapter->fdir_perfect_lock); |
| 4031 | |
| 4032 | hlist_for_each_entry_safe(filter, node, node2, |
| 4033 | &adapter->fdir_filter_list, fdir_node) { |
| 4034 | hlist_del(&filter->fdir_node); |
| 4035 | kfree(filter); |
| 4036 | } |
| 4037 | adapter->fdir_filter_count = 0; |
| 4038 | |
| 4039 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4040 | } |
| 4041 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4042 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4043 | { |
| 4044 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4045 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4046 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4047 | int i; |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4048 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4049 | |
| 4050 | /* signal that we are down to the interrupt handler */ |
| 4051 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4052 | |
| 4053 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4054 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4055 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4056 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4057 | /* disable all enabled rx queues */ |
| 4058 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4059 | /* this call also flushes the previous write */ |
| 4060 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4061 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4062 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4063 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4064 | netif_tx_stop_all_queues(netdev); |
| 4065 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4066 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4067 | netif_carrier_off(netdev); |
| 4068 | netif_tx_disable(netdev); |
| 4069 | |
| 4070 | ixgbe_irq_disable(adapter); |
| 4071 | |
| 4072 | ixgbe_napi_disable_all(adapter); |
| 4073 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4074 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4075 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4076 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4077 | |
| 4078 | del_timer_sync(&adapter->service_timer); |
| 4079 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4080 | /* disable receive for all VFs and wait one second */ |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4081 | if (adapter->num_vfs) { |
| 4082 | /* 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] | 4083 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4084 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4085 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4086 | ixgbe_disable_tx_rx(adapter); |
| 4087 | |
| 4088 | /* Mark all the VFs as inactive */ |
| 4089 | for (i = 0 ; i < adapter->num_vfs; i++) |
| 4090 | adapter->vfinfo[i].clear_to_send = 0; |
| 4091 | } |
| 4092 | |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4093 | /* Cleanup the affinity_hint CPU mask memory and callback */ |
| 4094 | for (i = 0; i < num_q_vectors; i++) { |
| 4095 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 4096 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4097 | irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL); |
| 4098 | /* release the CPU mask memory */ |
| 4099 | free_cpumask_var(q_vector->affinity_mask); |
| 4100 | } |
| 4101 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4102 | /* disable transmits in the hardware now that interrupts are off */ |
| 4103 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4104 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4105 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4106 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4107 | |
| 4108 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4109 | switch (hw->mac.type) { |
| 4110 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4111 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4112 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4113 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4114 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4115 | break; |
| 4116 | default: |
| 4117 | break; |
| 4118 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4119 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4120 | if (!pci_channel_offline(adapter->pdev)) |
| 4121 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4122 | |
| 4123 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 4124 | if (hw->mac.ops.disable_tx_laser && |
| 4125 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 4126 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4127 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 4128 | hw->mac.ops.disable_tx_laser(hw); |
| 4129 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4130 | ixgbe_clean_all_tx_rings(adapter); |
| 4131 | ixgbe_clean_all_rx_rings(adapter); |
| 4132 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4133 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4134 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4135 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4136 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4137 | } |
| 4138 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4139 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4140 | * ixgbe_poll - NAPI Rx polling callback |
| 4141 | * @napi: structure for representing this polling device |
| 4142 | * @budget: how many packets driver is allowed to clean |
| 4143 | * |
| 4144 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4145 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4146 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4147 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4148 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4149 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4150 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4151 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4152 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4153 | #ifdef CONFIG_IXGBE_DCA |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 4154 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 4155 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4156 | #endif |
| 4157 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4158 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]); |
| 4159 | 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] | 4160 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4161 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4162 | work_done = budget; |
| 4163 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 4164 | /* If budget not fully consumed, exit the polling mode */ |
| 4165 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 4166 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4167 | if (adapter->rx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 4168 | ixgbe_set_itr(q_vector); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4169 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 4170 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4171 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4172 | return work_done; |
| 4173 | } |
| 4174 | |
| 4175 | /** |
| 4176 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4177 | * @netdev: network interface device structure |
| 4178 | **/ |
| 4179 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4180 | { |
| 4181 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4182 | |
| 4183 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4184 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4187 | /** |
| 4188 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 4189 | * @adapter: board private structure to initialize |
| 4190 | * |
| 4191 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 4192 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 4193 | * |
| 4194 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4195 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 4196 | { |
| 4197 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4198 | 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] | 4199 | |
| 4200 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4201 | f->mask = 0xF; |
| 4202 | adapter->num_rx_queues = f->indices; |
| 4203 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4204 | ret = true; |
| 4205 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4206 | ret = false; |
| 4207 | } |
| 4208 | |
| 4209 | return ret; |
| 4210 | } |
| 4211 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4212 | /** |
| 4213 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 4214 | * @adapter: board private structure to initialize |
| 4215 | * |
| 4216 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 4217 | * to the original CPU that initiated the Tx session. This runs in addition |
| 4218 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 4219 | * Rx load across CPUs using RSS. |
| 4220 | * |
| 4221 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4222 | 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] | 4223 | { |
| 4224 | bool ret = false; |
| 4225 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 4226 | |
| 4227 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 4228 | f_fdir->mask = 0; |
| 4229 | |
| 4230 | /* Flow Director must have RSS enabled */ |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4231 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4232 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4233 | adapter->num_tx_queues = f_fdir->indices; |
| 4234 | adapter->num_rx_queues = f_fdir->indices; |
| 4235 | ret = true; |
| 4236 | } else { |
| 4237 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4238 | } |
| 4239 | return ret; |
| 4240 | } |
| 4241 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4242 | #ifdef IXGBE_FCOE |
| 4243 | /** |
| 4244 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 4245 | * @adapter: board private structure to initialize |
| 4246 | * |
| 4247 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 4248 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 4249 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 4250 | * index of the first rx queue used by FCoE. |
| 4251 | * |
| 4252 | **/ |
| 4253 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 4254 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4255 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 4256 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4257 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4258 | return false; |
| 4259 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4260 | f->indices = min((int)num_online_cpus(), f->indices); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4261 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4262 | adapter->num_rx_queues = 1; |
| 4263 | adapter->num_tx_queues = 1; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4264 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4265 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 4266 | e_info(probe, "FCoE enabled with RSS\n"); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4267 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4268 | ixgbe_set_fdir_queues(adapter); |
| 4269 | else |
| 4270 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4271 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4272 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4273 | /* adding FCoE rx rings to the end */ |
| 4274 | f->mask = adapter->num_rx_queues; |
| 4275 | adapter->num_rx_queues += f->indices; |
| 4276 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4277 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4278 | return true; |
| 4279 | } |
| 4280 | #endif /* IXGBE_FCOE */ |
| 4281 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4282 | /* Artificial max queue cap per traffic class in DCB mode */ |
| 4283 | #define DCB_QUEUE_CAP 8 |
| 4284 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4285 | #ifdef CONFIG_IXGBE_DCB |
| 4286 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
| 4287 | { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4288 | int per_tc_q, q, i, offset = 0; |
| 4289 | struct net_device *dev = adapter->netdev; |
| 4290 | int tcs = netdev_get_num_tc(dev); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4291 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4292 | if (!tcs) |
| 4293 | return false; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4294 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4295 | /* Map queue offset and counts onto allocated tx queues */ |
| 4296 | per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP); |
| 4297 | q = min((int)num_online_cpus(), per_tc_q); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4298 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4299 | for (i = 0; i < tcs; i++) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4300 | netdev_set_prio_tc_map(dev, i, i); |
| 4301 | netdev_set_tc_queue(dev, i, q, offset); |
| 4302 | offset += q; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4305 | adapter->num_tx_queues = q * tcs; |
| 4306 | adapter->num_rx_queues = q * tcs; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4307 | |
| 4308 | #ifdef IXGBE_FCOE |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4309 | /* FCoE enabled queues require special configuration indexed |
| 4310 | * by feature specific indices and mask. Here we map FCoE |
| 4311 | * indices onto the DCB queue pairs allowing FCoE to own |
| 4312 | * configuration later. |
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 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 4315 | int tc; |
| 4316 | struct ixgbe_ring_feature *f = |
| 4317 | &adapter->ring_feature[RING_F_FCOE]; |
| 4318 | |
| 4319 | tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up); |
| 4320 | f->indices = dev->tc_to_txq[tc].count; |
| 4321 | f->mask = dev->tc_to_txq[tc].offset; |
| 4322 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4323 | #endif |
| 4324 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4325 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4326 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4327 | #endif |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4328 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4329 | /** |
| 4330 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 4331 | * @adapter: board private structure to initialize |
| 4332 | * |
| 4333 | * IOV doesn't actually use anything, so just NAK the |
| 4334 | * request for now and let the other queue routines |
| 4335 | * figure out what to do. |
| 4336 | */ |
| 4337 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 4338 | { |
| 4339 | return false; |
| 4340 | } |
| 4341 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4342 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4343 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4344 | * @adapter: board private structure to initialize |
| 4345 | * |
| 4346 | * This is the top level queue allocation routine. The order here is very |
| 4347 | * important, starting with the "most" number of features turned on at once, |
| 4348 | * and ending with the smallest set of features. This way large combinations |
| 4349 | * can be allocated if they're turned on, and smaller combinations are the |
| 4350 | * fallthrough conditions. |
| 4351 | * |
| 4352 | **/ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4353 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4354 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4355 | /* Start with base case */ |
| 4356 | adapter->num_rx_queues = 1; |
| 4357 | adapter->num_tx_queues = 1; |
| 4358 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 4359 | adapter->num_rx_queues_per_pool = 1; |
| 4360 | |
| 4361 | if (ixgbe_set_sriov_queues(adapter)) |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4362 | goto done; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4363 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4364 | #ifdef CONFIG_IXGBE_DCB |
| 4365 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4366 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4367 | |
| 4368 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4369 | #ifdef IXGBE_FCOE |
| 4370 | if (ixgbe_set_fcoe_queues(adapter)) |
| 4371 | goto done; |
| 4372 | |
| 4373 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4374 | if (ixgbe_set_fdir_queues(adapter)) |
| 4375 | goto done; |
| 4376 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4377 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4378 | goto done; |
| 4379 | |
| 4380 | /* fallback to base case */ |
| 4381 | adapter->num_rx_queues = 1; |
| 4382 | adapter->num_tx_queues = 1; |
| 4383 | |
| 4384 | done: |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4385 | /* Notify the stack of the (possibly) reduced queue counts. */ |
John Fastabend | f0796d5 | 2010-07-01 13:21:57 +0000 | [diff] [blame] | 4386 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4387 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 4388 | adapter->num_rx_queues); |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4391 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4392 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4393 | { |
| 4394 | int err, vector_threshold; |
| 4395 | |
| 4396 | /* We'll want at least 3 (vector_threshold): |
| 4397 | * 1) TxQ[0] Cleanup |
| 4398 | * 2) RxQ[0] Cleanup |
| 4399 | * 3) Other (Link Status Change, etc.) |
| 4400 | * 4) TCP Timer (optional) |
| 4401 | */ |
| 4402 | vector_threshold = MIN_MSIX_COUNT; |
| 4403 | |
| 4404 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 4405 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 4406 | * Right now, we simply care about how many we'll get; we'll |
| 4407 | * set them up later while requesting irq's. |
| 4408 | */ |
| 4409 | while (vectors >= vector_threshold) { |
| 4410 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4411 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4412 | if (!err) /* Success in acquiring all requested vectors. */ |
| 4413 | break; |
| 4414 | else if (err < 0) |
| 4415 | vectors = 0; /* Nasty failure, quit now */ |
| 4416 | else /* err == number of vectors we should try again with */ |
| 4417 | vectors = err; |
| 4418 | } |
| 4419 | |
| 4420 | if (vectors < vector_threshold) { |
| 4421 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 4422 | * This just means we'll go with either a single MSI |
| 4423 | * vector or fall back to legacy interrupts. |
| 4424 | */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4425 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4426 | "Unable to allocate MSI-X interrupts\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4427 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4428 | kfree(adapter->msix_entries); |
| 4429 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4430 | } else { |
| 4431 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 4432 | /* |
| 4433 | * Adjust for only the vectors we'll use, which is minimum |
| 4434 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 4435 | * vectors we were allocated. |
| 4436 | */ |
| 4437 | adapter->num_msix_vectors = min(vectors, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4438 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4439 | } |
| 4440 | } |
| 4441 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4442 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4443 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4444 | * @adapter: board private structure to initialize |
| 4445 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4446 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 4447 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4448 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4449 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4450 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4451 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4452 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4453 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 4454 | return false; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4455 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4456 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4457 | adapter->rx_ring[i]->reg_idx = i; |
| 4458 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4459 | adapter->tx_ring[i]->reg_idx = i; |
| 4460 | |
| 4461 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4465 | |
| 4466 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 4467 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, |
| 4468 | unsigned int *tx, unsigned int *rx) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4469 | { |
| 4470 | struct net_device *dev = adapter->netdev; |
| 4471 | struct ixgbe_hw *hw = &adapter->hw; |
| 4472 | u8 num_tcs = netdev_get_num_tc(dev); |
| 4473 | |
| 4474 | *tx = 0; |
| 4475 | *rx = 0; |
| 4476 | |
| 4477 | switch (hw->mac.type) { |
| 4478 | case ixgbe_mac_82598EB: |
John Fastabend | aba70d5 | 2011-04-26 07:26:14 +0000 | [diff] [blame] | 4479 | *tx = tc << 2; |
| 4480 | *rx = tc << 3; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4481 | break; |
| 4482 | case ixgbe_mac_82599EB: |
| 4483 | case ixgbe_mac_X540: |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4484 | if (num_tcs > 4) { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4485 | if (tc < 3) { |
| 4486 | *tx = tc << 5; |
| 4487 | *rx = tc << 4; |
| 4488 | } else if (tc < 5) { |
| 4489 | *tx = ((tc + 2) << 4); |
| 4490 | *rx = tc << 4; |
| 4491 | } else if (tc < num_tcs) { |
| 4492 | *tx = ((tc + 8) << 3); |
| 4493 | *rx = tc << 4; |
| 4494 | } |
John Fastabend | 4fa2e0e | 2011-07-18 22:38:25 +0000 | [diff] [blame] | 4495 | } else { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4496 | *rx = tc << 5; |
| 4497 | switch (tc) { |
| 4498 | case 0: |
| 4499 | *tx = 0; |
| 4500 | break; |
| 4501 | case 1: |
| 4502 | *tx = 64; |
| 4503 | break; |
| 4504 | case 2: |
| 4505 | *tx = 96; |
| 4506 | break; |
| 4507 | case 3: |
| 4508 | *tx = 112; |
| 4509 | break; |
| 4510 | default: |
| 4511 | break; |
| 4512 | } |
| 4513 | } |
| 4514 | break; |
| 4515 | default: |
| 4516 | break; |
| 4517 | } |
| 4518 | } |
| 4519 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4520 | /** |
| 4521 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 4522 | * @adapter: board private structure to initialize |
| 4523 | * |
| 4524 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 4525 | * |
| 4526 | **/ |
| 4527 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 4528 | { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4529 | struct net_device *dev = adapter->netdev; |
| 4530 | int i, j, k; |
| 4531 | u8 num_tcs = netdev_get_num_tc(dev); |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4532 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4533 | if (!num_tcs) |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4534 | return false; |
| 4535 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4536 | for (i = 0, k = 0; i < num_tcs; i++) { |
| 4537 | unsigned int tx_s, rx_s; |
| 4538 | u16 count = dev->tc_to_txq[i].count; |
| 4539 | |
| 4540 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); |
| 4541 | for (j = 0; j < count; j++, k++) { |
| 4542 | adapter->tx_ring[k]->reg_idx = tx_s + j; |
| 4543 | adapter->rx_ring[k]->reg_idx = rx_s + j; |
| 4544 | adapter->tx_ring[k]->dcb_tc = i; |
| 4545 | adapter->rx_ring[k]->dcb_tc = i; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4546 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4547 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4548 | |
| 4549 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4550 | } |
| 4551 | #endif |
| 4552 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4553 | /** |
| 4554 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 4555 | * @adapter: board private structure to initialize |
| 4556 | * |
| 4557 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 4558 | * |
| 4559 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4560 | 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] | 4561 | { |
| 4562 | int i; |
| 4563 | bool ret = false; |
| 4564 | |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4565 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4566 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4567 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4568 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4569 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4570 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4571 | ret = true; |
| 4572 | } |
| 4573 | |
| 4574 | return ret; |
| 4575 | } |
| 4576 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4577 | #ifdef IXGBE_FCOE |
| 4578 | /** |
| 4579 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 4580 | * @adapter: board private structure to initialize |
| 4581 | * |
| 4582 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 4583 | * |
| 4584 | */ |
| 4585 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 4586 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4587 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4588 | int i; |
| 4589 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4590 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4591 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4592 | return false; |
| 4593 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4594 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4595 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4596 | ixgbe_cache_ring_fdir(adapter); |
| 4597 | else |
| 4598 | ixgbe_cache_ring_rss(adapter); |
| 4599 | |
| 4600 | fcoe_rx_i = f->mask; |
| 4601 | fcoe_tx_i = f->mask; |
| 4602 | } |
| 4603 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 4604 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 4605 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
| 4606 | } |
| 4607 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4611 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4612 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 4613 | * @adapter: board private structure to initialize |
| 4614 | * |
| 4615 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 4616 | * no other mapping is used. |
| 4617 | * |
| 4618 | */ |
| 4619 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 4620 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4621 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 4622 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4623 | if (adapter->num_vfs) |
| 4624 | return true; |
| 4625 | else |
| 4626 | return false; |
| 4627 | } |
| 4628 | |
| 4629 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4630 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 4631 | * @adapter: board private structure to initialize |
| 4632 | * |
| 4633 | * Once we know the feature-set enabled for the device, we'll cache |
| 4634 | * the register offset the descriptor ring is assigned to. |
| 4635 | * |
| 4636 | * Note, the order the various feature calls is important. It must start with |
| 4637 | * the "most" features enabled at the same time, then trickle down to the |
| 4638 | * least amount of features turned on at once. |
| 4639 | **/ |
| 4640 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 4641 | { |
| 4642 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4643 | adapter->rx_ring[0]->reg_idx = 0; |
| 4644 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4645 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4646 | if (ixgbe_cache_ring_sriov(adapter)) |
| 4647 | return; |
| 4648 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4649 | #ifdef CONFIG_IXGBE_DCB |
| 4650 | if (ixgbe_cache_ring_dcb(adapter)) |
| 4651 | return; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4652 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4653 | |
| 4654 | #ifdef IXGBE_FCOE |
| 4655 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 4656 | return; |
| 4657 | #endif /* IXGBE_FCOE */ |
| 4658 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4659 | if (ixgbe_cache_ring_fdir(adapter)) |
| 4660 | return; |
| 4661 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4662 | if (ixgbe_cache_ring_rss(adapter)) |
| 4663 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4664 | } |
| 4665 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4666 | /** |
| 4667 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 4668 | * @adapter: board private structure to initialize |
| 4669 | * |
| 4670 | * 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] | 4671 | * number of queues at compile-time. The polling_netdev array is |
| 4672 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4673 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4674 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4675 | { |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4676 | int rx = 0, tx = 0, nid = adapter->node; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4677 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4678 | if (nid < 0 || !node_online(nid)) |
| 4679 | nid = first_online_node; |
| 4680 | |
| 4681 | for (; tx < adapter->num_tx_queues; tx++) { |
| 4682 | struct ixgbe_ring *ring; |
| 4683 | |
| 4684 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4685 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4686 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4687 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4688 | goto err_allocation; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4689 | ring->count = adapter->tx_ring_count; |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4690 | ring->queue_index = tx; |
| 4691 | ring->numa_node = nid; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4692 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 4693 | ring->netdev = adapter->netdev; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4694 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4695 | adapter->tx_ring[tx] = ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4696 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4697 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4698 | for (; rx < adapter->num_rx_queues; rx++) { |
| 4699 | struct ixgbe_ring *ring; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4700 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4701 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4702 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4703 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4704 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4705 | goto err_allocation; |
| 4706 | ring->count = adapter->rx_ring_count; |
| 4707 | ring->queue_index = rx; |
| 4708 | ring->numa_node = nid; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4709 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 4710 | ring->netdev = adapter->netdev; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4711 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4712 | adapter->rx_ring[rx] = ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4713 | } |
| 4714 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4715 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4716 | |
| 4717 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4718 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4719 | err_allocation: |
| 4720 | while (tx) |
| 4721 | kfree(adapter->tx_ring[--tx]); |
| 4722 | |
| 4723 | while (rx) |
| 4724 | kfree(adapter->rx_ring[--rx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4725 | return -ENOMEM; |
| 4726 | } |
| 4727 | |
| 4728 | /** |
| 4729 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 4730 | * @adapter: board private structure to initialize |
| 4731 | * |
| 4732 | * Attempt to configure the interrupts using the best available |
| 4733 | * capabilities of the hardware and the kernel. |
| 4734 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 4735 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4736 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4737 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4738 | int err = 0; |
| 4739 | int vector, v_budget; |
| 4740 | |
| 4741 | /* |
| 4742 | * It's easy to be greedy for MSI-X vectors, but it really |
| 4743 | * doesn't do us much good if we have a lot more vectors |
| 4744 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 4745 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4746 | */ |
| 4747 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4748 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4749 | |
| 4750 | /* |
| 4751 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4752 | * hw.mac->max_msix_vectors vectors. With features |
| 4753 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 4754 | * descriptor queues supported by our device. Thus, we cap it off in |
| 4755 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4756 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4757 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4758 | |
| 4759 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 4760 | * mean we disable MSI-X capabilities of the adapter. */ |
| 4761 | adapter->msix_entries = kcalloc(v_budget, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4762 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4763 | if (adapter->msix_entries) { |
| 4764 | for (vector = 0; vector < v_budget; vector++) |
| 4765 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4766 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4767 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 4768 | |
| 4769 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4770 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4771 | } |
David S. Miller | 26d2784 | 2010-05-03 15:18:22 -0700 | [diff] [blame] | 4772 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4773 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 4774 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4775 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4776 | e_err(probe, |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4777 | "ATR is not supported while multiple " |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4778 | "queues are disabled. Disabling Flow Director\n"); |
| 4779 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4780 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4781 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4782 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4783 | ixgbe_disable_sriov(adapter); |
| 4784 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4785 | err = ixgbe_set_num_queues(adapter); |
| 4786 | if (err) |
| 4787 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4788 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4789 | err = pci_enable_msi(adapter->pdev); |
| 4790 | if (!err) { |
| 4791 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 4792 | } else { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4793 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4794 | "Unable to allocate MSI interrupt, " |
| 4795 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4796 | /* reset err */ |
| 4797 | err = 0; |
| 4798 | } |
| 4799 | |
| 4800 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4801 | return err; |
| 4802 | } |
| 4803 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4804 | /** |
| 4805 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 4806 | * @adapter: board private structure to initialize |
| 4807 | * |
| 4808 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 4809 | * return -ENOMEM. |
| 4810 | **/ |
| 4811 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 4812 | { |
| 4813 | int q_idx, num_q_vectors; |
| 4814 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4815 | int (*poll)(struct napi_struct *, int); |
| 4816 | |
| 4817 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 4818 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4819 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4820 | } else { |
| 4821 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4822 | poll = &ixgbe_poll; |
| 4823 | } |
| 4824 | |
| 4825 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4826 | q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4827 | GFP_KERNEL, adapter->node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4828 | if (!q_vector) |
| 4829 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4830 | GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4831 | if (!q_vector) |
| 4832 | goto err_out; |
| 4833 | q_vector->adapter = adapter; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 4834 | if (q_vector->tx.count && !q_vector->rx.count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4835 | q_vector->eitr = adapter->tx_eitr_param; |
| 4836 | else |
| 4837 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4838 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4839 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4840 | adapter->q_vector[q_idx] = q_vector; |
| 4841 | } |
| 4842 | |
| 4843 | return 0; |
| 4844 | |
| 4845 | err_out: |
| 4846 | while (q_idx) { |
| 4847 | q_idx--; |
| 4848 | q_vector = adapter->q_vector[q_idx]; |
| 4849 | netif_napi_del(&q_vector->napi); |
| 4850 | kfree(q_vector); |
| 4851 | adapter->q_vector[q_idx] = NULL; |
| 4852 | } |
| 4853 | return -ENOMEM; |
| 4854 | } |
| 4855 | |
| 4856 | /** |
| 4857 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 4858 | * @adapter: board private structure to initialize |
| 4859 | * |
| 4860 | * This function frees the memory allocated to the q_vectors. In addition if |
| 4861 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4862 | * to freeing the q_vector. |
| 4863 | **/ |
| 4864 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 4865 | { |
| 4866 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4867 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4868 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4869 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4870 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4871 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4872 | |
| 4873 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 4874 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4875 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4876 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4877 | kfree(q_vector); |
| 4878 | } |
| 4879 | } |
| 4880 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 4881 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4882 | { |
| 4883 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 4884 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4885 | pci_disable_msix(adapter->pdev); |
| 4886 | kfree(adapter->msix_entries); |
| 4887 | adapter->msix_entries = NULL; |
| 4888 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 4889 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 4890 | pci_disable_msi(adapter->pdev); |
| 4891 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | /** |
| 4895 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 4896 | * @adapter: board private structure to initialize |
| 4897 | * |
| 4898 | * We determine which interrupt scheme to use based on... |
| 4899 | * - Kernel support (MSI, MSI-X) |
| 4900 | * - which can be user-defined (via MODULE_PARAM) |
| 4901 | * - Hardware queue count (num_*_queues) |
| 4902 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 4903 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4904 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4905 | { |
| 4906 | int err; |
| 4907 | |
| 4908 | /* Number of supported queues */ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4909 | err = ixgbe_set_num_queues(adapter); |
| 4910 | if (err) |
| 4911 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4912 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4913 | err = ixgbe_set_interrupt_capability(adapter); |
| 4914 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4915 | e_dev_err("Unable to setup interrupt capabilities\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4916 | goto err_set_interrupt; |
| 4917 | } |
| 4918 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4919 | err = ixgbe_alloc_q_vectors(adapter); |
| 4920 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4921 | e_dev_err("Unable to allocate memory for queue vectors\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4922 | goto err_alloc_q_vectors; |
| 4923 | } |
| 4924 | |
| 4925 | err = ixgbe_alloc_queues(adapter); |
| 4926 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4927 | e_dev_err("Unable to allocate memory for queues\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4928 | goto err_alloc_queues; |
| 4929 | } |
| 4930 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4931 | 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] | 4932 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 4933 | adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4934 | |
| 4935 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4936 | |
| 4937 | return 0; |
| 4938 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4939 | err_alloc_queues: |
| 4940 | ixgbe_free_q_vectors(adapter); |
| 4941 | err_alloc_q_vectors: |
| 4942 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4943 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4944 | return err; |
| 4945 | } |
| 4946 | |
| 4947 | /** |
| 4948 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4949 | * @adapter: board private structure to clear interrupt scheme on |
| 4950 | * |
| 4951 | * We go through and clear interrupt specific resources and reset the structure |
| 4952 | * to pre-load conditions |
| 4953 | **/ |
| 4954 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 4955 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4956 | int i; |
| 4957 | |
| 4958 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4959 | kfree(adapter->tx_ring[i]); |
| 4960 | adapter->tx_ring[i] = NULL; |
| 4961 | } |
| 4962 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 4963 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4964 | |
| 4965 | /* ixgbe_get_stats64() might access this ring, we must wait |
| 4966 | * a grace period before freeing it. |
| 4967 | */ |
Lai Jiangshan | bcec8b6 | 2011-03-18 11:57:21 +0800 | [diff] [blame] | 4968 | kfree_rcu(ring, rcu); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4969 | adapter->rx_ring[i] = NULL; |
| 4970 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4971 | |
Don Skidmore | b8eb3a1 | 2010-12-01 20:54:53 +0000 | [diff] [blame] | 4972 | adapter->num_tx_queues = 0; |
| 4973 | adapter->num_rx_queues = 0; |
| 4974 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4975 | ixgbe_free_q_vectors(adapter); |
| 4976 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | /** |
| 4980 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 4981 | * @adapter: board private structure to initialize |
| 4982 | * |
| 4983 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 4984 | * Fields are initialized based on PCI device information and |
| 4985 | * OS network device settings (MTU size). |
| 4986 | **/ |
| 4987 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 4988 | { |
| 4989 | struct ixgbe_hw *hw = &adapter->hw; |
| 4990 | struct pci_dev *pdev = adapter->pdev; |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 4991 | struct net_device *dev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4992 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4993 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4994 | int j; |
| 4995 | struct tc_configuration *tc; |
| 4996 | #endif |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 4997 | int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4998 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4999 | /* PCI config space info */ |
| 5000 | |
| 5001 | hw->vendor_id = pdev->vendor; |
| 5002 | hw->device_id = pdev->device; |
| 5003 | hw->revision_id = pdev->revision; |
| 5004 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5005 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5006 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5007 | /* Set capability flags */ |
| 5008 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 5009 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 5010 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5011 | switch (hw->mac.type) { |
| 5012 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5013 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5014 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5015 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5016 | break; |
| 5017 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5018 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5019 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5020 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5021 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5022 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5023 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 5024 | /* Flow Director hash filters enabled */ |
| 5025 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5026 | adapter->atr_sample_rate = 20; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5027 | adapter->ring_feature[RING_F_FDIR].indices = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5028 | IXGBE_MAX_FDIR_INDICES; |
Alexander Duyck | c04f6ca | 2011-05-11 07:18:36 +0000 | [diff] [blame] | 5029 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5030 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5031 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5032 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5033 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5034 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 5035 | /* Default traffic class to use for FCoE */ |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 5036 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5037 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5038 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5039 | break; |
| 5040 | default: |
| 5041 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5042 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5043 | |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5044 | /* n-tuple support exists, always init our spinlock */ |
| 5045 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5046 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5047 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5048 | /* Configure DCB traffic classes */ |
| 5049 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5050 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5051 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5052 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5053 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5054 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5055 | tc->dcb_pfc = pfc_disabled; |
| 5056 | } |
| 5057 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5058 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5059 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5060 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5061 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5062 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 5063 | MAX_TRAFFIC_CLASS); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5064 | |
| 5065 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5066 | |
| 5067 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5068 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5069 | 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] | 5070 | #ifdef CONFIG_DCB |
| 5071 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 5072 | #endif |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5073 | hw->fc.high_water = FC_HIGH_WATER(max_frame); |
| 5074 | hw->fc.low_water = FC_LOW_WATER(max_frame); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5075 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5076 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5077 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5078 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5079 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5080 | adapter->rx_itr_setting = 1; |
| 5081 | adapter->rx_eitr_param = 20000; |
| 5082 | adapter->tx_itr_setting = 1; |
| 5083 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5084 | |
| 5085 | /* set defaults for eitr in MegaBytes */ |
| 5086 | adapter->eitr_low = 10; |
| 5087 | adapter->eitr_high = 20; |
| 5088 | |
| 5089 | /* set default ring sizes */ |
| 5090 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5091 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5092 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5093 | /* set default work limits */ |
| 5094 | adapter->tx_work_limit = adapter->tx_ring_count; |
| 5095 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5096 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5097 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5098 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5099 | return -EIO; |
| 5100 | } |
| 5101 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5102 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5103 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 5104 | |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5105 | /* get assigned NUMA node */ |
| 5106 | adapter->node = dev_to_node(&pdev->dev); |
| 5107 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5108 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5109 | |
| 5110 | return 0; |
| 5111 | } |
| 5112 | |
| 5113 | /** |
| 5114 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5115 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5116 | * |
| 5117 | * Return 0 on success, negative on failure |
| 5118 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5119 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5120 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5121 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5122 | int size; |
| 5123 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5124 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5125 | tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5126 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5127 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5128 | if (!tx_ring->tx_buffer_info) |
| 5129 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5130 | |
| 5131 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5132 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5133 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5134 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5135 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 5136 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5137 | if (!tx_ring->desc) |
| 5138 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5139 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5140 | tx_ring->next_to_use = 0; |
| 5141 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5142 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5143 | |
| 5144 | err: |
| 5145 | vfree(tx_ring->tx_buffer_info); |
| 5146 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5147 | 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] | 5148 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
| 5151 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5152 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5153 | * @adapter: board private structure |
| 5154 | * |
| 5155 | * If this function returns with an error, then it's possible one or |
| 5156 | * more of the rings is populated (while the rest are not). It is the |
| 5157 | * callers duty to clean those orphaned rings. |
| 5158 | * |
| 5159 | * Return 0 on success, negative on failure |
| 5160 | **/ |
| 5161 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5162 | { |
| 5163 | int i, err = 0; |
| 5164 | |
| 5165 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5166 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5167 | if (!err) |
| 5168 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5169 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5170 | break; |
| 5171 | } |
| 5172 | |
| 5173 | return err; |
| 5174 | } |
| 5175 | |
| 5176 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5177 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5178 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5179 | * |
| 5180 | * Returns 0 on success, negative on failure |
| 5181 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5182 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5183 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5184 | struct device *dev = rx_ring->dev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5185 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5186 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5187 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5188 | rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5189 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5190 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5191 | if (!rx_ring->rx_buffer_info) |
| 5192 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5193 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5194 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5195 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5196 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5197 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5198 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 5199 | &rx_ring->dma, GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5200 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5201 | if (!rx_ring->desc) |
| 5202 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5203 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5204 | rx_ring->next_to_clean = 0; |
| 5205 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5206 | |
| 5207 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5208 | err: |
| 5209 | vfree(rx_ring->rx_buffer_info); |
| 5210 | rx_ring->rx_buffer_info = NULL; |
| 5211 | 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] | 5212 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5216 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5217 | * @adapter: board private structure |
| 5218 | * |
| 5219 | * If this function returns with an error, then it's possible one or |
| 5220 | * more of the rings is populated (while the rest are not). It is the |
| 5221 | * callers duty to clean those orphaned rings. |
| 5222 | * |
| 5223 | * Return 0 on success, negative on failure |
| 5224 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5225 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5226 | { |
| 5227 | int i, err = 0; |
| 5228 | |
| 5229 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5230 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5231 | if (!err) |
| 5232 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5233 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5234 | break; |
| 5235 | } |
| 5236 | |
| 5237 | return err; |
| 5238 | } |
| 5239 | |
| 5240 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5241 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5242 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5243 | * |
| 5244 | * Free all transmit software resources |
| 5245 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5246 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5247 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5248 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5249 | |
| 5250 | vfree(tx_ring->tx_buffer_info); |
| 5251 | tx_ring->tx_buffer_info = NULL; |
| 5252 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5253 | /* if not set, then don't free */ |
| 5254 | if (!tx_ring->desc) |
| 5255 | return; |
| 5256 | |
| 5257 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5258 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5259 | |
| 5260 | tx_ring->desc = NULL; |
| 5261 | } |
| 5262 | |
| 5263 | /** |
| 5264 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5265 | * @adapter: board private structure |
| 5266 | * |
| 5267 | * Free all transmit software resources |
| 5268 | **/ |
| 5269 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5270 | { |
| 5271 | int i; |
| 5272 | |
| 5273 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5274 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5275 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5279 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5280 | * @rx_ring: ring to clean the resources from |
| 5281 | * |
| 5282 | * Free all receive software resources |
| 5283 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5284 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5285 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5286 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5287 | |
| 5288 | vfree(rx_ring->rx_buffer_info); |
| 5289 | rx_ring->rx_buffer_info = NULL; |
| 5290 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5291 | /* if not set, then don't free */ |
| 5292 | if (!rx_ring->desc) |
| 5293 | return; |
| 5294 | |
| 5295 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5296 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5297 | |
| 5298 | rx_ring->desc = NULL; |
| 5299 | } |
| 5300 | |
| 5301 | /** |
| 5302 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5303 | * @adapter: board private structure |
| 5304 | * |
| 5305 | * Free all receive software resources |
| 5306 | **/ |
| 5307 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5308 | { |
| 5309 | int i; |
| 5310 | |
| 5311 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5312 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5313 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5317 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5318 | * @netdev: network interface device structure |
| 5319 | * @new_mtu: new value for maximum frame size |
| 5320 | * |
| 5321 | * Returns 0 on success, negative on failure |
| 5322 | **/ |
| 5323 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5324 | { |
| 5325 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5326 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5327 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5328 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5329 | /* MTU < 68 is an error and causes problems on some kernels */ |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 5330 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED && |
| 5331 | hw->mac.type != ixgbe_mac_X540) { |
| 5332 | if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
| 5333 | return -EINVAL; |
| 5334 | } else { |
| 5335 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5336 | return -EINVAL; |
| 5337 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5338 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5339 | 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] | 5340 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5341 | netdev->mtu = new_mtu; |
| 5342 | |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5343 | hw->fc.high_water = FC_HIGH_WATER(max_frame); |
| 5344 | hw->fc.low_water = FC_LOW_WATER(max_frame); |
| 5345 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5346 | if (netif_running(netdev)) |
| 5347 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5348 | |
| 5349 | return 0; |
| 5350 | } |
| 5351 | |
| 5352 | /** |
| 5353 | * ixgbe_open - Called when a network interface is made active |
| 5354 | * @netdev: network interface device structure |
| 5355 | * |
| 5356 | * Returns 0 on success, negative value on failure |
| 5357 | * |
| 5358 | * The open entry point is called when a network interface is made |
| 5359 | * active by the system (IFF_UP). At this point all resources needed |
| 5360 | * for transmit and receive operations are allocated, the interrupt |
| 5361 | * handler is registered with the OS, the watchdog timer is started, |
| 5362 | * and the stack is notified that the interface is ready. |
| 5363 | **/ |
| 5364 | static int ixgbe_open(struct net_device *netdev) |
| 5365 | { |
| 5366 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5367 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5368 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5369 | /* disallow open during test */ |
| 5370 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5371 | return -EBUSY; |
| 5372 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5373 | netif_carrier_off(netdev); |
| 5374 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5375 | /* allocate transmit descriptors */ |
| 5376 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5377 | if (err) |
| 5378 | goto err_setup_tx; |
| 5379 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5380 | /* allocate receive descriptors */ |
| 5381 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5382 | if (err) |
| 5383 | goto err_setup_rx; |
| 5384 | |
| 5385 | ixgbe_configure(adapter); |
| 5386 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5387 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5388 | if (err) |
| 5389 | goto err_req_irq; |
| 5390 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5391 | err = ixgbe_up_complete(adapter); |
| 5392 | if (err) |
| 5393 | goto err_up; |
| 5394 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 5395 | netif_tx_start_all_queues(netdev); |
| 5396 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5397 | return 0; |
| 5398 | |
| 5399 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5400 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5401 | ixgbe_free_irq(adapter); |
| 5402 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5403 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5404 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5405 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5406 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5407 | ixgbe_reset(adapter); |
| 5408 | |
| 5409 | return err; |
| 5410 | } |
| 5411 | |
| 5412 | /** |
| 5413 | * ixgbe_close - Disables a network interface |
| 5414 | * @netdev: network interface device structure |
| 5415 | * |
| 5416 | * Returns 0, this is not allowed to fail |
| 5417 | * |
| 5418 | * The close entry point is called when an interface is de-activated |
| 5419 | * by the OS. The hardware is still under the drivers control, but |
| 5420 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5421 | * hardware, and all transmit and receive resources are freed. |
| 5422 | **/ |
| 5423 | static int ixgbe_close(struct net_device *netdev) |
| 5424 | { |
| 5425 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5426 | |
| 5427 | ixgbe_down(adapter); |
| 5428 | ixgbe_free_irq(adapter); |
| 5429 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5430 | ixgbe_fdir_filter_exit(adapter); |
| 5431 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5432 | ixgbe_free_all_tx_resources(adapter); |
| 5433 | ixgbe_free_all_rx_resources(adapter); |
| 5434 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5435 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5436 | |
| 5437 | return 0; |
| 5438 | } |
| 5439 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5440 | #ifdef CONFIG_PM |
| 5441 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5442 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5443 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5444 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5445 | u32 err; |
| 5446 | |
| 5447 | pci_set_power_state(pdev, PCI_D0); |
| 5448 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5449 | /* |
| 5450 | * pci_restore_state clears dev->state_saved so call |
| 5451 | * pci_save_state to restore it. |
| 5452 | */ |
| 5453 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5454 | |
| 5455 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5456 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5457 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5458 | return err; |
| 5459 | } |
| 5460 | pci_set_master(pdev); |
| 5461 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5462 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5463 | |
| 5464 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5465 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5466 | e_dev_err("Cannot initialize interrupts for device\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5467 | return err; |
| 5468 | } |
| 5469 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5470 | ixgbe_reset(adapter); |
| 5471 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5472 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5473 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5474 | if (netif_running(netdev)) { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5475 | err = ixgbe_open(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5476 | if (err) |
| 5477 | return err; |
| 5478 | } |
| 5479 | |
| 5480 | netif_device_attach(netdev); |
| 5481 | |
| 5482 | return 0; |
| 5483 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5484 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5485 | |
| 5486 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5487 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5488 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5489 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5490 | struct ixgbe_hw *hw = &adapter->hw; |
| 5491 | u32 ctrl, fctrl; |
| 5492 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5493 | #ifdef CONFIG_PM |
| 5494 | int retval = 0; |
| 5495 | #endif |
| 5496 | |
| 5497 | netif_device_detach(netdev); |
| 5498 | |
| 5499 | if (netif_running(netdev)) { |
| 5500 | ixgbe_down(adapter); |
| 5501 | ixgbe_free_irq(adapter); |
| 5502 | ixgbe_free_all_tx_resources(adapter); |
| 5503 | ixgbe_free_all_rx_resources(adapter); |
| 5504 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5505 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5506 | ixgbe_clear_interrupt_scheme(adapter); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 5507 | #ifdef CONFIG_DCB |
| 5508 | kfree(adapter->ixgbe_ieee_pfc); |
| 5509 | kfree(adapter->ixgbe_ieee_ets); |
| 5510 | #endif |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5511 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5512 | #ifdef CONFIG_PM |
| 5513 | retval = pci_save_state(pdev); |
| 5514 | if (retval) |
| 5515 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5516 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5517 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5518 | if (wufc) { |
| 5519 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5520 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5521 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5522 | if (wufc & IXGBE_WUFC_MC) { |
| 5523 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5524 | fctrl |= IXGBE_FCTRL_MPE; |
| 5525 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5526 | } |
| 5527 | |
| 5528 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5529 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5530 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5531 | |
| 5532 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5533 | } else { |
| 5534 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5535 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5536 | } |
| 5537 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5538 | switch (hw->mac.type) { |
| 5539 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5540 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5541 | break; |
| 5542 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5543 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5544 | pci_wake_from_d3(pdev, !!wufc); |
| 5545 | break; |
| 5546 | default: |
| 5547 | break; |
| 5548 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5549 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5550 | *enable_wake = !!wufc; |
| 5551 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5552 | ixgbe_release_hw_control(adapter); |
| 5553 | |
| 5554 | pci_disable_device(pdev); |
| 5555 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5556 | return 0; |
| 5557 | } |
| 5558 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5559 | #ifdef CONFIG_PM |
| 5560 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5561 | { |
| 5562 | int retval; |
| 5563 | bool wake; |
| 5564 | |
| 5565 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5566 | if (retval) |
| 5567 | return retval; |
| 5568 | |
| 5569 | if (wake) { |
| 5570 | pci_prepare_to_sleep(pdev); |
| 5571 | } else { |
| 5572 | pci_wake_from_d3(pdev, false); |
| 5573 | pci_set_power_state(pdev, PCI_D3hot); |
| 5574 | } |
| 5575 | |
| 5576 | return 0; |
| 5577 | } |
| 5578 | #endif /* CONFIG_PM */ |
| 5579 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5580 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5581 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5582 | bool wake; |
| 5583 | |
| 5584 | __ixgbe_shutdown(pdev, &wake); |
| 5585 | |
| 5586 | if (system_state == SYSTEM_POWER_OFF) { |
| 5587 | pci_wake_from_d3(pdev, wake); |
| 5588 | pci_set_power_state(pdev, PCI_D3hot); |
| 5589 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5590 | } |
| 5591 | |
| 5592 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5593 | * ixgbe_update_stats - Update the board statistics counters. |
| 5594 | * @adapter: board private structure |
| 5595 | **/ |
| 5596 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5597 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5598 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5599 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5600 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5601 | u64 total_mpc = 0; |
| 5602 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5603 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5604 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
| 5605 | u64 bytes = 0, packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5606 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5607 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5608 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5609 | return; |
| 5610 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5611 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5612 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5613 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5614 | for (i = 0; i < 16; i++) |
| 5615 | adapter->hw_rx_no_dma_resources += |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5616 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5617 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5618 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5619 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5620 | } |
| 5621 | adapter->rsc_total_count = rsc_count; |
| 5622 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5623 | } |
| 5624 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5625 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5626 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5627 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5628 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5629 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
| 5630 | bytes += rx_ring->stats.bytes; |
| 5631 | packets += rx_ring->stats.packets; |
| 5632 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5633 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5634 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5635 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
| 5636 | netdev->stats.rx_bytes = bytes; |
| 5637 | netdev->stats.rx_packets = packets; |
| 5638 | |
| 5639 | bytes = 0; |
| 5640 | packets = 0; |
| 5641 | /* gather some stats to the adapter struct that are per queue */ |
| 5642 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5643 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5644 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5645 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5646 | bytes += tx_ring->stats.bytes; |
| 5647 | packets += tx_ring->stats.packets; |
| 5648 | } |
| 5649 | adapter->restart_queue = restart_queue; |
| 5650 | adapter->tx_busy = tx_busy; |
| 5651 | netdev->stats.tx_bytes = bytes; |
| 5652 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5653 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5654 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5655 | for (i = 0; i < 8; i++) { |
| 5656 | /* for packet buffers not used, the register should read 0 */ |
| 5657 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5658 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5659 | hwstats->mpc[i] += mpc; |
| 5660 | total_mpc += hwstats->mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5661 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5662 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5663 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5664 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5665 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5666 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5667 | switch (hw->mac.type) { |
| 5668 | case ixgbe_mac_82598EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5669 | hwstats->pxonrxc[i] += |
| 5670 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5671 | break; |
| 5672 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5673 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5674 | hwstats->pxonrxc[i] += |
| 5675 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5676 | break; |
| 5677 | default: |
| 5678 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5679 | } |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5680 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5681 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5682 | } |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5683 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5684 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5685 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5686 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5687 | ixgbe_update_xoff_received(adapter); |
| 5688 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5689 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5690 | switch (hw->mac.type) { |
| 5691 | case ixgbe_mac_82598EB: |
| 5692 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5693 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5694 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5695 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5696 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5697 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5698 | /* OS2BMC stats are X540 only*/ |
| 5699 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5700 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5701 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5702 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5703 | case ixgbe_mac_82599EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5704 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5705 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5706 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5707 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5708 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5709 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5710 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5711 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5712 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5713 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5714 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5715 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5716 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5717 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5718 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5719 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5720 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5721 | break; |
| 5722 | default: |
| 5723 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5724 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5725 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5726 | hwstats->bprc += bprc; |
| 5727 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5728 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5729 | hwstats->mprc -= bprc; |
| 5730 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5731 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5732 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5733 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5734 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5735 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5736 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5737 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5738 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5739 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5740 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5741 | hwstats->lxofftxc += lxoff; |
| 5742 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5743 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5744 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5745 | /* |
| 5746 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5747 | */ |
| 5748 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5749 | hwstats->gptc -= xon_off_tot; |
| 5750 | hwstats->mptc -= xon_off_tot; |
| 5751 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5752 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5753 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 5754 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 5755 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 5756 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 5757 | hwstats->ptc64 -= xon_off_tot; |
| 5758 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 5759 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 5760 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 5761 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 5762 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 5763 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5764 | |
| 5765 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5766 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5767 | |
| 5768 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5769 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5770 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5771 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 5772 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5773 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5777 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
| 5778 | * @adapter - pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5779 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5780 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5781 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5782 | struct ixgbe_hw *hw = &adapter->hw; |
| 5783 | int i; |
| 5784 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5785 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 5786 | return; |
| 5787 | |
| 5788 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 5789 | |
| 5790 | /* if interface is down do nothing */ |
| 5791 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 5792 | return; |
| 5793 | |
| 5794 | /* do nothing if we are not using signature filters */ |
| 5795 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 5796 | return; |
| 5797 | |
| 5798 | adapter->fdir_overflow++; |
| 5799 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5800 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 5801 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 5802 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 5803 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5804 | /* re-enable flow director interrupts */ |
| 5805 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5806 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5807 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5808 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5809 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5810 | } |
| 5811 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5812 | /** |
| 5813 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
| 5814 | * @adapter - pointer to the device adapter structure |
| 5815 | * |
| 5816 | * This function serves two purposes. First it strobes the interrupt lines |
| 5817 | * in order to make certain interrupts are occuring. Secondly it sets the |
| 5818 | * bits needed to check for TX hangs. As a result we should immediately |
| 5819 | * determine if a hang has occured. |
| 5820 | */ |
| 5821 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 5822 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5823 | struct ixgbe_hw *hw = &adapter->hw; |
| 5824 | u64 eics = 0; |
| 5825 | int i; |
| 5826 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5827 | /* If we're down or resetting, just bail */ |
| 5828 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5829 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5830 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5831 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5832 | /* Force detection of hung controller */ |
| 5833 | if (netif_carrier_ok(adapter->netdev)) { |
| 5834 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 5835 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 5836 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5837 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5838 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5839 | /* |
| 5840 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5841 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5842 | * would set *both* EIMS and EICS for any bit in EIAM |
| 5843 | */ |
| 5844 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 5845 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5846 | } else { |
| 5847 | /* get one bit for every active tx/rx interrupt vector */ |
| 5848 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 5849 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 5850 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5851 | eics |= ((u64)1 << i); |
| 5852 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5853 | } |
| 5854 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5855 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5856 | ixgbe_irq_rearm_queues(adapter, eics); |
| 5857 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5858 | } |
| 5859 | |
| 5860 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5861 | * ixgbe_watchdog_update_link - update the link status |
| 5862 | * @adapter - pointer to the device adapter structure |
| 5863 | * @link_speed - pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5864 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5865 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5866 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5867 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5868 | u32 link_speed = adapter->link_speed; |
| 5869 | bool link_up = adapter->link_up; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5870 | int i; |
| 5871 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5872 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 5873 | return; |
| 5874 | |
| 5875 | if (hw->mac.ops.check_link) { |
| 5876 | 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] | 5877 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5878 | /* always assume link is up, if no check link function */ |
| 5879 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 5880 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5881 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5882 | if (link_up) { |
| 5883 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5884 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 5885 | hw->mac.ops.fc_enable(hw, i); |
| 5886 | } else { |
| 5887 | hw->mac.ops.fc_enable(hw, 0); |
| 5888 | } |
| 5889 | } |
| 5890 | |
| 5891 | if (link_up || |
| 5892 | time_after(jiffies, (adapter->link_check_timeout + |
| 5893 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 5894 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5895 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 5896 | IXGBE_WRITE_FLUSH(hw); |
| 5897 | } |
| 5898 | |
| 5899 | adapter->link_up = link_up; |
| 5900 | adapter->link_speed = link_speed; |
| 5901 | } |
| 5902 | |
| 5903 | /** |
| 5904 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 5905 | * print link up message |
| 5906 | * @adapter - pointer to the device adapter structure |
| 5907 | **/ |
| 5908 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 5909 | { |
| 5910 | struct net_device *netdev = adapter->netdev; |
| 5911 | struct ixgbe_hw *hw = &adapter->hw; |
| 5912 | u32 link_speed = adapter->link_speed; |
| 5913 | bool flow_rx, flow_tx; |
| 5914 | |
| 5915 | /* only continue if link was previously down */ |
| 5916 | if (netif_carrier_ok(netdev)) |
| 5917 | return; |
| 5918 | |
| 5919 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 5920 | |
| 5921 | switch (hw->mac.type) { |
| 5922 | case ixgbe_mac_82598EB: { |
| 5923 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5924 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 5925 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 5926 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 5927 | } |
| 5928 | break; |
| 5929 | case ixgbe_mac_X540: |
| 5930 | case ixgbe_mac_82599EB: { |
| 5931 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 5932 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 5933 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 5934 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 5935 | } |
| 5936 | break; |
| 5937 | default: |
| 5938 | flow_tx = false; |
| 5939 | flow_rx = false; |
| 5940 | break; |
| 5941 | } |
| 5942 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 5943 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 5944 | "10 Gbps" : |
| 5945 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 5946 | "1 Gbps" : |
| 5947 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 5948 | "100 Mbps" : |
| 5949 | "unknown speed"))), |
| 5950 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 5951 | (flow_rx ? "RX" : |
| 5952 | (flow_tx ? "TX" : "None")))); |
| 5953 | |
| 5954 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5955 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5956 | } |
| 5957 | |
| 5958 | /** |
| 5959 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 5960 | * print link down message |
| 5961 | * @adapter - pointer to the adapter structure |
| 5962 | **/ |
| 5963 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) |
| 5964 | { |
| 5965 | struct net_device *netdev = adapter->netdev; |
| 5966 | struct ixgbe_hw *hw = &adapter->hw; |
| 5967 | |
| 5968 | adapter->link_up = false; |
| 5969 | adapter->link_speed = 0; |
| 5970 | |
| 5971 | /* only continue if link was up previously */ |
| 5972 | if (!netif_carrier_ok(netdev)) |
| 5973 | return; |
| 5974 | |
| 5975 | /* poll for SFP+ cable when link is down */ |
| 5976 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 5977 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 5978 | |
| 5979 | e_info(drv, "NIC Link is Down\n"); |
| 5980 | netif_carrier_off(netdev); |
| 5981 | } |
| 5982 | |
| 5983 | /** |
| 5984 | * ixgbe_watchdog_flush_tx - flush queues on link down |
| 5985 | * @adapter - pointer to the device adapter structure |
| 5986 | **/ |
| 5987 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 5988 | { |
| 5989 | int i; |
| 5990 | int some_tx_pending = 0; |
| 5991 | |
| 5992 | if (!netif_carrier_ok(adapter->netdev)) { |
| 5993 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5994 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5995 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 5996 | some_tx_pending = 1; |
| 5997 | break; |
| 5998 | } |
| 5999 | } |
| 6000 | |
| 6001 | if (some_tx_pending) { |
| 6002 | /* We've lost link, so the controller stops DMA, |
| 6003 | * but we've got queued Tx work that's never going |
| 6004 | * to get done, so reset controller to flush Tx. |
| 6005 | * (Do the reset outside of interrupt context). |
| 6006 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6007 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6008 | } |
| 6009 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6010 | } |
| 6011 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6012 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6013 | { |
| 6014 | u32 ssvpc; |
| 6015 | |
| 6016 | /* Do not perform spoof check for 82598 */ |
| 6017 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6018 | return; |
| 6019 | |
| 6020 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6021 | |
| 6022 | /* |
| 6023 | * ssvpc register is cleared on read, if zero then no |
| 6024 | * spoofed packets in the last interval. |
| 6025 | */ |
| 6026 | if (!ssvpc) |
| 6027 | return; |
| 6028 | |
| 6029 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); |
| 6030 | } |
| 6031 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6032 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6033 | * ixgbe_watchdog_subtask - check and bring link up |
| 6034 | * @adapter - pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6035 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6036 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6037 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6038 | /* if interface is down do nothing */ |
| 6039 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6040 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6041 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6042 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6043 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6044 | if (adapter->link_up) |
| 6045 | ixgbe_watchdog_link_is_up(adapter); |
| 6046 | else |
| 6047 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6048 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6049 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6050 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6051 | |
| 6052 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6055 | /** |
| 6056 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
| 6057 | * @adapter - the ixgbe adapter structure |
| 6058 | **/ |
| 6059 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6060 | { |
| 6061 | struct ixgbe_hw *hw = &adapter->hw; |
| 6062 | s32 err; |
| 6063 | |
| 6064 | /* not searching for SFP so there is nothing to do here */ |
| 6065 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6066 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6067 | return; |
| 6068 | |
| 6069 | /* someone else is in init, wait until next service event */ |
| 6070 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6071 | return; |
| 6072 | |
| 6073 | err = hw->phy.ops.identify_sfp(hw); |
| 6074 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6075 | goto sfp_out; |
| 6076 | |
| 6077 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6078 | /* If no cable is present, then we need to reset |
| 6079 | * the next time we find a good cable. */ |
| 6080 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6081 | } |
| 6082 | |
| 6083 | /* exit on error */ |
| 6084 | if (err) |
| 6085 | goto sfp_out; |
| 6086 | |
| 6087 | /* exit if reset not needed */ |
| 6088 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6089 | goto sfp_out; |
| 6090 | |
| 6091 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6092 | |
| 6093 | /* |
| 6094 | * A module may be identified correctly, but the EEPROM may not have |
| 6095 | * support for that module. setup_sfp() will fail in that case, so |
| 6096 | * we should not allow that module to load. |
| 6097 | */ |
| 6098 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6099 | err = hw->phy.ops.reset(hw); |
| 6100 | else |
| 6101 | err = hw->mac.ops.setup_sfp(hw); |
| 6102 | |
| 6103 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6104 | goto sfp_out; |
| 6105 | |
| 6106 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6107 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6108 | |
| 6109 | sfp_out: |
| 6110 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6111 | |
| 6112 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6113 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6114 | e_dev_err("failed to initialize because an unsupported " |
| 6115 | "SFP+ module type was detected.\n"); |
| 6116 | e_dev_err("Reload the driver after installing a " |
| 6117 | "supported module.\n"); |
| 6118 | unregister_netdev(adapter->netdev); |
| 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | /** |
| 6123 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
| 6124 | * @adapter - the ixgbe adapter structure |
| 6125 | **/ |
| 6126 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6127 | { |
| 6128 | struct ixgbe_hw *hw = &adapter->hw; |
| 6129 | u32 autoneg; |
| 6130 | bool negotiation; |
| 6131 | |
| 6132 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6133 | return; |
| 6134 | |
| 6135 | /* someone else is in init, wait until next service event */ |
| 6136 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6137 | return; |
| 6138 | |
| 6139 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6140 | |
| 6141 | autoneg = hw->phy.autoneg_advertised; |
| 6142 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 6143 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 6144 | hw->mac.autotry_restart = false; |
| 6145 | if (hw->mac.ops.setup_link) |
| 6146 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 6147 | |
| 6148 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6149 | adapter->link_check_timeout = jiffies; |
| 6150 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6151 | } |
| 6152 | |
| 6153 | /** |
| 6154 | * ixgbe_service_timer - Timer Call-back |
| 6155 | * @data: pointer to adapter cast into an unsigned long |
| 6156 | **/ |
| 6157 | static void ixgbe_service_timer(unsigned long data) |
| 6158 | { |
| 6159 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6160 | unsigned long next_event_offset; |
| 6161 | |
| 6162 | /* poll faster when waiting for link */ |
| 6163 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6164 | next_event_offset = HZ / 10; |
| 6165 | else |
| 6166 | next_event_offset = HZ * 2; |
| 6167 | |
| 6168 | /* Reset the timer */ |
| 6169 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6170 | |
| 6171 | ixgbe_service_event_schedule(adapter); |
| 6172 | } |
| 6173 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6174 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6175 | { |
| 6176 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6177 | return; |
| 6178 | |
| 6179 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6180 | |
| 6181 | /* If we're already down or resetting, just bail */ |
| 6182 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6183 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6184 | return; |
| 6185 | |
| 6186 | ixgbe_dump(adapter); |
| 6187 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6188 | adapter->tx_timeout_count++; |
| 6189 | |
| 6190 | ixgbe_reinit_locked(adapter); |
| 6191 | } |
| 6192 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6193 | /** |
| 6194 | * ixgbe_service_task - manages and runs subtasks |
| 6195 | * @work: pointer to work_struct containing our data |
| 6196 | **/ |
| 6197 | static void ixgbe_service_task(struct work_struct *work) |
| 6198 | { |
| 6199 | struct ixgbe_adapter *adapter = container_of(work, |
| 6200 | struct ixgbe_adapter, |
| 6201 | service_task); |
| 6202 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6203 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6204 | ixgbe_sfp_detection_subtask(adapter); |
| 6205 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6206 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6207 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6208 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6209 | ixgbe_check_hang_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6210 | |
| 6211 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6212 | } |
| 6213 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6214 | void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens, |
| 6215 | u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6216 | { |
| 6217 | struct ixgbe_adv_tx_context_desc *context_desc; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6218 | u16 i = tx_ring->next_to_use; |
| 6219 | |
| 6220 | context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i); |
| 6221 | |
| 6222 | i++; |
| 6223 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 6224 | |
| 6225 | /* set bits to identify this as an advanced context descriptor */ |
| 6226 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 6227 | |
| 6228 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6229 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); |
| 6230 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 6231 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 6232 | } |
| 6233 | |
| 6234 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 6235 | u32 tx_flags, __be16 protocol, u8 *hdr_len) |
| 6236 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6237 | int err; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6238 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6239 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6240 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6241 | if (!skb_is_gso(skb)) |
| 6242 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6243 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6244 | if (skb_header_cloned(skb)) { |
| 6245 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 6246 | if (err) |
| 6247 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6248 | } |
| 6249 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6250 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6251 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6252 | |
| 6253 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6254 | struct iphdr *iph = ip_hdr(skb); |
| 6255 | iph->tot_len = 0; |
| 6256 | iph->check = 0; |
| 6257 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6258 | iph->daddr, 0, |
| 6259 | IPPROTO_TCP, |
| 6260 | 0); |
| 6261 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6262 | } else if (skb_is_gso_v6(skb)) { |
| 6263 | ipv6_hdr(skb)->payload_len = 0; |
| 6264 | tcp_hdr(skb)->check = |
| 6265 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6266 | &ipv6_hdr(skb)->daddr, |
| 6267 | 0, IPPROTO_TCP, 0); |
| 6268 | } |
| 6269 | |
| 6270 | l4len = tcp_hdrlen(skb); |
| 6271 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6272 | |
| 6273 | /* mss_l4len_id: use 1 as index for TSO */ |
| 6274 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6275 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 6276 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 6277 | |
| 6278 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6279 | vlan_macip_lens = skb_network_header_len(skb); |
| 6280 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6281 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6282 | |
| 6283 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
| 6284 | mss_l4len_idx); |
| 6285 | |
| 6286 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6287 | } |
| 6288 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6289 | static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6290 | struct sk_buff *skb, u32 tx_flags, |
| 6291 | __be16 protocol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6292 | { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6293 | u32 vlan_macip_lens = 0; |
| 6294 | u32 mss_l4len_idx = 0; |
| 6295 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6296 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6297 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6298 | if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) && |
| 6299 | !(tx_flags & IXGBE_TX_FLAGS_TXSW)) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6300 | return false; |
| 6301 | } else { |
| 6302 | u8 l4_hdr = 0; |
| 6303 | switch (protocol) { |
| 6304 | case __constant_htons(ETH_P_IP): |
| 6305 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6306 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6307 | l4_hdr = ip_hdr(skb)->protocol; |
| 6308 | break; |
| 6309 | case __constant_htons(ETH_P_IPV6): |
| 6310 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6311 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6312 | break; |
| 6313 | default: |
| 6314 | if (unlikely(net_ratelimit())) { |
| 6315 | dev_warn(tx_ring->dev, |
| 6316 | "partial checksum but proto=%x!\n", |
| 6317 | skb->protocol); |
| 6318 | } |
| 6319 | break; |
| 6320 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6321 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6322 | switch (l4_hdr) { |
| 6323 | case IPPROTO_TCP: |
| 6324 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6325 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6326 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6327 | break; |
| 6328 | case IPPROTO_SCTP: |
| 6329 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6330 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6331 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6332 | break; |
| 6333 | case IPPROTO_UDP: |
| 6334 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6335 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6336 | break; |
| 6337 | default: |
| 6338 | if (unlikely(net_ratelimit())) { |
| 6339 | dev_warn(tx_ring->dev, |
| 6340 | "partial checksum but l4 proto=%x!\n", |
| 6341 | skb->protocol); |
| 6342 | } |
| 6343 | break; |
| 6344 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6345 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6346 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6347 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6348 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6349 | |
| 6350 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6351 | type_tucmd, mss_l4len_idx); |
| 6352 | |
| 6353 | return (skb->ip_summed == CHECKSUM_PARTIAL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6354 | } |
| 6355 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6356 | static __le32 ixgbe_tx_cmd_type(u32 tx_flags) |
| 6357 | { |
| 6358 | /* set type for advanced descriptor with frame checksum insertion */ |
| 6359 | __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA | |
| 6360 | IXGBE_ADVTXD_DCMD_IFCS | |
| 6361 | IXGBE_ADVTXD_DCMD_DEXT); |
| 6362 | |
| 6363 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6364 | if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6365 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE); |
| 6366 | |
| 6367 | /* set segmentation enable bits for TSO/FSO */ |
| 6368 | #ifdef IXGBE_FCOE |
| 6369 | if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO)) |
| 6370 | #else |
| 6371 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6372 | #endif |
| 6373 | cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE); |
| 6374 | |
| 6375 | return cmd_type; |
| 6376 | } |
| 6377 | |
| 6378 | static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen) |
| 6379 | { |
| 6380 | __le32 olinfo_status = |
| 6381 | cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 6382 | |
| 6383 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 6384 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM | |
| 6385 | (1 << IXGBE_ADVTXD_IDX_SHIFT)); |
| 6386 | /* enble IPv4 checksum for TSO */ |
| 6387 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6388 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM); |
| 6389 | } |
| 6390 | |
| 6391 | /* enable L4 checksum for TSO and TX checksum offload */ |
| 6392 | if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6393 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM); |
| 6394 | |
| 6395 | #ifdef IXGBE_FCOE |
| 6396 | /* use index 1 context for FCOE/FSO */ |
| 6397 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 6398 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC | |
| 6399 | (1 << IXGBE_ADVTXD_IDX_SHIFT)); |
| 6400 | |
| 6401 | #endif |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6402 | /* |
| 6403 | * Check Context must be set if Tx switch is enabled, which it |
| 6404 | * always is for case where virtual functions are running |
| 6405 | */ |
| 6406 | if (tx_flags & IXGBE_TX_FLAGS_TXSW) |
| 6407 | olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC); |
| 6408 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6409 | return olinfo_status; |
| 6410 | } |
| 6411 | |
| 6412 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 6413 | IXGBE_TXD_CMD_RS) |
| 6414 | |
| 6415 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
| 6416 | struct sk_buff *skb, |
| 6417 | struct ixgbe_tx_buffer *first, |
| 6418 | u32 tx_flags, |
| 6419 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6420 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6421 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6422 | struct ixgbe_tx_buffer *tx_buffer_info; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6423 | union ixgbe_adv_tx_desc *tx_desc; |
| 6424 | dma_addr_t dma; |
| 6425 | __le32 cmd_type, olinfo_status; |
| 6426 | struct skb_frag_struct *frag; |
| 6427 | unsigned int f = 0; |
| 6428 | unsigned int data_len = skb->data_len; |
| 6429 | unsigned int size = skb_headlen(skb); |
| 6430 | u32 offset = 0; |
| 6431 | u32 paylen = skb->len - hdr_len; |
| 6432 | u16 i = tx_ring->next_to_use; |
| 6433 | u16 gso_segs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6434 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6435 | #ifdef IXGBE_FCOE |
| 6436 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6437 | if (data_len >= sizeof(struct fcoe_crc_eof)) { |
| 6438 | data_len -= sizeof(struct fcoe_crc_eof); |
| 6439 | } else { |
| 6440 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 6441 | data_len = 0; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6442 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6443 | } |
| 6444 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6445 | #endif |
| 6446 | dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE); |
| 6447 | if (dma_mapping_error(dev, dma)) |
| 6448 | goto dma_error; |
| 6449 | |
| 6450 | cmd_type = ixgbe_tx_cmd_type(tx_flags); |
| 6451 | olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen); |
| 6452 | |
| 6453 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
| 6454 | |
| 6455 | for (;;) { |
| 6456 | while (size > IXGBE_MAX_DATA_PER_TXD) { |
| 6457 | tx_desc->read.buffer_addr = cpu_to_le64(dma + offset); |
| 6458 | tx_desc->read.cmd_type_len = |
| 6459 | cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD); |
| 6460 | tx_desc->read.olinfo_status = olinfo_status; |
| 6461 | |
| 6462 | offset += IXGBE_MAX_DATA_PER_TXD; |
| 6463 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 6464 | |
| 6465 | tx_desc++; |
| 6466 | i++; |
| 6467 | if (i == tx_ring->count) { |
| 6468 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0); |
| 6469 | i = 0; |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6474 | tx_buffer_info->length = offset + size; |
| 6475 | tx_buffer_info->tx_flags = tx_flags; |
| 6476 | tx_buffer_info->dma = dma; |
| 6477 | |
| 6478 | tx_desc->read.buffer_addr = cpu_to_le64(dma + offset); |
| 6479 | tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size); |
| 6480 | tx_desc->read.olinfo_status = olinfo_status; |
| 6481 | |
| 6482 | if (!data_len) |
| 6483 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6484 | |
| 6485 | frag = &skb_shinfo(skb)->frags[f]; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6486 | #ifdef IXGBE_FCOE |
| 6487 | size = min_t(unsigned int, data_len, frag->size); |
| 6488 | #else |
| 6489 | size = frag->size; |
| 6490 | #endif |
| 6491 | data_len -= size; |
| 6492 | f++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6493 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6494 | offset = 0; |
| 6495 | tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6496 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6497 | dma = dma_map_page(dev, frag->page, frag->page_offset, |
| 6498 | size, DMA_TO_DEVICE); |
| 6499 | if (dma_mapping_error(dev, dma)) |
| 6500 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6501 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6502 | tx_desc++; |
| 6503 | i++; |
| 6504 | if (i == tx_ring->count) { |
| 6505 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0); |
| 6506 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6507 | } |
| 6508 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6509 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6510 | tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD); |
| 6511 | |
| 6512 | i++; |
| 6513 | if (i == tx_ring->count) |
| 6514 | i = 0; |
| 6515 | |
| 6516 | tx_ring->next_to_use = i; |
| 6517 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6518 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6519 | gso_segs = skb_shinfo(skb)->gso_segs; |
| 6520 | #ifdef IXGBE_FCOE |
| 6521 | /* adjust for FCoE Sequence Offload */ |
| 6522 | else if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6523 | gso_segs = DIV_ROUND_UP(skb->len - hdr_len, |
| 6524 | skb_shinfo(skb)->gso_size); |
| 6525 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6526 | else |
| 6527 | gso_segs = 1; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6528 | |
| 6529 | /* multiply data chunks by size of headers */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6530 | tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len); |
| 6531 | tx_buffer_info->gso_segs = gso_segs; |
| 6532 | tx_buffer_info->skb = skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6533 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6534 | /* set the timestamp */ |
| 6535 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6536 | |
| 6537 | /* |
| 6538 | * Force memory writes to complete before letting h/w |
| 6539 | * know there are new descriptors to fetch. (Only |
| 6540 | * applicable for weak-ordered memory model archs, |
| 6541 | * such as IA-64). |
| 6542 | */ |
| 6543 | wmb(); |
| 6544 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6545 | /* set next_to_watch value indicating a packet is present */ |
| 6546 | first->next_to_watch = tx_desc; |
| 6547 | |
| 6548 | /* notify HW of packet */ |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6549 | writel(i, tx_ring->tail); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6550 | |
| 6551 | return; |
| 6552 | dma_error: |
| 6553 | dev_err(dev, "TX DMA map failed\n"); |
| 6554 | |
| 6555 | /* clear dma mappings for failed tx_buffer_info map */ |
| 6556 | for (;;) { |
| 6557 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6558 | ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info); |
| 6559 | if (tx_buffer_info == first) |
| 6560 | break; |
| 6561 | if (i == 0) |
| 6562 | i = tx_ring->count; |
| 6563 | i--; |
| 6564 | } |
| 6565 | |
| 6566 | dev_kfree_skb_any(skb); |
| 6567 | |
| 6568 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6569 | } |
| 6570 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6571 | static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb, |
| 6572 | u32 tx_flags, __be16 protocol) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6573 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6574 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6575 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6576 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6577 | union { |
| 6578 | unsigned char *network; |
| 6579 | struct iphdr *ipv4; |
| 6580 | struct ipv6hdr *ipv6; |
| 6581 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6582 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6583 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6584 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6585 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6586 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6587 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6588 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6589 | /* do nothing if sampling is disabled */ |
| 6590 | if (!ring->atr_sample_rate) |
| 6591 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6592 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6593 | ring->atr_count++; |
| 6594 | |
| 6595 | /* snag network header to get L4 type and address */ |
| 6596 | hdr.network = skb_network_header(skb); |
| 6597 | |
| 6598 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 6599 | if ((protocol != __constant_htons(ETH_P_IPV6) || |
| 6600 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
| 6601 | (protocol != __constant_htons(ETH_P_IP) || |
| 6602 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6603 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6604 | |
| 6605 | th = tcp_hdr(skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6606 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6607 | /* skip this packet since it is invalid or the socket is closing */ |
| 6608 | if (!th || th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6609 | return; |
| 6610 | |
| 6611 | /* sample on all syn packets or once every atr sample count */ |
| 6612 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6613 | return; |
| 6614 | |
| 6615 | /* reset sample count */ |
| 6616 | ring->atr_count = 0; |
| 6617 | |
| 6618 | vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6619 | |
| 6620 | /* |
| 6621 | * src and dst are inverted, think how the receiver sees them |
| 6622 | * |
| 6623 | * The input is broken into two sections, a non-compressed section |
| 6624 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6625 | * is XORed together and stored in the compressed dword. |
| 6626 | */ |
| 6627 | input.formatted.vlan_id = vlan_id; |
| 6628 | |
| 6629 | /* |
| 6630 | * since src port and flex bytes occupy the same word XOR them together |
| 6631 | * and write the value to source port portion of compressed dword |
| 6632 | */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6633 | if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN)) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6634 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6635 | else |
| 6636 | common.port.src ^= th->dest ^ protocol; |
| 6637 | common.port.dst ^= th->source; |
| 6638 | |
| 6639 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6640 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6641 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6642 | } else { |
| 6643 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6644 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6645 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6646 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6647 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6648 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6649 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6650 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6651 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6652 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6653 | |
| 6654 | /* 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] | 6655 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6656 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6657 | } |
| 6658 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6659 | 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] | 6660 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6661 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6662 | /* Herbert's original patch had: |
| 6663 | * smp_mb__after_netif_stop_queue(); |
| 6664 | * but since that doesn't exist yet, just open code it. */ |
| 6665 | smp_mb(); |
| 6666 | |
| 6667 | /* We need to check again in a case another CPU has just |
| 6668 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6669 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6670 | return -EBUSY; |
| 6671 | |
| 6672 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6673 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6674 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6675 | return 0; |
| 6676 | } |
| 6677 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 6678 | 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] | 6679 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6680 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6681 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6682 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6683 | } |
| 6684 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6685 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 6686 | { |
| 6687 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 6688 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 6689 | smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6690 | #ifdef IXGBE_FCOE |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 6691 | __be16 protocol = vlan_get_protocol(skb); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6692 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6693 | if (((protocol == htons(ETH_P_FCOE)) || |
| 6694 | (protocol == htons(ETH_P_FIP))) && |
| 6695 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
| 6696 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 6697 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 6698 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6699 | } |
| 6700 | #endif |
| 6701 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6702 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 6703 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 6704 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6705 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6706 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6707 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6708 | return skb_tx_hash(dev, skb); |
| 6709 | } |
| 6710 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6711 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6712 | struct ixgbe_adapter *adapter, |
| 6713 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6714 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6715 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6716 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6717 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6718 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 6719 | unsigned short f; |
| 6720 | #endif |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6721 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6722 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6723 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6724 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6725 | /* |
| 6726 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
| 6727 | * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD, |
| 6728 | * + 2 desc gap to keep tail from touching head, |
| 6729 | * + 1 desc for context descriptor, |
| 6730 | * otherwise try next time |
| 6731 | */ |
| 6732 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 6733 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 6734 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 6735 | #else |
| 6736 | count += skb_shinfo(skb)->nr_frags; |
| 6737 | #endif |
| 6738 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 6739 | tx_ring->tx_stats.tx_busy++; |
| 6740 | return NETDEV_TX_BUSY; |
| 6741 | } |
| 6742 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6743 | #ifdef CONFIG_PCI_IOV |
| 6744 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 6745 | tx_flags |= IXGBE_TX_FLAGS_TXSW; |
| 6746 | |
| 6747 | #endif |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6748 | /* if we have a HW VLAN tag being added default to the HW one */ |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 6749 | if (vlan_tx_tag_present(skb)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6750 | tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6751 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 6752 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
| 6753 | } else if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 6754 | struct vlan_hdr *vhdr, _vhdr; |
| 6755 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 6756 | if (!vhdr) |
| 6757 | goto out_drop; |
| 6758 | |
| 6759 | protocol = vhdr->h_vlan_encapsulated_proto; |
| 6760 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6761 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6762 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6763 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6764 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 6765 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 6766 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6767 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
| 6768 | tx_flags |= tx_ring->dcb_tc << |
| 6769 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
| 6770 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 6771 | struct vlan_ethhdr *vhdr; |
| 6772 | if (skb_header_cloned(skb) && |
| 6773 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 6774 | goto out_drop; |
| 6775 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 6776 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 6777 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6778 | } else { |
| 6779 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 6780 | } |
| 6781 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6782 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6783 | /* record the location of the first descriptor for this packet */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6784 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6785 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6786 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6787 | /* setup tx offload for FCoE */ |
| 6788 | if ((protocol == __constant_htons(ETH_P_FCOE)) && |
| 6789 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6790 | tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len); |
| 6791 | if (tso < 0) |
| 6792 | goto out_drop; |
| 6793 | else if (tso) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6794 | tx_flags |= IXGBE_TX_FLAGS_FSO | |
| 6795 | IXGBE_TX_FLAGS_FCOE; |
| 6796 | else |
| 6797 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6798 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6799 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6800 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6801 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6802 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6803 | /* setup IPv4/IPv6 offloads */ |
| 6804 | if (protocol == __constant_htons(ETH_P_IP)) |
| 6805 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6806 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6807 | tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len); |
| 6808 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6809 | goto out_drop; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6810 | else if (tso) |
| 6811 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 6812 | else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol)) |
| 6813 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 6814 | |
| 6815 | /* add the ATR filter if ATR is on */ |
| 6816 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
| 6817 | ixgbe_atr(tx_ring, skb, tx_flags, protocol); |
| 6818 | |
| 6819 | #ifdef IXGBE_FCOE |
| 6820 | xmit_fcoe: |
| 6821 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6822 | ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len); |
| 6823 | |
| 6824 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6825 | |
| 6826 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6827 | |
| 6828 | out_drop: |
| 6829 | dev_kfree_skb_any(skb); |
| 6830 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6831 | } |
| 6832 | |
| 6833 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 6834 | { |
| 6835 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6836 | struct ixgbe_ring *tx_ring; |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6837 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6838 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
| 6839 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 6840 | } |
| 6841 | |
| 6842 | /** |
| 6843 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6844 | * @netdev: network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6845 | * @p: pointer to an address structure |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6846 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6847 | * Returns 0 on success, negative on failure |
| 6848 | **/ |
| 6849 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 6850 | { |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 6851 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6852 | struct ixgbe_hw *hw = &adapter->hw; |
| 6853 | struct sockaddr *addr = p; |
| 6854 | |
| 6855 | if (!is_valid_ether_addr(addr->sa_data)) |
| 6856 | return -EADDRNOTAVAIL; |
| 6857 | |
| 6858 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 6859 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
| 6860 | |
| 6861 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 6862 | IXGBE_RAH_AV); |
| 6863 | |
| 6864 | return 0; |
| 6865 | } |
| 6866 | |
| 6867 | static int |
| 6868 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 6869 | { |
| 6870 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6871 | struct ixgbe_hw *hw = &adapter->hw; |
| 6872 | u16 value; |
| 6873 | int rc; |
| 6874 | |
| 6875 | if (prtad != hw->phy.mdio.prtad) |
| 6876 | return -EINVAL; |
| 6877 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 6878 | if (!rc) |
| 6879 | rc = value; |
| 6880 | return rc; |
| 6881 | } |
| 6882 | |
| 6883 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 6884 | u16 addr, u16 value) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6885 | { |
| 6886 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 6887 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6888 | |
| 6889 | if (prtad != hw->phy.mdio.prtad) |
| 6890 | return -EINVAL; |
| 6891 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 6892 | } |
| 6893 | |
| 6894 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 6895 | { |
| 6896 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6897 | |
| 6898 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 6899 | } |
| 6900 | |
| 6901 | /** |
| 6902 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
| 6903 | * netdev->dev_addrs |
| 6904 | * @netdev: network interface device structure |
| 6905 | * |
| 6906 | * Returns non-zero on failure |
| 6907 | **/ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 6908 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6909 | { |
| 6910 | int err = 0; |
| 6911 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6912 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 6913 | |
| 6914 | if (is_valid_ether_addr(mac->san_addr)) { |
| 6915 | rtnl_lock(); |
| 6916 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 6917 | rtnl_unlock(); |
| 6918 | } |
| 6919 | return err; |
| 6920 | } |
| 6921 | |
| 6922 | /** |
| 6923 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
| 6924 | * netdev->dev_addrs |
| 6925 | * @netdev: network interface device structure |
| 6926 | * |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6927 | * Returns non-zero on failure |
| 6928 | **/ |
| 6929 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 6930 | { |
| 6931 | int err = 0; |
| 6932 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6933 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 6934 | |
| 6935 | if (is_valid_ether_addr(mac->san_addr)) { |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6936 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6937 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 6938 | rtnl_unlock(); |
| 6939 | } |
| 6940 | return err; |
| 6941 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6942 | |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6943 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6944 | /* |
| 6945 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 6946 | * without having to re-enable interrupts. It's not called while |
| 6947 | * the interrupt routine is executing. |
| 6948 | */ |
| 6949 | static void ixgbe_netpoll(struct net_device *netdev) |
| 6950 | { |
| 6951 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6952 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6953 | |
| 6954 | /* if interface is down do nothing */ |
| 6955 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 6956 | return; |
| 6957 | |
| 6958 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 6959 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6960 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 6961 | for (i = 0; i < num_q_vectors; i++) { |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 6962 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 6963 | ixgbe_msix_clean_many(0, q_vector); |
| 6964 | } |
| 6965 | } else { |
| 6966 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 6967 | } |
| 6968 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6969 | } |
| 6970 | #endif |
| 6971 | |
| 6972 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 6973 | struct rtnl_link_stats64 *stats) |
| 6974 | { |
| 6975 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6976 | int i; |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6977 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6978 | rcu_read_lock(); |
| 6979 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6980 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6981 | u64 bytes, packets; |
| 6982 | unsigned int start; |
| 6983 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6984 | if (ring) { |
| 6985 | do { |
| 6986 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 6987 | packets = ring->stats.packets; |
| 6988 | bytes = ring->stats.bytes; |
| 6989 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 6990 | stats->rx_packets += packets; |
| 6991 | stats->rx_bytes += bytes; |
| 6992 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6993 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 6994 | |
| 6995 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6996 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 6997 | u64 bytes, packets; |
| 6998 | unsigned int start; |
| 6999 | |
| 7000 | if (ring) { |
| 7001 | do { |
| 7002 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7003 | packets = ring->stats.packets; |
| 7004 | bytes = ring->stats.bytes; |
| 7005 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7006 | stats->tx_packets += packets; |
| 7007 | stats->tx_bytes += bytes; |
| 7008 | } |
| 7009 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7010 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7011 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7012 | stats->multicast = netdev->stats.multicast; |
| 7013 | stats->rx_errors = netdev->stats.rx_errors; |
| 7014 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7015 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7016 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7017 | return stats; |
| 7018 | } |
| 7019 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7020 | /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7021 | * #adapter: pointer to ixgbe_adapter |
| 7022 | * @tc: number of traffic classes currently enabled |
| 7023 | * |
| 7024 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7025 | * 802.1Q priority maps to a packet buffer that exists. |
| 7026 | */ |
| 7027 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7028 | { |
| 7029 | struct ixgbe_hw *hw = &adapter->hw; |
| 7030 | u32 reg, rsave; |
| 7031 | int i; |
| 7032 | |
| 7033 | /* 82598 have a static priority to TC mapping that can not |
| 7034 | * be changed so no validation is needed. |
| 7035 | */ |
| 7036 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7037 | return; |
| 7038 | |
| 7039 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7040 | rsave = reg; |
| 7041 | |
| 7042 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7043 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7044 | |
| 7045 | /* If up2tc is out of bounds default to zero */ |
| 7046 | if (up2tc > tc) |
| 7047 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7048 | } |
| 7049 | |
| 7050 | if (reg != rsave) |
| 7051 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7052 | |
| 7053 | return; |
| 7054 | } |
| 7055 | |
| 7056 | |
| 7057 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic |
| 7058 | * classes. |
| 7059 | * |
| 7060 | * @netdev: net device to configure |
| 7061 | * @tc: number of traffic classes to enable |
| 7062 | */ |
| 7063 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7064 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7065 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7066 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7067 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame^] | 7068 | /* Multiple traffic classes requires multiple queues */ |
| 7069 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 7070 | e_err(drv, "Enable failed, needs MSI-X\n"); |
| 7071 | return -EINVAL; |
| 7072 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7073 | |
| 7074 | /* Hardware supports up to 8 traffic classes */ |
| 7075 | if (tc > MAX_TRAFFIC_CLASS || |
| 7076 | (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS)) |
| 7077 | return -EINVAL; |
| 7078 | |
| 7079 | /* Hardware has to reinitialize queues and interrupts to |
| 7080 | * match packet buffer alignment. Unfortunantly, the |
| 7081 | * hardware is not flexible enough to do this dynamically. |
| 7082 | */ |
| 7083 | if (netif_running(dev)) |
| 7084 | ixgbe_close(dev); |
| 7085 | ixgbe_clear_interrupt_scheme(adapter); |
| 7086 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame^] | 7087 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7088 | netdev_set_num_tc(dev, tc); |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame^] | 7089 | adapter->last_lfc_mode = adapter->hw.fc.current_mode; |
| 7090 | |
| 7091 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
| 7092 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7093 | |
| 7094 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 7095 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
| 7096 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7097 | netdev_reset_tc(dev); |
| 7098 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame^] | 7099 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
| 7100 | |
| 7101 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 7102 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7103 | |
| 7104 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 7105 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 7106 | } |
| 7107 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7108 | ixgbe_init_interrupt_scheme(adapter); |
| 7109 | ixgbe_validate_rtr(adapter, tc); |
| 7110 | if (netif_running(dev)) |
| 7111 | ixgbe_open(dev); |
| 7112 | |
| 7113 | return 0; |
| 7114 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7115 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7116 | void ixgbe_do_reset(struct net_device *netdev) |
| 7117 | { |
| 7118 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7119 | |
| 7120 | if (netif_running(netdev)) |
| 7121 | ixgbe_reinit_locked(adapter); |
| 7122 | else |
| 7123 | ixgbe_reset(adapter); |
| 7124 | } |
| 7125 | |
| 7126 | static u32 ixgbe_fix_features(struct net_device *netdev, u32 data) |
| 7127 | { |
| 7128 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7129 | |
| 7130 | #ifdef CONFIG_DCB |
| 7131 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 7132 | data &= ~NETIF_F_HW_VLAN_RX; |
| 7133 | #endif |
| 7134 | |
| 7135 | /* return error if RXHASH is being enabled when RSS is not supported */ |
| 7136 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 7137 | data &= ~NETIF_F_RXHASH; |
| 7138 | |
| 7139 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
| 7140 | if (!(data & NETIF_F_RXCSUM)) |
| 7141 | data &= ~NETIF_F_LRO; |
| 7142 | |
| 7143 | /* Turn off LRO if not RSC capable or invalid ITR settings */ |
| 7144 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) { |
| 7145 | data &= ~NETIF_F_LRO; |
| 7146 | } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
| 7147 | (adapter->rx_itr_setting != 1 && |
| 7148 | adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) { |
| 7149 | data &= ~NETIF_F_LRO; |
| 7150 | e_info(probe, "rx-usecs set too low, not enabling RSC\n"); |
| 7151 | } |
| 7152 | |
| 7153 | return data; |
| 7154 | } |
| 7155 | |
| 7156 | static int ixgbe_set_features(struct net_device *netdev, u32 data) |
| 7157 | { |
| 7158 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7159 | bool need_reset = false; |
| 7160 | |
| 7161 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
| 7162 | if (!(data & NETIF_F_RXCSUM)) |
| 7163 | adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED; |
| 7164 | else |
| 7165 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 7166 | |
| 7167 | /* Make sure RSC matches LRO, reset if change */ |
| 7168 | if (!!(data & NETIF_F_LRO) != |
| 7169 | !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 7170 | adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED; |
| 7171 | switch (adapter->hw.mac.type) { |
| 7172 | case ixgbe_mac_X540: |
| 7173 | case ixgbe_mac_82599EB: |
| 7174 | need_reset = true; |
| 7175 | break; |
| 7176 | default: |
| 7177 | break; |
| 7178 | } |
| 7179 | } |
| 7180 | |
| 7181 | /* |
| 7182 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 7183 | * the state changed, we need to reset. |
| 7184 | */ |
| 7185 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { |
| 7186 | /* turn off ATR, enable perfect filters and reset */ |
| 7187 | if (data & NETIF_F_NTUPLE) { |
| 7188 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7189 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7190 | need_reset = true; |
| 7191 | } |
| 7192 | } else if (!(data & NETIF_F_NTUPLE)) { |
| 7193 | /* turn off Flow Director, set ATR and reset */ |
| 7194 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7195 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 7196 | !(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 7197 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7198 | need_reset = true; |
| 7199 | } |
| 7200 | |
| 7201 | if (need_reset) |
| 7202 | ixgbe_do_reset(netdev); |
| 7203 | |
| 7204 | return 0; |
| 7205 | |
| 7206 | } |
| 7207 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7208 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7209 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7210 | .ndo_stop = ixgbe_close, |
| 7211 | .ndo_start_xmit = ixgbe_xmit_frame, |
| 7212 | .ndo_select_queue = ixgbe_select_queue, |
| 7213 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7214 | .ndo_validate_addr = eth_validate_addr, |
| 7215 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7216 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7217 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7218 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7219 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7220 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7221 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7222 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7223 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
| 7224 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7225 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7226 | .ndo_setup_tc = ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7227 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7228 | .ndo_poll_controller = ixgbe_netpoll, |
| 7229 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7230 | #ifdef IXGBE_FCOE |
| 7231 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7232 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7233 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7234 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7235 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7236 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7237 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7238 | .ndo_set_features = ixgbe_set_features, |
| 7239 | .ndo_fix_features = ixgbe_fix_features, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7240 | }; |
| 7241 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7242 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 7243 | const struct ixgbe_info *ii) |
| 7244 | { |
| 7245 | #ifdef CONFIG_PCI_IOV |
| 7246 | struct ixgbe_hw *hw = &adapter->hw; |
| 7247 | int err; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 7248 | int num_vf_macvlans, i; |
| 7249 | struct vf_macvlans *mv_list; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7250 | |
Greg Rose | 3377eba79 | 2010-12-07 08:16:45 +0000 | [diff] [blame] | 7251 | if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs) |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7252 | return; |
| 7253 | |
| 7254 | /* The 82599 supports up to 64 VFs per physical function |
| 7255 | * but this implementation limits allocation to 63 so that |
| 7256 | * basic networking resources are still available to the |
| 7257 | * physical function |
| 7258 | */ |
| 7259 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
| 7260 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
| 7261 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 7262 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7263 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7264 | goto err_novfs; |
| 7265 | } |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 7266 | |
| 7267 | num_vf_macvlans = hw->mac.num_rar_entries - |
| 7268 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); |
| 7269 | |
| 7270 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, |
| 7271 | sizeof(struct vf_macvlans), |
| 7272 | GFP_KERNEL); |
| 7273 | if (mv_list) { |
| 7274 | /* Initialize list of VF macvlans */ |
| 7275 | INIT_LIST_HEAD(&adapter->vf_mvs.l); |
| 7276 | for (i = 0; i < num_vf_macvlans; i++) { |
| 7277 | mv_list->vf = -1; |
| 7278 | mv_list->free = true; |
| 7279 | mv_list->rar_entry = hw->mac.num_rar_entries - |
| 7280 | (i + adapter->num_vfs + 1); |
| 7281 | list_add(&mv_list->l, &adapter->vf_mvs.l); |
| 7282 | mv_list++; |
| 7283 | } |
| 7284 | } |
| 7285 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7286 | /* If call to enable VFs succeeded then allocate memory |
| 7287 | * for per VF control structures. |
| 7288 | */ |
| 7289 | adapter->vfinfo = |
| 7290 | kcalloc(adapter->num_vfs, |
| 7291 | sizeof(struct vf_data_storage), GFP_KERNEL); |
| 7292 | if (adapter->vfinfo) { |
| 7293 | /* Now that we're sure SR-IOV is enabled |
| 7294 | * and memory allocated set up the mailbox parameters |
| 7295 | */ |
| 7296 | ixgbe_init_mbx_params_pf(hw); |
| 7297 | memcpy(&hw->mbx.ops, ii->mbx_ops, |
| 7298 | sizeof(hw->mbx.ops)); |
| 7299 | |
| 7300 | /* Disable RSC when in SR-IOV mode */ |
| 7301 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | |
| 7302 | IXGBE_FLAG2_RSC_ENABLED); |
| 7303 | return; |
| 7304 | } |
| 7305 | |
| 7306 | /* Oh oh */ |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7307 | e_err(probe, "Unable to allocate memory for VF Data Storage - " |
| 7308 | "SRIOV disabled\n"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7309 | pci_disable_sriov(adapter->pdev); |
| 7310 | |
| 7311 | err_novfs: |
| 7312 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 7313 | adapter->num_vfs = 0; |
| 7314 | #endif /* CONFIG_PCI_IOV */ |
| 7315 | } |
| 7316 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7317 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7318 | * ixgbe_probe - Device Initialization Routine |
| 7319 | * @pdev: PCI device information struct |
| 7320 | * @ent: entry in ixgbe_pci_tbl |
| 7321 | * |
| 7322 | * Returns 0 on success, negative on failure |
| 7323 | * |
| 7324 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7325 | * The OS initialization, configuring of the adapter private structure, |
| 7326 | * and a hardware reset occur. |
| 7327 | **/ |
| 7328 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7329 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7330 | { |
| 7331 | struct net_device *netdev; |
| 7332 | struct ixgbe_adapter *adapter = NULL; |
| 7333 | struct ixgbe_hw *hw; |
| 7334 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7335 | static int cards_found; |
| 7336 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7337 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7338 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7339 | #ifdef IXGBE_FCOE |
| 7340 | u16 device_caps; |
| 7341 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7342 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7343 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7344 | /* Catch broken hardware that put the wrong VF device ID in |
| 7345 | * the PCIe SR-IOV capability. |
| 7346 | */ |
| 7347 | if (pdev->is_virtfn) { |
| 7348 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7349 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7350 | return -EINVAL; |
| 7351 | } |
| 7352 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7353 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7354 | if (err) |
| 7355 | return err; |
| 7356 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7357 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7358 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7359 | pci_using_dac = 1; |
| 7360 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7361 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7362 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7363 | err = dma_set_coherent_mask(&pdev->dev, |
| 7364 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7365 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7366 | dev_err(&pdev->dev, |
| 7367 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7368 | goto err_dma; |
| 7369 | } |
| 7370 | } |
| 7371 | pci_using_dac = 0; |
| 7372 | } |
| 7373 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7374 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7375 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7376 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7377 | dev_err(&pdev->dev, |
| 7378 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7379 | goto err_pci_reg; |
| 7380 | } |
| 7381 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7382 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7383 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7384 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7385 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7386 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7387 | #ifdef CONFIG_IXGBE_DCB |
| 7388 | indices *= MAX_TRAFFIC_CLASS; |
| 7389 | #endif |
| 7390 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7391 | if (ii->mac == ixgbe_mac_82598EB) |
| 7392 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7393 | else |
| 7394 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7395 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7396 | #ifdef IXGBE_FCOE |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7397 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7398 | IXGBE_MAX_FCOE_INDICES); |
| 7399 | #endif |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7400 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7401 | if (!netdev) { |
| 7402 | err = -ENOMEM; |
| 7403 | goto err_alloc_etherdev; |
| 7404 | } |
| 7405 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7406 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7407 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7408 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7409 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7410 | |
| 7411 | adapter->netdev = netdev; |
| 7412 | adapter->pdev = pdev; |
| 7413 | hw = &adapter->hw; |
| 7414 | hw->back = adapter; |
| 7415 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 7416 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7417 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7418 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7419 | if (!hw->hw_addr) { |
| 7420 | err = -EIO; |
| 7421 | goto err_ioremap; |
| 7422 | } |
| 7423 | |
| 7424 | for (i = 1; i <= 5; i++) { |
| 7425 | if (pci_resource_len(pdev, i) == 0) |
| 7426 | continue; |
| 7427 | } |
| 7428 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7429 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7430 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7431 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7432 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7433 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7434 | adapter->bd_number = cards_found; |
| 7435 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7436 | /* Setup hw api */ |
| 7437 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7438 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7439 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7440 | /* EEPROM */ |
| 7441 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7442 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7443 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7444 | if (!(eec & (1 << 8))) |
| 7445 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7446 | |
| 7447 | /* PHY */ |
| 7448 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7449 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7450 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7451 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7452 | hw->phy.mdio.mmds = 0; |
| 7453 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7454 | hw->phy.mdio.dev = netdev; |
| 7455 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7456 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7457 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7458 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7459 | |
| 7460 | /* setup the private structure */ |
| 7461 | err = ixgbe_sw_init(adapter); |
| 7462 | if (err) |
| 7463 | goto err_sw_init; |
| 7464 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7465 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7466 | switch (adapter->hw.mac.type) { |
| 7467 | case ixgbe_mac_82599EB: |
| 7468 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7469 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7470 | break; |
| 7471 | default: |
| 7472 | break; |
| 7473 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7474 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7475 | /* |
| 7476 | * If there is a fan on this device and it has failed log the |
| 7477 | * failure. |
| 7478 | */ |
| 7479 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7480 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7481 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7482 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7483 | } |
| 7484 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7485 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7486 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7487 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7488 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7489 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7490 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7491 | err = 0; |
| 7492 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7493 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7494 | "module type was detected.\n"); |
| 7495 | e_dev_err("Reload the driver after installing a supported " |
| 7496 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7497 | goto err_sw_init; |
| 7498 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7499 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7500 | goto err_sw_init; |
| 7501 | } |
| 7502 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7503 | ixgbe_probe_vf(adapter, ii); |
| 7504 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7505 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7506 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7507 | NETIF_F_IPV6_CSUM | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7508 | NETIF_F_HW_VLAN_TX | |
| 7509 | NETIF_F_HW_VLAN_RX | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7510 | NETIF_F_HW_VLAN_FILTER | |
| 7511 | NETIF_F_TSO | |
| 7512 | NETIF_F_TSO6 | |
| 7513 | NETIF_F_GRO | |
| 7514 | NETIF_F_RXHASH | |
| 7515 | NETIF_F_RXCSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7516 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7517 | netdev->hw_features = netdev->features; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7518 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7519 | switch (adapter->hw.mac.type) { |
| 7520 | case ixgbe_mac_82599EB: |
| 7521 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7522 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7523 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 7524 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7525 | break; |
| 7526 | default: |
| 7527 | break; |
| 7528 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7529 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7530 | netdev->vlan_features |= NETIF_F_TSO; |
| 7531 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7532 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7533 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7534 | netdev->vlan_features |= NETIF_F_SG; |
| 7535 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 7536 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 7537 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7538 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7539 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 7540 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7541 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7542 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7543 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7544 | #endif |
| 7545 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7546 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7547 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7548 | if (hw->mac.ops.get_device_caps) { |
| 7549 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7550 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7551 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7552 | } |
| 7553 | } |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7554 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
| 7555 | netdev->vlan_features |= NETIF_F_FCOE_CRC; |
| 7556 | netdev->vlan_features |= NETIF_F_FSO; |
| 7557 | netdev->vlan_features |= NETIF_F_FCOE_MTU; |
| 7558 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7559 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7560 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7561 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7562 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7563 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7564 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7565 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 7566 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7567 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7568 | netdev->features |= NETIF_F_LRO; |
| 7569 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7570 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7571 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7572 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7573 | err = -EIO; |
| 7574 | goto err_eeprom; |
| 7575 | } |
| 7576 | |
| 7577 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7578 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7579 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7580 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7581 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7582 | err = -EIO; |
| 7583 | goto err_eeprom; |
| 7584 | } |
| 7585 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 7586 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 7587 | if (hw->mac.ops.disable_tx_laser && |
| 7588 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 7589 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 7590 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 7591 | hw->mac.ops.disable_tx_laser(hw); |
| 7592 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7593 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
| 7594 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7595 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7596 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7597 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7598 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7599 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7600 | if (err) |
| 7601 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7602 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7603 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
| 7604 | netdev->hw_features &= ~NETIF_F_RXHASH; |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7605 | netdev->features &= ~NETIF_F_RXHASH; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7606 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7607 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7608 | switch (pdev->device) { |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7609 | case IXGBE_DEV_ID_82599_SFP: |
| 7610 | /* Only this subdevice supports WOL */ |
| 7611 | if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7612 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7613 | break; |
Alexander Duyck | 50d6c68 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 7614 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7615 | /* All except this subdevice support WOL */ |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7616 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7617 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7618 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7619 | case IXGBE_DEV_ID_82599_KX4: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7620 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7621 | break; |
| 7622 | default: |
| 7623 | adapter->wol = 0; |
| 7624 | break; |
| 7625 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7626 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7627 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7628 | /* pick up the PCI bus settings for reporting later */ |
| 7629 | hw->mac.ops.get_bus_info(hw); |
| 7630 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7631 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7632 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7633 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7634 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7635 | "Unknown"), |
| 7636 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7637 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7638 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7639 | "Unknown"), |
| 7640 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7641 | |
| 7642 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7643 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7644 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7645 | 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] | 7646 | 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] | 7647 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7648 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7649 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7650 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7651 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7652 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7653 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7654 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7655 | "not sufficient for optimal performance.\n"); |
| 7656 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7657 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7658 | } |
| 7659 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 7660 | /* save off EEPROM version number */ |
| 7661 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 7662 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7663 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7664 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7665 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7666 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7667 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7668 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7669 | "Please be aware there may be issues associated " |
| 7670 | "with your hardware. If you are experiencing " |
| 7671 | "problems please contact your Intel or hardware " |
| 7672 | "representative who provided you with this " |
| 7673 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7674 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7675 | strcpy(netdev->name, "eth%d"); |
| 7676 | err = register_netdev(netdev); |
| 7677 | if (err) |
| 7678 | goto err_register; |
| 7679 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 7680 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7681 | netif_carrier_off(netdev); |
| 7682 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7683 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 7684 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7685 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7686 | ixgbe_setup_dca(adapter); |
| 7687 | } |
| 7688 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7689 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7690 | 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] | 7691 | for (i = 0; i < adapter->num_vfs; i++) |
| 7692 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 7693 | } |
| 7694 | |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 7695 | /* Inform firmware of driver version */ |
| 7696 | if (hw->mac.ops.set_fw_drv_ver) |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 7697 | hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD, |
| 7698 | FW_CEM_UNUSED_VER); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 7699 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7700 | /* add san mac addr to netdev */ |
| 7701 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7702 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7703 | e_dev_info("Intel(R) 10 Gigabit Network Connection\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7704 | cards_found++; |
| 7705 | return 0; |
| 7706 | |
| 7707 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7708 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7709 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7710 | err_sw_init: |
| 7711 | err_eeprom: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7712 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7713 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7714 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7715 | iounmap(hw->hw_addr); |
| 7716 | err_ioremap: |
| 7717 | free_netdev(netdev); |
| 7718 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7719 | pci_release_selected_regions(pdev, |
| 7720 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7721 | err_pci_reg: |
| 7722 | err_dma: |
| 7723 | pci_disable_device(pdev); |
| 7724 | return err; |
| 7725 | } |
| 7726 | |
| 7727 | /** |
| 7728 | * ixgbe_remove - Device Removal Routine |
| 7729 | * @pdev: PCI device information struct |
| 7730 | * |
| 7731 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 7732 | * that it should release a PCI device. The could be caused by a |
| 7733 | * Hot-Plug event, or because the driver is going to be removed from |
| 7734 | * memory. |
| 7735 | **/ |
| 7736 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 7737 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7738 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7739 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7740 | |
| 7741 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7742 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7743 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7744 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7745 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 7746 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 7747 | dca_remove_requester(&pdev->dev); |
| 7748 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 7749 | } |
| 7750 | |
| 7751 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7752 | #ifdef IXGBE_FCOE |
| 7753 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7754 | ixgbe_cleanup_fcoe(adapter); |
| 7755 | |
| 7756 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7757 | |
| 7758 | /* remove the added san mac */ |
| 7759 | ixgbe_del_sanmac_netdev(netdev); |
| 7760 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7761 | if (netdev->reg_state == NETREG_REGISTERED) |
| 7762 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7763 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7764 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7765 | ixgbe_disable_sriov(adapter); |
| 7766 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7767 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7768 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7769 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7770 | |
| 7771 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7772 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7773 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7774 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7775 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7776 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7777 | free_netdev(netdev); |
| 7778 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7779 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7780 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7781 | pci_disable_device(pdev); |
| 7782 | } |
| 7783 | |
| 7784 | /** |
| 7785 | * ixgbe_io_error_detected - called when PCI error is detected |
| 7786 | * @pdev: Pointer to PCI device |
| 7787 | * @state: The current pci connection state |
| 7788 | * |
| 7789 | * This function is called after a PCI bus error affecting |
| 7790 | * this device has been detected. |
| 7791 | */ |
| 7792 | 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] | 7793 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7794 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7795 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7796 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7797 | |
| 7798 | netif_device_detach(netdev); |
| 7799 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 7800 | if (state == pci_channel_io_perm_failure) |
| 7801 | return PCI_ERS_RESULT_DISCONNECT; |
| 7802 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7803 | if (netif_running(netdev)) |
| 7804 | ixgbe_down(adapter); |
| 7805 | pci_disable_device(pdev); |
| 7806 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7807 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7808 | return PCI_ERS_RESULT_NEED_RESET; |
| 7809 | } |
| 7810 | |
| 7811 | /** |
| 7812 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 7813 | * @pdev: Pointer to PCI device |
| 7814 | * |
| 7815 | * Restart the card from scratch, as if from a cold-boot. |
| 7816 | */ |
| 7817 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 7818 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7819 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7820 | pci_ers_result_t result; |
| 7821 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7822 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7823 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7824 | 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] | 7825 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7826 | } else { |
| 7827 | pci_set_master(pdev); |
| 7828 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 7829 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7830 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 7831 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7832 | |
| 7833 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 7834 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7835 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7836 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7837 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7838 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7839 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7840 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 7841 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7842 | /* non-fatal, continue */ |
| 7843 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7844 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7845 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7846 | } |
| 7847 | |
| 7848 | /** |
| 7849 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 7850 | * @pdev: Pointer to PCI device |
| 7851 | * |
| 7852 | * This callback is called when the error recovery driver tells us that |
| 7853 | * its OK to resume normal operation. |
| 7854 | */ |
| 7855 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 7856 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7857 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7858 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7859 | |
| 7860 | if (netif_running(netdev)) { |
| 7861 | if (ixgbe_up(adapter)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7862 | e_info(probe, "ixgbe_up failed after reset\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7863 | return; |
| 7864 | } |
| 7865 | } |
| 7866 | |
| 7867 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7868 | } |
| 7869 | |
| 7870 | static struct pci_error_handlers ixgbe_err_handler = { |
| 7871 | .error_detected = ixgbe_io_error_detected, |
| 7872 | .slot_reset = ixgbe_io_slot_reset, |
| 7873 | .resume = ixgbe_io_resume, |
| 7874 | }; |
| 7875 | |
| 7876 | static struct pci_driver ixgbe_driver = { |
| 7877 | .name = ixgbe_driver_name, |
| 7878 | .id_table = ixgbe_pci_tbl, |
| 7879 | .probe = ixgbe_probe, |
| 7880 | .remove = __devexit_p(ixgbe_remove), |
| 7881 | #ifdef CONFIG_PM |
| 7882 | .suspend = ixgbe_suspend, |
| 7883 | .resume = ixgbe_resume, |
| 7884 | #endif |
| 7885 | .shutdown = ixgbe_shutdown, |
| 7886 | .err_handler = &ixgbe_err_handler |
| 7887 | }; |
| 7888 | |
| 7889 | /** |
| 7890 | * ixgbe_init_module - Driver Registration Routine |
| 7891 | * |
| 7892 | * ixgbe_init_module is the first routine called when the driver is |
| 7893 | * loaded. All it does is register with the PCI subsystem. |
| 7894 | **/ |
| 7895 | static int __init ixgbe_init_module(void) |
| 7896 | { |
| 7897 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 7898 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7899 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7900 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7901 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7902 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7903 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7904 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7905 | ret = pci_register_driver(&ixgbe_driver); |
| 7906 | return ret; |
| 7907 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7908 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7909 | module_init(ixgbe_init_module); |
| 7910 | |
| 7911 | /** |
| 7912 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 7913 | * |
| 7914 | * ixgbe_exit_module is called just before the driver is removed |
| 7915 | * from memory. |
| 7916 | **/ |
| 7917 | static void __exit ixgbe_exit_module(void) |
| 7918 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7919 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7920 | dca_unregister_notify(&dca_notifier); |
| 7921 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7922 | pci_unregister_driver(&ixgbe_driver); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7923 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7924 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7925 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7926 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7927 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7928 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7929 | { |
| 7930 | int ret_val; |
| 7931 | |
| 7932 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7933 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7934 | |
| 7935 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 7936 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7937 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 7938 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7939 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7940 | module_exit(ixgbe_exit_module); |
| 7941 | |
| 7942 | /* ixgbe_main.c */ |