Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2011 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 35 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 36 | #include <linux/ip.h> |
| 37 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 38 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 39 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 40 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 42 | #include <net/checksum.h> |
| 43 | #include <net/ip6_checksum.h> |
| 44 | #include <linux/ethtool.h> |
| 45 | #include <linux/if_vlan.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 46 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 47 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 48 | |
| 49 | #include "ixgbe.h" |
| 50 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 51 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 52 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 53 | |
| 54 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 55 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 56 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 57 | #define MAJ 3 |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 58 | #define MIN 4 |
Don Skidmore | c89c711 | 2011-04-14 07:40:11 +0000 | [diff] [blame] | 59 | #define BUILD 8 |
Jeff Kirsher | 75e3d3c | 2011-03-17 18:11:38 +0000 | [diff] [blame] | 60 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 61 | __stringify(BUILD) "-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 62 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 63 | static const char ixgbe_copyright[] = |
| 64 | "Copyright (c) 1999-2011 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 65 | |
| 66 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 67 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 68 | [board_82599] = &ixgbe_82599_info, |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 69 | [board_X540] = &ixgbe_X540_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 73 | * |
| 74 | * Wildcard entries (PCI_ANY_ID) should come last |
| 75 | * Last entry must be all 0s |
| 76 | * |
| 77 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 78 | * Class, Class Mask, private data (not used) } |
| 79 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 80 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 82 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 84 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 86 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 88 | board_82598 }, |
Peter P Waskiewicz Jr | 3845bec | 2009-07-16 15:50:52 +0000 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), |
| 90 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 92 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 94 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 96 | board_82598 }, |
| 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 98 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 100 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 102 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 104 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 106 | board_82599 }, |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
| 108 | board_82599 }, |
Don Skidmore | 74757d4 | 2009-12-08 07:22:23 +0000 | [diff] [blame] | 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), |
| 110 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 112 | board_82599 }, |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame] | 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
| 114 | board_82599 }, |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
| 116 | board_82599 }, |
Peter P Waskiewicz Jr | 8911184 | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
| 118 | board_82599 }, |
Don Skidmore | dbffcb2 | 2010-12-03 03:32:34 +0000 | [diff] [blame] | 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), |
| 120 | board_82599 }, |
| 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), |
| 122 | board_82599 }, |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), |
| 124 | board_82599 }, |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
| 126 | board_82599 }, |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), |
Don Skidmore | d994653 | 2010-12-09 06:55:19 +0000 | [diff] [blame] | 128 | board_X540 }, |
Emil Tantilov | 4c40ef0 | 2011-03-24 07:06:02 +0000 | [diff] [blame] | 129 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), |
| 130 | board_82599 }, |
Don Skidmore | 4f6290c | 2011-05-14 06:36:35 +0000 | [diff] [blame] | 131 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), |
| 132 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 133 | |
| 134 | /* required last entry */ |
| 135 | {0, } |
| 136 | }; |
| 137 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 138 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 139 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 140 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 141 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 142 | static struct notifier_block dca_notifier = { |
| 143 | .notifier_call = ixgbe_notify_dca, |
| 144 | .next = NULL, |
| 145 | .priority = 0 |
| 146 | }; |
| 147 | #endif |
| 148 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 149 | #ifdef CONFIG_PCI_IOV |
| 150 | static unsigned int max_vfs; |
| 151 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 152 | MODULE_PARM_DESC(max_vfs, |
| 153 | "Maximum number of virtual functions to allocate per physical function"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 154 | #endif /* CONFIG_PCI_IOV */ |
| 155 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 156 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 157 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 158 | MODULE_LICENSE("GPL"); |
| 159 | MODULE_VERSION(DRV_VERSION); |
| 160 | |
| 161 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 162 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 163 | static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) |
| 164 | { |
| 165 | struct ixgbe_hw *hw = &adapter->hw; |
| 166 | u32 gcr; |
| 167 | u32 gpie; |
| 168 | u32 vmdctl; |
| 169 | |
| 170 | #ifdef CONFIG_PCI_IOV |
| 171 | /* disable iov and allow time for transactions to clear */ |
| 172 | pci_disable_sriov(adapter->pdev); |
| 173 | #endif |
| 174 | |
| 175 | /* turn off device IOV mode */ |
| 176 | gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 177 | gcr &= ~(IXGBE_GCR_EXT_SRIOV); |
| 178 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr); |
| 179 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 180 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 181 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 182 | |
| 183 | /* set default pool back to 0 */ |
| 184 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 185 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
| 186 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame^] | 187 | IXGBE_WRITE_FLUSH(hw); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 188 | |
| 189 | /* take a breather then clean up driver data */ |
| 190 | msleep(100); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 191 | |
| 192 | kfree(adapter->vfinfo); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 193 | adapter->vfinfo = NULL; |
| 194 | |
| 195 | adapter->num_vfs = 0; |
| 196 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 197 | } |
| 198 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 199 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 200 | { |
| 201 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
| 202 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
| 203 | schedule_work(&adapter->service_task); |
| 204 | } |
| 205 | |
| 206 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 207 | { |
| 208 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 209 | |
| 210 | /* flush memory to make sure state is correct before next watchog */ |
| 211 | smp_mb__before_clear_bit(); |
| 212 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 213 | } |
| 214 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 215 | struct ixgbe_reg_info { |
| 216 | u32 ofs; |
| 217 | char *name; |
| 218 | }; |
| 219 | |
| 220 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 221 | |
| 222 | /* General Registers */ |
| 223 | {IXGBE_CTRL, "CTRL"}, |
| 224 | {IXGBE_STATUS, "STATUS"}, |
| 225 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 226 | |
| 227 | /* Interrupt Registers */ |
| 228 | {IXGBE_EICR, "EICR"}, |
| 229 | |
| 230 | /* RX Registers */ |
| 231 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 232 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 233 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 234 | {IXGBE_RDH(0), "RDH"}, |
| 235 | {IXGBE_RDT(0), "RDT"}, |
| 236 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 237 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 238 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 239 | |
| 240 | /* TX Registers */ |
| 241 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 242 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 243 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 244 | {IXGBE_TDH(0), "TDH"}, |
| 245 | {IXGBE_TDT(0), "TDT"}, |
| 246 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 247 | |
| 248 | /* List Terminator */ |
| 249 | {} |
| 250 | }; |
| 251 | |
| 252 | |
| 253 | /* |
| 254 | * ixgbe_regdump - register printout routine |
| 255 | */ |
| 256 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 257 | { |
| 258 | int i = 0, j = 0; |
| 259 | char rname[16]; |
| 260 | u32 regs[64]; |
| 261 | |
| 262 | switch (reginfo->ofs) { |
| 263 | case IXGBE_SRRCTL(0): |
| 264 | for (i = 0; i < 64; i++) |
| 265 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 266 | break; |
| 267 | case IXGBE_DCA_RXCTRL(0): |
| 268 | for (i = 0; i < 64; i++) |
| 269 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 270 | break; |
| 271 | case IXGBE_RDLEN(0): |
| 272 | for (i = 0; i < 64; i++) |
| 273 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 274 | break; |
| 275 | case IXGBE_RDH(0): |
| 276 | for (i = 0; i < 64; i++) |
| 277 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 278 | break; |
| 279 | case IXGBE_RDT(0): |
| 280 | for (i = 0; i < 64; i++) |
| 281 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 282 | break; |
| 283 | case IXGBE_RXDCTL(0): |
| 284 | for (i = 0; i < 64; i++) |
| 285 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 286 | break; |
| 287 | case IXGBE_RDBAL(0): |
| 288 | for (i = 0; i < 64; i++) |
| 289 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 290 | break; |
| 291 | case IXGBE_RDBAH(0): |
| 292 | for (i = 0; i < 64; i++) |
| 293 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 294 | break; |
| 295 | case IXGBE_TDBAL(0): |
| 296 | for (i = 0; i < 64; i++) |
| 297 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 298 | break; |
| 299 | case IXGBE_TDBAH(0): |
| 300 | for (i = 0; i < 64; i++) |
| 301 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 302 | break; |
| 303 | case IXGBE_TDLEN(0): |
| 304 | for (i = 0; i < 64; i++) |
| 305 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 306 | break; |
| 307 | case IXGBE_TDH(0): |
| 308 | for (i = 0; i < 64; i++) |
| 309 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 310 | break; |
| 311 | case IXGBE_TDT(0): |
| 312 | for (i = 0; i < 64; i++) |
| 313 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 314 | break; |
| 315 | case IXGBE_TXDCTL(0): |
| 316 | for (i = 0; i < 64; i++) |
| 317 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 318 | break; |
| 319 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 320 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 321 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | for (i = 0; i < 8; i++) { |
| 326 | 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] | 327 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 328 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 329 | pr_cont(" %08x", regs[i*8+j]); |
| 330 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 337 | */ |
| 338 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 339 | { |
| 340 | struct net_device *netdev = adapter->netdev; |
| 341 | struct ixgbe_hw *hw = &adapter->hw; |
| 342 | struct ixgbe_reg_info *reginfo; |
| 343 | int n = 0; |
| 344 | struct ixgbe_ring *tx_ring; |
| 345 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 346 | union ixgbe_adv_tx_desc *tx_desc; |
| 347 | struct my_u0 { u64 a; u64 b; } *u0; |
| 348 | struct ixgbe_ring *rx_ring; |
| 349 | union ixgbe_adv_rx_desc *rx_desc; |
| 350 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 351 | u32 staterr; |
| 352 | int i = 0; |
| 353 | |
| 354 | if (!netif_msg_hw(adapter)) |
| 355 | return; |
| 356 | |
| 357 | /* Print netdevice Info */ |
| 358 | if (netdev) { |
| 359 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 360 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 361 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 362 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 363 | netdev->name, |
| 364 | netdev->state, |
| 365 | netdev->trans_start, |
| 366 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /* Print Registers */ |
| 370 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 371 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 372 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 373 | reginfo->name; reginfo++) { |
| 374 | ixgbe_regdump(hw, reginfo); |
| 375 | } |
| 376 | |
| 377 | /* Print TX Ring Summary */ |
| 378 | if (!netdev || !netif_running(netdev)) |
| 379 | goto exit; |
| 380 | |
| 381 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 382 | pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 383 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 384 | tx_ring = adapter->tx_ring[n]; |
| 385 | tx_buffer_info = |
| 386 | &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 387 | pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 388 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 389 | (u64)tx_buffer_info->dma, |
| 390 | tx_buffer_info->length, |
| 391 | tx_buffer_info->next_to_watch, |
| 392 | (u64)tx_buffer_info->time_stamp); |
| 393 | } |
| 394 | |
| 395 | /* Print TX Rings */ |
| 396 | if (!netif_msg_tx_done(adapter)) |
| 397 | goto rx_ring_summary; |
| 398 | |
| 399 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 400 | |
| 401 | /* Transmit Descriptor Formats |
| 402 | * |
| 403 | * Advanced Transmit Descriptor |
| 404 | * +--------------------------------------------------------------+ |
| 405 | * 0 | Buffer Address [63:0] | |
| 406 | * +--------------------------------------------------------------+ |
| 407 | * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
| 408 | * +--------------------------------------------------------------+ |
| 409 | * 63 46 45 40 39 36 35 32 31 24 23 20 19 0 |
| 410 | */ |
| 411 | |
| 412 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 413 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 414 | pr_info("------------------------------------\n"); |
| 415 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 416 | pr_info("------------------------------------\n"); |
| 417 | pr_info("T [desc] [address 63:0 ] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 418 | "[PlPOIdStDDt Ln] [bi->dma ] " |
| 419 | "leng ntw timestamp bi->skb\n"); |
| 420 | |
| 421 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 422 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 423 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 424 | u0 = (struct my_u0 *)tx_desc; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 425 | pr_info("T [0x%03X] %016llX %016llX %016llX" |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 426 | " %04X %3X %016llX %p", i, |
| 427 | le64_to_cpu(u0->a), |
| 428 | le64_to_cpu(u0->b), |
| 429 | (u64)tx_buffer_info->dma, |
| 430 | tx_buffer_info->length, |
| 431 | tx_buffer_info->next_to_watch, |
| 432 | (u64)tx_buffer_info->time_stamp, |
| 433 | tx_buffer_info->skb); |
| 434 | if (i == tx_ring->next_to_use && |
| 435 | i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 436 | pr_cont(" NTC/U\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 437 | else if (i == tx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 438 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 439 | else if (i == tx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 440 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 441 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 442 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 443 | |
| 444 | if (netif_msg_pktdata(adapter) && |
| 445 | tx_buffer_info->dma != 0) |
| 446 | print_hex_dump(KERN_INFO, "", |
| 447 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 448 | phys_to_virt(tx_buffer_info->dma), |
| 449 | tx_buffer_info->length, true); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /* Print RX Rings Summary */ |
| 454 | rx_ring_summary: |
| 455 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 456 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 457 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 458 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 459 | pr_info("%5d %5X %5X\n", |
| 460 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /* Print RX Rings */ |
| 464 | if (!netif_msg_rx_status(adapter)) |
| 465 | goto exit; |
| 466 | |
| 467 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 468 | |
| 469 | /* Advanced Receive Descriptor (Read) Format |
| 470 | * 63 1 0 |
| 471 | * +-----------------------------------------------------+ |
| 472 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 473 | * +----------------------------------------------+------+ |
| 474 | * 8 | Header Buffer Address [63:1] | DD | |
| 475 | * +-----------------------------------------------------+ |
| 476 | * |
| 477 | * |
| 478 | * Advanced Receive Descriptor (Write-Back) Format |
| 479 | * |
| 480 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 481 | * +------------------------------------------------------+ |
| 482 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | |
| 483 | * | Checksum Ident | | | | Type | Type | |
| 484 | * +------------------------------------------------------+ |
| 485 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 486 | * +------------------------------------------------------+ |
| 487 | * 63 48 47 32 31 20 19 0 |
| 488 | */ |
| 489 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 490 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 491 | pr_info("------------------------------------\n"); |
| 492 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 493 | pr_info("------------------------------------\n"); |
| 494 | pr_info("R [desc] [ PktBuf A0] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 495 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " |
| 496 | "<-- Adv Rx Read format\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 497 | pr_info("RWB[desc] [PcsmIpSHl PtRs] " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 498 | "[vl er S cks ln] ---------------- [bi->skb] " |
| 499 | "<-- Adv Rx Write-Back format\n"); |
| 500 | |
| 501 | for (i = 0; i < rx_ring->count; i++) { |
| 502 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 503 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 504 | u0 = (struct my_u0 *)rx_desc; |
| 505 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 506 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 507 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 508 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 509 | "%016llX ---------------- %p", i, |
| 510 | le64_to_cpu(u0->a), |
| 511 | le64_to_cpu(u0->b), |
| 512 | rx_buffer_info->skb); |
| 513 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 514 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 515 | "%016llX %016llX %p", i, |
| 516 | le64_to_cpu(u0->a), |
| 517 | le64_to_cpu(u0->b), |
| 518 | (u64)rx_buffer_info->dma, |
| 519 | rx_buffer_info->skb); |
| 520 | |
| 521 | if (netif_msg_pktdata(adapter)) { |
| 522 | print_hex_dump(KERN_INFO, "", |
| 523 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 524 | phys_to_virt(rx_buffer_info->dma), |
| 525 | rx_ring->rx_buf_len, true); |
| 526 | |
| 527 | if (rx_ring->rx_buf_len |
| 528 | < IXGBE_RXBUFFER_2048) |
| 529 | print_hex_dump(KERN_INFO, "", |
| 530 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 531 | phys_to_virt( |
| 532 | rx_buffer_info->page_dma + |
| 533 | rx_buffer_info->page_offset |
| 534 | ), |
| 535 | PAGE_SIZE/2, true); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 540 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 541 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 542 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 543 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 544 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 545 | |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | exit: |
| 550 | return; |
| 551 | } |
| 552 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 553 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 554 | { |
| 555 | u32 ctrl_ext; |
| 556 | |
| 557 | /* Let firmware take over control of h/w */ |
| 558 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 559 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 560 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 564 | { |
| 565 | u32 ctrl_ext; |
| 566 | |
| 567 | /* Let firmware know the driver has taken over */ |
| 568 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 569 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 570 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 571 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 572 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 573 | /* |
| 574 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 575 | * @adapter: pointer to adapter struct |
| 576 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 577 | * @queue: queue to map the corresponding interrupt to |
| 578 | * @msix_vector: the vector to map to the corresponding queue |
| 579 | * |
| 580 | */ |
| 581 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 582 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 583 | { |
| 584 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 585 | struct ixgbe_hw *hw = &adapter->hw; |
| 586 | switch (hw->mac.type) { |
| 587 | case ixgbe_mac_82598EB: |
| 588 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 589 | if (direction == -1) |
| 590 | direction = 0; |
| 591 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 592 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 593 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 594 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 595 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 596 | break; |
| 597 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 598 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 599 | if (direction == -1) { |
| 600 | /* other causes */ |
| 601 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 602 | index = ((queue & 1) * 8); |
| 603 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 604 | ivar &= ~(0xFF << index); |
| 605 | ivar |= (msix_vector << index); |
| 606 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 607 | break; |
| 608 | } else { |
| 609 | /* tx or rx causes */ |
| 610 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 611 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 612 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 613 | ivar &= ~(0xFF << index); |
| 614 | ivar |= (msix_vector << index); |
| 615 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 616 | break; |
| 617 | } |
| 618 | default: |
| 619 | break; |
| 620 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 623 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 624 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 625 | { |
| 626 | u32 mask; |
| 627 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 628 | switch (adapter->hw.mac.type) { |
| 629 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 630 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 631 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 632 | break; |
| 633 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 634 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 635 | mask = (qmask & 0xFFFFFFFF); |
| 636 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 637 | mask = (qmask >> 32); |
| 638 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 639 | break; |
| 640 | default: |
| 641 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 645 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring, |
| 646 | struct ixgbe_tx_buffer *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 647 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 648 | if (tx_buffer_info->dma) { |
| 649 | if (tx_buffer_info->mapped_as_page) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 650 | dma_unmap_page(tx_ring->dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 651 | tx_buffer_info->dma, |
| 652 | tx_buffer_info->length, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 653 | DMA_TO_DEVICE); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 654 | else |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 655 | dma_unmap_single(tx_ring->dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 656 | tx_buffer_info->dma, |
| 657 | tx_buffer_info->length, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 658 | DMA_TO_DEVICE); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 659 | tx_buffer_info->dma = 0; |
| 660 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 661 | if (tx_buffer_info->skb) { |
| 662 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 663 | tx_buffer_info->skb = NULL; |
| 664 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 665 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 666 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 667 | } |
| 668 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 669 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 670 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 671 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 672 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 673 | u32 data = 0; |
| 674 | u32 xoff[8] = {0}; |
| 675 | int i; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 676 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 677 | if ((hw->fc.current_mode == ixgbe_fc_full) || |
| 678 | (hw->fc.current_mode == ixgbe_fc_rx_pause)) { |
| 679 | switch (hw->mac.type) { |
| 680 | case ixgbe_mac_82598EB: |
| 681 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 682 | break; |
| 683 | default: |
| 684 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 685 | } |
| 686 | hwstats->lxoffrxc += data; |
| 687 | |
| 688 | /* refill credits (no tx hang) if we received xoff */ |
| 689 | if (!data) |
| 690 | return; |
| 691 | |
| 692 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 693 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 694 | &adapter->tx_ring[i]->state); |
| 695 | return; |
| 696 | } else if (!(adapter->dcb_cfg.pfc_mode_enable)) |
| 697 | return; |
| 698 | |
| 699 | /* update stats for each tc, only valid with PFC enabled */ |
| 700 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
| 701 | switch (hw->mac.type) { |
| 702 | case ixgbe_mac_82598EB: |
| 703 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
| 704 | break; |
| 705 | default: |
| 706 | xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
| 707 | } |
| 708 | hwstats->pxoffrxc[i] += xoff[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 709 | } |
| 710 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 711 | /* disarm tx queues that have received xoff frames */ |
| 712 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 713 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | fb5475f | 2011-04-26 07:26:36 +0000 | [diff] [blame] | 714 | u8 tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 715 | |
| 716 | if (xoff[tc]) |
| 717 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 722 | { |
| 723 | return ring->tx_stats.completed; |
| 724 | } |
| 725 | |
| 726 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 727 | { |
| 728 | struct ixgbe_adapter *adapter = netdev_priv(ring->netdev); |
| 729 | struct ixgbe_hw *hw = &adapter->hw; |
| 730 | |
| 731 | u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 732 | u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
| 733 | |
| 734 | if (head != tail) |
| 735 | return (head < tail) ? |
| 736 | tail - head : (tail + ring->count - head); |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 742 | { |
| 743 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 744 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 745 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 746 | bool ret = false; |
| 747 | |
| 748 | clear_check_for_tx_hang(tx_ring); |
| 749 | |
| 750 | /* |
| 751 | * Check for a hung queue, but be thorough. This verifies |
| 752 | * that a transmit has been completed since the previous |
| 753 | * check AND there is at least one packet pending. The |
| 754 | * ARMED bit is set to indicate a potential hang. The |
| 755 | * bit is cleared if a pause frame is received to remove |
| 756 | * false hang detection due to PFC or 802.3x frames. By |
| 757 | * requiring this to fail twice we avoid races with |
| 758 | * pfc clearing the ARMED bit and conditions where we |
| 759 | * run the check_tx_hang logic with a transmit completion |
| 760 | * pending but without time to complete it yet. |
| 761 | */ |
| 762 | if ((tx_done_old == tx_done) && tx_pending) { |
| 763 | /* make sure it is true for two checks in a row */ |
| 764 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 765 | &tx_ring->state); |
| 766 | } else { |
| 767 | /* update completed stats and continue */ |
| 768 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 769 | /* reset the countdown */ |
| 770 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 771 | } |
| 772 | |
| 773 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 776 | /** |
| 777 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 778 | * @adapter: driver private struct |
| 779 | **/ |
| 780 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 781 | { |
| 782 | |
| 783 | /* Do the reset outside of interrupt context */ |
| 784 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 785 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
| 786 | ixgbe_service_event_schedule(adapter); |
| 787 | } |
| 788 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 789 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 790 | /** |
| 791 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 792 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 793 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 794 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 795 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 796 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 797 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 798 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 799 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 800 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 801 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 802 | u16 i, eop, count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 803 | |
| 804 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 805 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 806 | eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 807 | |
| 808 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 809 | (count < q_vector->tx.work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 810 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 811 | rmb(); /* read buffer_info after eop_desc */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 812 | for ( ; !cleaned; count++) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 813 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 814 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 815 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 816 | tx_desc->wb.status = 0; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 817 | cleaned = (i == eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 818 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 819 | i++; |
| 820 | if (i == tx_ring->count) |
| 821 | i = 0; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 822 | |
| 823 | if (cleaned && tx_buffer_info->skb) { |
| 824 | total_bytes += tx_buffer_info->bytecount; |
| 825 | total_packets += tx_buffer_info->gso_segs; |
| 826 | } |
| 827 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 828 | ixgbe_unmap_and_free_tx_resource(tx_ring, |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 829 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 830 | } |
| 831 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 832 | tx_ring->tx_stats.completed++; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 833 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 834 | eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 835 | } |
| 836 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 837 | tx_ring->next_to_clean = i; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 838 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 839 | tx_ring->stats.packets += total_packets; |
| 840 | u64_stats_update_begin(&tx_ring->syncp); |
| 841 | q_vector->tx.total_bytes += total_bytes; |
| 842 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 843 | u64_stats_update_end(&tx_ring->syncp); |
| 844 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 845 | 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] | 846 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 847 | struct ixgbe_hw *hw = &adapter->hw; |
| 848 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop); |
| 849 | e_err(drv, "Detected Tx Unit Hang\n" |
| 850 | " Tx Queue <%d>\n" |
| 851 | " TDH, TDT <%x>, <%x>\n" |
| 852 | " next_to_use <%x>\n" |
| 853 | " next_to_clean <%x>\n" |
| 854 | "tx_buffer_info[next_to_clean]\n" |
| 855 | " time_stamp <%lx>\n" |
| 856 | " jiffies <%lx>\n", |
| 857 | tx_ring->queue_index, |
| 858 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 859 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
| 860 | tx_ring->next_to_use, eop, |
| 861 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
| 862 | |
| 863 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 864 | |
| 865 | e_info(probe, |
| 866 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 867 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 868 | |
| 869 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 870 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 871 | |
| 872 | /* the adapter is about to reset, no point in enabling stuff */ |
| 873 | return true; |
| 874 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 875 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 876 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 877 | if (unlikely(count && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 878 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 879 | /* Make sure that anybody stopping the queue after this |
| 880 | * sees the new next_to_clean. |
| 881 | */ |
| 882 | smp_mb(); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 883 | if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) && |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 884 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 885 | netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 886 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 887 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 888 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 889 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 890 | return count < q_vector->tx.work_limit; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 893 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 894 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 895 | struct ixgbe_ring *rx_ring, |
| 896 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 897 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 898 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 899 | u32 rxctrl; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 900 | u8 reg_idx = rx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 901 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 902 | rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx)); |
| 903 | switch (hw->mac.type) { |
| 904 | case ixgbe_mac_82598EB: |
| 905 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 906 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 907 | break; |
| 908 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 909 | case ixgbe_mac_X540: |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 910 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 911 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 912 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 913 | break; |
| 914 | default: |
| 915 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 916 | } |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 917 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 918 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
| 919 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 920 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 924 | struct ixgbe_ring *tx_ring, |
| 925 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 926 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 927 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 928 | u32 txctrl; |
| 929 | u8 reg_idx = tx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 930 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 931 | switch (hw->mac.type) { |
| 932 | case ixgbe_mac_82598EB: |
| 933 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx)); |
| 934 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 935 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 936 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 937 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl); |
| 938 | break; |
| 939 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 940 | case ixgbe_mac_X540: |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 941 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx)); |
| 942 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 943 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 944 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 945 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 946 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl); |
| 947 | break; |
| 948 | default: |
| 949 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 950 | } |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 954 | { |
| 955 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 956 | int cpu = get_cpu(); |
| 957 | long r_idx; |
| 958 | int i; |
| 959 | |
| 960 | if (q_vector->cpu == cpu) |
| 961 | goto out_no_update; |
| 962 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 963 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
| 964 | for (i = 0; i < q_vector->tx.count; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 965 | ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 966 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 967 | r_idx + 1); |
| 968 | } |
| 969 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 970 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
| 971 | for (i = 0; i < q_vector->rx.count; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 972 | ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 973 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 974 | r_idx + 1); |
| 975 | } |
| 976 | |
| 977 | q_vector->cpu = cpu; |
| 978 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 979 | put_cpu(); |
| 980 | } |
| 981 | |
| 982 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 983 | { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 984 | int num_q_vectors; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 985 | int i; |
| 986 | |
| 987 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 988 | return; |
| 989 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 990 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 991 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 992 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 993 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 994 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 995 | else |
| 996 | num_q_vectors = 1; |
| 997 | |
| 998 | for (i = 0; i < num_q_vectors; i++) { |
| 999 | adapter->q_vector[i]->cpu = -1; |
| 1000 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1005 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1006 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1007 | unsigned long event = *(unsigned long *)data; |
| 1008 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1009 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 1010 | return 0; |
| 1011 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1012 | switch (event) { |
| 1013 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1014 | /* if we're already enabled, don't do it again */ |
| 1015 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1016 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1017 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1018 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1019 | ixgbe_setup_dca(adapter); |
| 1020 | break; |
| 1021 | } |
| 1022 | /* Fall Through since DCA is disabled. */ |
| 1023 | case DCA_PROVIDER_REMOVE: |
| 1024 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1025 | dca_remove_requester(dev); |
| 1026 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 1027 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 1028 | } |
| 1029 | break; |
| 1030 | } |
| 1031 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1032 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1033 | } |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1034 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1035 | |
| 1036 | static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc, |
| 1037 | struct sk_buff *skb) |
| 1038 | { |
| 1039 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
| 1040 | } |
| 1041 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1042 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1043 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
| 1044 | * @adapter: address of board private structure |
| 1045 | * @rx_desc: advanced rx descriptor |
| 1046 | * |
| 1047 | * Returns : true if it is FCoE pkt |
| 1048 | */ |
| 1049 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter, |
| 1050 | union ixgbe_adv_rx_desc *rx_desc) |
| 1051 | { |
| 1052 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1053 | |
| 1054 | return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 1055 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1056 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1057 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1058 | } |
| 1059 | |
| 1060 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1061 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 1062 | * @adapter: board private structure |
| 1063 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1064 | * @status: hardware indication of status of receive |
| 1065 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 1066 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1067 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1068 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1069 | struct sk_buff *skb, u8 status, |
| 1070 | struct ixgbe_ring *ring, |
| 1071 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1072 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1073 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1074 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1075 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 1076 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1077 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 1078 | if (is_vlan && (tag & VLAN_VID_MASK)) |
| 1079 | __vlan_hwaccel_put_tag(skb, tag); |
| 1080 | |
| 1081 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
| 1082 | napi_gro_receive(napi, skb); |
| 1083 | else |
| 1084 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1087 | /** |
| 1088 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 1089 | * @adapter: address of board private structure |
| 1090 | * @status_err: hardware indication of status of receive |
| 1091 | * @skb: skb currently being received and modified |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1092 | * @status_err: status error value of last descriptor in packet |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1093 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1094 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1095 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1096 | struct sk_buff *skb, |
| 1097 | u32 status_err) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1098 | { |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1099 | skb->ip_summed = CHECKSUM_NONE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1100 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1101 | /* Rx csum disabled */ |
| 1102 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1103 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1104 | |
| 1105 | /* if IP and error */ |
| 1106 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 1107 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1108 | adapter->hw_csum_rx_error++; |
| 1109 | return; |
| 1110 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1111 | |
| 1112 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 1113 | return; |
| 1114 | |
| 1115 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1116 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1117 | |
| 1118 | /* |
| 1119 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1120 | * checksum errors. |
| 1121 | */ |
| 1122 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 1123 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 1124 | return; |
| 1125 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1126 | adapter->hw_csum_rx_error++; |
| 1127 | return; |
| 1128 | } |
| 1129 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1130 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1131 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1134 | 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] | 1135 | { |
| 1136 | /* |
| 1137 | * Force memory writes to complete before letting h/w |
| 1138 | * know there are new descriptors to fetch. (Only |
| 1139 | * applicable for weak-ordered memory model archs, |
| 1140 | * such as IA-64). |
| 1141 | */ |
| 1142 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1143 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1146 | /** |
| 1147 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1148 | * @rx_ring: ring to place buffers on |
| 1149 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1150 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1151 | 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] | 1152 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1153 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1154 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1155 | struct sk_buff *skb; |
| 1156 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1157 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1158 | /* do nothing if no valid netdev defined */ |
| 1159 | if (!rx_ring->netdev) |
| 1160 | return; |
| 1161 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1162 | while (cleaned_count--) { |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1163 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1164 | bi = &rx_ring->rx_buffer_info[i]; |
| 1165 | skb = bi->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1166 | |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1167 | if (!skb) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1168 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1169 | rx_ring->rx_buf_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1170 | if (!skb) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1171 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1172 | goto no_buffers; |
| 1173 | } |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1174 | /* initialize queue mapping */ |
| 1175 | skb_record_rx_queue(skb, rx_ring->queue_index); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1176 | bi->skb = skb; |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1177 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1178 | |
Alexander Duyck | d716a7d | 2010-08-19 13:33:41 +0000 | [diff] [blame] | 1179 | if (!bi->dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1180 | bi->dma = dma_map_single(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1181 | skb->data, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1182 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 1183 | DMA_FROM_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1184 | if (dma_mapping_error(rx_ring->dev, bi->dma)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1185 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1186 | bi->dma = 0; |
| 1187 | goto no_buffers; |
| 1188 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1189 | } |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1190 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1191 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1192 | if (!bi->page) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1193 | bi->page = netdev_alloc_page(rx_ring->netdev); |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1194 | if (!bi->page) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1195 | rx_ring->rx_stats.alloc_rx_page_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1196 | goto no_buffers; |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | if (!bi->page_dma) { |
| 1201 | /* use a half page if we're re-using */ |
| 1202 | bi->page_offset ^= PAGE_SIZE / 2; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1203 | bi->page_dma = dma_map_page(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1204 | bi->page, |
| 1205 | bi->page_offset, |
| 1206 | PAGE_SIZE / 2, |
| 1207 | DMA_FROM_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1208 | if (dma_mapping_error(rx_ring->dev, |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1209 | bi->page_dma)) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1210 | rx_ring->rx_stats.alloc_rx_page_failed++; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1211 | bi->page_dma = 0; |
| 1212 | goto no_buffers; |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | /* Refresh the desc even if buffer_addrs didn't change |
| 1217 | * because each write-back erases this info. */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1218 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 1219 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1220 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1221 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1222 | rx_desc->read.hdr_addr = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | i++; |
| 1226 | if (i == rx_ring->count) |
| 1227 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1228 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1229 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1230 | no_buffers: |
| 1231 | if (rx_ring->next_to_use != i) { |
| 1232 | rx_ring->next_to_use = i; |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1233 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1234 | } |
| 1235 | } |
| 1236 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1237 | 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] | 1238 | { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1239 | /* HW will not DMA in data larger than the given buffer, even if it |
| 1240 | * parses the (NFS, of course) header to be larger. In that case, it |
| 1241 | * fills the header buffer and spills the rest into the page. |
| 1242 | */ |
| 1243 | u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info); |
| 1244 | u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
| 1245 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
| 1246 | if (hlen > IXGBE_RX_HDR_SIZE) |
| 1247 | hlen = IXGBE_RX_HDR_SIZE; |
| 1248 | return hlen; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1251 | /** |
| 1252 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 1253 | * @skb: pointer to the last skb in the rsc queue |
| 1254 | * |
| 1255 | * This function changes a queue full of hw rsc buffers into a completed |
| 1256 | * packet. It uses the ->prev pointers to find the first packet and then |
| 1257 | * turns it into the frag list owner. |
| 1258 | **/ |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1259 | 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] | 1260 | { |
| 1261 | unsigned int frag_list_size = 0; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1262 | unsigned int skb_cnt = 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1263 | |
| 1264 | while (skb->prev) { |
| 1265 | struct sk_buff *prev = skb->prev; |
| 1266 | frag_list_size += skb->len; |
| 1267 | skb->prev = NULL; |
| 1268 | skb = prev; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1269 | skb_cnt++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | skb_shinfo(skb)->frag_list = skb->next; |
| 1273 | skb->next = NULL; |
| 1274 | skb->len += frag_list_size; |
| 1275 | skb->data_len += frag_list_size; |
| 1276 | skb->truesize += frag_list_size; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1277 | IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt; |
| 1278 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1279 | return skb; |
| 1280 | } |
| 1281 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1282 | static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc) |
| 1283 | { |
| 1284 | return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 1285 | IXGBE_RXDADV_RSCCNT_MASK); |
| 1286 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1287 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1288 | static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1289 | struct ixgbe_ring *rx_ring, |
| 1290 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1291 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1292 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1293 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 1294 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 1295 | struct sk_buff *skb; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1296 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1297 | const int current_node = numa_node_id(); |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1298 | #ifdef IXGBE_FCOE |
| 1299 | int ddp_bytes = 0; |
| 1300 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1301 | u32 staterr; |
| 1302 | u16 i; |
| 1303 | u16 cleaned_count = 0; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1304 | bool pkt_is_rsc = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1305 | |
| 1306 | i = rx_ring->next_to_clean; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1307 | rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1308 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1309 | |
| 1310 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1311 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1312 | |
Milton Miller | 3c945e5 | 2010-02-19 17:44:42 +0000 | [diff] [blame] | 1313 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1314 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1315 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 1316 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1317 | skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1318 | rx_buffer_info->skb = NULL; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1319 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1320 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1321 | if (ring_is_rsc_enabled(rx_ring)) |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1322 | pkt_is_rsc = ixgbe_get_rsc_state(rx_desc); |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1323 | |
| 1324 | /* if this is a skb from previous receive DMA will be 0 */ |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 1325 | if (rx_buffer_info->dma) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1326 | u16 hlen; |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1327 | if (pkt_is_rsc && |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1328 | !(staterr & IXGBE_RXD_STAT_EOP) && |
| 1329 | !skb->prev) { |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1330 | /* |
| 1331 | * When HWRSC is enabled, delay unmapping |
| 1332 | * of the first packet. It carries the |
| 1333 | * header information, HW may still |
| 1334 | * access the header after the writeback. |
| 1335 | * Only unmap it when EOP is reached |
| 1336 | */ |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1337 | IXGBE_RSC_CB(skb)->delay_unmap = true; |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1338 | IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1339 | } else { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1340 | dma_unmap_single(rx_ring->dev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1341 | rx_buffer_info->dma, |
| 1342 | rx_ring->rx_buf_len, |
| 1343 | DMA_FROM_DEVICE); |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 1344 | } |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 1345 | rx_buffer_info->dma = 0; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1346 | |
| 1347 | if (ring_is_ps_enabled(rx_ring)) { |
| 1348 | hlen = ixgbe_get_hlen(rx_desc); |
| 1349 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
| 1350 | } else { |
| 1351 | hlen = le16_to_cpu(rx_desc->wb.upper.length); |
| 1352 | } |
| 1353 | |
| 1354 | skb_put(skb, hlen); |
| 1355 | } else { |
| 1356 | /* assume packet split since header is unmapped */ |
| 1357 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | if (upper_len) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1361 | dma_unmap_page(rx_ring->dev, |
| 1362 | rx_buffer_info->page_dma, |
| 1363 | PAGE_SIZE / 2, |
| 1364 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1365 | rx_buffer_info->page_dma = 0; |
| 1366 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1367 | rx_buffer_info->page, |
| 1368 | rx_buffer_info->page_offset, |
| 1369 | upper_len); |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1370 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1371 | if ((page_count(rx_buffer_info->page) == 1) && |
| 1372 | (page_to_nid(rx_buffer_info->page) == current_node)) |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1373 | get_page(rx_buffer_info->page); |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1374 | else |
| 1375 | rx_buffer_info->page = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1376 | |
| 1377 | skb->len += upper_len; |
| 1378 | skb->data_len += upper_len; |
| 1379 | skb->truesize += upper_len; |
| 1380 | } |
| 1381 | |
| 1382 | i++; |
| 1383 | if (i == rx_ring->count) |
| 1384 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1385 | |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 1386 | next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1387 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1388 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1389 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1390 | if (pkt_is_rsc) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1391 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 1392 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 1393 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1394 | } else { |
| 1395 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 1396 | } |
| 1397 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1398 | if (!(staterr & IXGBE_RXD_STAT_EOP)) { |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 1399 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1400 | rx_buffer_info->skb = next_buffer->skb; |
| 1401 | rx_buffer_info->dma = next_buffer->dma; |
| 1402 | next_buffer->skb = skb; |
| 1403 | next_buffer->dma = 0; |
| 1404 | } else { |
| 1405 | skb->next = next_buffer->skb; |
| 1406 | skb->next->prev = skb; |
| 1407 | } |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1408 | rx_ring->rx_stats.non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1409 | goto next_desc; |
| 1410 | } |
| 1411 | |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1412 | if (skb->prev) { |
| 1413 | skb = ixgbe_transform_rsc_queue(skb); |
| 1414 | /* if we got here without RSC the packet is invalid */ |
| 1415 | if (!pkt_is_rsc) { |
| 1416 | __pskb_trim(skb, 0); |
| 1417 | rx_buffer_info->skb = skb; |
| 1418 | goto next_desc; |
| 1419 | } |
| 1420 | } |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1421 | |
| 1422 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1423 | if (IXGBE_RSC_CB(skb)->delay_unmap) { |
| 1424 | dma_unmap_single(rx_ring->dev, |
| 1425 | IXGBE_RSC_CB(skb)->dma, |
| 1426 | rx_ring->rx_buf_len, |
| 1427 | DMA_FROM_DEVICE); |
| 1428 | IXGBE_RSC_CB(skb)->dma = 0; |
| 1429 | IXGBE_RSC_CB(skb)->delay_unmap = false; |
| 1430 | } |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1431 | } |
| 1432 | if (pkt_is_rsc) { |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1433 | if (ring_is_ps_enabled(rx_ring)) |
| 1434 | rx_ring->rx_stats.rsc_count += |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1435 | skb_shinfo(skb)->nr_frags; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1436 | else |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1437 | rx_ring->rx_stats.rsc_count += |
| 1438 | IXGBE_RSC_CB(skb)->skb_cnt; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1439 | rx_ring->rx_stats.rsc_flush++; |
| 1440 | } |
| 1441 | |
| 1442 | /* ERR_MASK will only have valid bits if EOP set */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1443 | if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) { |
| 1444 | dev_kfree_skb_any(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1445 | goto next_desc; |
| 1446 | } |
| 1447 | |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1448 | ixgbe_rx_checksum(adapter, rx_desc, skb, staterr); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1449 | if (adapter->netdev->features & NETIF_F_RXHASH) |
| 1450 | ixgbe_rx_hash(rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1451 | |
| 1452 | /* probably a little skewed due to removing CRC */ |
| 1453 | total_rx_bytes += skb->len; |
| 1454 | total_rx_packets++; |
| 1455 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1456 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1457 | #ifdef IXGBE_FCOE |
| 1458 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1459 | if (ixgbe_rx_is_fcoe(adapter, rx_desc)) { |
| 1460 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb, |
| 1461 | staterr); |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1462 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1463 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1464 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 1465 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 1466 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1467 | |
| 1468 | next_desc: |
| 1469 | rx_desc->wb.upper.status_error = 0; |
| 1470 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1471 | (*work_done)++; |
| 1472 | if (*work_done >= work_to_do) |
| 1473 | break; |
| 1474 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1475 | /* return some buffers to hardware, one at a time is too slow */ |
| 1476 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1477 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1478 | cleaned_count = 0; |
| 1479 | } |
| 1480 | |
| 1481 | /* use prefetched values */ |
| 1482 | rx_desc = next_rxd; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1483 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1486 | rx_ring->next_to_clean = i; |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1487 | cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1488 | |
| 1489 | if (cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1490 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1491 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1492 | #ifdef IXGBE_FCOE |
| 1493 | /* include DDPed FCoE data */ |
| 1494 | if (ddp_bytes > 0) { |
| 1495 | unsigned int mss; |
| 1496 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1497 | mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) - |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1498 | sizeof(struct fc_frame_header) - |
| 1499 | sizeof(struct fcoe_crc_eof); |
| 1500 | if (mss > 512) |
| 1501 | mss &= ~511; |
| 1502 | total_rx_bytes += ddp_bytes; |
| 1503 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1504 | } |
| 1505 | #endif /* IXGBE_FCOE */ |
| 1506 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 1507 | u64_stats_update_begin(&rx_ring->syncp); |
| 1508 | rx_ring->stats.packets += total_rx_packets; |
| 1509 | rx_ring->stats.bytes += total_rx_bytes; |
| 1510 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1511 | q_vector->rx.total_packets += total_rx_packets; |
| 1512 | q_vector->rx.total_bytes += total_rx_bytes; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1515 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1516 | /** |
| 1517 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1518 | * @adapter: board private structure |
| 1519 | * |
| 1520 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1521 | * interrupts. |
| 1522 | **/ |
| 1523 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1524 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1525 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1526 | int i, q_vectors, v_idx, r_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1527 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1528 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1529 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1530 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1531 | /* |
| 1532 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1533 | * corresponding register. |
| 1534 | */ |
| 1535 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1536 | q_vector = adapter->q_vector[v_idx]; |
Akinobu Mita | 984b3f5 | 2010-03-05 13:41:37 -0800 | [diff] [blame] | 1537 | /* XXX for_each_set_bit(...) */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1538 | r_idx = find_first_bit(q_vector->rx.idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1539 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1540 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1541 | for (i = 0; i < q_vector->rx.count; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1542 | u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx; |
| 1543 | ixgbe_set_ivar(adapter, 0, reg_idx, v_idx); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1544 | r_idx = find_next_bit(q_vector->rx.idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1545 | adapter->num_rx_queues, |
| 1546 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1547 | } |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1548 | r_idx = find_first_bit(q_vector->tx.idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1549 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1550 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1551 | for (i = 0; i < q_vector->tx.count; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 1552 | u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx; |
| 1553 | ixgbe_set_ivar(adapter, 1, reg_idx, v_idx); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1554 | r_idx = find_next_bit(q_vector->tx.idx, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1555 | adapter->num_tx_queues, |
| 1556 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1557 | } |
| 1558 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1559 | if (q_vector->tx.count && !q_vector->rx.count) |
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 | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1562 | else if (q_vector->rx.count) |
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; |
| 1986 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1987 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1988 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1989 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1990 | if (!q_vector->tx.count) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1991 | return IRQ_HANDLED; |
| 1992 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1993 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
| 1994 | for (i = 0; i < q_vector->tx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1995 | tx_ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 1996 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1997 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1998 | } |
| 1999 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2000 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2001 | napi_schedule(&q_vector->napi); |
| 2002 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2003 | return IRQ_HANDLED; |
| 2004 | } |
| 2005 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2006 | /** |
| 2007 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 2008 | * @irq: unused |
| 2009 | * @data: pointer to our q_vector struct for this interrupt vector |
| 2010 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2011 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 2012 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2013 | struct ixgbe_q_vector *q_vector = data; |
| 2014 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2015 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2016 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2017 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2018 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2019 | #ifdef CONFIG_IXGBE_DCA |
| 2020 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2021 | ixgbe_update_dca(q_vector); |
| 2022 | #endif |
| 2023 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2024 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
| 2025 | for (i = 0; i < q_vector->rx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2026 | rx_ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2027 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2028 | r_idx + 1); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2031 | if (!q_vector->rx.count) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2032 | return IRQ_HANDLED; |
| 2033 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2034 | /* EIAM disabled interrupts (on this vector) for us */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2035 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2036 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2037 | return IRQ_HANDLED; |
| 2038 | } |
| 2039 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2040 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 2041 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2042 | struct ixgbe_q_vector *q_vector = data; |
| 2043 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2044 | struct ixgbe_ring *ring; |
| 2045 | int r_idx; |
| 2046 | int i; |
| 2047 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2048 | if (!q_vector->tx.count && !q_vector->rx.count) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2049 | return IRQ_HANDLED; |
| 2050 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2051 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
| 2052 | for (i = 0; i < q_vector->tx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2053 | ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2054 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2055 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2058 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
| 2059 | for (i = 0; i < q_vector->rx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2060 | ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2061 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2062 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2065 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2066 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2067 | |
| 2068 | return IRQ_HANDLED; |
| 2069 | } |
| 2070 | |
| 2071 | /** |
| 2072 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 2073 | * @napi: napi struct with our devices info in it |
| 2074 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2075 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2076 | * This function is optimized for cleaning one queue only on a single |
| 2077 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2078 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2079 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 2080 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2081 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2082 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2083 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2084 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2085 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2086 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2087 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2088 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2089 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2090 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2091 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2092 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2093 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2094 | rx_ring = adapter->rx_ring[r_idx]; |
| 2095 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 2096 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2097 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2098 | /* If all Rx work done, exit the polling mode */ |
| 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); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -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)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | return work_done; |
| 2109 | } |
| 2110 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2111 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2112 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2113 | * @napi: napi struct with our devices info in it |
| 2114 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2115 | * |
| 2116 | * This function will clean more than one rx queue associated with a |
| 2117 | * q_vector. |
| 2118 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2119 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2120 | { |
| 2121 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2122 | container_of(napi, struct ixgbe_q_vector, napi); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2123 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2124 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2125 | int work_done = 0, i; |
| 2126 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2127 | bool tx_clean_complete = true; |
| 2128 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2129 | #ifdef CONFIG_IXGBE_DCA |
| 2130 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2131 | ixgbe_update_dca(q_vector); |
| 2132 | #endif |
| 2133 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2134 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
| 2135 | for (i = 0; i < q_vector->tx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2136 | ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2137 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2138 | r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2139 | r_idx + 1); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2140 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2141 | |
| 2142 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2143 | * the budget to go below 1 because we'll exit polling */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2144 | budget /= (q_vector->rx.count ?: 1); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2145 | budget = max(budget, 1); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2146 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
| 2147 | for (i = 0; i < q_vector->rx.count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2148 | ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2149 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2150 | r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2151 | r_idx + 1); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2154 | r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2155 | ring = adapter->rx_ring[r_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2156 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2157 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2158 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2159 | if (adapter->rx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2160 | ixgbe_set_itr(q_vector); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2161 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2162 | ixgbe_irq_enable_queues(adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2163 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2164 | return 0; |
| 2165 | } |
| 2166 | |
| 2167 | return work_done; |
| 2168 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2169 | |
| 2170 | /** |
| 2171 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 2172 | * @napi: napi struct with our devices info in it |
| 2173 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 2174 | * |
| 2175 | * This function is optimized for cleaning one queue only on a single |
| 2176 | * q_vector!!! |
| 2177 | **/ |
| 2178 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 2179 | { |
| 2180 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2181 | container_of(napi, struct ixgbe_q_vector, napi); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2182 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2183 | struct ixgbe_ring *tx_ring = NULL; |
| 2184 | int work_done = 0; |
| 2185 | long r_idx; |
| 2186 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2187 | #ifdef CONFIG_IXGBE_DCA |
| 2188 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2189 | ixgbe_update_dca(q_vector); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2190 | #endif |
| 2191 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2192 | r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 2193 | tx_ring = adapter->tx_ring[r_idx]; |
| 2194 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2195 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 2196 | work_done = budget; |
| 2197 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2198 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2199 | if (work_done < budget) { |
| 2200 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2201 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2202 | ixgbe_set_itr(q_vector); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2203 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2204 | ixgbe_irq_enable_queues(adapter, |
| 2205 | ((u64)1 << q_vector->v_idx)); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | return work_done; |
| 2209 | } |
| 2210 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2211 | 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] | 2212 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2213 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2214 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2215 | struct ixgbe_ring *rx_ring = a->rx_ring[r_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2216 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2217 | set_bit(r_idx, q_vector->rx.idx); |
| 2218 | q_vector->rx.count++; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2219 | rx_ring->q_vector = q_vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2220 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2221 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2222 | 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] | 2223 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2224 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2225 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2226 | struct ixgbe_ring *tx_ring = a->tx_ring[t_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2227 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2228 | set_bit(t_idx, q_vector->tx.idx); |
| 2229 | q_vector->tx.count++; |
Alexander Duyck | 2274543 | 2010-11-16 19:27:10 -0800 | [diff] [blame] | 2230 | tx_ring->q_vector = q_vector; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2231 | q_vector->tx.work_limit = a->tx_work_limit; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2232 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2233 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2234 | /** |
| 2235 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 2236 | * @adapter: board private structure to initialize |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2237 | * |
| 2238 | * This function maps descriptor rings to the queue-specific vectors |
| 2239 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 2240 | * one vector per ring/queue, but on a constrained vector budget, we |
| 2241 | * group the rings as "efficiently" as possible. You would add new |
| 2242 | * mapping configurations in here. |
| 2243 | **/ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2244 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2245 | { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2246 | int q_vectors; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2247 | int v_start = 0; |
| 2248 | int rxr_idx = 0, txr_idx = 0; |
| 2249 | int rxr_remaining = adapter->num_rx_queues; |
| 2250 | int txr_remaining = adapter->num_tx_queues; |
| 2251 | int i, j; |
| 2252 | int rqpv, tqpv; |
| 2253 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2254 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2255 | /* No mapping required if MSI-X is disabled. */ |
| 2256 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2257 | goto out; |
| 2258 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2259 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2260 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2261 | /* |
| 2262 | * The ideal configuration... |
| 2263 | * We have enough vectors to map one per queue. |
| 2264 | */ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2265 | if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2266 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 2267 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 2268 | |
| 2269 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 2270 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 2271 | |
| 2272 | goto out; |
| 2273 | } |
| 2274 | |
| 2275 | /* |
| 2276 | * If we don't have enough vectors for a 1-to-1 |
| 2277 | * mapping, we'll have to group them so there are |
| 2278 | * multiple queues per vector. |
| 2279 | */ |
| 2280 | /* Re-adjusting *qpv takes care of the remainder. */ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2281 | for (i = v_start; i < q_vectors; i++) { |
| 2282 | rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2283 | for (j = 0; j < rqpv; j++) { |
| 2284 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 2285 | rxr_idx++; |
| 2286 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2287 | } |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2288 | tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2289 | for (j = 0; j < tqpv; j++) { |
| 2290 | map_vector_to_txq(adapter, i, txr_idx); |
| 2291 | txr_idx++; |
| 2292 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2293 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2294 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2295 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2296 | return err; |
| 2297 | } |
| 2298 | |
| 2299 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2300 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2301 | * @adapter: board private structure |
| 2302 | * |
| 2303 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2304 | * interrupts from the kernel. |
| 2305 | **/ |
| 2306 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2307 | { |
| 2308 | struct net_device *netdev = adapter->netdev; |
| 2309 | irqreturn_t (*handler)(int, void *); |
| 2310 | int i, vector, q_vectors, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2311 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2312 | |
| 2313 | /* Decrement for Other and TCP Timer vectors */ |
| 2314 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2315 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2316 | err = ixgbe_map_rings_to_vectors(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2317 | if (err) |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2318 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2319 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2320 | #define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2321 | ? &ixgbe_msix_clean_many : \ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2322 | (_v)->rx.count ? &ixgbe_msix_clean_rx : \ |
| 2323 | (_v)->tx.count ? &ixgbe_msix_clean_tx : \ |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2324 | NULL) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2325 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2326 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 2327 | handler = SET_HANDLER(q_vector); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2328 | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2329 | if (handler == &ixgbe_msix_clean_rx) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2330 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2331 | "%s-%s-%d", netdev->name, "rx", ri++); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2332 | } else if (handler == &ixgbe_msix_clean_tx) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2333 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2334 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2335 | } else if (handler == &ixgbe_msix_clean_many) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2336 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2337 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2338 | ti++; |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2339 | } else { |
| 2340 | /* skip this unused q_vector */ |
| 2341 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2342 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2343 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2344 | handler, 0, q_vector->name, |
| 2345 | q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2346 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2347 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2348 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2349 | goto free_queue_irqs; |
| 2350 | } |
| 2351 | } |
| 2352 | |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2353 | sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2354 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2355 | ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2356 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2357 | e_err(probe, "request_irq for msix_lsc failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2358 | goto free_queue_irqs; |
| 2359 | } |
| 2360 | |
| 2361 | return 0; |
| 2362 | |
| 2363 | free_queue_irqs: |
| 2364 | for (i = vector - 1; i >= 0; i--) |
| 2365 | free_irq(adapter->msix_entries[--vector].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2366 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2367 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2368 | pci_disable_msix(adapter->pdev); |
| 2369 | kfree(adapter->msix_entries); |
| 2370 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2371 | return err; |
| 2372 | } |
| 2373 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2374 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2375 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2376 | * @adapter: board private structure |
| 2377 | **/ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2378 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2379 | bool flush) |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2380 | { |
| 2381 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2382 | |
| 2383 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2384 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
| 2385 | mask |= IXGBE_EIMS_GPI_SDP0; |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 2386 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2387 | mask |= IXGBE_EIMS_GPI_SDP1; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2388 | switch (adapter->hw.mac.type) { |
| 2389 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2390 | case ixgbe_mac_X540: |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2391 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2392 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2393 | mask |= IXGBE_EIMS_GPI_SDP2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2394 | if (adapter->num_vfs) |
| 2395 | mask |= IXGBE_EIMS_MAILBOX; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2396 | break; |
| 2397 | default: |
| 2398 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2399 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 2400 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2401 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2402 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2403 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2404 | if (queues) |
| 2405 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2406 | if (flush) |
| 2407 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2408 | |
| 2409 | if (adapter->num_vfs > 32) { |
| 2410 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 2411 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2412 | } |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2413 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2414 | |
| 2415 | /** |
| 2416 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2417 | * @irq: interrupt number |
| 2418 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2419 | **/ |
| 2420 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2421 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2422 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2423 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2424 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2425 | u32 eicr; |
| 2426 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2427 | /* |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2428 | * Workaround for silicon errata on 82598. Mask the interrupts |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2429 | * before the read of EICR. |
| 2430 | */ |
| 2431 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2432 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2433 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 2434 | * therefore no explict interrupt disable is necessary */ |
| 2435 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2436 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2437 | /* |
| 2438 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2439 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2440 | * have disabled interrupts due to EIAM |
| 2441 | * finish the workaround of silicon errata on 82598. Unmask |
| 2442 | * the interrupt that we masked before the EICR read. |
| 2443 | */ |
| 2444 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2445 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2446 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2447 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2448 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2449 | if (eicr & IXGBE_EICR_LSC) |
| 2450 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2451 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2452 | switch (hw->mac.type) { |
| 2453 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2454 | ixgbe_check_sfp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2455 | if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2456 | ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2457 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2458 | adapter->interrupt_event = eicr; |
| 2459 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2460 | ixgbe_service_event_schedule(adapter); |
| 2461 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2462 | } |
| 2463 | break; |
| 2464 | default: |
| 2465 | break; |
| 2466 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2467 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2468 | ixgbe_check_fan_failure(adapter, eicr); |
| 2469 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2470 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2471 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2472 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2475 | /* |
| 2476 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2477 | * ixgbe_poll will re-enable the queue interrupts |
| 2478 | */ |
| 2479 | |
| 2480 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2481 | ixgbe_irq_enable(adapter, false, false); |
| 2482 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2483 | return IRQ_HANDLED; |
| 2484 | } |
| 2485 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2486 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 2487 | { |
| 2488 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2489 | |
| 2490 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2491 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2492 | bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES); |
| 2493 | bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES); |
| 2494 | q_vector->rx.count = 0; |
| 2495 | q_vector->tx.count = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2496 | } |
| 2497 | } |
| 2498 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2499 | /** |
| 2500 | * ixgbe_request_irq - initialize interrupts |
| 2501 | * @adapter: board private structure |
| 2502 | * |
| 2503 | * Attempts to configure interrupts using the best available |
| 2504 | * capabilities of the hardware and kernel. |
| 2505 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2506 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2507 | { |
| 2508 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2509 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2510 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2511 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2512 | err = ixgbe_request_msix_irqs(adapter); |
| 2513 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2514 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2515 | netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2516 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2517 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2518 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2521 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2522 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2523 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2524 | return err; |
| 2525 | } |
| 2526 | |
| 2527 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2528 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2529 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2530 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2531 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2532 | q_vectors = adapter->num_msix_vectors; |
| 2533 | |
| 2534 | i = q_vectors - 1; |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2535 | free_irq(adapter->msix_entries[i].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2536 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2537 | i--; |
| 2538 | for (; i >= 0; i--) { |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2539 | /* free only the irqs that were actually requested */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2540 | if (!adapter->q_vector[i]->rx.count && |
| 2541 | !adapter->q_vector[i]->tx.count) |
Alexander Duyck | 894ff7c | 2011-02-15 02:12:05 +0000 | [diff] [blame] | 2542 | continue; |
| 2543 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2544 | free_irq(adapter->msix_entries[i].vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2545 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | ixgbe_reset_q_vectors(adapter); |
| 2549 | } else { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2550 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2555 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2556 | * @adapter: board private structure |
| 2557 | **/ |
| 2558 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2559 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2560 | switch (adapter->hw.mac.type) { |
| 2561 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2562 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2563 | break; |
| 2564 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2565 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2566 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2567 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2568 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2569 | if (adapter->num_vfs > 32) |
| 2570 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2571 | break; |
| 2572 | default: |
| 2573 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2574 | } |
| 2575 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2576 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2577 | int i; |
| 2578 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 2579 | synchronize_irq(adapter->msix_entries[i].vector); |
| 2580 | } else { |
| 2581 | synchronize_irq(adapter->pdev->irq); |
| 2582 | } |
| 2583 | } |
| 2584 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2585 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2586 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2587 | * |
| 2588 | **/ |
| 2589 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2590 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2591 | struct ixgbe_hw *hw = &adapter->hw; |
| 2592 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2593 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2594 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2595 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2596 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2597 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2598 | |
| 2599 | map_vector_to_rxq(adapter, 0, 0); |
| 2600 | map_vector_to_txq(adapter, 0, 0); |
| 2601 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2602 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2605 | /** |
| 2606 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2607 | * @adapter: board private structure |
| 2608 | * @ring: structure containing ring specific data |
| 2609 | * |
| 2610 | * Configure the Tx descriptor ring after a reset. |
| 2611 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2612 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2613 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2614 | { |
| 2615 | struct ixgbe_hw *hw = &adapter->hw; |
| 2616 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2617 | int wait_loop = 10; |
| 2618 | u32 txdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2619 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2620 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2621 | /* disable queue to avoid issues while updating state */ |
| 2622 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2623 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), |
| 2624 | txdctl & ~IXGBE_TXDCTL_ENABLE); |
| 2625 | IXGBE_WRITE_FLUSH(hw); |
| 2626 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2627 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2628 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2629 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2630 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2631 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2632 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2633 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2634 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2635 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2636 | /* configure fetching thresholds */ |
| 2637 | if (adapter->rx_itr_setting == 0) { |
| 2638 | /* cannot set wthresh when itr==0 */ |
| 2639 | txdctl &= ~0x007F0000; |
| 2640 | } else { |
| 2641 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2642 | txdctl |= (8 << 16); |
| 2643 | } |
| 2644 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2645 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2646 | txdctl |= 32; |
| 2647 | } |
| 2648 | |
| 2649 | /* reinitialize flowdirector state */ |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 2650 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2651 | adapter->atr_sample_rate) { |
| 2652 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 2653 | ring->atr_count = 0; |
| 2654 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 2655 | } else { |
| 2656 | ring->atr_sample_rate = 0; |
| 2657 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2658 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 2659 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 2660 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2661 | /* enable queue */ |
| 2662 | txdctl |= IXGBE_TXDCTL_ENABLE; |
| 2663 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 2664 | |
| 2665 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2666 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2667 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2668 | return; |
| 2669 | |
| 2670 | /* poll to verify queue is enabled */ |
| 2671 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2672 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2673 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 2674 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2675 | if (!wait_loop) |
| 2676 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2679 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 2680 | { |
| 2681 | struct ixgbe_hw *hw = &adapter->hw; |
| 2682 | u32 rttdcs; |
John Fastabend | 72a32f1 | 2011-04-26 07:25:58 +0000 | [diff] [blame] | 2683 | u32 reg; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2684 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2685 | |
| 2686 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2687 | return; |
| 2688 | |
| 2689 | /* disable the arbiter while setting MTQC */ |
| 2690 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2691 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2692 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2693 | |
| 2694 | /* set transmit pool layout */ |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2695 | switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2696 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2697 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2698 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2699 | break; |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2700 | default: |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2701 | if (!tcs) |
| 2702 | reg = IXGBE_MTQC_64Q_1PB; |
| 2703 | else if (tcs <= 4) |
| 2704 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 2705 | else |
| 2706 | reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 2707 | |
| 2708 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg); |
| 2709 | |
| 2710 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 2711 | if (tcs) { |
| 2712 | reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 2713 | reg |= IXGBE_SECTX_DCB; |
| 2714 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg); |
| 2715 | } |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 2716 | break; |
| 2717 | } |
| 2718 | |
| 2719 | /* re-enable the arbiter */ |
| 2720 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2721 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2722 | } |
| 2723 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2724 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2725 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2726 | * @adapter: board private structure |
| 2727 | * |
| 2728 | * Configure the Tx unit of the MAC after a reset. |
| 2729 | **/ |
| 2730 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2731 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2732 | struct ixgbe_hw *hw = &adapter->hw; |
| 2733 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2734 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2735 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2736 | ixgbe_setup_mtqc(adapter); |
| 2737 | |
| 2738 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 2739 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 2740 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2741 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2742 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2743 | } |
| 2744 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2745 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2746 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2747 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2748 | } |
| 2749 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2750 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2751 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2752 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2753 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2754 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2755 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2756 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2757 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2758 | switch (adapter->hw.mac.type) { |
| 2759 | case ixgbe_mac_82598EB: { |
| 2760 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
| 2761 | const int mask = feature[RING_F_RSS].mask; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2762 | reg_idx = reg_idx & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2763 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2764 | break; |
| 2765 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2766 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2767 | default: |
| 2768 | break; |
| 2769 | } |
| 2770 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2771 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx)); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2772 | |
| 2773 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2774 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2775 | if (adapter->num_vfs) |
| 2776 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2777 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2778 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2779 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2780 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2781 | if (ring_is_ps_enabled(rx_ring)) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2782 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2783 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2784 | #else |
| 2785 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2786 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2787 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2788 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2789 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2790 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2791 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2792 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2793 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2794 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2797 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2798 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2799 | struct ixgbe_hw *hw = &adapter->hw; |
| 2800 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2801 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2802 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2803 | u32 mrqc = 0, reta = 0; |
| 2804 | u32 rxcsum; |
| 2805 | int i, j; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2806 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2807 | int maxq = adapter->ring_feature[RING_F_RSS].indices; |
| 2808 | |
| 2809 | if (tcs) |
| 2810 | maxq = min(maxq, adapter->num_tx_queues / tcs); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2811 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2812 | /* Fill out hash function seeds */ |
| 2813 | for (i = 0; i < 10; i++) |
| 2814 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2815 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2816 | /* Fill out redirection table */ |
| 2817 | for (i = 0, j = 0; i < 128; i++, j++) { |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 2818 | if (j == maxq) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2819 | j = 0; |
| 2820 | /* reta = 4-byte sliding window of |
| 2821 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2822 | reta = (reta << 8) | (j * 0x11); |
| 2823 | if ((i & 3) == 3) |
| 2824 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 2825 | } |
| 2826 | |
| 2827 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 2828 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2829 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2830 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 2831 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2832 | if (adapter->hw.mac.type == ixgbe_mac_82598EB && |
| 2833 | (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2834 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 2835 | } else { |
| 2836 | int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2837 | | IXGBE_FLAG_SRIOV_ENABLED); |
| 2838 | |
| 2839 | switch (mask) { |
| 2840 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2841 | if (!tcs) |
| 2842 | mrqc = IXGBE_MRQC_RSSEN; |
| 2843 | else if (tcs <= 4) |
| 2844 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 2845 | else |
| 2846 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 2847 | break; |
| 2848 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2849 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2850 | break; |
| 2851 | default: |
| 2852 | break; |
| 2853 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 2856 | /* Perform hash on these packet types */ |
| 2857 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2858 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2859 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2860 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2861 | |
| 2862 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2863 | } |
| 2864 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2865 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2866 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2867 | * @adapter: address of board private structure |
| 2868 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2869 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 2870 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2871 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2872 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2873 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2874 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2875 | int rx_buf_len; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2876 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2877 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2878 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2879 | return; |
| 2880 | |
| 2881 | rx_buf_len = ring->rx_buf_len; |
| 2882 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2883 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2884 | /* |
| 2885 | * we must limit the number of descriptors so that the |
| 2886 | * total size of max desc * buf_len is not greater |
| 2887 | * than 65535 |
| 2888 | */ |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 2889 | if (ring_is_ps_enabled(ring)) { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2890 | #if (MAX_SKB_FRAGS > 16) |
| 2891 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2892 | #elif (MAX_SKB_FRAGS > 8) |
| 2893 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2894 | #elif (MAX_SKB_FRAGS > 4) |
| 2895 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2896 | #else |
| 2897 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2898 | #endif |
| 2899 | } else { |
| 2900 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2901 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2902 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2903 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2904 | else |
| 2905 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2906 | } |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 2907 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2908 | } |
| 2909 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2910 | /** |
| 2911 | * ixgbe_set_uta - Set unicast filter table address |
| 2912 | * @adapter: board private structure |
| 2913 | * |
| 2914 | * The unicast table address is a register array of 32-bit registers. |
| 2915 | * The table is meant to be used in a way similar to how the MTA is used |
| 2916 | * however due to certain limitations in the hardware it is necessary to |
| 2917 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 2918 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
| 2919 | **/ |
| 2920 | static void ixgbe_set_uta(struct ixgbe_adapter *adapter) |
| 2921 | { |
| 2922 | struct ixgbe_hw *hw = &adapter->hw; |
| 2923 | int i; |
| 2924 | |
| 2925 | /* The UTA table only exists on 82599 hardware and newer */ |
| 2926 | if (hw->mac.type < ixgbe_mac_82599EB) |
| 2927 | return; |
| 2928 | |
| 2929 | /* we only need to do this if VMDq is enabled */ |
| 2930 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2931 | return; |
| 2932 | |
| 2933 | for (i = 0; i < 128; i++) |
| 2934 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0); |
| 2935 | } |
| 2936 | |
| 2937 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2938 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2939 | struct ixgbe_ring *ring) |
| 2940 | { |
| 2941 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2942 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2943 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2944 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2945 | |
| 2946 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 2947 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2948 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2949 | return; |
| 2950 | |
| 2951 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 2952 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2953 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2954 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2955 | |
| 2956 | if (!wait_loop) { |
| 2957 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 2958 | "the polling period\n", reg_idx); |
| 2959 | } |
| 2960 | } |
| 2961 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 2962 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 2963 | struct ixgbe_ring *ring) |
| 2964 | { |
| 2965 | struct ixgbe_hw *hw = &adapter->hw; |
| 2966 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 2967 | u32 rxdctl; |
| 2968 | u8 reg_idx = ring->reg_idx; |
| 2969 | |
| 2970 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2971 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 2972 | |
| 2973 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 2974 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 2975 | |
| 2976 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 2977 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 2978 | return; |
| 2979 | |
| 2980 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 2981 | do { |
| 2982 | udelay(10); |
| 2983 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 2984 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 2985 | |
| 2986 | if (!wait_loop) { |
| 2987 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 2988 | "the polling period\n", reg_idx); |
| 2989 | } |
| 2990 | } |
| 2991 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2992 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 2993 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2994 | { |
| 2995 | struct ixgbe_hw *hw = &adapter->hw; |
| 2996 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 2997 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2998 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 2999 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3000 | /* disable queue to avoid issues while updating state */ |
| 3001 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3002 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3003 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3004 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3005 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3006 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3007 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 3008 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3009 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3010 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3011 | |
| 3012 | ixgbe_configure_srrctl(adapter, ring); |
| 3013 | ixgbe_configure_rscctl(adapter, ring); |
| 3014 | |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 3015 | /* If operating in IOV mode set RLPML for X540 */ |
| 3016 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 3017 | hw->mac.type == ixgbe_mac_X540) { |
| 3018 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 3019 | rxdctl |= ((ring->netdev->mtu + ETH_HLEN + |
| 3020 | ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN); |
| 3021 | } |
| 3022 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3023 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3024 | /* |
| 3025 | * enable cache line friendly hardware writes: |
| 3026 | * PTHRESH=32 descriptors (half the internal cache), |
| 3027 | * this also removes ugly rx_no_buffer_count increment |
| 3028 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3029 | * WTHRESH=8 burst writeback up to two cache lines |
| 3030 | */ |
| 3031 | rxdctl &= ~0x3FFFFF; |
| 3032 | rxdctl |= 0x080420; |
| 3033 | } |
| 3034 | |
| 3035 | /* enable receive descriptor ring */ |
| 3036 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3037 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3038 | |
| 3039 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3040 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3043 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3044 | { |
| 3045 | struct ixgbe_hw *hw = &adapter->hw; |
| 3046 | int p; |
| 3047 | |
| 3048 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3049 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3050 | IXGBE_PSRTYPE_UDPHDR | |
| 3051 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3052 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3053 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3054 | |
| 3055 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3056 | return; |
| 3057 | |
| 3058 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) |
| 3059 | psrtype |= (adapter->num_rx_queues_per_pool << 29); |
| 3060 | |
| 3061 | for (p = 0; p < adapter->num_rx_pools; p++) |
| 3062 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p), |
| 3063 | psrtype); |
| 3064 | } |
| 3065 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3066 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3067 | { |
| 3068 | struct ixgbe_hw *hw = &adapter->hw; |
| 3069 | u32 gcr_ext; |
| 3070 | u32 vt_reg_bits; |
| 3071 | u32 reg_offset, vf_shift; |
| 3072 | u32 vmdctl; |
| 3073 | |
| 3074 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3075 | return; |
| 3076 | |
| 3077 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 3078 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN; |
| 3079 | vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT); |
| 3080 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 3081 | |
| 3082 | vf_shift = adapter->num_vfs % 32; |
| 3083 | reg_offset = (adapter->num_vfs > 32) ? 1 : 0; |
| 3084 | |
| 3085 | /* Enable only the PF's pool for Tx/Rx */ |
| 3086 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 3087 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0); |
| 3088 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 3089 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0); |
| 3090 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 3091 | |
| 3092 | /* Map PF MAC address in RAR Entry 0 to first pool following VFs */ |
| 3093 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 3094 | |
| 3095 | /* |
| 3096 | * Set up VF register offsets for selected VT Mode, |
| 3097 | * i.e. 32 or 64 VFs for SR-IOV |
| 3098 | */ |
| 3099 | gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 3100 | gcr_ext |= IXGBE_GCR_EXT_MSIX_EN; |
| 3101 | gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64; |
| 3102 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3103 | |
| 3104 | /* enable Tx loopback for VF/PF communication */ |
| 3105 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3106 | /* Enable MAC Anti-Spoofing */ |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3107 | hw->mac.ops.set_mac_anti_spoofing(hw, |
| 3108 | (adapter->antispoofing_enabled = |
| 3109 | (adapter->num_vfs != 0)), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3110 | adapter->num_vfs); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3113 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3114 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3115 | struct ixgbe_hw *hw = &adapter->hw; |
| 3116 | struct net_device *netdev = adapter->netdev; |
| 3117 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3118 | int rx_buf_len; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3119 | struct ixgbe_ring *rx_ring; |
| 3120 | int i; |
| 3121 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3122 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3123 | /* Decide whether to use packet split mode or not */ |
Don Skidmore | a124339 | 2011-01-18 22:53:47 +0000 | [diff] [blame] | 3124 | /* On by default */ |
| 3125 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
| 3126 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3127 | /* Do not use packet split if we're in SR-IOV Mode */ |
Don Skidmore | a124339 | 2011-01-18 22:53:47 +0000 | [diff] [blame] | 3128 | if (adapter->num_vfs) |
| 3129 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
| 3130 | |
| 3131 | /* Disable packet split due to 82599 erratum #45 */ |
| 3132 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3133 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3134 | |
| 3135 | /* Set the RX buffer length according to the mode */ |
| 3136 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3137 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3138 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3139 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3140 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 3141 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3142 | else |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3143 | rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024); |
| 3144 | } |
| 3145 | |
| 3146 | #ifdef IXGBE_FCOE |
| 3147 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3148 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3149 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3150 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3151 | |
| 3152 | #endif /* IXGBE_FCOE */ |
| 3153 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3154 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3155 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3156 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3157 | |
| 3158 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3161 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3162 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3163 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3164 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3165 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3166 | /* |
| 3167 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3168 | * the Base and Length of the Rx Descriptor Ring |
| 3169 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3170 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3171 | rx_ring = adapter->rx_ring[i]; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3172 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3173 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3174 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3175 | set_ring_ps_enabled(rx_ring); |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 3176 | else |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3177 | clear_ring_ps_enabled(rx_ring); |
| 3178 | |
| 3179 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3180 | set_ring_rsc_enabled(rx_ring); |
| 3181 | else |
| 3182 | clear_ring_rsc_enabled(rx_ring); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3183 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3184 | #ifdef IXGBE_FCOE |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3185 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3186 | struct ixgbe_ring_feature *f; |
| 3187 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3188 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3189 | clear_ring_ps_enabled(rx_ring); |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3190 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 3191 | rx_ring->rx_buf_len = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3192 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3193 | } else if (!ring_is_rsc_enabled(rx_ring) && |
| 3194 | !ring_is_ps_enabled(rx_ring)) { |
| 3195 | rx_ring->rx_buf_len = |
| 3196 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 3197 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3198 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 3199 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3200 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3201 | } |
| 3202 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3203 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3204 | { |
| 3205 | struct ixgbe_hw *hw = &adapter->hw; |
| 3206 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3207 | |
| 3208 | switch (hw->mac.type) { |
| 3209 | case ixgbe_mac_82598EB: |
| 3210 | /* |
| 3211 | * For VMDq support of different descriptor types or |
| 3212 | * buffer sizes through the use of multiple SRRCTL |
| 3213 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3214 | * |
| 3215 | * also, the manual doesn't mention it clearly but DCA hints |
| 3216 | * will only use queue 0's tags unless this bit is set. Side |
| 3217 | * effects of setting this bit are only that SRRCTL must be |
| 3218 | * fully programmed [0..15] |
| 3219 | */ |
| 3220 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3221 | break; |
| 3222 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3223 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3224 | /* Disable RSC for ACK packets */ |
| 3225 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3226 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3227 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3228 | /* hardware requires some bits to be set by default */ |
| 3229 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3230 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3231 | break; |
| 3232 | default: |
| 3233 | /* We should do nothing since we don't know this hardware */ |
| 3234 | return; |
| 3235 | } |
| 3236 | |
| 3237 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3238 | } |
| 3239 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3240 | /** |
| 3241 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3242 | * @adapter: board private structure |
| 3243 | * |
| 3244 | * Configure the Rx unit of the MAC after a reset. |
| 3245 | **/ |
| 3246 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3247 | { |
| 3248 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3249 | int i; |
| 3250 | u32 rxctrl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3251 | |
| 3252 | /* disable receives while setting up the descriptors */ |
| 3253 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3254 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3255 | |
| 3256 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3257 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3258 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3259 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3260 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3261 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3262 | ixgbe_set_uta(adapter); |
| 3263 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3264 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3265 | ixgbe_set_rx_buffer_len(adapter); |
| 3266 | |
| 3267 | /* |
| 3268 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3269 | * the Base and Length of the Rx Descriptor Ring |
| 3270 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3271 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3272 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3273 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3274 | /* disable drop enable for 82598 parts */ |
| 3275 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3276 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3277 | |
| 3278 | /* enable all receives */ |
| 3279 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3280 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3281 | } |
| 3282 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3283 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 3284 | { |
| 3285 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3286 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3287 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3288 | |
| 3289 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3290 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3291 | set_bit(vid, adapter->active_vlans); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 3295 | { |
| 3296 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3297 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3298 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3299 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3300 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 3301 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3302 | clear_bit(vid, adapter->active_vlans); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3303 | } |
| 3304 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3305 | /** |
| 3306 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3307 | * @adapter: driver data |
| 3308 | */ |
| 3309 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3310 | { |
| 3311 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3312 | u32 vlnctrl; |
| 3313 | |
| 3314 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3315 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3316 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3317 | } |
| 3318 | |
| 3319 | /** |
| 3320 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3321 | * @adapter: driver data |
| 3322 | */ |
| 3323 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3324 | { |
| 3325 | struct ixgbe_hw *hw = &adapter->hw; |
| 3326 | u32 vlnctrl; |
| 3327 | |
| 3328 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3329 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3330 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3331 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3332 | } |
| 3333 | |
| 3334 | /** |
| 3335 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3336 | * @adapter: driver data |
| 3337 | */ |
| 3338 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3339 | { |
| 3340 | struct ixgbe_hw *hw = &adapter->hw; |
| 3341 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3342 | int i, j; |
| 3343 | |
| 3344 | switch (hw->mac.type) { |
| 3345 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3346 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3347 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3348 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3349 | break; |
| 3350 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3351 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3352 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3353 | j = adapter->rx_ring[i]->reg_idx; |
| 3354 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3355 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3356 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3357 | } |
| 3358 | break; |
| 3359 | default: |
| 3360 | break; |
| 3361 | } |
| 3362 | } |
| 3363 | |
| 3364 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3365 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3366 | * @adapter: driver data |
| 3367 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3368 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3369 | { |
| 3370 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3371 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3372 | int i, j; |
| 3373 | |
| 3374 | switch (hw->mac.type) { |
| 3375 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3376 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3377 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3378 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3379 | break; |
| 3380 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3381 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3382 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3383 | j = adapter->rx_ring[i]->reg_idx; |
| 3384 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3385 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3386 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3387 | } |
| 3388 | break; |
| 3389 | default: |
| 3390 | break; |
| 3391 | } |
| 3392 | } |
| 3393 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3394 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3395 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3396 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3397 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3398 | ixgbe_vlan_rx_add_vid(adapter->netdev, 0); |
| 3399 | |
| 3400 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 3401 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3405 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3406 | * @netdev: network interface device structure |
| 3407 | * |
| 3408 | * Writes unicast address list to the RAR table. |
| 3409 | * Returns: -ENOMEM on failure/insufficient address space |
| 3410 | * 0 on no addresses written |
| 3411 | * X on writing X addresses to the RAR table |
| 3412 | **/ |
| 3413 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3414 | { |
| 3415 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3416 | struct ixgbe_hw *hw = &adapter->hw; |
| 3417 | unsigned int vfn = adapter->num_vfs; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 3418 | unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3419 | int count = 0; |
| 3420 | |
| 3421 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3422 | if (netdev_uc_count(netdev) > rar_entries) |
| 3423 | return -ENOMEM; |
| 3424 | |
| 3425 | if (!netdev_uc_empty(netdev) && rar_entries) { |
| 3426 | struct netdev_hw_addr *ha; |
| 3427 | /* return error if we do not support writing to RAR table */ |
| 3428 | if (!hw->mac.ops.set_rar) |
| 3429 | return -ENOMEM; |
| 3430 | |
| 3431 | netdev_for_each_uc_addr(ha, netdev) { |
| 3432 | if (!rar_entries) |
| 3433 | break; |
| 3434 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
| 3435 | vfn, IXGBE_RAH_AV); |
| 3436 | count++; |
| 3437 | } |
| 3438 | } |
| 3439 | /* write the addresses in reverse order to avoid write combining */ |
| 3440 | for (; rar_entries > 0 ; rar_entries--) |
| 3441 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3442 | |
| 3443 | return count; |
| 3444 | } |
| 3445 | |
| 3446 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3447 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3448 | * @netdev: network interface device structure |
| 3449 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3450 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3451 | * address list or the network interface flags are updated. This routine is |
| 3452 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3453 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3454 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3455 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3456 | { |
| 3457 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3458 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3459 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3460 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3461 | |
| 3462 | /* Check for Promiscuous and All Multicast modes */ |
| 3463 | |
| 3464 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3465 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3466 | /* set all bits that we expect to always be set */ |
| 3467 | fctrl |= IXGBE_FCTRL_BAM; |
| 3468 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3469 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3470 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3471 | /* clear the bits we are changing the status of */ |
| 3472 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3473 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3474 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3475 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3476 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3477 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3478 | /* don't hardware filter vlans in promisc mode */ |
| 3479 | ixgbe_vlan_filter_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3480 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3481 | if (netdev->flags & IFF_ALLMULTI) { |
| 3482 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3483 | vmolr |= IXGBE_VMOLR_MPE; |
| 3484 | } else { |
| 3485 | /* |
| 3486 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3487 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3488 | * that we can at least receive multicast traffic |
| 3489 | */ |
| 3490 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3491 | vmolr |= IXGBE_VMOLR_ROMPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3492 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3493 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3494 | hw->addr_ctrl.user_set_promisc = false; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3495 | /* |
| 3496 | * Write addresses to available RAR registers, if there is not |
| 3497 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3498 | * unicast promiscuous mode |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3499 | */ |
| 3500 | count = ixgbe_write_uc_addr_list(netdev); |
| 3501 | if (count < 0) { |
| 3502 | fctrl |= IXGBE_FCTRL_UPE; |
| 3503 | vmolr |= IXGBE_VMOLR_ROPE; |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | if (adapter->num_vfs) { |
| 3508 | ixgbe_restore_vf_multicasts(adapter); |
| 3509 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) & |
| 3510 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3511 | IXGBE_VMOLR_ROPE); |
| 3512 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3516 | |
| 3517 | if (netdev->features & NETIF_F_HW_VLAN_RX) |
| 3518 | ixgbe_vlan_strip_enable(adapter); |
| 3519 | else |
| 3520 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3523 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3524 | { |
| 3525 | int q_idx; |
| 3526 | struct ixgbe_q_vector *q_vector; |
| 3527 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3528 | |
| 3529 | /* legacy and MSI only use one vector */ |
| 3530 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3531 | q_vectors = 1; |
| 3532 | |
| 3533 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3534 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3535 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3536 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3537 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 3538 | if (!q_vector->rx.count || !q_vector->tx.count) { |
| 3539 | if (q_vector->tx.count == 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3540 | napi->poll = &ixgbe_clean_txonly; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 3541 | else if (q_vector->rx.count == 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3542 | napi->poll = &ixgbe_clean_rxonly; |
| 3543 | } |
| 3544 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 3545 | |
| 3546 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3551 | { |
| 3552 | int q_idx; |
| 3553 | struct ixgbe_q_vector *q_vector; |
| 3554 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3555 | |
| 3556 | /* legacy and MSI only use one vector */ |
| 3557 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3558 | q_vectors = 1; |
| 3559 | |
| 3560 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3561 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3562 | napi_disable(&q_vector->napi); |
| 3563 | } |
| 3564 | } |
| 3565 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3566 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3567 | /* |
| 3568 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3569 | * @adapter: ixgbe adapter struct |
| 3570 | * |
| 3571 | * This is called by the driver on open to configure the DCB hardware. |
| 3572 | * This is also called by the gennetlink interface when reconfiguring |
| 3573 | * the DCB state. |
| 3574 | */ |
| 3575 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3576 | { |
| 3577 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3578 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3579 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3580 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3581 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3582 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3583 | return; |
| 3584 | } |
| 3585 | |
| 3586 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3587 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3588 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3589 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3590 | /* Enable VLAN tag insert/strip */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3591 | adapter->netdev->features |= NETIF_F_HW_VLAN_RX; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3592 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3593 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3594 | |
| 3595 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3596 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3597 | #ifdef CONFIG_FCOE |
| 3598 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3599 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3600 | #endif |
| 3601 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3602 | DCB_TX_CONFIG); |
| 3603 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3604 | DCB_RX_CONFIG); |
| 3605 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
| 3606 | } else { |
| 3607 | struct net_device *dev = adapter->netdev; |
| 3608 | |
| 3609 | if (adapter->ixgbe_ieee_ets) |
| 3610 | dev->dcbnl_ops->ieee_setets(dev, |
| 3611 | adapter->ixgbe_ieee_ets); |
| 3612 | if (adapter->ixgbe_ieee_pfc) |
| 3613 | dev->dcbnl_ops->ieee_setpfc(dev, |
| 3614 | adapter->ixgbe_ieee_pfc); |
| 3615 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3616 | |
| 3617 | /* Enable RSS Hash per TC */ |
| 3618 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3619 | int i; |
| 3620 | u32 reg = 0; |
| 3621 | |
| 3622 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 3623 | u8 msb = 0; |
| 3624 | u8 cnt = adapter->netdev->tc_to_txq[i].count; |
| 3625 | |
| 3626 | while (cnt >>= 1) |
| 3627 | msb++; |
| 3628 | |
| 3629 | reg |= msb << IXGBE_RQTC_SHIFT_TC(i); |
| 3630 | } |
| 3631 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg); |
| 3632 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | #endif |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3636 | |
| 3637 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 3638 | { |
| 3639 | int hdrm = 0; |
| 3640 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 3641 | struct ixgbe_hw *hw = &adapter->hw; |
| 3642 | |
| 3643 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3644 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3645 | hdrm = 64 << adapter->fdir_pballoc; |
| 3646 | |
| 3647 | hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL); |
| 3648 | } |
| 3649 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3650 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 3651 | { |
| 3652 | struct ixgbe_hw *hw = &adapter->hw; |
| 3653 | struct hlist_node *node, *node2; |
| 3654 | struct ixgbe_fdir_filter *filter; |
| 3655 | |
| 3656 | spin_lock(&adapter->fdir_perfect_lock); |
| 3657 | |
| 3658 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 3659 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 3660 | |
| 3661 | hlist_for_each_entry_safe(filter, node, node2, |
| 3662 | &adapter->fdir_filter_list, fdir_node) { |
| 3663 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 3664 | &filter->filter, |
| 3665 | filter->sw_idx, |
| 3666 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 3667 | IXGBE_FDIR_DROP_QUEUE : |
| 3668 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | spin_unlock(&adapter->fdir_perfect_lock); |
| 3672 | } |
| 3673 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3674 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 3675 | { |
| 3676 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3677 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3678 | int i; |
| 3679 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 3680 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3681 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3682 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3683 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3684 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3685 | ixgbe_set_rx_mode(netdev); |
| 3686 | ixgbe_restore_vlan(adapter); |
| 3687 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3688 | #ifdef IXGBE_FCOE |
| 3689 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 3690 | ixgbe_configure_fcoe(adapter); |
| 3691 | |
| 3692 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3693 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 3694 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3695 | adapter->tx_ring[i]->atr_sample_rate = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3696 | adapter->atr_sample_rate; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3697 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3698 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 3699 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 3700 | adapter->fdir_pballoc); |
| 3701 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3702 | } |
Alexander Duyck | 933d41f | 2010-09-07 21:34:29 +0000 | [diff] [blame] | 3703 | ixgbe_configure_virtualization(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3704 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3705 | ixgbe_configure_tx(adapter); |
| 3706 | ixgbe_configure_rx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3709 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 3710 | { |
| 3711 | switch (hw->phy.type) { |
| 3712 | case ixgbe_phy_sfp_avago: |
| 3713 | case ixgbe_phy_sfp_ftl: |
| 3714 | case ixgbe_phy_sfp_intel: |
| 3715 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 3716 | case ixgbe_phy_sfp_passive_tyco: |
| 3717 | case ixgbe_phy_sfp_passive_unknown: |
| 3718 | case ixgbe_phy_sfp_active_unknown: |
| 3719 | case ixgbe_phy_sfp_ftl_active: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3720 | return true; |
| 3721 | default: |
| 3722 | return false; |
| 3723 | } |
| 3724 | } |
| 3725 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3726 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3727 | * ixgbe_sfp_link_config - set up SFP+ link |
| 3728 | * @adapter: pointer to private adapter struct |
| 3729 | **/ |
| 3730 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 3731 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3732 | /* |
| 3733 | * We are assuming the worst case scenerio here, and that |
| 3734 | * is that an SFP was inserted/removed after the reset |
| 3735 | * but before SFP detection was enabled. As such the best |
| 3736 | * solution is to just start searching as soon as we start |
| 3737 | */ |
| 3738 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3739 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3740 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3741 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | /** |
| 3745 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3746 | * @hw: pointer to private hardware struct |
| 3747 | * |
| 3748 | * Returns 0 on success, negative on failure |
| 3749 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3750 | 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] | 3751 | { |
| 3752 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3753 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3754 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 3755 | |
| 3756 | if (hw->mac.ops.check_link) |
| 3757 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 3758 | |
| 3759 | if (ret) |
| 3760 | goto link_cfg_out; |
| 3761 | |
Emil Tantilov | 0b0c2b3 | 2011-02-26 06:40:16 +0000 | [diff] [blame] | 3762 | autoneg = hw->phy.autoneg_advertised; |
| 3763 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3764 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3765 | &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3766 | if (ret) |
| 3767 | goto link_cfg_out; |
| 3768 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 3769 | if (hw->mac.ops.setup_link) |
| 3770 | 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] | 3771 | link_cfg_out: |
| 3772 | return ret; |
| 3773 | } |
| 3774 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3775 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3776 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3777 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3778 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3779 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3780 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3781 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 3782 | IXGBE_GPIE_OCD; |
| 3783 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3784 | /* |
| 3785 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 3786 | * this saves a register write for every interrupt |
| 3787 | */ |
| 3788 | switch (hw->mac.type) { |
| 3789 | case ixgbe_mac_82598EB: |
| 3790 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 3791 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3792 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3793 | case ixgbe_mac_X540: |
| 3794 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 3795 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 3796 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 3797 | break; |
| 3798 | } |
| 3799 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3800 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 3801 | * specifically only auto mask tx and rx interrupts */ |
| 3802 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3803 | } |
| 3804 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3805 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 3806 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 3807 | |
| 3808 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3809 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 3810 | gpie |= IXGBE_GPIE_VTMODE_64; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3813 | /* Enable fan failure interrupt */ |
| 3814 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3815 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3816 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3817 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3818 | gpie |= IXGBE_SDP1_GPIEN; |
| 3819 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 3820 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3821 | |
| 3822 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 3823 | } |
| 3824 | |
| 3825 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 3826 | { |
| 3827 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3828 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 3829 | u32 ctrl_ext; |
| 3830 | |
| 3831 | ixgbe_get_hw_control(adapter); |
| 3832 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3833 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3834 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3835 | ixgbe_configure_msix(adapter); |
| 3836 | else |
| 3837 | ixgbe_configure_msi_and_legacy(adapter); |
| 3838 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3839 | /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */ |
| 3840 | if (hw->mac.ops.enable_tx_laser && |
| 3841 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 3842 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 3843 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 3844 | hw->mac.ops.enable_tx_laser(hw); |
| 3845 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3846 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3847 | ixgbe_napi_enable_all(adapter); |
| 3848 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 3849 | if (ixgbe_is_sfp(hw)) { |
| 3850 | ixgbe_sfp_link_config(adapter); |
| 3851 | } else { |
| 3852 | err = ixgbe_non_sfp_link_config(hw); |
| 3853 | if (err) |
| 3854 | e_err(probe, "link_config FAILED %d\n", err); |
| 3855 | } |
| 3856 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3857 | /* clear any pending interrupts, may auto mask */ |
| 3858 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3859 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3860 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3861 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3862 | * If this adapter has a fan, check to see if we had a failure |
| 3863 | * before we enabled the interrupt. |
| 3864 | */ |
| 3865 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 3866 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 3867 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3868 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3871 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3872 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3873 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3874 | /* bring the link up in the watchdog, this could race with our first |
| 3875 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3876 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3877 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3878 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 3879 | |
| 3880 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 3881 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 3882 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 3883 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
| 3884 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3885 | return 0; |
| 3886 | } |
| 3887 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3888 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 3889 | { |
| 3890 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3891 | /* put off any impending NetWatchDogTimeout */ |
| 3892 | adapter->netdev->trans_start = jiffies; |
| 3893 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3894 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3895 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3896 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 3897 | /* |
| 3898 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 3899 | * back up to give the VFs time to respond to the reset. The |
| 3900 | * two second wait is based upon the watchdog timer cycle in |
| 3901 | * the VF driver. |
| 3902 | */ |
| 3903 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3904 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3905 | ixgbe_up(adapter); |
| 3906 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 3907 | } |
| 3908 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3909 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 3910 | { |
| 3911 | /* hardware has been reset, we need to reload some things */ |
| 3912 | ixgbe_configure(adapter); |
| 3913 | |
| 3914 | return ixgbe_up_complete(adapter); |
| 3915 | } |
| 3916 | |
| 3917 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 3918 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3919 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3920 | int err; |
| 3921 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3922 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 3923 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 3924 | usleep_range(1000, 2000); |
| 3925 | |
| 3926 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 3927 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 3928 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 3929 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 3930 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3931 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3932 | switch (err) { |
| 3933 | case 0: |
| 3934 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3935 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3936 | break; |
| 3937 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3938 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3939 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3940 | case IXGBE_ERR_EEPROM_VERSION: |
| 3941 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3942 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 3943 | "Please be aware there may be issuesassociated with " |
| 3944 | "your hardware. If you are experiencing problems " |
| 3945 | "please contact your Intel or hardware " |
| 3946 | "representative who provided you with this " |
| 3947 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3948 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3949 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3950 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3951 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3952 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 3953 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 3954 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3955 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3956 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 3957 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3960 | /** |
| 3961 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3962 | * @rx_ring: ring to free buffers from |
| 3963 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3964 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3965 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3966 | struct device *dev = rx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3967 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3968 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3969 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3970 | /* ring already cleared, nothing to do */ |
| 3971 | if (!rx_ring->rx_buffer_info) |
| 3972 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3973 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3974 | /* Free all the Rx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3975 | for (i = 0; i < rx_ring->count; i++) { |
| 3976 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 3977 | |
| 3978 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 3979 | if (rx_buffer_info->dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3980 | dma_unmap_single(rx_ring->dev, rx_buffer_info->dma, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3981 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3982 | DMA_FROM_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3983 | rx_buffer_info->dma = 0; |
| 3984 | } |
| 3985 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3986 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3987 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3988 | do { |
| 3989 | struct sk_buff *this = skb; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 3990 | if (IXGBE_RSC_CB(this)->delay_unmap) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3991 | dma_unmap_single(dev, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3992 | IXGBE_RSC_CB(this)->dma, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3993 | rx_ring->rx_buf_len, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 3994 | DMA_FROM_DEVICE); |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 3995 | IXGBE_RSC_CB(this)->dma = 0; |
Mallikarjuna R Chilakala | e8171aa | 2010-05-13 17:33:21 +0000 | [diff] [blame] | 3996 | IXGBE_RSC_CB(skb)->delay_unmap = false; |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 3997 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3998 | skb = skb->prev; |
| 3999 | dev_kfree_skb(this); |
| 4000 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4001 | } |
| 4002 | if (!rx_buffer_info->page) |
| 4003 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 4004 | if (rx_buffer_info->page_dma) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4005 | dma_unmap_page(dev, rx_buffer_info->page_dma, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 4006 | PAGE_SIZE / 2, DMA_FROM_DEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 4007 | rx_buffer_info->page_dma = 0; |
| 4008 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4009 | put_page(rx_buffer_info->page); |
| 4010 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 4011 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4015 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4016 | |
| 4017 | /* Zero out the descriptor ring */ |
| 4018 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4019 | |
| 4020 | rx_ring->next_to_clean = 0; |
| 4021 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | /** |
| 4025 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4026 | * @tx_ring: ring to be cleaned |
| 4027 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4028 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4029 | { |
| 4030 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4031 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4032 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4033 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4034 | /* ring already cleared, nothing to do */ |
| 4035 | if (!tx_ring->tx_buffer_info) |
| 4036 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4037 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4038 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4039 | for (i = 0; i < tx_ring->count; i++) { |
| 4040 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4041 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4045 | memset(tx_ring->tx_buffer_info, 0, size); |
| 4046 | |
| 4047 | /* Zero out the descriptor ring */ |
| 4048 | memset(tx_ring->desc, 0, tx_ring->size); |
| 4049 | |
| 4050 | tx_ring->next_to_use = 0; |
| 4051 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4055 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4056 | * @adapter: board private structure |
| 4057 | **/ |
| 4058 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4059 | { |
| 4060 | int i; |
| 4061 | |
| 4062 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4063 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4066 | /** |
| 4067 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4068 | * @adapter: board private structure |
| 4069 | **/ |
| 4070 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4071 | { |
| 4072 | int i; |
| 4073 | |
| 4074 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4075 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4076 | } |
| 4077 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4078 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4079 | { |
| 4080 | struct hlist_node *node, *node2; |
| 4081 | struct ixgbe_fdir_filter *filter; |
| 4082 | |
| 4083 | spin_lock(&adapter->fdir_perfect_lock); |
| 4084 | |
| 4085 | hlist_for_each_entry_safe(filter, node, node2, |
| 4086 | &adapter->fdir_filter_list, fdir_node) { |
| 4087 | hlist_del(&filter->fdir_node); |
| 4088 | kfree(filter); |
| 4089 | } |
| 4090 | adapter->fdir_filter_count = 0; |
| 4091 | |
| 4092 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4093 | } |
| 4094 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4095 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4096 | { |
| 4097 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4098 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4099 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4100 | int i; |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4101 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4102 | |
| 4103 | /* signal that we are down to the interrupt handler */ |
| 4104 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4105 | |
| 4106 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4107 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4108 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4109 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4110 | /* disable all enabled rx queues */ |
| 4111 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4112 | /* this call also flushes the previous write */ |
| 4113 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4114 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4115 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4116 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4117 | netif_tx_stop_all_queues(netdev); |
| 4118 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4119 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4120 | netif_carrier_off(netdev); |
| 4121 | netif_tx_disable(netdev); |
| 4122 | |
| 4123 | ixgbe_irq_disable(adapter); |
| 4124 | |
| 4125 | ixgbe_napi_disable_all(adapter); |
| 4126 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4127 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4128 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4129 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4130 | |
| 4131 | del_timer_sync(&adapter->service_timer); |
| 4132 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4133 | /* disable receive for all VFs and wait one second */ |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4134 | if (adapter->num_vfs) { |
| 4135 | /* 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] | 4136 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4137 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4138 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4139 | ixgbe_disable_tx_rx(adapter); |
| 4140 | |
| 4141 | /* Mark all the VFs as inactive */ |
| 4142 | for (i = 0 ; i < adapter->num_vfs; i++) |
| 4143 | adapter->vfinfo[i].clear_to_send = 0; |
| 4144 | } |
| 4145 | |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4146 | /* Cleanup the affinity_hint CPU mask memory and callback */ |
| 4147 | for (i = 0; i < num_q_vectors; i++) { |
| 4148 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 4149 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4150 | irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL); |
| 4151 | /* release the CPU mask memory */ |
| 4152 | free_cpumask_var(q_vector->affinity_mask); |
| 4153 | } |
| 4154 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4155 | /* disable transmits in the hardware now that interrupts are off */ |
| 4156 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4157 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4158 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4159 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4160 | |
| 4161 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4162 | switch (hw->mac.type) { |
| 4163 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4164 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4165 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4166 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4167 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4168 | break; |
| 4169 | default: |
| 4170 | break; |
| 4171 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4172 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4173 | if (!pci_channel_offline(adapter->pdev)) |
| 4174 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4175 | |
| 4176 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 4177 | if (hw->mac.ops.disable_tx_laser && |
| 4178 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 4179 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4180 | (hw->mac.type == ixgbe_mac_82599EB)))) |
| 4181 | hw->mac.ops.disable_tx_laser(hw); |
| 4182 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4183 | ixgbe_clean_all_tx_rings(adapter); |
| 4184 | ixgbe_clean_all_rx_rings(adapter); |
| 4185 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4186 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4187 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4188 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4189 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4190 | } |
| 4191 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4192 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4193 | * ixgbe_poll - NAPI Rx polling callback |
| 4194 | * @napi: structure for representing this polling device |
| 4195 | * @budget: how many packets driver is allowed to clean |
| 4196 | * |
| 4197 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4198 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4199 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4200 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4201 | struct ixgbe_q_vector *q_vector = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4202 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4203 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4204 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4205 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4206 | #ifdef CONFIG_IXGBE_DCA |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 4207 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 4208 | ixgbe_update_dca(q_vector); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4209 | #endif |
| 4210 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4211 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]); |
| 4212 | 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] | 4213 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 4214 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4215 | work_done = budget; |
| 4216 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 4217 | /* If budget not fully consumed, exit the polling mode */ |
| 4218 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 4219 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4220 | if (adapter->rx_itr_setting & 1) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 4221 | ixgbe_set_itr(q_vector); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4222 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 4223 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4224 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4225 | return work_done; |
| 4226 | } |
| 4227 | |
| 4228 | /** |
| 4229 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4230 | * @netdev: network interface device structure |
| 4231 | **/ |
| 4232 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4233 | { |
| 4234 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4235 | |
| 4236 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4237 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4240 | /** |
| 4241 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 4242 | * @adapter: board private structure to initialize |
| 4243 | * |
| 4244 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 4245 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 4246 | * |
| 4247 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4248 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 4249 | { |
| 4250 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4251 | 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] | 4252 | |
| 4253 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4254 | f->mask = 0xF; |
| 4255 | adapter->num_rx_queues = f->indices; |
| 4256 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4257 | ret = true; |
| 4258 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4259 | ret = false; |
| 4260 | } |
| 4261 | |
| 4262 | return ret; |
| 4263 | } |
| 4264 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4265 | /** |
| 4266 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 4267 | * @adapter: board private structure to initialize |
| 4268 | * |
| 4269 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 4270 | * to the original CPU that initiated the Tx session. This runs in addition |
| 4271 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 4272 | * Rx load across CPUs using RSS. |
| 4273 | * |
| 4274 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4275 | 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] | 4276 | { |
| 4277 | bool ret = false; |
| 4278 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 4279 | |
| 4280 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 4281 | f_fdir->mask = 0; |
| 4282 | |
| 4283 | /* Flow Director must have RSS enabled */ |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4284 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4285 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4286 | adapter->num_tx_queues = f_fdir->indices; |
| 4287 | adapter->num_rx_queues = f_fdir->indices; |
| 4288 | ret = true; |
| 4289 | } else { |
| 4290 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4291 | } |
| 4292 | return ret; |
| 4293 | } |
| 4294 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4295 | #ifdef IXGBE_FCOE |
| 4296 | /** |
| 4297 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 4298 | * @adapter: board private structure to initialize |
| 4299 | * |
| 4300 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 4301 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 4302 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 4303 | * index of the first rx queue used by FCoE. |
| 4304 | * |
| 4305 | **/ |
| 4306 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 4307 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4308 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 4309 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4310 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4311 | return false; |
| 4312 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4313 | f->indices = min((int)num_online_cpus(), f->indices); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4314 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4315 | adapter->num_rx_queues = 1; |
| 4316 | adapter->num_tx_queues = 1; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4317 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4318 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 4319 | e_info(probe, "FCoE enabled with RSS\n"); |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4320 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4321 | ixgbe_set_fdir_queues(adapter); |
| 4322 | else |
| 4323 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4324 | } |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4325 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4326 | /* adding FCoE rx rings to the end */ |
| 4327 | f->mask = adapter->num_rx_queues; |
| 4328 | adapter->num_rx_queues += f->indices; |
| 4329 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4330 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4331 | return true; |
| 4332 | } |
| 4333 | #endif /* IXGBE_FCOE */ |
| 4334 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4335 | /* Artificial max queue cap per traffic class in DCB mode */ |
| 4336 | #define DCB_QUEUE_CAP 8 |
| 4337 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4338 | #ifdef CONFIG_IXGBE_DCB |
| 4339 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
| 4340 | { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4341 | int per_tc_q, q, i, offset = 0; |
| 4342 | struct net_device *dev = adapter->netdev; |
| 4343 | int tcs = netdev_get_num_tc(dev); |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4344 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4345 | if (!tcs) |
| 4346 | return false; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4347 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4348 | /* Map queue offset and counts onto allocated tx queues */ |
| 4349 | per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP); |
| 4350 | q = min((int)num_online_cpus(), per_tc_q); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4351 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4352 | for (i = 0; i < tcs; i++) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4353 | netdev_set_prio_tc_map(dev, i, i); |
| 4354 | netdev_set_tc_queue(dev, i, q, offset); |
| 4355 | offset += q; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4356 | } |
| 4357 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4358 | adapter->num_tx_queues = q * tcs; |
| 4359 | adapter->num_rx_queues = q * tcs; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4360 | |
| 4361 | #ifdef IXGBE_FCOE |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4362 | /* FCoE enabled queues require special configuration indexed |
| 4363 | * by feature specific indices and mask. Here we map FCoE |
| 4364 | * indices onto the DCB queue pairs allowing FCoE to own |
| 4365 | * configuration later. |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4366 | */ |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4367 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 4368 | int tc; |
| 4369 | struct ixgbe_ring_feature *f = |
| 4370 | &adapter->ring_feature[RING_F_FCOE]; |
| 4371 | |
| 4372 | tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up); |
| 4373 | f->indices = dev->tc_to_txq[tc].count; |
| 4374 | f->mask = dev->tc_to_txq[tc].offset; |
| 4375 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4376 | #endif |
| 4377 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 4378 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4379 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4380 | #endif |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4381 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4382 | /** |
| 4383 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 4384 | * @adapter: board private structure to initialize |
| 4385 | * |
| 4386 | * IOV doesn't actually use anything, so just NAK the |
| 4387 | * request for now and let the other queue routines |
| 4388 | * figure out what to do. |
| 4389 | */ |
| 4390 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 4391 | { |
| 4392 | return false; |
| 4393 | } |
| 4394 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4395 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4396 | * ixgbe_set_num_queues: Allocate queues for device, feature dependent |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4397 | * @adapter: board private structure to initialize |
| 4398 | * |
| 4399 | * This is the top level queue allocation routine. The order here is very |
| 4400 | * important, starting with the "most" number of features turned on at once, |
| 4401 | * and ending with the smallest set of features. This way large combinations |
| 4402 | * can be allocated if they're turned on, and smaller combinations are the |
| 4403 | * fallthrough conditions. |
| 4404 | * |
| 4405 | **/ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4406 | static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4407 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4408 | /* Start with base case */ |
| 4409 | adapter->num_rx_queues = 1; |
| 4410 | adapter->num_tx_queues = 1; |
| 4411 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 4412 | adapter->num_rx_queues_per_pool = 1; |
| 4413 | |
| 4414 | if (ixgbe_set_sriov_queues(adapter)) |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4415 | goto done; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4416 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4417 | #ifdef CONFIG_IXGBE_DCB |
| 4418 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4419 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4420 | |
| 4421 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4422 | #ifdef IXGBE_FCOE |
| 4423 | if (ixgbe_set_fcoe_queues(adapter)) |
| 4424 | goto done; |
| 4425 | |
| 4426 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4427 | if (ixgbe_set_fdir_queues(adapter)) |
| 4428 | goto done; |
| 4429 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4430 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 4431 | goto done; |
| 4432 | |
| 4433 | /* fallback to base case */ |
| 4434 | adapter->num_rx_queues = 1; |
| 4435 | adapter->num_tx_queues = 1; |
| 4436 | |
| 4437 | done: |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4438 | /* Notify the stack of the (possibly) reduced queue counts. */ |
John Fastabend | f0796d5 | 2010-07-01 13:21:57 +0000 | [diff] [blame] | 4439 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4440 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 4441 | adapter->num_rx_queues); |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4442 | } |
| 4443 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4444 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4445 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4446 | { |
| 4447 | int err, vector_threshold; |
| 4448 | |
| 4449 | /* We'll want at least 3 (vector_threshold): |
| 4450 | * 1) TxQ[0] Cleanup |
| 4451 | * 2) RxQ[0] Cleanup |
| 4452 | * 3) Other (Link Status Change, etc.) |
| 4453 | * 4) TCP Timer (optional) |
| 4454 | */ |
| 4455 | vector_threshold = MIN_MSIX_COUNT; |
| 4456 | |
| 4457 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 4458 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 4459 | * Right now, we simply care about how many we'll get; we'll |
| 4460 | * set them up later while requesting irq's. |
| 4461 | */ |
| 4462 | while (vectors >= vector_threshold) { |
| 4463 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4464 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4465 | if (!err) /* Success in acquiring all requested vectors. */ |
| 4466 | break; |
| 4467 | else if (err < 0) |
| 4468 | vectors = 0; /* Nasty failure, quit now */ |
| 4469 | else /* err == number of vectors we should try again with */ |
| 4470 | vectors = err; |
| 4471 | } |
| 4472 | |
| 4473 | if (vectors < vector_threshold) { |
| 4474 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 4475 | * This just means we'll go with either a single MSI |
| 4476 | * vector or fall back to legacy interrupts. |
| 4477 | */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4478 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4479 | "Unable to allocate MSI-X interrupts\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4480 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4481 | kfree(adapter->msix_entries); |
| 4482 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4483 | } else { |
| 4484 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 4485 | /* |
| 4486 | * Adjust for only the vectors we'll use, which is minimum |
| 4487 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 4488 | * vectors we were allocated. |
| 4489 | */ |
| 4490 | adapter->num_msix_vectors = min(vectors, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4491 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4492 | } |
| 4493 | } |
| 4494 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4495 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4496 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4497 | * @adapter: board private structure to initialize |
| 4498 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4499 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 4500 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4501 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4502 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4503 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4504 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4505 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4506 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 4507 | return false; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4508 | |
Alexander Duyck | 9d6b758 | 2010-11-16 19:27:06 -0800 | [diff] [blame] | 4509 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4510 | adapter->rx_ring[i]->reg_idx = i; |
| 4511 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4512 | adapter->tx_ring[i]->reg_idx = i; |
| 4513 | |
| 4514 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4515 | } |
| 4516 | |
| 4517 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4518 | |
| 4519 | /* ixgbe_get_first_reg_idx - Return first register index associated with ring */ |
John Fastabend | b32c8dc | 2011-04-12 02:44:55 +0000 | [diff] [blame] | 4520 | static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc, |
| 4521 | unsigned int *tx, unsigned int *rx) |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4522 | { |
| 4523 | struct net_device *dev = adapter->netdev; |
| 4524 | struct ixgbe_hw *hw = &adapter->hw; |
| 4525 | u8 num_tcs = netdev_get_num_tc(dev); |
| 4526 | |
| 4527 | *tx = 0; |
| 4528 | *rx = 0; |
| 4529 | |
| 4530 | switch (hw->mac.type) { |
| 4531 | case ixgbe_mac_82598EB: |
John Fastabend | aba70d5 | 2011-04-26 07:26:14 +0000 | [diff] [blame] | 4532 | *tx = tc << 2; |
| 4533 | *rx = tc << 3; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4534 | break; |
| 4535 | case ixgbe_mac_82599EB: |
| 4536 | case ixgbe_mac_X540: |
| 4537 | if (num_tcs == 8) { |
| 4538 | if (tc < 3) { |
| 4539 | *tx = tc << 5; |
| 4540 | *rx = tc << 4; |
| 4541 | } else if (tc < 5) { |
| 4542 | *tx = ((tc + 2) << 4); |
| 4543 | *rx = tc << 4; |
| 4544 | } else if (tc < num_tcs) { |
| 4545 | *tx = ((tc + 8) << 3); |
| 4546 | *rx = tc << 4; |
| 4547 | } |
| 4548 | } else if (num_tcs == 4) { |
| 4549 | *rx = tc << 5; |
| 4550 | switch (tc) { |
| 4551 | case 0: |
| 4552 | *tx = 0; |
| 4553 | break; |
| 4554 | case 1: |
| 4555 | *tx = 64; |
| 4556 | break; |
| 4557 | case 2: |
| 4558 | *tx = 96; |
| 4559 | break; |
| 4560 | case 3: |
| 4561 | *tx = 112; |
| 4562 | break; |
| 4563 | default: |
| 4564 | break; |
| 4565 | } |
| 4566 | } |
| 4567 | break; |
| 4568 | default: |
| 4569 | break; |
| 4570 | } |
| 4571 | } |
| 4572 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4573 | /** |
| 4574 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 4575 | * @adapter: board private structure to initialize |
| 4576 | * |
| 4577 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 4578 | * |
| 4579 | **/ |
| 4580 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 4581 | { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4582 | struct net_device *dev = adapter->netdev; |
| 4583 | int i, j, k; |
| 4584 | u8 num_tcs = netdev_get_num_tc(dev); |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4585 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 4586 | if (!num_tcs) |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4587 | return false; |
| 4588 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4589 | for (i = 0, k = 0; i < num_tcs; i++) { |
| 4590 | unsigned int tx_s, rx_s; |
| 4591 | u16 count = dev->tc_to_txq[i].count; |
| 4592 | |
| 4593 | ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s); |
| 4594 | for (j = 0; j < count; j++, k++) { |
| 4595 | adapter->tx_ring[k]->reg_idx = tx_s + j; |
| 4596 | adapter->rx_ring[k]->reg_idx = rx_s + j; |
| 4597 | adapter->tx_ring[k]->dcb_tc = i; |
| 4598 | adapter->rx_ring[k]->dcb_tc = i; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4599 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4600 | } |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4601 | |
| 4602 | return true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4603 | } |
| 4604 | #endif |
| 4605 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4606 | /** |
| 4607 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 4608 | * @adapter: board private structure to initialize |
| 4609 | * |
| 4610 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 4611 | * |
| 4612 | **/ |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4613 | 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] | 4614 | { |
| 4615 | int i; |
| 4616 | bool ret = false; |
| 4617 | |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4618 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 4619 | (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4620 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4621 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4622 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4623 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4624 | ret = true; |
| 4625 | } |
| 4626 | |
| 4627 | return ret; |
| 4628 | } |
| 4629 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4630 | #ifdef IXGBE_FCOE |
| 4631 | /** |
| 4632 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 4633 | * @adapter: board private structure to initialize |
| 4634 | * |
| 4635 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 4636 | * |
| 4637 | */ |
| 4638 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 4639 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4640 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4641 | int i; |
| 4642 | u8 fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4643 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4644 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
| 4645 | return false; |
| 4646 | |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4647 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4648 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4649 | ixgbe_cache_ring_fdir(adapter); |
| 4650 | else |
| 4651 | ixgbe_cache_ring_rss(adapter); |
| 4652 | |
| 4653 | fcoe_rx_i = f->mask; |
| 4654 | fcoe_tx_i = f->mask; |
| 4655 | } |
| 4656 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 4657 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 4658 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
| 4659 | } |
| 4660 | return true; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4664 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4665 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 4666 | * @adapter: board private structure to initialize |
| 4667 | * |
| 4668 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 4669 | * no other mapping is used. |
| 4670 | * |
| 4671 | */ |
| 4672 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 4673 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4674 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 4675 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4676 | if (adapter->num_vfs) |
| 4677 | return true; |
| 4678 | else |
| 4679 | return false; |
| 4680 | } |
| 4681 | |
| 4682 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4683 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 4684 | * @adapter: board private structure to initialize |
| 4685 | * |
| 4686 | * Once we know the feature-set enabled for the device, we'll cache |
| 4687 | * the register offset the descriptor ring is assigned to. |
| 4688 | * |
| 4689 | * Note, the order the various feature calls is important. It must start with |
| 4690 | * the "most" features enabled at the same time, then trickle down to the |
| 4691 | * least amount of features turned on at once. |
| 4692 | **/ |
| 4693 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 4694 | { |
| 4695 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4696 | adapter->rx_ring[0]->reg_idx = 0; |
| 4697 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4698 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4699 | if (ixgbe_cache_ring_sriov(adapter)) |
| 4700 | return; |
| 4701 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4702 | #ifdef CONFIG_IXGBE_DCB |
| 4703 | if (ixgbe_cache_ring_dcb(adapter)) |
| 4704 | return; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4705 | #endif |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 4706 | |
| 4707 | #ifdef IXGBE_FCOE |
| 4708 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 4709 | return; |
| 4710 | #endif /* IXGBE_FCOE */ |
| 4711 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4712 | if (ixgbe_cache_ring_fdir(adapter)) |
| 4713 | return; |
| 4714 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 4715 | if (ixgbe_cache_ring_rss(adapter)) |
| 4716 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4717 | } |
| 4718 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4719 | /** |
| 4720 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 4721 | * @adapter: board private structure to initialize |
| 4722 | * |
| 4723 | * 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] | 4724 | * number of queues at compile-time. The polling_netdev array is |
| 4725 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4726 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4727 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4728 | { |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4729 | int rx = 0, tx = 0, nid = adapter->node; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4730 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4731 | if (nid < 0 || !node_online(nid)) |
| 4732 | nid = first_online_node; |
| 4733 | |
| 4734 | for (; tx < adapter->num_tx_queues; tx++) { |
| 4735 | struct ixgbe_ring *ring; |
| 4736 | |
| 4737 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4738 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4739 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4740 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4741 | goto err_allocation; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4742 | ring->count = adapter->tx_ring_count; |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4743 | ring->queue_index = tx; |
| 4744 | ring->numa_node = nid; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4745 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 4746 | ring->netdev = adapter->netdev; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4747 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4748 | adapter->tx_ring[tx] = ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4749 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 4750 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4751 | for (; rx < adapter->num_rx_queues; rx++) { |
| 4752 | struct ixgbe_ring *ring; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4753 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4754 | ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4755 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4756 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4757 | if (!ring) |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4758 | goto err_allocation; |
| 4759 | ring->count = adapter->rx_ring_count; |
| 4760 | ring->queue_index = rx; |
| 4761 | ring->numa_node = nid; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4762 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 4763 | ring->netdev = adapter->netdev; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4764 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4765 | adapter->rx_ring[rx] = ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4766 | } |
| 4767 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4768 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4769 | |
| 4770 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4771 | |
Eric Dumazet | e2ddeba | 2010-11-16 19:27:18 -0800 | [diff] [blame] | 4772 | err_allocation: |
| 4773 | while (tx) |
| 4774 | kfree(adapter->tx_ring[--tx]); |
| 4775 | |
| 4776 | while (rx) |
| 4777 | kfree(adapter->rx_ring[--rx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4778 | return -ENOMEM; |
| 4779 | } |
| 4780 | |
| 4781 | /** |
| 4782 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 4783 | * @adapter: board private structure to initialize |
| 4784 | * |
| 4785 | * Attempt to configure the interrupts using the best available |
| 4786 | * capabilities of the hardware and the kernel. |
| 4787 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 4788 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4789 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4790 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4791 | int err = 0; |
| 4792 | int vector, v_budget; |
| 4793 | |
| 4794 | /* |
| 4795 | * It's easy to be greedy for MSI-X vectors, but it really |
| 4796 | * doesn't do us much good if we have a lot more vectors |
| 4797 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 4798 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4799 | */ |
| 4800 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4801 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4802 | |
| 4803 | /* |
| 4804 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4805 | * hw.mac->max_msix_vectors vectors. With features |
| 4806 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 4807 | * descriptor queues supported by our device. Thus, we cap it off in |
| 4808 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4809 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 4810 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4811 | |
| 4812 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 4813 | * mean we disable MSI-X capabilities of the adapter. */ |
| 4814 | adapter->msix_entries = kcalloc(v_budget, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4815 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4816 | if (adapter->msix_entries) { |
| 4817 | for (vector = 0; vector < v_budget; vector++) |
| 4818 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4819 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4820 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 4821 | |
| 4822 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4823 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4824 | } |
David S. Miller | 26d2784 | 2010-05-03 15:18:22 -0700 | [diff] [blame] | 4825 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4826 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 4827 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4828 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4829 | e_err(probe, |
Alexander Duyck | 03ecf91 | 2011-05-20 07:36:17 +0000 | [diff] [blame] | 4830 | "ATR is not supported while multiple " |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 4831 | "queues are disabled. Disabling Flow Director\n"); |
| 4832 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4833 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4834 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 4835 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4836 | ixgbe_disable_sriov(adapter); |
| 4837 | |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4838 | err = ixgbe_set_num_queues(adapter); |
| 4839 | if (err) |
| 4840 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4841 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4842 | err = pci_enable_msi(adapter->pdev); |
| 4843 | if (!err) { |
| 4844 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 4845 | } else { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4846 | netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev, |
| 4847 | "Unable to allocate MSI interrupt, " |
| 4848 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4849 | /* reset err */ |
| 4850 | err = 0; |
| 4851 | } |
| 4852 | |
| 4853 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4854 | return err; |
| 4855 | } |
| 4856 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4857 | /** |
| 4858 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 4859 | * @adapter: board private structure to initialize |
| 4860 | * |
| 4861 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 4862 | * return -ENOMEM. |
| 4863 | **/ |
| 4864 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 4865 | { |
| 4866 | int q_idx, num_q_vectors; |
| 4867 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4868 | int (*poll)(struct napi_struct *, int); |
| 4869 | |
| 4870 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 4871 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4872 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4873 | } else { |
| 4874 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4875 | poll = &ixgbe_poll; |
| 4876 | } |
| 4877 | |
| 4878 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4879 | q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4880 | GFP_KERNEL, adapter->node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4881 | if (!q_vector) |
| 4882 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4883 | GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4884 | if (!q_vector) |
| 4885 | goto err_out; |
| 4886 | q_vector->adapter = adapter; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 4887 | if (q_vector->tx.count && !q_vector->rx.count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4888 | q_vector->eitr = adapter->tx_eitr_param; |
| 4889 | else |
| 4890 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4891 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4892 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4893 | adapter->q_vector[q_idx] = q_vector; |
| 4894 | } |
| 4895 | |
| 4896 | return 0; |
| 4897 | |
| 4898 | err_out: |
| 4899 | while (q_idx) { |
| 4900 | q_idx--; |
| 4901 | q_vector = adapter->q_vector[q_idx]; |
| 4902 | netif_napi_del(&q_vector->napi); |
| 4903 | kfree(q_vector); |
| 4904 | adapter->q_vector[q_idx] = NULL; |
| 4905 | } |
| 4906 | return -ENOMEM; |
| 4907 | } |
| 4908 | |
| 4909 | /** |
| 4910 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 4911 | * @adapter: board private structure to initialize |
| 4912 | * |
| 4913 | * This function frees the memory allocated to the q_vectors. In addition if |
| 4914 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4915 | * to freeing the q_vector. |
| 4916 | **/ |
| 4917 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 4918 | { |
| 4919 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4920 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4921 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4922 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4923 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4924 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4925 | |
| 4926 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 4927 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4928 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4929 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4930 | kfree(q_vector); |
| 4931 | } |
| 4932 | } |
| 4933 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 4934 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4935 | { |
| 4936 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 4937 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4938 | pci_disable_msix(adapter->pdev); |
| 4939 | kfree(adapter->msix_entries); |
| 4940 | adapter->msix_entries = NULL; |
| 4941 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 4942 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 4943 | pci_disable_msi(adapter->pdev); |
| 4944 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | /** |
| 4948 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 4949 | * @adapter: board private structure to initialize |
| 4950 | * |
| 4951 | * We determine which interrupt scheme to use based on... |
| 4952 | * - Kernel support (MSI, MSI-X) |
| 4953 | * - which can be user-defined (via MODULE_PARAM) |
| 4954 | * - Hardware queue count (num_*_queues) |
| 4955 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 4956 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4957 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4958 | { |
| 4959 | int err; |
| 4960 | |
| 4961 | /* Number of supported queues */ |
Ben Hutchings | 847f53f | 2010-09-27 08:28:56 +0000 | [diff] [blame] | 4962 | err = ixgbe_set_num_queues(adapter); |
| 4963 | if (err) |
| 4964 | return err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4965 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4966 | err = ixgbe_set_interrupt_capability(adapter); |
| 4967 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4968 | e_dev_err("Unable to setup interrupt capabilities\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4969 | goto err_set_interrupt; |
| 4970 | } |
| 4971 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4972 | err = ixgbe_alloc_q_vectors(adapter); |
| 4973 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4974 | e_dev_err("Unable to allocate memory for queue vectors\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4975 | goto err_alloc_q_vectors; |
| 4976 | } |
| 4977 | |
| 4978 | err = ixgbe_alloc_queues(adapter); |
| 4979 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4980 | e_dev_err("Unable to allocate memory for queues\n"); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4981 | goto err_alloc_queues; |
| 4982 | } |
| 4983 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4984 | 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] | 4985 | (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 4986 | adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4987 | |
| 4988 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4989 | |
| 4990 | return 0; |
| 4991 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4992 | err_alloc_queues: |
| 4993 | ixgbe_free_q_vectors(adapter); |
| 4994 | err_alloc_q_vectors: |
| 4995 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4996 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4997 | return err; |
| 4998 | } |
| 4999 | |
| 5000 | /** |
| 5001 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 5002 | * @adapter: board private structure to clear interrupt scheme on |
| 5003 | * |
| 5004 | * We go through and clear interrupt specific resources and reset the structure |
| 5005 | * to pre-load conditions |
| 5006 | **/ |
| 5007 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 5008 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5009 | int i; |
| 5010 | |
| 5011 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5012 | kfree(adapter->tx_ring[i]); |
| 5013 | adapter->tx_ring[i] = NULL; |
| 5014 | } |
| 5015 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 5016 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 5017 | |
| 5018 | /* ixgbe_get_stats64() might access this ring, we must wait |
| 5019 | * a grace period before freeing it. |
| 5020 | */ |
Lai Jiangshan | bcec8b6 | 2011-03-18 11:57:21 +0800 | [diff] [blame] | 5021 | kfree_rcu(ring, rcu); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5022 | adapter->rx_ring[i] = NULL; |
| 5023 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5024 | |
Don Skidmore | b8eb3a1 | 2010-12-01 20:54:53 +0000 | [diff] [blame] | 5025 | adapter->num_tx_queues = 0; |
| 5026 | adapter->num_rx_queues = 0; |
| 5027 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5028 | ixgbe_free_q_vectors(adapter); |
| 5029 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | /** |
| 5033 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5034 | * @adapter: board private structure to initialize |
| 5035 | * |
| 5036 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5037 | * Fields are initialized based on PCI device information and |
| 5038 | * OS network device settings (MTU size). |
| 5039 | **/ |
| 5040 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 5041 | { |
| 5042 | struct ixgbe_hw *hw = &adapter->hw; |
| 5043 | struct pci_dev *pdev = adapter->pdev; |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 5044 | struct net_device *dev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5045 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5046 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5047 | int j; |
| 5048 | struct tc_configuration *tc; |
| 5049 | #endif |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5050 | int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5051 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5052 | /* PCI config space info */ |
| 5053 | |
| 5054 | hw->vendor_id = pdev->vendor; |
| 5055 | hw->device_id = pdev->device; |
| 5056 | hw->revision_id = pdev->revision; |
| 5057 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 5058 | hw->subsystem_device_id = pdev->subsystem_device; |
| 5059 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5060 | /* Set capability flags */ |
| 5061 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 5062 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 5063 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5064 | switch (hw->mac.type) { |
| 5065 | case ixgbe_mac_82598EB: |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5066 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 5067 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5068 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5069 | break; |
| 5070 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5071 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5072 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5073 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 5074 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5075 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 5076 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | 45b9f50 | 2011-01-06 14:29:59 +0000 | [diff] [blame] | 5077 | /* Flow Director hash filters enabled */ |
| 5078 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5079 | adapter->atr_sample_rate = 20; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5080 | adapter->ring_feature[RING_F_FDIR].indices = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5081 | IXGBE_MAX_FDIR_INDICES; |
Alexander Duyck | c04f6ca | 2011-05-11 07:18:36 +0000 | [diff] [blame] | 5082 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5083 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5084 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 5085 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5086 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5087 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 5088 | /* Default traffic class to use for FCoE */ |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 5089 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5090 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5091 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5092 | break; |
| 5093 | default: |
| 5094 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5095 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5096 | |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 5097 | /* n-tuple support exists, always init our spinlock */ |
| 5098 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 5099 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5100 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5101 | /* Configure DCB traffic classes */ |
| 5102 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5103 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5104 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5105 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5106 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5107 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5108 | tc->dcb_pfc = pfc_disabled; |
| 5109 | } |
| 5110 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5111 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5112 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5113 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5114 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5115 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 5116 | MAX_TRAFFIC_CLASS); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5117 | |
| 5118 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5119 | |
| 5120 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5121 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5122 | 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] | 5123 | #ifdef CONFIG_DCB |
| 5124 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 5125 | #endif |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5126 | hw->fc.high_water = FC_HIGH_WATER(max_frame); |
| 5127 | hw->fc.low_water = FC_LOW_WATER(max_frame); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5128 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5129 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5130 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5131 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5132 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5133 | adapter->rx_itr_setting = 1; |
| 5134 | adapter->rx_eitr_param = 20000; |
| 5135 | adapter->tx_itr_setting = 1; |
| 5136 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5137 | |
| 5138 | /* set defaults for eitr in MegaBytes */ |
| 5139 | adapter->eitr_low = 10; |
| 5140 | adapter->eitr_high = 20; |
| 5141 | |
| 5142 | /* set default ring sizes */ |
| 5143 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5144 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5145 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5146 | /* set default work limits */ |
| 5147 | adapter->tx_work_limit = adapter->tx_ring_count; |
| 5148 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5149 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5150 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5151 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5152 | return -EIO; |
| 5153 | } |
| 5154 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5155 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5156 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 5157 | |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5158 | /* get assigned NUMA node */ |
| 5159 | adapter->node = dev_to_node(&pdev->dev); |
| 5160 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5161 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5162 | |
| 5163 | return 0; |
| 5164 | } |
| 5165 | |
| 5166 | /** |
| 5167 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5168 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5169 | * |
| 5170 | * Return 0 on success, negative on failure |
| 5171 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5172 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5173 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5174 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5175 | int size; |
| 5176 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5177 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5178 | tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5179 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5180 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5181 | if (!tx_ring->tx_buffer_info) |
| 5182 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5183 | |
| 5184 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5185 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5186 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5187 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5188 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 5189 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5190 | if (!tx_ring->desc) |
| 5191 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5192 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5193 | tx_ring->next_to_use = 0; |
| 5194 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5195 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5196 | |
| 5197 | err: |
| 5198 | vfree(tx_ring->tx_buffer_info); |
| 5199 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5200 | 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] | 5201 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5205 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5206 | * @adapter: board private structure |
| 5207 | * |
| 5208 | * If this function returns with an error, then it's possible one or |
| 5209 | * more of the rings is populated (while the rest are not). It is the |
| 5210 | * callers duty to clean those orphaned rings. |
| 5211 | * |
| 5212 | * Return 0 on success, negative on failure |
| 5213 | **/ |
| 5214 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5215 | { |
| 5216 | int i, err = 0; |
| 5217 | |
| 5218 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5219 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5220 | if (!err) |
| 5221 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5222 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5223 | break; |
| 5224 | } |
| 5225 | |
| 5226 | return err; |
| 5227 | } |
| 5228 | |
| 5229 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5230 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5231 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5232 | * |
| 5233 | * Returns 0 on success, negative on failure |
| 5234 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5235 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5236 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5237 | struct device *dev = rx_ring->dev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5238 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5239 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5240 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5241 | rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5242 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5243 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5244 | if (!rx_ring->rx_buffer_info) |
| 5245 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5246 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5247 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5248 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5249 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5250 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5251 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 5252 | &rx_ring->dma, GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5253 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5254 | if (!rx_ring->desc) |
| 5255 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5256 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5257 | rx_ring->next_to_clean = 0; |
| 5258 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5259 | |
| 5260 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5261 | err: |
| 5262 | vfree(rx_ring->rx_buffer_info); |
| 5263 | rx_ring->rx_buffer_info = NULL; |
| 5264 | 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] | 5265 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5269 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5270 | * @adapter: board private structure |
| 5271 | * |
| 5272 | * If this function returns with an error, then it's possible one or |
| 5273 | * more of the rings is populated (while the rest are not). It is the |
| 5274 | * callers duty to clean those orphaned rings. |
| 5275 | * |
| 5276 | * Return 0 on success, negative on failure |
| 5277 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5278 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5279 | { |
| 5280 | int i, err = 0; |
| 5281 | |
| 5282 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5283 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5284 | if (!err) |
| 5285 | continue; |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5286 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5287 | break; |
| 5288 | } |
| 5289 | |
| 5290 | return err; |
| 5291 | } |
| 5292 | |
| 5293 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5294 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5295 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5296 | * |
| 5297 | * Free all transmit software resources |
| 5298 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5299 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5300 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5301 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5302 | |
| 5303 | vfree(tx_ring->tx_buffer_info); |
| 5304 | tx_ring->tx_buffer_info = NULL; |
| 5305 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5306 | /* if not set, then don't free */ |
| 5307 | if (!tx_ring->desc) |
| 5308 | return; |
| 5309 | |
| 5310 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5311 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5312 | |
| 5313 | tx_ring->desc = NULL; |
| 5314 | } |
| 5315 | |
| 5316 | /** |
| 5317 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5318 | * @adapter: board private structure |
| 5319 | * |
| 5320 | * Free all transmit software resources |
| 5321 | **/ |
| 5322 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5323 | { |
| 5324 | int i; |
| 5325 | |
| 5326 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5327 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5328 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5332 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5333 | * @rx_ring: ring to clean the resources from |
| 5334 | * |
| 5335 | * Free all receive software resources |
| 5336 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5337 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5338 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5339 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5340 | |
| 5341 | vfree(rx_ring->rx_buffer_info); |
| 5342 | rx_ring->rx_buffer_info = NULL; |
| 5343 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5344 | /* if not set, then don't free */ |
| 5345 | if (!rx_ring->desc) |
| 5346 | return; |
| 5347 | |
| 5348 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5349 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5350 | |
| 5351 | rx_ring->desc = NULL; |
| 5352 | } |
| 5353 | |
| 5354 | /** |
| 5355 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5356 | * @adapter: board private structure |
| 5357 | * |
| 5358 | * Free all receive software resources |
| 5359 | **/ |
| 5360 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5361 | { |
| 5362 | int i; |
| 5363 | |
| 5364 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5365 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5366 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5367 | } |
| 5368 | |
| 5369 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5370 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5371 | * @netdev: network interface device structure |
| 5372 | * @new_mtu: new value for maximum frame size |
| 5373 | * |
| 5374 | * Returns 0 on success, negative on failure |
| 5375 | **/ |
| 5376 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5377 | { |
| 5378 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5379 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5380 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5381 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5382 | /* MTU < 68 is an error and causes problems on some kernels */ |
Greg Rose | e9f9807 | 2011-01-26 01:06:07 +0000 | [diff] [blame] | 5383 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED && |
| 5384 | hw->mac.type != ixgbe_mac_X540) { |
| 5385 | if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE)) |
| 5386 | return -EINVAL; |
| 5387 | } else { |
| 5388 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5389 | return -EINVAL; |
| 5390 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5391 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5392 | 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] | 5393 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5394 | netdev->mtu = new_mtu; |
| 5395 | |
John Fastabend | 16b61be | 2010-11-16 19:26:44 -0800 | [diff] [blame] | 5396 | hw->fc.high_water = FC_HIGH_WATER(max_frame); |
| 5397 | hw->fc.low_water = FC_LOW_WATER(max_frame); |
| 5398 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5399 | if (netif_running(netdev)) |
| 5400 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5401 | |
| 5402 | return 0; |
| 5403 | } |
| 5404 | |
| 5405 | /** |
| 5406 | * ixgbe_open - Called when a network interface is made active |
| 5407 | * @netdev: network interface device structure |
| 5408 | * |
| 5409 | * Returns 0 on success, negative value on failure |
| 5410 | * |
| 5411 | * The open entry point is called when a network interface is made |
| 5412 | * active by the system (IFF_UP). At this point all resources needed |
| 5413 | * for transmit and receive operations are allocated, the interrupt |
| 5414 | * handler is registered with the OS, the watchdog timer is started, |
| 5415 | * and the stack is notified that the interface is ready. |
| 5416 | **/ |
| 5417 | static int ixgbe_open(struct net_device *netdev) |
| 5418 | { |
| 5419 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5420 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5421 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5422 | /* disallow open during test */ |
| 5423 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5424 | return -EBUSY; |
| 5425 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5426 | netif_carrier_off(netdev); |
| 5427 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5428 | /* allocate transmit descriptors */ |
| 5429 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5430 | if (err) |
| 5431 | goto err_setup_tx; |
| 5432 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5433 | /* allocate receive descriptors */ |
| 5434 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5435 | if (err) |
| 5436 | goto err_setup_rx; |
| 5437 | |
| 5438 | ixgbe_configure(adapter); |
| 5439 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5440 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5441 | if (err) |
| 5442 | goto err_req_irq; |
| 5443 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5444 | err = ixgbe_up_complete(adapter); |
| 5445 | if (err) |
| 5446 | goto err_up; |
| 5447 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 5448 | netif_tx_start_all_queues(netdev); |
| 5449 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5450 | return 0; |
| 5451 | |
| 5452 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5453 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5454 | ixgbe_free_irq(adapter); |
| 5455 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5456 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5457 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5458 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5459 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5460 | ixgbe_reset(adapter); |
| 5461 | |
| 5462 | return err; |
| 5463 | } |
| 5464 | |
| 5465 | /** |
| 5466 | * ixgbe_close - Disables a network interface |
| 5467 | * @netdev: network interface device structure |
| 5468 | * |
| 5469 | * Returns 0, this is not allowed to fail |
| 5470 | * |
| 5471 | * The close entry point is called when an interface is de-activated |
| 5472 | * by the OS. The hardware is still under the drivers control, but |
| 5473 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5474 | * hardware, and all transmit and receive resources are freed. |
| 5475 | **/ |
| 5476 | static int ixgbe_close(struct net_device *netdev) |
| 5477 | { |
| 5478 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5479 | |
| 5480 | ixgbe_down(adapter); |
| 5481 | ixgbe_free_irq(adapter); |
| 5482 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5483 | ixgbe_fdir_filter_exit(adapter); |
| 5484 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5485 | ixgbe_free_all_tx_resources(adapter); |
| 5486 | ixgbe_free_all_rx_resources(adapter); |
| 5487 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5488 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5489 | |
| 5490 | return 0; |
| 5491 | } |
| 5492 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5493 | #ifdef CONFIG_PM |
| 5494 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5495 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5496 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5497 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5498 | u32 err; |
| 5499 | |
| 5500 | pci_set_power_state(pdev, PCI_D0); |
| 5501 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5502 | /* |
| 5503 | * pci_restore_state clears dev->state_saved so call |
| 5504 | * pci_save_state to restore it. |
| 5505 | */ |
| 5506 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5507 | |
| 5508 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5509 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5510 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5511 | return err; |
| 5512 | } |
| 5513 | pci_set_master(pdev); |
| 5514 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5515 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5516 | |
| 5517 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5518 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5519 | e_dev_err("Cannot initialize interrupts for device\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5520 | return err; |
| 5521 | } |
| 5522 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5523 | ixgbe_reset(adapter); |
| 5524 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5525 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5526 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5527 | if (netif_running(netdev)) { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5528 | err = ixgbe_open(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5529 | if (err) |
| 5530 | return err; |
| 5531 | } |
| 5532 | |
| 5533 | netif_device_attach(netdev); |
| 5534 | |
| 5535 | return 0; |
| 5536 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5537 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5538 | |
| 5539 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5540 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5541 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5542 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5543 | struct ixgbe_hw *hw = &adapter->hw; |
| 5544 | u32 ctrl, fctrl; |
| 5545 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5546 | #ifdef CONFIG_PM |
| 5547 | int retval = 0; |
| 5548 | #endif |
| 5549 | |
| 5550 | netif_device_detach(netdev); |
| 5551 | |
| 5552 | if (netif_running(netdev)) { |
| 5553 | ixgbe_down(adapter); |
| 5554 | ixgbe_free_irq(adapter); |
| 5555 | ixgbe_free_all_tx_resources(adapter); |
| 5556 | ixgbe_free_all_rx_resources(adapter); |
| 5557 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5558 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5559 | ixgbe_clear_interrupt_scheme(adapter); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 5560 | #ifdef CONFIG_DCB |
| 5561 | kfree(adapter->ixgbe_ieee_pfc); |
| 5562 | kfree(adapter->ixgbe_ieee_ets); |
| 5563 | #endif |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5564 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5565 | #ifdef CONFIG_PM |
| 5566 | retval = pci_save_state(pdev); |
| 5567 | if (retval) |
| 5568 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5569 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5570 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5571 | if (wufc) { |
| 5572 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5573 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5574 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5575 | if (wufc & IXGBE_WUFC_MC) { |
| 5576 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5577 | fctrl |= IXGBE_FCTRL_MPE; |
| 5578 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5579 | } |
| 5580 | |
| 5581 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5582 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5583 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5584 | |
| 5585 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5586 | } else { |
| 5587 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5588 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5589 | } |
| 5590 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5591 | switch (hw->mac.type) { |
| 5592 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5593 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5594 | break; |
| 5595 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5596 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5597 | pci_wake_from_d3(pdev, !!wufc); |
| 5598 | break; |
| 5599 | default: |
| 5600 | break; |
| 5601 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5602 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5603 | *enable_wake = !!wufc; |
| 5604 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5605 | ixgbe_release_hw_control(adapter); |
| 5606 | |
| 5607 | pci_disable_device(pdev); |
| 5608 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5609 | return 0; |
| 5610 | } |
| 5611 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5612 | #ifdef CONFIG_PM |
| 5613 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5614 | { |
| 5615 | int retval; |
| 5616 | bool wake; |
| 5617 | |
| 5618 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5619 | if (retval) |
| 5620 | return retval; |
| 5621 | |
| 5622 | if (wake) { |
| 5623 | pci_prepare_to_sleep(pdev); |
| 5624 | } else { |
| 5625 | pci_wake_from_d3(pdev, false); |
| 5626 | pci_set_power_state(pdev, PCI_D3hot); |
| 5627 | } |
| 5628 | |
| 5629 | return 0; |
| 5630 | } |
| 5631 | #endif /* CONFIG_PM */ |
| 5632 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5633 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5634 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5635 | bool wake; |
| 5636 | |
| 5637 | __ixgbe_shutdown(pdev, &wake); |
| 5638 | |
| 5639 | if (system_state == SYSTEM_POWER_OFF) { |
| 5640 | pci_wake_from_d3(pdev, wake); |
| 5641 | pci_set_power_state(pdev, PCI_D3hot); |
| 5642 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5643 | } |
| 5644 | |
| 5645 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5646 | * ixgbe_update_stats - Update the board statistics counters. |
| 5647 | * @adapter: board private structure |
| 5648 | **/ |
| 5649 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5650 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5651 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5652 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5653 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5654 | u64 total_mpc = 0; |
| 5655 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5656 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5657 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
| 5658 | u64 bytes = 0, packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5659 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5660 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5661 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5662 | return; |
| 5663 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5664 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5665 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5666 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5667 | for (i = 0; i < 16; i++) |
| 5668 | adapter->hw_rx_no_dma_resources += |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5669 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5670 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5671 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5672 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5673 | } |
| 5674 | adapter->rsc_total_count = rsc_count; |
| 5675 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5676 | } |
| 5677 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5678 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5679 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5680 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5681 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5682 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
| 5683 | bytes += rx_ring->stats.bytes; |
| 5684 | packets += rx_ring->stats.packets; |
| 5685 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5686 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5687 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5688 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
| 5689 | netdev->stats.rx_bytes = bytes; |
| 5690 | netdev->stats.rx_packets = packets; |
| 5691 | |
| 5692 | bytes = 0; |
| 5693 | packets = 0; |
| 5694 | /* gather some stats to the adapter struct that are per queue */ |
| 5695 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5696 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5697 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5698 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5699 | bytes += tx_ring->stats.bytes; |
| 5700 | packets += tx_ring->stats.packets; |
| 5701 | } |
| 5702 | adapter->restart_queue = restart_queue; |
| 5703 | adapter->tx_busy = tx_busy; |
| 5704 | netdev->stats.tx_bytes = bytes; |
| 5705 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5706 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5707 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5708 | for (i = 0; i < 8; i++) { |
| 5709 | /* for packet buffers not used, the register should read 0 */ |
| 5710 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5711 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5712 | hwstats->mpc[i] += mpc; |
| 5713 | total_mpc += hwstats->mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5714 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5715 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5716 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5717 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5718 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5719 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5720 | switch (hw->mac.type) { |
| 5721 | case ixgbe_mac_82598EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5722 | hwstats->pxonrxc[i] += |
| 5723 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5724 | break; |
| 5725 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5726 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5727 | hwstats->pxonrxc[i] += |
| 5728 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5729 | break; |
| 5730 | default: |
| 5731 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5732 | } |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5733 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5734 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5735 | } |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5736 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5737 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5738 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5739 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5740 | ixgbe_update_xoff_received(adapter); |
| 5741 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5742 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5743 | switch (hw->mac.type) { |
| 5744 | case ixgbe_mac_82598EB: |
| 5745 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5746 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5747 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5748 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5749 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5750 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5751 | /* OS2BMC stats are X540 only*/ |
| 5752 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5753 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5754 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5755 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5756 | case ixgbe_mac_82599EB: |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5757 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5758 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5759 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5760 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5761 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5762 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5763 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5764 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5765 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5766 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5767 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5768 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5769 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5770 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5771 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5772 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5773 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5774 | break; |
| 5775 | default: |
| 5776 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5777 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5778 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5779 | hwstats->bprc += bprc; |
| 5780 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5781 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5782 | hwstats->mprc -= bprc; |
| 5783 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5784 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5785 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5786 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5787 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5788 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5789 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5790 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5791 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5792 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5793 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5794 | hwstats->lxofftxc += lxoff; |
| 5795 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5796 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5797 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5798 | /* |
| 5799 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5800 | */ |
| 5801 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5802 | hwstats->gptc -= xon_off_tot; |
| 5803 | hwstats->mptc -= xon_off_tot; |
| 5804 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5805 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5806 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 5807 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 5808 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 5809 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 5810 | hwstats->ptc64 -= xon_off_tot; |
| 5811 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 5812 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 5813 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 5814 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 5815 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 5816 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5817 | |
| 5818 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5819 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5820 | |
| 5821 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5822 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5823 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5824 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 5825 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5826 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5830 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
| 5831 | * @adapter - pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5832 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5833 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5834 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5835 | struct ixgbe_hw *hw = &adapter->hw; |
| 5836 | int i; |
| 5837 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5838 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 5839 | return; |
| 5840 | |
| 5841 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 5842 | |
| 5843 | /* if interface is down do nothing */ |
| 5844 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 5845 | return; |
| 5846 | |
| 5847 | /* do nothing if we are not using signature filters */ |
| 5848 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 5849 | return; |
| 5850 | |
| 5851 | adapter->fdir_overflow++; |
| 5852 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5853 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 5854 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 5855 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 5856 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5857 | /* re-enable flow director interrupts */ |
| 5858 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5859 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5860 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5861 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5862 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5863 | } |
| 5864 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5865 | /** |
| 5866 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
| 5867 | * @adapter - pointer to the device adapter structure |
| 5868 | * |
| 5869 | * This function serves two purposes. First it strobes the interrupt lines |
| 5870 | * in order to make certain interrupts are occuring. Secondly it sets the |
| 5871 | * bits needed to check for TX hangs. As a result we should immediately |
| 5872 | * determine if a hang has occured. |
| 5873 | */ |
| 5874 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 5875 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5876 | struct ixgbe_hw *hw = &adapter->hw; |
| 5877 | u64 eics = 0; |
| 5878 | int i; |
| 5879 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5880 | /* If we're down or resetting, just bail */ |
| 5881 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5882 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5883 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5884 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5885 | /* Force detection of hung controller */ |
| 5886 | if (netif_carrier_ok(adapter->netdev)) { |
| 5887 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 5888 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 5889 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5890 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5891 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5892 | /* |
| 5893 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5894 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5895 | * would set *both* EIMS and EICS for any bit in EIAM |
| 5896 | */ |
| 5897 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 5898 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5899 | } else { |
| 5900 | /* get one bit for every active tx/rx interrupt vector */ |
| 5901 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 5902 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 5903 | if (qv->rx.count || qv->tx.count) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5904 | eics |= ((u64)1 << i); |
| 5905 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5908 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5909 | ixgbe_irq_rearm_queues(adapter, eics); |
| 5910 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5914 | * ixgbe_watchdog_update_link - update the link status |
| 5915 | * @adapter - pointer to the device adapter structure |
| 5916 | * @link_speed - pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5917 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5918 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5919 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5920 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5921 | u32 link_speed = adapter->link_speed; |
| 5922 | bool link_up = adapter->link_up; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5923 | int i; |
| 5924 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5925 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 5926 | return; |
| 5927 | |
| 5928 | if (hw->mac.ops.check_link) { |
| 5929 | 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] | 5930 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5931 | /* always assume link is up, if no check link function */ |
| 5932 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 5933 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5934 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5935 | if (link_up) { |
| 5936 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5937 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 5938 | hw->mac.ops.fc_enable(hw, i); |
| 5939 | } else { |
| 5940 | hw->mac.ops.fc_enable(hw, 0); |
| 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | if (link_up || |
| 5945 | time_after(jiffies, (adapter->link_check_timeout + |
| 5946 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 5947 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5948 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 5949 | IXGBE_WRITE_FLUSH(hw); |
| 5950 | } |
| 5951 | |
| 5952 | adapter->link_up = link_up; |
| 5953 | adapter->link_speed = link_speed; |
| 5954 | } |
| 5955 | |
| 5956 | /** |
| 5957 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 5958 | * print link up message |
| 5959 | * @adapter - pointer to the device adapter structure |
| 5960 | **/ |
| 5961 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 5962 | { |
| 5963 | struct net_device *netdev = adapter->netdev; |
| 5964 | struct ixgbe_hw *hw = &adapter->hw; |
| 5965 | u32 link_speed = adapter->link_speed; |
| 5966 | bool flow_rx, flow_tx; |
| 5967 | |
| 5968 | /* only continue if link was previously down */ |
| 5969 | if (netif_carrier_ok(netdev)) |
| 5970 | return; |
| 5971 | |
| 5972 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 5973 | |
| 5974 | switch (hw->mac.type) { |
| 5975 | case ixgbe_mac_82598EB: { |
| 5976 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5977 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 5978 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 5979 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 5980 | } |
| 5981 | break; |
| 5982 | case ixgbe_mac_X540: |
| 5983 | case ixgbe_mac_82599EB: { |
| 5984 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 5985 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 5986 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 5987 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 5988 | } |
| 5989 | break; |
| 5990 | default: |
| 5991 | flow_tx = false; |
| 5992 | flow_rx = false; |
| 5993 | break; |
| 5994 | } |
| 5995 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 5996 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 5997 | "10 Gbps" : |
| 5998 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 5999 | "1 Gbps" : |
| 6000 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6001 | "100 Mbps" : |
| 6002 | "unknown speed"))), |
| 6003 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6004 | (flow_rx ? "RX" : |
| 6005 | (flow_tx ? "TX" : "None")))); |
| 6006 | |
| 6007 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6008 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | /** |
| 6012 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6013 | * print link down message |
| 6014 | * @adapter - pointer to the adapter structure |
| 6015 | **/ |
| 6016 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter) |
| 6017 | { |
| 6018 | struct net_device *netdev = adapter->netdev; |
| 6019 | struct ixgbe_hw *hw = &adapter->hw; |
| 6020 | |
| 6021 | adapter->link_up = false; |
| 6022 | adapter->link_speed = 0; |
| 6023 | |
| 6024 | /* only continue if link was up previously */ |
| 6025 | if (!netif_carrier_ok(netdev)) |
| 6026 | return; |
| 6027 | |
| 6028 | /* poll for SFP+ cable when link is down */ |
| 6029 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6030 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6031 | |
| 6032 | e_info(drv, "NIC Link is Down\n"); |
| 6033 | netif_carrier_off(netdev); |
| 6034 | } |
| 6035 | |
| 6036 | /** |
| 6037 | * ixgbe_watchdog_flush_tx - flush queues on link down |
| 6038 | * @adapter - pointer to the device adapter structure |
| 6039 | **/ |
| 6040 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6041 | { |
| 6042 | int i; |
| 6043 | int some_tx_pending = 0; |
| 6044 | |
| 6045 | if (!netif_carrier_ok(adapter->netdev)) { |
| 6046 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6047 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6048 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 6049 | some_tx_pending = 1; |
| 6050 | break; |
| 6051 | } |
| 6052 | } |
| 6053 | |
| 6054 | if (some_tx_pending) { |
| 6055 | /* We've lost link, so the controller stops DMA, |
| 6056 | * but we've got queued Tx work that's never going |
| 6057 | * to get done, so reset controller to flush Tx. |
| 6058 | * (Do the reset outside of interrupt context). |
| 6059 | */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6060 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6061 | } |
| 6062 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6063 | } |
| 6064 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6065 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6066 | { |
| 6067 | u32 ssvpc; |
| 6068 | |
| 6069 | /* Do not perform spoof check for 82598 */ |
| 6070 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 6071 | return; |
| 6072 | |
| 6073 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6074 | |
| 6075 | /* |
| 6076 | * ssvpc register is cleared on read, if zero then no |
| 6077 | * spoofed packets in the last interval. |
| 6078 | */ |
| 6079 | if (!ssvpc) |
| 6080 | return; |
| 6081 | |
| 6082 | e_warn(drv, "%d Spoofed packets detected\n", ssvpc); |
| 6083 | } |
| 6084 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6085 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6086 | * ixgbe_watchdog_subtask - check and bring link up |
| 6087 | * @adapter - pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6088 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6089 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6090 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6091 | /* if interface is down do nothing */ |
| 6092 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6093 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6094 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6095 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6096 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6097 | if (adapter->link_up) |
| 6098 | ixgbe_watchdog_link_is_up(adapter); |
| 6099 | else |
| 6100 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6101 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6102 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6103 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6104 | |
| 6105 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6106 | } |
| 6107 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6108 | /** |
| 6109 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
| 6110 | * @adapter - the ixgbe adapter structure |
| 6111 | **/ |
| 6112 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6113 | { |
| 6114 | struct ixgbe_hw *hw = &adapter->hw; |
| 6115 | s32 err; |
| 6116 | |
| 6117 | /* not searching for SFP so there is nothing to do here */ |
| 6118 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6119 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6120 | return; |
| 6121 | |
| 6122 | /* someone else is in init, wait until next service event */ |
| 6123 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6124 | return; |
| 6125 | |
| 6126 | err = hw->phy.ops.identify_sfp(hw); |
| 6127 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6128 | goto sfp_out; |
| 6129 | |
| 6130 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6131 | /* If no cable is present, then we need to reset |
| 6132 | * the next time we find a good cable. */ |
| 6133 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6134 | } |
| 6135 | |
| 6136 | /* exit on error */ |
| 6137 | if (err) |
| 6138 | goto sfp_out; |
| 6139 | |
| 6140 | /* exit if reset not needed */ |
| 6141 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6142 | goto sfp_out; |
| 6143 | |
| 6144 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6145 | |
| 6146 | /* |
| 6147 | * A module may be identified correctly, but the EEPROM may not have |
| 6148 | * support for that module. setup_sfp() will fail in that case, so |
| 6149 | * we should not allow that module to load. |
| 6150 | */ |
| 6151 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6152 | err = hw->phy.ops.reset(hw); |
| 6153 | else |
| 6154 | err = hw->mac.ops.setup_sfp(hw); |
| 6155 | |
| 6156 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6157 | goto sfp_out; |
| 6158 | |
| 6159 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6160 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6161 | |
| 6162 | sfp_out: |
| 6163 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6164 | |
| 6165 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6166 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6167 | e_dev_err("failed to initialize because an unsupported " |
| 6168 | "SFP+ module type was detected.\n"); |
| 6169 | e_dev_err("Reload the driver after installing a " |
| 6170 | "supported module.\n"); |
| 6171 | unregister_netdev(adapter->netdev); |
| 6172 | } |
| 6173 | } |
| 6174 | |
| 6175 | /** |
| 6176 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
| 6177 | * @adapter - the ixgbe adapter structure |
| 6178 | **/ |
| 6179 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6180 | { |
| 6181 | struct ixgbe_hw *hw = &adapter->hw; |
| 6182 | u32 autoneg; |
| 6183 | bool negotiation; |
| 6184 | |
| 6185 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6186 | return; |
| 6187 | |
| 6188 | /* someone else is in init, wait until next service event */ |
| 6189 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6190 | return; |
| 6191 | |
| 6192 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6193 | |
| 6194 | autoneg = hw->phy.autoneg_advertised; |
| 6195 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
| 6196 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 6197 | hw->mac.autotry_restart = false; |
| 6198 | if (hw->mac.ops.setup_link) |
| 6199 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
| 6200 | |
| 6201 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6202 | adapter->link_check_timeout = jiffies; |
| 6203 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6204 | } |
| 6205 | |
| 6206 | /** |
| 6207 | * ixgbe_service_timer - Timer Call-back |
| 6208 | * @data: pointer to adapter cast into an unsigned long |
| 6209 | **/ |
| 6210 | static void ixgbe_service_timer(unsigned long data) |
| 6211 | { |
| 6212 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6213 | unsigned long next_event_offset; |
| 6214 | |
| 6215 | /* poll faster when waiting for link */ |
| 6216 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6217 | next_event_offset = HZ / 10; |
| 6218 | else |
| 6219 | next_event_offset = HZ * 2; |
| 6220 | |
| 6221 | /* Reset the timer */ |
| 6222 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6223 | |
| 6224 | ixgbe_service_event_schedule(adapter); |
| 6225 | } |
| 6226 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6227 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6228 | { |
| 6229 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6230 | return; |
| 6231 | |
| 6232 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6233 | |
| 6234 | /* If we're already down or resetting, just bail */ |
| 6235 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6236 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6237 | return; |
| 6238 | |
| 6239 | ixgbe_dump(adapter); |
| 6240 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6241 | adapter->tx_timeout_count++; |
| 6242 | |
| 6243 | ixgbe_reinit_locked(adapter); |
| 6244 | } |
| 6245 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6246 | /** |
| 6247 | * ixgbe_service_task - manages and runs subtasks |
| 6248 | * @work: pointer to work_struct containing our data |
| 6249 | **/ |
| 6250 | static void ixgbe_service_task(struct work_struct *work) |
| 6251 | { |
| 6252 | struct ixgbe_adapter *adapter = container_of(work, |
| 6253 | struct ixgbe_adapter, |
| 6254 | service_task); |
| 6255 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6256 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6257 | ixgbe_sfp_detection_subtask(adapter); |
| 6258 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6259 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6260 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6261 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6262 | ixgbe_check_hang_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6263 | |
| 6264 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6265 | } |
| 6266 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6267 | void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens, |
| 6268 | u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6269 | { |
| 6270 | struct ixgbe_adv_tx_context_desc *context_desc; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6271 | u16 i = tx_ring->next_to_use; |
| 6272 | |
| 6273 | context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i); |
| 6274 | |
| 6275 | i++; |
| 6276 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 6277 | |
| 6278 | /* set bits to identify this as an advanced context descriptor */ |
| 6279 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 6280 | |
| 6281 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 6282 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); |
| 6283 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 6284 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 6285 | } |
| 6286 | |
| 6287 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 6288 | u32 tx_flags, __be16 protocol, u8 *hdr_len) |
| 6289 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6290 | int err; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6291 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6292 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6293 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6294 | if (!skb_is_gso(skb)) |
| 6295 | return 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_header_cloned(skb)) { |
| 6298 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 6299 | if (err) |
| 6300 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6303 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6304 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6305 | |
| 6306 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6307 | struct iphdr *iph = ip_hdr(skb); |
| 6308 | iph->tot_len = 0; |
| 6309 | iph->check = 0; |
| 6310 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6311 | iph->daddr, 0, |
| 6312 | IPPROTO_TCP, |
| 6313 | 0); |
| 6314 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6315 | } else if (skb_is_gso_v6(skb)) { |
| 6316 | ipv6_hdr(skb)->payload_len = 0; |
| 6317 | tcp_hdr(skb)->check = |
| 6318 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6319 | &ipv6_hdr(skb)->daddr, |
| 6320 | 0, IPPROTO_TCP, 0); |
| 6321 | } |
| 6322 | |
| 6323 | l4len = tcp_hdrlen(skb); |
| 6324 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6325 | |
| 6326 | /* mss_l4len_id: use 1 as index for TSO */ |
| 6327 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6328 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 6329 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 6330 | |
| 6331 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6332 | vlan_macip_lens = skb_network_header_len(skb); |
| 6333 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6334 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6335 | |
| 6336 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
| 6337 | mss_l4len_idx); |
| 6338 | |
| 6339 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6340 | } |
| 6341 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6342 | static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6343 | struct sk_buff *skb, u32 tx_flags, |
| 6344 | __be16 protocol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6345 | { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6346 | u32 vlan_macip_lens = 0; |
| 6347 | u32 mss_l4len_idx = 0; |
| 6348 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6349 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6350 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
| 6351 | if (!(tx_flags & IXGBE_TX_FLAGS_VLAN)) |
| 6352 | return false; |
| 6353 | } else { |
| 6354 | u8 l4_hdr = 0; |
| 6355 | switch (protocol) { |
| 6356 | case __constant_htons(ETH_P_IP): |
| 6357 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6358 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6359 | l4_hdr = ip_hdr(skb)->protocol; |
| 6360 | break; |
| 6361 | case __constant_htons(ETH_P_IPV6): |
| 6362 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6363 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6364 | break; |
| 6365 | default: |
| 6366 | if (unlikely(net_ratelimit())) { |
| 6367 | dev_warn(tx_ring->dev, |
| 6368 | "partial checksum but proto=%x!\n", |
| 6369 | skb->protocol); |
| 6370 | } |
| 6371 | break; |
| 6372 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6373 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6374 | switch (l4_hdr) { |
| 6375 | case IPPROTO_TCP: |
| 6376 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6377 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6378 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6379 | break; |
| 6380 | case IPPROTO_SCTP: |
| 6381 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6382 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6383 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6384 | break; |
| 6385 | case IPPROTO_UDP: |
| 6386 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6387 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6388 | break; |
| 6389 | default: |
| 6390 | if (unlikely(net_ratelimit())) { |
| 6391 | dev_warn(tx_ring->dev, |
| 6392 | "partial checksum but l4 proto=%x!\n", |
| 6393 | skb->protocol); |
| 6394 | } |
| 6395 | break; |
| 6396 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6397 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6398 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6399 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 6400 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 6401 | |
| 6402 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6403 | type_tucmd, mss_l4len_idx); |
| 6404 | |
| 6405 | return (skb->ip_summed == CHECKSUM_PARTIAL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6406 | } |
| 6407 | |
| 6408 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6409 | struct ixgbe_ring *tx_ring, |
| 6410 | struct sk_buff *skb, u32 tx_flags, |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6411 | unsigned int first, const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6412 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6413 | struct device *dev = tx_ring->dev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6414 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6415 | unsigned int len; |
| 6416 | unsigned int total = skb->len; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6417 | unsigned int offset = 0, size, count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6418 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 6419 | unsigned int f; |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6420 | unsigned int bytecount = skb->len; |
| 6421 | u16 gso_segs = 1; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6422 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6423 | |
| 6424 | i = tx_ring->next_to_use; |
| 6425 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6426 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 6427 | /* excluding fcoe_crc_eof for FCoE */ |
| 6428 | total -= sizeof(struct fcoe_crc_eof); |
| 6429 | |
| 6430 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6431 | while (len) { |
| 6432 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6433 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 6434 | |
| 6435 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6436 | tx_buffer_info->mapped_as_page = false; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6437 | tx_buffer_info->dma = dma_map_single(dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6438 | skb->data + offset, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 6439 | size, DMA_TO_DEVICE); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6440 | if (dma_mapping_error(dev, tx_buffer_info->dma)) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6441 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6442 | tx_buffer_info->time_stamp = jiffies; |
| 6443 | tx_buffer_info->next_to_watch = i; |
| 6444 | |
| 6445 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6446 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6447 | offset += size; |
| 6448 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6449 | |
| 6450 | if (len) { |
| 6451 | i++; |
| 6452 | if (i == tx_ring->count) |
| 6453 | i = 0; |
| 6454 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6455 | } |
| 6456 | |
| 6457 | for (f = 0; f < nr_frags; f++) { |
| 6458 | struct skb_frag_struct *frag; |
| 6459 | |
| 6460 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6461 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6462 | offset = frag->page_offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6463 | |
| 6464 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6465 | i++; |
| 6466 | if (i == tx_ring->count) |
| 6467 | i = 0; |
| 6468 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6469 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 6470 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 6471 | |
| 6472 | tx_buffer_info->length = size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6473 | tx_buffer_info->dma = dma_map_page(dev, |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6474 | frag->page, |
| 6475 | offset, size, |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 6476 | DMA_TO_DEVICE); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6477 | tx_buffer_info->mapped_as_page = true; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6478 | if (dma_mapping_error(dev, tx_buffer_info->dma)) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6479 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6480 | tx_buffer_info->time_stamp = jiffies; |
| 6481 | tx_buffer_info->next_to_watch = i; |
| 6482 | |
| 6483 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6484 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6485 | offset += size; |
| 6486 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6487 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6488 | if (total == 0) |
| 6489 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6490 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6491 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6492 | if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 6493 | gso_segs = skb_shinfo(skb)->gso_segs; |
| 6494 | #ifdef IXGBE_FCOE |
| 6495 | /* adjust for FCoE Sequence Offload */ |
| 6496 | else if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6497 | gso_segs = DIV_ROUND_UP(skb->len - hdr_len, |
| 6498 | skb_shinfo(skb)->gso_size); |
| 6499 | #endif /* IXGBE_FCOE */ |
| 6500 | bytecount += (gso_segs - 1) * hdr_len; |
| 6501 | |
| 6502 | /* multiply data chunks by size of headers */ |
| 6503 | tx_ring->tx_buffer_info[i].bytecount = bytecount; |
| 6504 | tx_ring->tx_buffer_info[i].gso_segs = gso_segs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6505 | tx_ring->tx_buffer_info[i].skb = skb; |
| 6506 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 6507 | |
| 6508 | return count; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6509 | |
| 6510 | dma_error: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6511 | e_dev_err("TX DMA map failed\n"); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6512 | |
| 6513 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 6514 | tx_buffer_info->dma = 0; |
| 6515 | tx_buffer_info->time_stamp = 0; |
| 6516 | tx_buffer_info->next_to_watch = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6517 | if (count) |
| 6518 | count--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6519 | |
| 6520 | /* clear timestamp and dma mappings for remaining portion of packet */ |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6521 | while (count--) { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6522 | if (i == 0) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6523 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 6524 | i--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6525 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6526 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 6527 | } |
| 6528 | |
Anton Blanchard | e44d38e | 2010-02-03 13:12:51 +0000 | [diff] [blame] | 6529 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6530 | } |
| 6531 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6532 | static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6533 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6534 | { |
| 6535 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 6536 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 6537 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 6538 | unsigned int i; |
| 6539 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 6540 | |
| 6541 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 6542 | |
| 6543 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 6544 | |
| 6545 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 6546 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 6547 | |
| 6548 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 6549 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 6550 | |
| 6551 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6552 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6553 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 6554 | /* use index 1 context for tso */ |
| 6555 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6556 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 6557 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6558 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6559 | |
| 6560 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 6561 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6562 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6563 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6564 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6565 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 6566 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 6567 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 6568 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 6569 | } |
| 6570 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6571 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 6572 | |
| 6573 | i = tx_ring->next_to_use; |
| 6574 | while (count--) { |
| 6575 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 31f05a2 | 2010-08-19 13:40:31 +0000 | [diff] [blame] | 6576 | tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6577 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 6578 | tx_desc->read.cmd_type_len = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 6579 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6580 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6581 | i++; |
| 6582 | if (i == tx_ring->count) |
| 6583 | i = 0; |
| 6584 | } |
| 6585 | |
| 6586 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 6587 | |
| 6588 | /* |
| 6589 | * Force memory writes to complete before letting h/w |
| 6590 | * know there are new descriptors to fetch. (Only |
| 6591 | * applicable for weak-ordered memory model archs, |
| 6592 | * such as IA-64). |
| 6593 | */ |
| 6594 | wmb(); |
| 6595 | |
| 6596 | tx_ring->next_to_use = i; |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6597 | writel(i, tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6598 | } |
| 6599 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6600 | static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb, |
| 6601 | u32 tx_flags, __be16 protocol) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6602 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6603 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6604 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6605 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6606 | union { |
| 6607 | unsigned char *network; |
| 6608 | struct iphdr *ipv4; |
| 6609 | struct ipv6hdr *ipv6; |
| 6610 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6611 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6612 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6613 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6614 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6615 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6616 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6617 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6618 | /* do nothing if sampling is disabled */ |
| 6619 | if (!ring->atr_sample_rate) |
| 6620 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6621 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6622 | ring->atr_count++; |
| 6623 | |
| 6624 | /* snag network header to get L4 type and address */ |
| 6625 | hdr.network = skb_network_header(skb); |
| 6626 | |
| 6627 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 6628 | if ((protocol != __constant_htons(ETH_P_IPV6) || |
| 6629 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
| 6630 | (protocol != __constant_htons(ETH_P_IP) || |
| 6631 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6632 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6633 | |
| 6634 | th = tcp_hdr(skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6635 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6636 | /* skip this packet since the socket is closing */ |
| 6637 | if (th->fin) |
| 6638 | return; |
| 6639 | |
| 6640 | /* sample on all syn packets or once every atr sample count */ |
| 6641 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6642 | return; |
| 6643 | |
| 6644 | /* reset sample count */ |
| 6645 | ring->atr_count = 0; |
| 6646 | |
| 6647 | vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6648 | |
| 6649 | /* |
| 6650 | * src and dst are inverted, think how the receiver sees them |
| 6651 | * |
| 6652 | * The input is broken into two sections, a non-compressed section |
| 6653 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6654 | * is XORed together and stored in the compressed dword. |
| 6655 | */ |
| 6656 | input.formatted.vlan_id = vlan_id; |
| 6657 | |
| 6658 | /* |
| 6659 | * since src port and flex bytes occupy the same word XOR them together |
| 6660 | * and write the value to source port portion of compressed dword |
| 6661 | */ |
| 6662 | if (vlan_id) |
| 6663 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6664 | else |
| 6665 | common.port.src ^= th->dest ^ protocol; |
| 6666 | common.port.dst ^= th->source; |
| 6667 | |
| 6668 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 6669 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6670 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6671 | } else { |
| 6672 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6673 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6674 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6675 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6676 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6677 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6678 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6679 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6680 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6681 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6682 | |
| 6683 | /* 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] | 6684 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6685 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6686 | } |
| 6687 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6688 | 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] | 6689 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6690 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6691 | /* Herbert's original patch had: |
| 6692 | * smp_mb__after_netif_stop_queue(); |
| 6693 | * but since that doesn't exist yet, just open code it. */ |
| 6694 | smp_mb(); |
| 6695 | |
| 6696 | /* We need to check again in a case another CPU has just |
| 6697 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6698 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6699 | return -EBUSY; |
| 6700 | |
| 6701 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6702 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6703 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6704 | return 0; |
| 6705 | } |
| 6706 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 6707 | 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] | 6708 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6709 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6710 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6711 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6712 | } |
| 6713 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6714 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 6715 | { |
| 6716 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 6717 | int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 6718 | smp_processor_id(); |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6719 | #ifdef IXGBE_FCOE |
Alexander Duyck | 6440752 | 2011-06-11 01:44:53 +0000 | [diff] [blame] | 6720 | __be16 protocol = vlan_get_protocol(skb); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6721 | |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6722 | if (((protocol == htons(ETH_P_FCOE)) || |
| 6723 | (protocol == htons(ETH_P_FIP))) && |
| 6724 | (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) { |
| 6725 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 6726 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 6727 | return txq; |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6728 | } |
| 6729 | #endif |
| 6730 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6731 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 6732 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 6733 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6734 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6735 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6736 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6737 | return skb_tx_hash(dev, skb); |
| 6738 | } |
| 6739 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6740 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6741 | struct ixgbe_adapter *adapter, |
| 6742 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6743 | { |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6744 | int tso; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6745 | u32 tx_flags = 0; |
| 6746 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 6747 | unsigned short f; |
| 6748 | #endif |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6749 | u16 first; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6750 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6751 | __be16 protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6752 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6753 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6754 | /* |
| 6755 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
| 6756 | * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD, |
| 6757 | * + 2 desc gap to keep tail from touching head, |
| 6758 | * + 1 desc for context descriptor, |
| 6759 | * otherwise try next time |
| 6760 | */ |
| 6761 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 6762 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 6763 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 6764 | #else |
| 6765 | count += skb_shinfo(skb)->nr_frags; |
| 6766 | #endif |
| 6767 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 6768 | tx_ring->tx_stats.tx_busy++; |
| 6769 | return NETDEV_TX_BUSY; |
| 6770 | } |
| 6771 | |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6772 | protocol = vlan_get_protocol(skb); |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6773 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 6774 | if (vlan_tx_tag_present(skb)) { |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6775 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6776 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 6777 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6778 | tx_flags |= tx_ring->dcb_tc << 13; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6779 | } |
| 6780 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6781 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
John Fastabend | 33c66bd | 2010-05-18 16:00:11 +0000 | [diff] [blame] | 6782 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED && |
| 6783 | skb->priority != TC_PRIO_CONTROL) { |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6784 | tx_flags |= tx_ring->dcb_tc << 13; |
John Fastabend | 2ea186a | 2010-02-27 03:28:24 -0800 | [diff] [blame] | 6785 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6786 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6787 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6788 | |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 6789 | #ifdef IXGBE_FCOE |
John Fastabend | 56075a9 | 2010-07-26 20:41:31 +0000 | [diff] [blame] | 6790 | /* for FCoE with DCB, we force the priority to what |
| 6791 | * was specified by the switch */ |
| 6792 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED && |
John Fastabend | e5b6463 | 2011-03-08 03:44:52 +0000 | [diff] [blame] | 6793 | (protocol == htons(ETH_P_FCOE))) |
| 6794 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6795 | |
Robert Love | ca77cd5 | 2010-03-24 12:45:00 +0000 | [diff] [blame] | 6796 | #endif |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6797 | /* record the location of the first descriptor for this packet */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6798 | first = tx_ring->next_to_use; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6799 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6800 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 6801 | #ifdef IXGBE_FCOE |
| 6802 | /* setup tx offload for FCoE */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6803 | tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len); |
| 6804 | if (tso < 0) |
| 6805 | goto out_drop; |
| 6806 | else if (tso) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6807 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 6808 | #endif /* IXGBE_FCOE */ |
| 6809 | } else { |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6810 | if (protocol == htons(ETH_P_IP)) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6811 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6812 | tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len); |
| 6813 | if (tso < 0) |
| 6814 | goto out_drop; |
| 6815 | else if (tso) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6816 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6817 | else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol)) |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6818 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6819 | } |
| 6820 | |
Alexander Duyck | 8ad494b | 2010-11-16 19:26:47 -0800 | [diff] [blame] | 6821 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6822 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6823 | /* add the ATR filter if ATR is on */ |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6824 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
| 6825 | ixgbe_atr(tx_ring, skb, tx_flags, protocol); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6826 | ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len); |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6827 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6828 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6829 | } else { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6830 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 6831 | tx_ring->next_to_use = first; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6832 | goto out_drop; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6833 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6834 | |
| 6835 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6836 | |
| 6837 | out_drop: |
| 6838 | dev_kfree_skb_any(skb); |
| 6839 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6840 | } |
| 6841 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6842 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 6843 | { |
| 6844 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6845 | struct ixgbe_ring *tx_ring; |
| 6846 | |
| 6847 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6848 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6849 | } |
| 6850 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6851 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6852 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 6853 | * @netdev: network interface device structure |
| 6854 | * @p: pointer to an address structure |
| 6855 | * |
| 6856 | * Returns 0 on success, negative on failure |
| 6857 | **/ |
| 6858 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 6859 | { |
| 6860 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6861 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6862 | struct sockaddr *addr = p; |
| 6863 | |
| 6864 | if (!is_valid_ether_addr(addr->sa_data)) |
| 6865 | return -EADDRNOTAVAIL; |
| 6866 | |
| 6867 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6868 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6869 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6870 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 6871 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6872 | |
| 6873 | return 0; |
| 6874 | } |
| 6875 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 6876 | static int |
| 6877 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 6878 | { |
| 6879 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6880 | struct ixgbe_hw *hw = &adapter->hw; |
| 6881 | u16 value; |
| 6882 | int rc; |
| 6883 | |
| 6884 | if (prtad != hw->phy.mdio.prtad) |
| 6885 | return -EINVAL; |
| 6886 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 6887 | if (!rc) |
| 6888 | rc = value; |
| 6889 | return rc; |
| 6890 | } |
| 6891 | |
| 6892 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 6893 | u16 addr, u16 value) |
| 6894 | { |
| 6895 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6896 | struct ixgbe_hw *hw = &adapter->hw; |
| 6897 | |
| 6898 | if (prtad != hw->phy.mdio.prtad) |
| 6899 | return -EINVAL; |
| 6900 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 6901 | } |
| 6902 | |
| 6903 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 6904 | { |
| 6905 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6906 | |
| 6907 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 6908 | } |
| 6909 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6910 | /** |
| 6911 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 6912 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6913 | * @netdev: network interface device structure |
| 6914 | * |
| 6915 | * Returns non-zero on failure |
| 6916 | **/ |
| 6917 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 6918 | { |
| 6919 | int err = 0; |
| 6920 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6921 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 6922 | |
| 6923 | if (is_valid_ether_addr(mac->san_addr)) { |
| 6924 | rtnl_lock(); |
| 6925 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 6926 | rtnl_unlock(); |
| 6927 | } |
| 6928 | return err; |
| 6929 | } |
| 6930 | |
| 6931 | /** |
| 6932 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 6933 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6934 | * @netdev: network interface device structure |
| 6935 | * |
| 6936 | * Returns non-zero on failure |
| 6937 | **/ |
| 6938 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 6939 | { |
| 6940 | int err = 0; |
| 6941 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 6942 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 6943 | |
| 6944 | if (is_valid_ether_addr(mac->san_addr)) { |
| 6945 | rtnl_lock(); |
| 6946 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 6947 | rtnl_unlock(); |
| 6948 | } |
| 6949 | return err; |
| 6950 | } |
| 6951 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6952 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6953 | /* |
| 6954 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 6955 | * without having to re-enable interrupts. It's not called while |
| 6956 | * the interrupt routine is executing. |
| 6957 | */ |
| 6958 | static void ixgbe_netpoll(struct net_device *netdev) |
| 6959 | { |
| 6960 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6961 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6962 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 6963 | /* if interface is down do nothing */ |
| 6964 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 6965 | return; |
| 6966 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6967 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 6968 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 6969 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 6970 | for (i = 0; i < num_q_vectors; i++) { |
| 6971 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 6972 | ixgbe_msix_clean_many(0, q_vector); |
| 6973 | } |
| 6974 | } else { |
| 6975 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 6976 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6977 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6978 | } |
| 6979 | #endif |
| 6980 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6981 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 6982 | struct rtnl_link_stats64 *stats) |
| 6983 | { |
| 6984 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6985 | int i; |
| 6986 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6987 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6988 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6989 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 6990 | u64 bytes, packets; |
| 6991 | unsigned int start; |
| 6992 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 6993 | if (ring) { |
| 6994 | do { |
| 6995 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 6996 | packets = ring->stats.packets; |
| 6997 | bytes = ring->stats.bytes; |
| 6998 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 6999 | stats->rx_packets += packets; |
| 7000 | stats->rx_bytes += bytes; |
| 7001 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7002 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7003 | |
| 7004 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7005 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7006 | u64 bytes, packets; |
| 7007 | unsigned int start; |
| 7008 | |
| 7009 | if (ring) { |
| 7010 | do { |
| 7011 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7012 | packets = ring->stats.packets; |
| 7013 | bytes = ring->stats.bytes; |
| 7014 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7015 | stats->tx_packets += packets; |
| 7016 | stats->tx_bytes += bytes; |
| 7017 | } |
| 7018 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7019 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7020 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7021 | stats->multicast = netdev->stats.multicast; |
| 7022 | stats->rx_errors = netdev->stats.rx_errors; |
| 7023 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7024 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7025 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7026 | return stats; |
| 7027 | } |
| 7028 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7029 | /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7030 | * #adapter: pointer to ixgbe_adapter |
| 7031 | * @tc: number of traffic classes currently enabled |
| 7032 | * |
| 7033 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7034 | * 802.1Q priority maps to a packet buffer that exists. |
| 7035 | */ |
| 7036 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7037 | { |
| 7038 | struct ixgbe_hw *hw = &adapter->hw; |
| 7039 | u32 reg, rsave; |
| 7040 | int i; |
| 7041 | |
| 7042 | /* 82598 have a static priority to TC mapping that can not |
| 7043 | * be changed so no validation is needed. |
| 7044 | */ |
| 7045 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7046 | return; |
| 7047 | |
| 7048 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7049 | rsave = reg; |
| 7050 | |
| 7051 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7052 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7053 | |
| 7054 | /* If up2tc is out of bounds default to zero */ |
| 7055 | if (up2tc > tc) |
| 7056 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7057 | } |
| 7058 | |
| 7059 | if (reg != rsave) |
| 7060 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7061 | |
| 7062 | return; |
| 7063 | } |
| 7064 | |
| 7065 | |
| 7066 | /* ixgbe_setup_tc - routine to configure net_device for multiple traffic |
| 7067 | * classes. |
| 7068 | * |
| 7069 | * @netdev: net device to configure |
| 7070 | * @tc: number of traffic classes to enable |
| 7071 | */ |
| 7072 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7073 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7074 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7075 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7076 | |
| 7077 | /* If DCB is anabled do not remove traffic classes, multiple |
| 7078 | * traffic classes are required to implement DCB |
| 7079 | */ |
| 7080 | if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 7081 | return 0; |
| 7082 | |
| 7083 | /* Hardware supports up to 8 traffic classes */ |
| 7084 | if (tc > MAX_TRAFFIC_CLASS || |
| 7085 | (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS)) |
| 7086 | return -EINVAL; |
| 7087 | |
| 7088 | /* Hardware has to reinitialize queues and interrupts to |
| 7089 | * match packet buffer alignment. Unfortunantly, the |
| 7090 | * hardware is not flexible enough to do this dynamically. |
| 7091 | */ |
| 7092 | if (netif_running(dev)) |
| 7093 | ixgbe_close(dev); |
| 7094 | ixgbe_clear_interrupt_scheme(adapter); |
| 7095 | |
| 7096 | if (tc) |
| 7097 | netdev_set_num_tc(dev, tc); |
| 7098 | else |
| 7099 | netdev_reset_tc(dev); |
| 7100 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7101 | ixgbe_init_interrupt_scheme(adapter); |
| 7102 | ixgbe_validate_rtr(adapter, tc); |
| 7103 | if (netif_running(dev)) |
| 7104 | ixgbe_open(dev); |
| 7105 | |
| 7106 | return 0; |
| 7107 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7108 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7109 | void ixgbe_do_reset(struct net_device *netdev) |
| 7110 | { |
| 7111 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7112 | |
| 7113 | if (netif_running(netdev)) |
| 7114 | ixgbe_reinit_locked(adapter); |
| 7115 | else |
| 7116 | ixgbe_reset(adapter); |
| 7117 | } |
| 7118 | |
| 7119 | static u32 ixgbe_fix_features(struct net_device *netdev, u32 data) |
| 7120 | { |
| 7121 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7122 | |
| 7123 | #ifdef CONFIG_DCB |
| 7124 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 7125 | data &= ~NETIF_F_HW_VLAN_RX; |
| 7126 | #endif |
| 7127 | |
| 7128 | /* return error if RXHASH is being enabled when RSS is not supported */ |
| 7129 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) |
| 7130 | data &= ~NETIF_F_RXHASH; |
| 7131 | |
| 7132 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
| 7133 | if (!(data & NETIF_F_RXCSUM)) |
| 7134 | data &= ~NETIF_F_LRO; |
| 7135 | |
| 7136 | /* Turn off LRO if not RSC capable or invalid ITR settings */ |
| 7137 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) { |
| 7138 | data &= ~NETIF_F_LRO; |
| 7139 | } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
| 7140 | (adapter->rx_itr_setting != 1 && |
| 7141 | adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) { |
| 7142 | data &= ~NETIF_F_LRO; |
| 7143 | e_info(probe, "rx-usecs set too low, not enabling RSC\n"); |
| 7144 | } |
| 7145 | |
| 7146 | return data; |
| 7147 | } |
| 7148 | |
| 7149 | static int ixgbe_set_features(struct net_device *netdev, u32 data) |
| 7150 | { |
| 7151 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7152 | bool need_reset = false; |
| 7153 | |
| 7154 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
| 7155 | if (!(data & NETIF_F_RXCSUM)) |
| 7156 | adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED; |
| 7157 | else |
| 7158 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 7159 | |
| 7160 | /* Make sure RSC matches LRO, reset if change */ |
| 7161 | if (!!(data & NETIF_F_LRO) != |
| 7162 | !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 7163 | adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED; |
| 7164 | switch (adapter->hw.mac.type) { |
| 7165 | case ixgbe_mac_X540: |
| 7166 | case ixgbe_mac_82599EB: |
| 7167 | need_reset = true; |
| 7168 | break; |
| 7169 | default: |
| 7170 | break; |
| 7171 | } |
| 7172 | } |
| 7173 | |
| 7174 | /* |
| 7175 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 7176 | * the state changed, we need to reset. |
| 7177 | */ |
| 7178 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) { |
| 7179 | /* turn off ATR, enable perfect filters and reset */ |
| 7180 | if (data & NETIF_F_NTUPLE) { |
| 7181 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7182 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7183 | need_reset = true; |
| 7184 | } |
| 7185 | } else if (!(data & NETIF_F_NTUPLE)) { |
| 7186 | /* turn off Flow Director, set ATR and reset */ |
| 7187 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7188 | if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) && |
| 7189 | !(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 7190 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7191 | need_reset = true; |
| 7192 | } |
| 7193 | |
| 7194 | if (need_reset) |
| 7195 | ixgbe_do_reset(netdev); |
| 7196 | |
| 7197 | return 0; |
| 7198 | |
| 7199 | } |
| 7200 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7201 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7202 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7203 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7204 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7205 | .ndo_select_queue = ixgbe_select_queue, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 7206 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7207 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 7208 | .ndo_validate_addr = eth_validate_addr, |
| 7209 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7210 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7211 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7212 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7213 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7214 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7215 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7216 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7217 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
| 7218 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7219 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7220 | .ndo_setup_tc = ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7221 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7222 | .ndo_poll_controller = ixgbe_netpoll, |
| 7223 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7224 | #ifdef IXGBE_FCOE |
| 7225 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7226 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7227 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7228 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7229 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7230 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7231 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7232 | .ndo_set_features = ixgbe_set_features, |
| 7233 | .ndo_fix_features = ixgbe_fix_features, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7234 | }; |
| 7235 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7236 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 7237 | const struct ixgbe_info *ii) |
| 7238 | { |
| 7239 | #ifdef CONFIG_PCI_IOV |
| 7240 | struct ixgbe_hw *hw = &adapter->hw; |
| 7241 | int err; |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 7242 | int num_vf_macvlans, i; |
| 7243 | struct vf_macvlans *mv_list; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7244 | |
Greg Rose | 3377eba79 | 2010-12-07 08:16:45 +0000 | [diff] [blame] | 7245 | if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs) |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7246 | return; |
| 7247 | |
| 7248 | /* The 82599 supports up to 64 VFs per physical function |
| 7249 | * but this implementation limits allocation to 63 so that |
| 7250 | * basic networking resources are still available to the |
| 7251 | * physical function |
| 7252 | */ |
| 7253 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
| 7254 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
| 7255 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 7256 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7257 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7258 | goto err_novfs; |
| 7259 | } |
Greg Rose | a1cbb15c | 2011-05-13 01:33:48 +0000 | [diff] [blame] | 7260 | |
| 7261 | num_vf_macvlans = hw->mac.num_rar_entries - |
| 7262 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); |
| 7263 | |
| 7264 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, |
| 7265 | sizeof(struct vf_macvlans), |
| 7266 | GFP_KERNEL); |
| 7267 | if (mv_list) { |
| 7268 | /* Initialize list of VF macvlans */ |
| 7269 | INIT_LIST_HEAD(&adapter->vf_mvs.l); |
| 7270 | for (i = 0; i < num_vf_macvlans; i++) { |
| 7271 | mv_list->vf = -1; |
| 7272 | mv_list->free = true; |
| 7273 | mv_list->rar_entry = hw->mac.num_rar_entries - |
| 7274 | (i + adapter->num_vfs + 1); |
| 7275 | list_add(&mv_list->l, &adapter->vf_mvs.l); |
| 7276 | mv_list++; |
| 7277 | } |
| 7278 | } |
| 7279 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7280 | /* If call to enable VFs succeeded then allocate memory |
| 7281 | * for per VF control structures. |
| 7282 | */ |
| 7283 | adapter->vfinfo = |
| 7284 | kcalloc(adapter->num_vfs, |
| 7285 | sizeof(struct vf_data_storage), GFP_KERNEL); |
| 7286 | if (adapter->vfinfo) { |
| 7287 | /* Now that we're sure SR-IOV is enabled |
| 7288 | * and memory allocated set up the mailbox parameters |
| 7289 | */ |
| 7290 | ixgbe_init_mbx_params_pf(hw); |
| 7291 | memcpy(&hw->mbx.ops, ii->mbx_ops, |
| 7292 | sizeof(hw->mbx.ops)); |
| 7293 | |
| 7294 | /* Disable RSC when in SR-IOV mode */ |
| 7295 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | |
| 7296 | IXGBE_FLAG2_RSC_ENABLED); |
| 7297 | return; |
| 7298 | } |
| 7299 | |
| 7300 | /* Oh oh */ |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7301 | e_err(probe, "Unable to allocate memory for VF Data Storage - " |
| 7302 | "SRIOV disabled\n"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7303 | pci_disable_sriov(adapter->pdev); |
| 7304 | |
| 7305 | err_novfs: |
| 7306 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 7307 | adapter->num_vfs = 0; |
| 7308 | #endif /* CONFIG_PCI_IOV */ |
| 7309 | } |
| 7310 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7311 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7312 | * ixgbe_probe - Device Initialization Routine |
| 7313 | * @pdev: PCI device information struct |
| 7314 | * @ent: entry in ixgbe_pci_tbl |
| 7315 | * |
| 7316 | * Returns 0 on success, negative on failure |
| 7317 | * |
| 7318 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7319 | * The OS initialization, configuring of the adapter private structure, |
| 7320 | * and a hardware reset occur. |
| 7321 | **/ |
| 7322 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7323 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7324 | { |
| 7325 | struct net_device *netdev; |
| 7326 | struct ixgbe_adapter *adapter = NULL; |
| 7327 | struct ixgbe_hw *hw; |
| 7328 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7329 | static int cards_found; |
| 7330 | int i, err, pci_using_dac; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7331 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7332 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7333 | #ifdef IXGBE_FCOE |
| 7334 | u16 device_caps; |
| 7335 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7336 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7337 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7338 | /* Catch broken hardware that put the wrong VF device ID in |
| 7339 | * the PCIe SR-IOV capability. |
| 7340 | */ |
| 7341 | if (pdev->is_virtfn) { |
| 7342 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7343 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7344 | return -EINVAL; |
| 7345 | } |
| 7346 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7347 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7348 | if (err) |
| 7349 | return err; |
| 7350 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7351 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7352 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7353 | pci_using_dac = 1; |
| 7354 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7355 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7356 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7357 | err = dma_set_coherent_mask(&pdev->dev, |
| 7358 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7359 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7360 | dev_err(&pdev->dev, |
| 7361 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7362 | goto err_dma; |
| 7363 | } |
| 7364 | } |
| 7365 | pci_using_dac = 0; |
| 7366 | } |
| 7367 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7368 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7369 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7370 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7371 | dev_err(&pdev->dev, |
| 7372 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7373 | goto err_pci_reg; |
| 7374 | } |
| 7375 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7376 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7377 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7378 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7379 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7380 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7381 | #ifdef CONFIG_IXGBE_DCB |
| 7382 | indices *= MAX_TRAFFIC_CLASS; |
| 7383 | #endif |
| 7384 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7385 | if (ii->mac == ixgbe_mac_82598EB) |
| 7386 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 7387 | else |
| 7388 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 7389 | |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7390 | #ifdef IXGBE_FCOE |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7391 | indices += min_t(unsigned int, num_possible_cpus(), |
| 7392 | IXGBE_MAX_FCOE_INDICES); |
| 7393 | #endif |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7394 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7395 | if (!netdev) { |
| 7396 | err = -ENOMEM; |
| 7397 | goto err_alloc_etherdev; |
| 7398 | } |
| 7399 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7400 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7401 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7402 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7403 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7404 | |
| 7405 | adapter->netdev = netdev; |
| 7406 | adapter->pdev = pdev; |
| 7407 | hw = &adapter->hw; |
| 7408 | hw->back = adapter; |
| 7409 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 7410 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7411 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7412 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7413 | if (!hw->hw_addr) { |
| 7414 | err = -EIO; |
| 7415 | goto err_ioremap; |
| 7416 | } |
| 7417 | |
| 7418 | for (i = 1; i <= 5; i++) { |
| 7419 | if (pci_resource_len(pdev, i) == 0) |
| 7420 | continue; |
| 7421 | } |
| 7422 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7423 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7424 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7425 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7426 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7427 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7428 | adapter->bd_number = cards_found; |
| 7429 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7430 | /* Setup hw api */ |
| 7431 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7432 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7433 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7434 | /* EEPROM */ |
| 7435 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7436 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7437 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7438 | if (!(eec & (1 << 8))) |
| 7439 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7440 | |
| 7441 | /* PHY */ |
| 7442 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7443 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7444 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7445 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7446 | hw->phy.mdio.mmds = 0; |
| 7447 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7448 | hw->phy.mdio.dev = netdev; |
| 7449 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7450 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7451 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7452 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7453 | |
| 7454 | /* setup the private structure */ |
| 7455 | err = ixgbe_sw_init(adapter); |
| 7456 | if (err) |
| 7457 | goto err_sw_init; |
| 7458 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7459 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7460 | switch (adapter->hw.mac.type) { |
| 7461 | case ixgbe_mac_82599EB: |
| 7462 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7463 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7464 | break; |
| 7465 | default: |
| 7466 | break; |
| 7467 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7468 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7469 | /* |
| 7470 | * If there is a fan on this device and it has failed log the |
| 7471 | * failure. |
| 7472 | */ |
| 7473 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7474 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7475 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7476 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7477 | } |
| 7478 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7479 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7480 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7481 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7482 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7483 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7484 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7485 | err = 0; |
| 7486 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7487 | e_dev_err("failed to load because an unsupported SFP+ " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7488 | "module type was detected.\n"); |
| 7489 | e_dev_err("Reload the driver after installing a supported " |
| 7490 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7491 | goto err_sw_init; |
| 7492 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7493 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7494 | goto err_sw_init; |
| 7495 | } |
| 7496 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7497 | ixgbe_probe_vf(adapter, ii); |
| 7498 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7499 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7500 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7501 | NETIF_F_IPV6_CSUM | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7502 | NETIF_F_HW_VLAN_TX | |
| 7503 | NETIF_F_HW_VLAN_RX | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7504 | NETIF_F_HW_VLAN_FILTER | |
| 7505 | NETIF_F_TSO | |
| 7506 | NETIF_F_TSO6 | |
| 7507 | NETIF_F_GRO | |
| 7508 | NETIF_F_RXHASH | |
| 7509 | NETIF_F_RXCSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7510 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7511 | netdev->hw_features = netdev->features; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7512 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7513 | switch (adapter->hw.mac.type) { |
| 7514 | case ixgbe_mac_82599EB: |
| 7515 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7516 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7517 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 7518 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7519 | break; |
| 7520 | default: |
| 7521 | break; |
| 7522 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7523 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7524 | netdev->vlan_features |= NETIF_F_TSO; |
| 7525 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 7526 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 7527 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7528 | netdev->vlan_features |= NETIF_F_SG; |
| 7529 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7530 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7531 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 7532 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7533 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 7534 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 7535 | netdev->dcbnl_ops = &dcbnl_ops; |
| 7536 | #endif |
| 7537 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7538 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7539 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7540 | if (hw->mac.ops.get_device_caps) { |
| 7541 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 7542 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 7543 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7544 | } |
| 7545 | } |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 7546 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
| 7547 | netdev->vlan_features |= NETIF_F_FCOE_CRC; |
| 7548 | netdev->vlan_features |= NETIF_F_FSO; |
| 7549 | netdev->vlan_features |= NETIF_F_FCOE_MTU; |
| 7550 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7551 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7552 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7553 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 7554 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 7555 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7556 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7557 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 7558 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 7559 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 7560 | netdev->features |= NETIF_F_LRO; |
| 7561 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7562 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7563 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7564 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7565 | err = -EIO; |
| 7566 | goto err_eeprom; |
| 7567 | } |
| 7568 | |
| 7569 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7570 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 7571 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7572 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7573 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7574 | err = -EIO; |
| 7575 | goto err_eeprom; |
| 7576 | } |
| 7577 | |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 7578 | /* power down the optics for multispeed fiber and 82599 SFP+ fiber */ |
| 7579 | if (hw->mac.ops.disable_tx_laser && |
| 7580 | ((hw->phy.multispeed_fiber) || |
Don Skidmore | 9f91170 | 2010-12-03 13:24:05 +0000 | [diff] [blame] | 7581 | ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) && |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 7582 | (hw->mac.type == ixgbe_mac_82599EB)))) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 7583 | hw->mac.ops.disable_tx_laser(hw); |
| 7584 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7585 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
| 7586 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7587 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7588 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 7589 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7590 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7591 | err = ixgbe_init_interrupt_scheme(adapter); |
| 7592 | if (err) |
| 7593 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7594 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7595 | if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) { |
| 7596 | netdev->hw_features &= ~NETIF_F_RXHASH; |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7597 | netdev->features &= ~NETIF_F_RXHASH; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7598 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 7599 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7600 | switch (pdev->device) { |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7601 | case IXGBE_DEV_ID_82599_SFP: |
| 7602 | /* Only this subdevice supports WOL */ |
| 7603 | if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7604 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7605 | break; |
Alexander Duyck | 50d6c68 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 7606 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7607 | /* All except this subdevice support WOL */ |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7608 | if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7609 | adapter->wol = IXGBE_WUFC_MAG; |
Don Skidmore | 0b077fe | 2010-12-03 03:32:13 +0000 | [diff] [blame] | 7610 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7611 | case IXGBE_DEV_ID_82599_KX4: |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 7612 | adapter->wol = IXGBE_WUFC_MAG; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7613 | break; |
| 7614 | default: |
| 7615 | adapter->wol = 0; |
| 7616 | break; |
| 7617 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7618 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 7619 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7620 | /* pick up the PCI bus settings for reporting later */ |
| 7621 | hw->mac.ops.get_bus_info(hw); |
| 7622 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7623 | /* print bus type/speed/width info */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7624 | e_dev_info("(PCI Express:%s:%s) %pM\n", |
Don Skidmore | 6716344 | 2011-04-26 08:00:00 +0000 | [diff] [blame] | 7625 | (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" : |
| 7626 | hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" : |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7627 | "Unknown"), |
| 7628 | (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" : |
| 7629 | hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" : |
| 7630 | hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" : |
| 7631 | "Unknown"), |
| 7632 | netdev->dev_addr); |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7633 | |
| 7634 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 7635 | if (err) |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7636 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7637 | 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] | 7638 | 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] | 7639 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7640 | part_str); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7641 | else |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7642 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 7643 | hw->mac.type, hw->phy.type, part_str); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7644 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7645 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7646 | e_dev_warn("PCI-Express bandwidth available for this card is " |
| 7647 | "not sufficient for optimal performance.\n"); |
| 7648 | e_dev_warn("For optimal performance a x8 PCI-Express slot " |
| 7649 | "is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 7650 | } |
| 7651 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 7652 | /* save off EEPROM version number */ |
| 7653 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 7654 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7655 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7656 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7657 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7658 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 7659 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7660 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 7661 | "Please be aware there may be issues associated " |
| 7662 | "with your hardware. If you are experiencing " |
| 7663 | "problems please contact your Intel or hardware " |
| 7664 | "representative who provided you with this " |
| 7665 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 7666 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7667 | strcpy(netdev->name, "eth%d"); |
| 7668 | err = register_netdev(netdev); |
| 7669 | if (err) |
| 7670 | goto err_register; |
| 7671 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 7672 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 7673 | netif_carrier_off(netdev); |
| 7674 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7675 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 7676 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7677 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7678 | ixgbe_setup_dca(adapter); |
| 7679 | } |
| 7680 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7681 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7682 | 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] | 7683 | for (i = 0; i < adapter->num_vfs; i++) |
| 7684 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 7685 | } |
| 7686 | |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 7687 | /* Inform firmware of driver version */ |
| 7688 | if (hw->mac.ops.set_fw_drv_ver) |
Don Skidmore | a38a104 | 2011-05-20 03:05:14 +0000 | [diff] [blame] | 7689 | hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD, |
| 7690 | FW_CEM_UNUSED_VER); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 7691 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7692 | /* add san mac addr to netdev */ |
| 7693 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7694 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7695 | e_dev_info("Intel(R) 10 Gigabit Network Connection\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7696 | cards_found++; |
| 7697 | return 0; |
| 7698 | |
| 7699 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7700 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7701 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7702 | err_sw_init: |
| 7703 | err_eeprom: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7704 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7705 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7706 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7707 | iounmap(hw->hw_addr); |
| 7708 | err_ioremap: |
| 7709 | free_netdev(netdev); |
| 7710 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7711 | pci_release_selected_regions(pdev, |
| 7712 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7713 | err_pci_reg: |
| 7714 | err_dma: |
| 7715 | pci_disable_device(pdev); |
| 7716 | return err; |
| 7717 | } |
| 7718 | |
| 7719 | /** |
| 7720 | * ixgbe_remove - Device Removal Routine |
| 7721 | * @pdev: PCI device information struct |
| 7722 | * |
| 7723 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 7724 | * that it should release a PCI device. The could be caused by a |
| 7725 | * Hot-Plug event, or because the driver is going to be removed from |
| 7726 | * memory. |
| 7727 | **/ |
| 7728 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 7729 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7730 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7731 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7732 | |
| 7733 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7734 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7735 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7736 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7737 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 7738 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 7739 | dca_remove_requester(&pdev->dev); |
| 7740 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 7741 | } |
| 7742 | |
| 7743 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7744 | #ifdef IXGBE_FCOE |
| 7745 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 7746 | ixgbe_cleanup_fcoe(adapter); |
| 7747 | |
| 7748 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7749 | |
| 7750 | /* remove the added san mac */ |
| 7751 | ixgbe_del_sanmac_netdev(netdev); |
| 7752 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7753 | if (netdev->reg_state == NETREG_REGISTERED) |
| 7754 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7755 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7756 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7757 | ixgbe_disable_sriov(adapter); |
| 7758 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 7759 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 7760 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7761 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7762 | |
| 7763 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7764 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7765 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7766 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7767 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7768 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7769 | free_netdev(netdev); |
| 7770 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7771 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7772 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7773 | pci_disable_device(pdev); |
| 7774 | } |
| 7775 | |
| 7776 | /** |
| 7777 | * ixgbe_io_error_detected - called when PCI error is detected |
| 7778 | * @pdev: Pointer to PCI device |
| 7779 | * @state: The current pci connection state |
| 7780 | * |
| 7781 | * This function is called after a PCI bus error affecting |
| 7782 | * this device has been detected. |
| 7783 | */ |
| 7784 | 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] | 7785 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7786 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7787 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7788 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7789 | |
| 7790 | netif_device_detach(netdev); |
| 7791 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 7792 | if (state == pci_channel_io_perm_failure) |
| 7793 | return PCI_ERS_RESULT_DISCONNECT; |
| 7794 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7795 | if (netif_running(netdev)) |
| 7796 | ixgbe_down(adapter); |
| 7797 | pci_disable_device(pdev); |
| 7798 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7799 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7800 | return PCI_ERS_RESULT_NEED_RESET; |
| 7801 | } |
| 7802 | |
| 7803 | /** |
| 7804 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 7805 | * @pdev: Pointer to PCI device |
| 7806 | * |
| 7807 | * Restart the card from scratch, as if from a cold-boot. |
| 7808 | */ |
| 7809 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 7810 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7811 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7812 | pci_ers_result_t result; |
| 7813 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7814 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7815 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7816 | 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] | 7817 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7818 | } else { |
| 7819 | pci_set_master(pdev); |
| 7820 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 7821 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7822 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 7823 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7824 | |
| 7825 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 7826 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7827 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7828 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7829 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7830 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7831 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7832 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 7833 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7834 | /* non-fatal, continue */ |
| 7835 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7836 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7837 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7838 | } |
| 7839 | |
| 7840 | /** |
| 7841 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 7842 | * @pdev: Pointer to PCI device |
| 7843 | * |
| 7844 | * This callback is called when the error recovery driver tells us that |
| 7845 | * its OK to resume normal operation. |
| 7846 | */ |
| 7847 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 7848 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7849 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 7850 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7851 | |
| 7852 | if (netif_running(netdev)) { |
| 7853 | if (ixgbe_up(adapter)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7854 | e_info(probe, "ixgbe_up failed after reset\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7855 | return; |
| 7856 | } |
| 7857 | } |
| 7858 | |
| 7859 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7860 | } |
| 7861 | |
| 7862 | static struct pci_error_handlers ixgbe_err_handler = { |
| 7863 | .error_detected = ixgbe_io_error_detected, |
| 7864 | .slot_reset = ixgbe_io_slot_reset, |
| 7865 | .resume = ixgbe_io_resume, |
| 7866 | }; |
| 7867 | |
| 7868 | static struct pci_driver ixgbe_driver = { |
| 7869 | .name = ixgbe_driver_name, |
| 7870 | .id_table = ixgbe_pci_tbl, |
| 7871 | .probe = ixgbe_probe, |
| 7872 | .remove = __devexit_p(ixgbe_remove), |
| 7873 | #ifdef CONFIG_PM |
| 7874 | .suspend = ixgbe_suspend, |
| 7875 | .resume = ixgbe_resume, |
| 7876 | #endif |
| 7877 | .shutdown = ixgbe_shutdown, |
| 7878 | .err_handler = &ixgbe_err_handler |
| 7879 | }; |
| 7880 | |
| 7881 | /** |
| 7882 | * ixgbe_init_module - Driver Registration Routine |
| 7883 | * |
| 7884 | * ixgbe_init_module is the first routine called when the driver is |
| 7885 | * loaded. All it does is register with the PCI subsystem. |
| 7886 | **/ |
| 7887 | static int __init ixgbe_init_module(void) |
| 7888 | { |
| 7889 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 7890 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7891 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7892 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7893 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7894 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7895 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7896 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7897 | ret = pci_register_driver(&ixgbe_driver); |
| 7898 | return ret; |
| 7899 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7900 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7901 | module_init(ixgbe_init_module); |
| 7902 | |
| 7903 | /** |
| 7904 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 7905 | * |
| 7906 | * ixgbe_exit_module is called just before the driver is removed |
| 7907 | * from memory. |
| 7908 | **/ |
| 7909 | static void __exit ixgbe_exit_module(void) |
| 7910 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7911 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7912 | dca_unregister_notify(&dca_notifier); |
| 7913 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7914 | pci_unregister_driver(&ixgbe_driver); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7915 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7916 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7917 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 7918 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7919 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7920 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7921 | { |
| 7922 | int ret_val; |
| 7923 | |
| 7924 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7925 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7926 | |
| 7927 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 7928 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 7929 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 7930 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7931 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7932 | module_exit(ixgbe_exit_module); |
| 7933 | |
| 7934 | /* ixgbe_main.c */ |