Commit | Line | Data |
---|---|---|
9a799d71 AK |
1 | /******************************************************************************* |
2 | ||
3 | Intel 10 Gigabit PCI Express Linux driver | |
8c47eaa7 | 4 | Copyright(c) 1999 - 2010 Intel Corporation. |
9a799d71 AK |
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: | |
9a799d71 AK |
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> | |
35 | #include <linux/ip.h> | |
36 | #include <linux/tcp.h> | |
60127865 | 37 | #include <linux/pkt_sched.h> |
9a799d71 AK |
38 | #include <linux/ipv6.h> |
39 | #include <net/checksum.h> | |
40 | #include <net/ip6_checksum.h> | |
41 | #include <linux/ethtool.h> | |
42 | #include <linux/if_vlan.h> | |
eacd73f7 | 43 | #include <scsi/fc/fc_fcoe.h> |
9a799d71 AK |
44 | |
45 | #include "ixgbe.h" | |
46 | #include "ixgbe_common.h" | |
ee5f784a | 47 | #include "ixgbe_dcb_82599.h" |
1cdd1ec8 | 48 | #include "ixgbe_sriov.h" |
9a799d71 AK |
49 | |
50 | char ixgbe_driver_name[] = "ixgbe"; | |
9c8eb720 | 51 | static const char ixgbe_driver_string[] = |
b4617240 | 52 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
9a799d71 | 53 | |
e0f4daff | 54 | #define DRV_VERSION "2.0.44-k2" |
9c8eb720 | 55 | const char ixgbe_driver_version[] = DRV_VERSION; |
8c47eaa7 | 56 | static char ixgbe_copyright[] = "Copyright (c) 1999-2010 Intel Corporation."; |
9a799d71 AK |
57 | |
58 | static const struct ixgbe_info *ixgbe_info_tbl[] = { | |
b4617240 | 59 | [board_82598] = &ixgbe_82598_info, |
e8e26350 | 60 | [board_82599] = &ixgbe_82599_info, |
9a799d71 AK |
61 | }; |
62 | ||
63 | /* ixgbe_pci_tbl - PCI Device ID Table | |
64 | * | |
65 | * Wildcard entries (PCI_ANY_ID) should come last | |
66 | * Last entry must be all 0s | |
67 | * | |
68 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, | |
69 | * Class, Class Mask, private data (not used) } | |
70 | */ | |
a3aa1884 | 71 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
1e336d0f DS |
72 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
73 | board_82598 }, | |
9a799d71 | 74 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
3957d63d | 75 | board_82598 }, |
9a799d71 | 76 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
3957d63d | 77 | board_82598 }, |
0befdb3e JB |
78 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
79 | board_82598 }, | |
3845bec0 PWJ |
80 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), |
81 | board_82598 }, | |
9a799d71 | 82 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
3957d63d | 83 | board_82598 }, |
8d792cd9 JB |
84 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
85 | board_82598 }, | |
c4900be0 DS |
86 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
87 | board_82598 }, | |
88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), | |
89 | board_82598 }, | |
b95f5fcb JB |
90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
91 | board_82598 }, | |
c4900be0 DS |
92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
93 | board_82598 }, | |
2f21bdd3 DS |
94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
95 | board_82598 }, | |
e8e26350 PW |
96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
97 | board_82599 }, | |
1fcf03e6 PWJ |
98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
99 | board_82599 }, | |
74757d49 DS |
100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), |
101 | board_82599 }, | |
e8e26350 PW |
102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
103 | board_82599 }, | |
38ad1c8e DS |
104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
105 | board_82599 }, | |
dbfec662 DS |
106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
107 | board_82599 }, | |
8911184f PWJ |
108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
109 | board_82599 }, | |
312eb931 DS |
110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
111 | board_82599 }, | |
9a799d71 AK |
112 | |
113 | /* required last entry */ | |
114 | {0, } | |
115 | }; | |
116 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); | |
117 | ||
5dd2d332 | 118 | #ifdef CONFIG_IXGBE_DCA |
bd0362dd | 119 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
b4617240 | 120 | void *p); |
bd0362dd JC |
121 | static struct notifier_block dca_notifier = { |
122 | .notifier_call = ixgbe_notify_dca, | |
123 | .next = NULL, | |
124 | .priority = 0 | |
125 | }; | |
126 | #endif | |
127 | ||
1cdd1ec8 GR |
128 | #ifdef CONFIG_PCI_IOV |
129 | static unsigned int max_vfs; | |
130 | module_param(max_vfs, uint, 0); | |
131 | MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate " | |
132 | "per physical function"); | |
133 | #endif /* CONFIG_PCI_IOV */ | |
134 | ||
9a799d71 AK |
135 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
136 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); | |
137 | MODULE_LICENSE("GPL"); | |
138 | MODULE_VERSION(DRV_VERSION); | |
139 | ||
140 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 | |
141 | ||
1cdd1ec8 GR |
142 | static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) |
143 | { | |
144 | struct ixgbe_hw *hw = &adapter->hw; | |
145 | u32 gcr; | |
146 | u32 gpie; | |
147 | u32 vmdctl; | |
148 | ||
149 | #ifdef CONFIG_PCI_IOV | |
150 | /* disable iov and allow time for transactions to clear */ | |
151 | pci_disable_sriov(adapter->pdev); | |
152 | #endif | |
153 | ||
154 | /* turn off device IOV mode */ | |
155 | gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); | |
156 | gcr &= ~(IXGBE_GCR_EXT_SRIOV); | |
157 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr); | |
158 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); | |
159 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; | |
160 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); | |
161 | ||
162 | /* set default pool back to 0 */ | |
163 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); | |
164 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; | |
165 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); | |
166 | ||
167 | /* take a breather then clean up driver data */ | |
168 | msleep(100); | |
169 | if (adapter->vfinfo) | |
170 | kfree(adapter->vfinfo); | |
171 | adapter->vfinfo = NULL; | |
172 | ||
173 | adapter->num_vfs = 0; | |
174 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; | |
175 | } | |
176 | ||
5eba3699 AV |
177 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
178 | { | |
179 | u32 ctrl_ext; | |
180 | ||
181 | /* Let firmware take over control of h/w */ | |
182 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); | |
183 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, | |
b4617240 | 184 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
5eba3699 AV |
185 | } |
186 | ||
187 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) | |
188 | { | |
189 | u32 ctrl_ext; | |
190 | ||
191 | /* Let firmware know the driver has taken over */ | |
192 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); | |
193 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, | |
b4617240 | 194 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
5eba3699 | 195 | } |
9a799d71 | 196 | |
e8e26350 PW |
197 | /* |
198 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors | |
199 | * @adapter: pointer to adapter struct | |
200 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes | |
201 | * @queue: queue to map the corresponding interrupt to | |
202 | * @msix_vector: the vector to map to the corresponding queue | |
203 | * | |
204 | */ | |
205 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, | |
206 | u8 queue, u8 msix_vector) | |
9a799d71 AK |
207 | { |
208 | u32 ivar, index; | |
e8e26350 PW |
209 | struct ixgbe_hw *hw = &adapter->hw; |
210 | switch (hw->mac.type) { | |
211 | case ixgbe_mac_82598EB: | |
212 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; | |
213 | if (direction == -1) | |
214 | direction = 0; | |
215 | index = (((direction * 64) + queue) >> 2) & 0x1F; | |
216 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); | |
217 | ivar &= ~(0xFF << (8 * (queue & 0x3))); | |
218 | ivar |= (msix_vector << (8 * (queue & 0x3))); | |
219 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); | |
220 | break; | |
221 | case ixgbe_mac_82599EB: | |
222 | if (direction == -1) { | |
223 | /* other causes */ | |
224 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; | |
225 | index = ((queue & 1) * 8); | |
226 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); | |
227 | ivar &= ~(0xFF << index); | |
228 | ivar |= (msix_vector << index); | |
229 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); | |
230 | break; | |
231 | } else { | |
232 | /* tx or rx causes */ | |
233 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; | |
234 | index = ((16 * (queue & 1)) + (8 * direction)); | |
235 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); | |
236 | ivar &= ~(0xFF << index); | |
237 | ivar |= (msix_vector << index); | |
238 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); | |
239 | break; | |
240 | } | |
241 | default: | |
242 | break; | |
243 | } | |
9a799d71 AK |
244 | } |
245 | ||
fe49f04a AD |
246 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
247 | u64 qmask) | |
248 | { | |
249 | u32 mask; | |
250 | ||
251 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { | |
252 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); | |
253 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); | |
254 | } else { | |
255 | mask = (qmask & 0xFFFFFFFF); | |
256 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); | |
257 | mask = (qmask >> 32); | |
258 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); | |
259 | } | |
260 | } | |
261 | ||
9a799d71 | 262 | static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter, |
b4617240 PW |
263 | struct ixgbe_tx_buffer |
264 | *tx_buffer_info) | |
9a799d71 | 265 | { |
e5a43549 AD |
266 | if (tx_buffer_info->dma) { |
267 | if (tx_buffer_info->mapped_as_page) | |
268 | pci_unmap_page(adapter->pdev, | |
269 | tx_buffer_info->dma, | |
270 | tx_buffer_info->length, | |
271 | PCI_DMA_TODEVICE); | |
272 | else | |
273 | pci_unmap_single(adapter->pdev, | |
274 | tx_buffer_info->dma, | |
275 | tx_buffer_info->length, | |
276 | PCI_DMA_TODEVICE); | |
277 | tx_buffer_info->dma = 0; | |
278 | } | |
9a799d71 AK |
279 | if (tx_buffer_info->skb) { |
280 | dev_kfree_skb_any(tx_buffer_info->skb); | |
281 | tx_buffer_info->skb = NULL; | |
282 | } | |
44df32c5 | 283 | tx_buffer_info->time_stamp = 0; |
9a799d71 AK |
284 | /* tx_buffer_info must be completely set up in the transmit path */ |
285 | } | |
286 | ||
26f23d82 YZ |
287 | /** |
288 | * ixgbe_tx_is_paused - check if the tx ring is paused | |
289 | * @adapter: the ixgbe adapter | |
290 | * @tx_ring: the corresponding tx_ring | |
291 | * | |
292 | * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the | |
293 | * corresponding TC of this tx_ring when checking TFCS. | |
294 | * | |
295 | * Returns : true if paused | |
296 | */ | |
297 | static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter, | |
298 | struct ixgbe_ring *tx_ring) | |
299 | { | |
26f23d82 YZ |
300 | u32 txoff = IXGBE_TFCS_TXOFF; |
301 | ||
302 | #ifdef CONFIG_IXGBE_DCB | |
303 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | |
30b76832 | 304 | int tc; |
26f23d82 YZ |
305 | int reg_idx = tx_ring->reg_idx; |
306 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; | |
307 | ||
6837e895 PW |
308 | switch (adapter->hw.mac.type) { |
309 | case ixgbe_mac_82598EB: | |
26f23d82 YZ |
310 | tc = reg_idx >> 2; |
311 | txoff = IXGBE_TFCS_TXOFF0; | |
6837e895 PW |
312 | break; |
313 | case ixgbe_mac_82599EB: | |
26f23d82 YZ |
314 | tc = 0; |
315 | txoff = IXGBE_TFCS_TXOFF; | |
316 | if (dcb_i == 8) { | |
317 | /* TC0, TC1 */ | |
318 | tc = reg_idx >> 5; | |
319 | if (tc == 2) /* TC2, TC3 */ | |
320 | tc += (reg_idx - 64) >> 4; | |
321 | else if (tc == 3) /* TC4, TC5, TC6, TC7 */ | |
322 | tc += 1 + ((reg_idx - 96) >> 3); | |
323 | } else if (dcb_i == 4) { | |
324 | /* TC0, TC1 */ | |
325 | tc = reg_idx >> 6; | |
326 | if (tc == 1) { | |
327 | tc += (reg_idx - 64) >> 5; | |
328 | if (tc == 2) /* TC2, TC3 */ | |
329 | tc += (reg_idx - 96) >> 4; | |
330 | } | |
331 | } | |
6837e895 PW |
332 | break; |
333 | default: | |
334 | tc = 0; | |
26f23d82 YZ |
335 | } |
336 | txoff <<= tc; | |
337 | } | |
338 | #endif | |
339 | return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff; | |
340 | } | |
341 | ||
9a799d71 | 342 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
b4617240 PW |
343 | struct ixgbe_ring *tx_ring, |
344 | unsigned int eop) | |
9a799d71 | 345 | { |
e01c31a5 | 346 | struct ixgbe_hw *hw = &adapter->hw; |
e01c31a5 | 347 | |
9a799d71 | 348 | /* Detect a transmit hang in hardware, this serializes the |
e01c31a5 | 349 | * check with the clearing of time_stamp and movement of eop */ |
9a799d71 | 350 | adapter->detect_tx_hung = false; |
44df32c5 | 351 | if (tx_ring->tx_buffer_info[eop].time_stamp && |
9a799d71 | 352 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
26f23d82 | 353 | !ixgbe_tx_is_paused(adapter, tx_ring)) { |
9a799d71 | 354 | /* detected Tx unit hang */ |
e01c31a5 JB |
355 | union ixgbe_adv_tx_desc *tx_desc; |
356 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); | |
9a799d71 | 357 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
e01c31a5 JB |
358 | " Tx Queue <%d>\n" |
359 | " TDH, TDT <%x>, <%x>\n" | |
9a799d71 AK |
360 | " next_to_use <%x>\n" |
361 | " next_to_clean <%x>\n" | |
362 | "tx_buffer_info[next_to_clean]\n" | |
363 | " time_stamp <%lx>\n" | |
e01c31a5 JB |
364 | " jiffies <%lx>\n", |
365 | tx_ring->queue_index, | |
44df32c5 AD |
366 | IXGBE_READ_REG(hw, tx_ring->head), |
367 | IXGBE_READ_REG(hw, tx_ring->tail), | |
e01c31a5 JB |
368 | tx_ring->next_to_use, eop, |
369 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); | |
9a799d71 AK |
370 | return true; |
371 | } | |
372 | ||
373 | return false; | |
374 | } | |
375 | ||
b4617240 PW |
376 | #define IXGBE_MAX_TXD_PWR 14 |
377 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) | |
e092be60 AV |
378 | |
379 | /* Tx Descriptors needed, worst case */ | |
380 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ | |
381 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) | |
382 | #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \ | |
b4617240 | 383 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
e092be60 | 384 | |
e01c31a5 JB |
385 | static void ixgbe_tx_timeout(struct net_device *netdev); |
386 | ||
9a799d71 AK |
387 | /** |
388 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes | |
fe49f04a | 389 | * @q_vector: structure containing interrupt and ring information |
e01c31a5 | 390 | * @tx_ring: tx ring to clean |
9a799d71 | 391 | **/ |
fe49f04a | 392 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
e01c31a5 | 393 | struct ixgbe_ring *tx_ring) |
9a799d71 | 394 | { |
fe49f04a | 395 | struct ixgbe_adapter *adapter = q_vector->adapter; |
e01c31a5 | 396 | struct net_device *netdev = adapter->netdev; |
12207e49 PWJ |
397 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
398 | struct ixgbe_tx_buffer *tx_buffer_info; | |
399 | unsigned int i, eop, count = 0; | |
e01c31a5 | 400 | unsigned int total_bytes = 0, total_packets = 0; |
9a799d71 AK |
401 | |
402 | i = tx_ring->next_to_clean; | |
12207e49 PWJ |
403 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
404 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); | |
405 | ||
406 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && | |
9a1a69ad | 407 | (count < tx_ring->work_limit)) { |
12207e49 PWJ |
408 | bool cleaned = false; |
409 | for ( ; !cleaned; count++) { | |
410 | struct sk_buff *skb; | |
9a799d71 AK |
411 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
412 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | |
12207e49 | 413 | cleaned = (i == eop); |
e01c31a5 | 414 | skb = tx_buffer_info->skb; |
9a799d71 | 415 | |
12207e49 | 416 | if (cleaned && skb) { |
e092be60 | 417 | unsigned int segs, bytecount; |
3d8fd385 | 418 | unsigned int hlen = skb_headlen(skb); |
e01c31a5 JB |
419 | |
420 | /* gso_segs is currently only valid for tcp */ | |
e092be60 | 421 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
3d8fd385 YZ |
422 | #ifdef IXGBE_FCOE |
423 | /* adjust for FCoE Sequence Offload */ | |
424 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) | |
425 | && (skb->protocol == htons(ETH_P_FCOE)) && | |
426 | skb_is_gso(skb)) { | |
427 | hlen = skb_transport_offset(skb) + | |
428 | sizeof(struct fc_frame_header) + | |
429 | sizeof(struct fcoe_crc_eof); | |
430 | segs = DIV_ROUND_UP(skb->len - hlen, | |
431 | skb_shinfo(skb)->gso_size); | |
432 | } | |
433 | #endif /* IXGBE_FCOE */ | |
e092be60 | 434 | /* multiply data chunks by size of headers */ |
3d8fd385 | 435 | bytecount = ((segs - 1) * hlen) + skb->len; |
e01c31a5 JB |
436 | total_packets += segs; |
437 | total_bytes += bytecount; | |
e092be60 | 438 | } |
e01c31a5 | 439 | |
9a799d71 | 440 | ixgbe_unmap_and_free_tx_resource(adapter, |
e01c31a5 | 441 | tx_buffer_info); |
9a799d71 | 442 | |
12207e49 PWJ |
443 | tx_desc->wb.status = 0; |
444 | ||
9a799d71 AK |
445 | i++; |
446 | if (i == tx_ring->count) | |
447 | i = 0; | |
e01c31a5 | 448 | } |
12207e49 PWJ |
449 | |
450 | eop = tx_ring->tx_buffer_info[i].next_to_watch; | |
451 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); | |
452 | } | |
453 | ||
9a799d71 AK |
454 | tx_ring->next_to_clean = i; |
455 | ||
e092be60 | 456 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
e01c31a5 JB |
457 | if (unlikely(count && netif_carrier_ok(netdev) && |
458 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { | |
e092be60 AV |
459 | /* Make sure that anybody stopping the queue after this |
460 | * sees the new next_to_clean. | |
461 | */ | |
462 | smp_mb(); | |
30eba97a AV |
463 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
464 | !test_bit(__IXGBE_DOWN, &adapter->state)) { | |
465 | netif_wake_subqueue(netdev, tx_ring->queue_index); | |
7ca3bc58 | 466 | ++tx_ring->restart_queue; |
30eba97a | 467 | } |
e092be60 | 468 | } |
9a799d71 | 469 | |
e01c31a5 JB |
470 | if (adapter->detect_tx_hung) { |
471 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { | |
472 | /* schedule immediate reset if we believe we hung */ | |
473 | DPRINTK(PROBE, INFO, | |
474 | "tx hang %d detected, resetting adapter\n", | |
475 | adapter->tx_timeout_count + 1); | |
476 | ixgbe_tx_timeout(adapter->netdev); | |
477 | } | |
478 | } | |
9a799d71 | 479 | |
e01c31a5 | 480 | /* re-arm the interrupt */ |
fe49f04a AD |
481 | if (count >= tx_ring->work_limit) |
482 | ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx)); | |
9a799d71 | 483 | |
e01c31a5 JB |
484 | tx_ring->total_bytes += total_bytes; |
485 | tx_ring->total_packets += total_packets; | |
e01c31a5 | 486 | tx_ring->stats.packets += total_packets; |
12207e49 | 487 | tx_ring->stats.bytes += total_bytes; |
9a1a69ad | 488 | return (count < tx_ring->work_limit); |
9a799d71 AK |
489 | } |
490 | ||
5dd2d332 | 491 | #ifdef CONFIG_IXGBE_DCA |
bd0362dd | 492 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
b4617240 | 493 | struct ixgbe_ring *rx_ring) |
bd0362dd JC |
494 | { |
495 | u32 rxctrl; | |
496 | int cpu = get_cpu(); | |
3a581073 | 497 | int q = rx_ring - adapter->rx_ring; |
bd0362dd | 498 | |
3a581073 | 499 | if (rx_ring->cpu != cpu) { |
bd0362dd | 500 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
e8e26350 PW |
501 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
502 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; | |
503 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); | |
504 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { | |
505 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; | |
506 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << | |
507 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); | |
508 | } | |
bd0362dd JC |
509 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
510 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; | |
15005a32 DS |
511 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
512 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | | |
e8e26350 | 513 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
bd0362dd | 514 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
3a581073 | 515 | rx_ring->cpu = cpu; |
bd0362dd JC |
516 | } |
517 | put_cpu(); | |
518 | } | |
519 | ||
520 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, | |
b4617240 | 521 | struct ixgbe_ring *tx_ring) |
bd0362dd JC |
522 | { |
523 | u32 txctrl; | |
524 | int cpu = get_cpu(); | |
3a581073 | 525 | int q = tx_ring - adapter->tx_ring; |
ee5f784a | 526 | struct ixgbe_hw *hw = &adapter->hw; |
bd0362dd | 527 | |
3a581073 | 528 | if (tx_ring->cpu != cpu) { |
e8e26350 | 529 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
ee5f784a | 530 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q)); |
e8e26350 PW |
531 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
532 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); | |
ee5f784a DS |
533 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
534 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl); | |
e8e26350 | 535 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
ee5f784a | 536 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q)); |
e8e26350 PW |
537 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
538 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << | |
ee5f784a DS |
539 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
540 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; | |
541 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl); | |
e8e26350 | 542 | } |
3a581073 | 543 | tx_ring->cpu = cpu; |
bd0362dd JC |
544 | } |
545 | put_cpu(); | |
546 | } | |
547 | ||
548 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) | |
549 | { | |
550 | int i; | |
551 | ||
552 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) | |
553 | return; | |
554 | ||
e35ec126 AD |
555 | /* always use CB2 mode, difference is masked in the CB driver */ |
556 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); | |
557 | ||
bd0362dd JC |
558 | for (i = 0; i < adapter->num_tx_queues; i++) { |
559 | adapter->tx_ring[i].cpu = -1; | |
560 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); | |
561 | } | |
562 | for (i = 0; i < adapter->num_rx_queues; i++) { | |
563 | adapter->rx_ring[i].cpu = -1; | |
564 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); | |
565 | } | |
566 | } | |
567 | ||
568 | static int __ixgbe_notify_dca(struct device *dev, void *data) | |
569 | { | |
570 | struct net_device *netdev = dev_get_drvdata(dev); | |
571 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
572 | unsigned long event = *(unsigned long *)data; | |
573 | ||
574 | switch (event) { | |
575 | case DCA_PROVIDER_ADD: | |
96b0e0f6 JB |
576 | /* if we're already enabled, don't do it again */ |
577 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | |
578 | break; | |
652f093f | 579 | if (dca_add_requester(dev) == 0) { |
96b0e0f6 | 580 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
bd0362dd JC |
581 | ixgbe_setup_dca(adapter); |
582 | break; | |
583 | } | |
584 | /* Fall Through since DCA is disabled. */ | |
585 | case DCA_PROVIDER_REMOVE: | |
586 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { | |
587 | dca_remove_requester(dev); | |
588 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; | |
589 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); | |
590 | } | |
591 | break; | |
592 | } | |
593 | ||
652f093f | 594 | return 0; |
bd0362dd JC |
595 | } |
596 | ||
5dd2d332 | 597 | #endif /* CONFIG_IXGBE_DCA */ |
9a799d71 AK |
598 | /** |
599 | * ixgbe_receive_skb - Send a completed packet up the stack | |
600 | * @adapter: board private structure | |
601 | * @skb: packet to send up | |
177db6ff MC |
602 | * @status: hardware indication of status of receive |
603 | * @rx_ring: rx descriptor ring (for a specific queue) to setup | |
604 | * @rx_desc: rx descriptor | |
9a799d71 | 605 | **/ |
78b6f4ce | 606 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
b4617240 | 607 | struct sk_buff *skb, u8 status, |
fdaff1ce | 608 | struct ixgbe_ring *ring, |
177db6ff | 609 | union ixgbe_adv_rx_desc *rx_desc) |
9a799d71 | 610 | { |
78b6f4ce HX |
611 | struct ixgbe_adapter *adapter = q_vector->adapter; |
612 | struct napi_struct *napi = &q_vector->napi; | |
177db6ff MC |
613 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
614 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); | |
9a799d71 | 615 | |
fdaff1ce | 616 | skb_record_rx_queue(skb, ring->queue_index); |
182ff8df | 617 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
8a62babf | 618 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
78b6f4ce | 619 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
9a799d71 | 620 | else |
78b6f4ce | 621 | napi_gro_receive(napi, skb); |
177db6ff | 622 | } else { |
8a62babf | 623 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
182ff8df AD |
624 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
625 | else | |
626 | netif_rx(skb); | |
9a799d71 AK |
627 | } |
628 | } | |
629 | ||
e59bd25d AV |
630 | /** |
631 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum | |
632 | * @adapter: address of board private structure | |
633 | * @status_err: hardware indication of status of receive | |
634 | * @skb: skb currently being received and modified | |
635 | **/ | |
9a799d71 | 636 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
8bae1b2b DS |
637 | union ixgbe_adv_rx_desc *rx_desc, |
638 | struct sk_buff *skb) | |
9a799d71 | 639 | { |
8bae1b2b DS |
640 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
641 | ||
9a799d71 AK |
642 | skb->ip_summed = CHECKSUM_NONE; |
643 | ||
712744be JB |
644 | /* Rx csum disabled */ |
645 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) | |
9a799d71 | 646 | return; |
e59bd25d AV |
647 | |
648 | /* if IP and error */ | |
649 | if ((status_err & IXGBE_RXD_STAT_IPCS) && | |
650 | (status_err & IXGBE_RXDADV_ERR_IPE)) { | |
9a799d71 AK |
651 | adapter->hw_csum_rx_error++; |
652 | return; | |
653 | } | |
e59bd25d AV |
654 | |
655 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) | |
656 | return; | |
657 | ||
658 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { | |
8bae1b2b DS |
659 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
660 | ||
661 | /* | |
662 | * 82599 errata, UDP frames with a 0 checksum can be marked as | |
663 | * checksum errors. | |
664 | */ | |
665 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && | |
666 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) | |
667 | return; | |
668 | ||
e59bd25d AV |
669 | adapter->hw_csum_rx_error++; |
670 | return; | |
671 | } | |
672 | ||
9a799d71 | 673 | /* It must be a TCP or UDP packet with a valid checksum */ |
e59bd25d | 674 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
9a799d71 AK |
675 | } |
676 | ||
e8e26350 PW |
677 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
678 | struct ixgbe_ring *rx_ring, u32 val) | |
679 | { | |
680 | /* | |
681 | * Force memory writes to complete before letting h/w | |
682 | * know there are new descriptors to fetch. (Only | |
683 | * applicable for weak-ordered memory model archs, | |
684 | * such as IA-64). | |
685 | */ | |
686 | wmb(); | |
687 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); | |
688 | } | |
689 | ||
9a799d71 AK |
690 | /** |
691 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split | |
692 | * @adapter: address of board private structure | |
693 | **/ | |
694 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, | |
7c6e0a43 JB |
695 | struct ixgbe_ring *rx_ring, |
696 | int cleaned_count) | |
9a799d71 | 697 | { |
9a799d71 AK |
698 | struct pci_dev *pdev = adapter->pdev; |
699 | union ixgbe_adv_rx_desc *rx_desc; | |
3a581073 | 700 | struct ixgbe_rx_buffer *bi; |
9a799d71 | 701 | unsigned int i; |
9a799d71 AK |
702 | |
703 | i = rx_ring->next_to_use; | |
3a581073 | 704 | bi = &rx_ring->rx_buffer_info[i]; |
9a799d71 AK |
705 | |
706 | while (cleaned_count--) { | |
707 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); | |
708 | ||
762f4c57 | 709 | if (!bi->page_dma && |
6e455b89 | 710 | (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) { |
3a581073 | 711 | if (!bi->page) { |
762f4c57 JB |
712 | bi->page = alloc_page(GFP_ATOMIC); |
713 | if (!bi->page) { | |
714 | adapter->alloc_rx_page_failed++; | |
715 | goto no_buffers; | |
716 | } | |
717 | bi->page_offset = 0; | |
718 | } else { | |
719 | /* use a half page if we're re-using */ | |
720 | bi->page_offset ^= (PAGE_SIZE / 2); | |
9a799d71 | 721 | } |
762f4c57 JB |
722 | |
723 | bi->page_dma = pci_map_page(pdev, bi->page, | |
724 | bi->page_offset, | |
725 | (PAGE_SIZE / 2), | |
726 | PCI_DMA_FROMDEVICE); | |
9a799d71 AK |
727 | } |
728 | ||
3a581073 | 729 | if (!bi->skb) { |
5ecc3614 | 730 | struct sk_buff *skb; |
7ca3bc58 JB |
731 | /* netdev_alloc_skb reserves 32 bytes up front!! */ |
732 | uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES; | |
733 | skb = netdev_alloc_skb(adapter->netdev, bufsz); | |
9a799d71 AK |
734 | |
735 | if (!skb) { | |
736 | adapter->alloc_rx_buff_failed++; | |
737 | goto no_buffers; | |
738 | } | |
739 | ||
7ca3bc58 JB |
740 | /* advance the data pointer to the next cache line */ |
741 | skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES) | |
742 | - skb->data)); | |
743 | ||
3a581073 | 744 | bi->skb = skb; |
4f57ca6e JB |
745 | bi->dma = pci_map_single(pdev, skb->data, |
746 | rx_ring->rx_buf_len, | |
3a581073 | 747 | PCI_DMA_FROMDEVICE); |
9a799d71 AK |
748 | } |
749 | /* Refresh the desc even if buffer_addrs didn't change because | |
750 | * each write-back erases this info. */ | |
6e455b89 | 751 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
3a581073 JB |
752 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
753 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); | |
9a799d71 | 754 | } else { |
3a581073 | 755 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
9a799d71 AK |
756 | } |
757 | ||
758 | i++; | |
759 | if (i == rx_ring->count) | |
760 | i = 0; | |
3a581073 | 761 | bi = &rx_ring->rx_buffer_info[i]; |
9a799d71 | 762 | } |
7c6e0a43 | 763 | |
9a799d71 AK |
764 | no_buffers: |
765 | if (rx_ring->next_to_use != i) { | |
766 | rx_ring->next_to_use = i; | |
767 | if (i-- == 0) | |
768 | i = (rx_ring->count - 1); | |
769 | ||
e8e26350 | 770 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
9a799d71 AK |
771 | } |
772 | } | |
773 | ||
7c6e0a43 JB |
774 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
775 | { | |
776 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; | |
777 | } | |
778 | ||
779 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) | |
780 | { | |
781 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; | |
782 | } | |
783 | ||
f8212f97 AD |
784 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
785 | { | |
786 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & | |
787 | IXGBE_RXDADV_RSCCNT_MASK) >> | |
788 | IXGBE_RXDADV_RSCCNT_SHIFT; | |
789 | } | |
790 | ||
791 | /** | |
792 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet | |
793 | * @skb: pointer to the last skb in the rsc queue | |
94b982b2 | 794 | * @count: pointer to number of packets coalesced in this context |
f8212f97 AD |
795 | * |
796 | * This function changes a queue full of hw rsc buffers into a completed | |
797 | * packet. It uses the ->prev pointers to find the first packet and then | |
798 | * turns it into the frag list owner. | |
799 | **/ | |
94b982b2 MC |
800 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb, |
801 | u64 *count) | |
f8212f97 AD |
802 | { |
803 | unsigned int frag_list_size = 0; | |
804 | ||
805 | while (skb->prev) { | |
806 | struct sk_buff *prev = skb->prev; | |
807 | frag_list_size += skb->len; | |
808 | skb->prev = NULL; | |
809 | skb = prev; | |
94b982b2 | 810 | *count += 1; |
f8212f97 AD |
811 | } |
812 | ||
813 | skb_shinfo(skb)->frag_list = skb->next; | |
814 | skb->next = NULL; | |
815 | skb->len += frag_list_size; | |
816 | skb->data_len += frag_list_size; | |
817 | skb->truesize += frag_list_size; | |
818 | return skb; | |
819 | } | |
820 | ||
78b6f4ce | 821 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
b4617240 PW |
822 | struct ixgbe_ring *rx_ring, |
823 | int *work_done, int work_to_do) | |
9a799d71 | 824 | { |
78b6f4ce | 825 | struct ixgbe_adapter *adapter = q_vector->adapter; |
2d86f139 | 826 | struct net_device *netdev = adapter->netdev; |
9a799d71 AK |
827 | struct pci_dev *pdev = adapter->pdev; |
828 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; | |
829 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; | |
830 | struct sk_buff *skb; | |
f8212f97 | 831 | unsigned int i, rsc_count = 0; |
7c6e0a43 | 832 | u32 len, staterr; |
177db6ff MC |
833 | u16 hdr_info; |
834 | bool cleaned = false; | |
9a799d71 | 835 | int cleaned_count = 0; |
d2f4fbe2 | 836 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
3d8fd385 YZ |
837 | #ifdef IXGBE_FCOE |
838 | int ddp_bytes = 0; | |
839 | #endif /* IXGBE_FCOE */ | |
9a799d71 AK |
840 | |
841 | i = rx_ring->next_to_clean; | |
9a799d71 AK |
842 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
843 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | |
844 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; | |
9a799d71 AK |
845 | |
846 | while (staterr & IXGBE_RXD_STAT_DD) { | |
7c6e0a43 | 847 | u32 upper_len = 0; |
9a799d71 AK |
848 | if (*work_done >= work_to_do) |
849 | break; | |
850 | (*work_done)++; | |
851 | ||
6e455b89 | 852 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
7c6e0a43 JB |
853 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
854 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> | |
762f4c57 | 855 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
9a799d71 AK |
856 | if (len > IXGBE_RX_HDR_SIZE) |
857 | len = IXGBE_RX_HDR_SIZE; | |
858 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); | |
7c6e0a43 | 859 | } else { |
9a799d71 | 860 | len = le16_to_cpu(rx_desc->wb.upper.length); |
7c6e0a43 | 861 | } |
9a799d71 AK |
862 | |
863 | cleaned = true; | |
864 | skb = rx_buffer_info->skb; | |
7ca3bc58 | 865 | prefetch(skb->data); |
9a799d71 AK |
866 | rx_buffer_info->skb = NULL; |
867 | ||
21fa4e66 | 868 | if (rx_buffer_info->dma) { |
9a799d71 | 869 | pci_unmap_single(pdev, rx_buffer_info->dma, |
5ecc3614 | 870 | rx_ring->rx_buf_len, |
b4617240 | 871 | PCI_DMA_FROMDEVICE); |
4f57ca6e | 872 | rx_buffer_info->dma = 0; |
9a799d71 AK |
873 | skb_put(skb, len); |
874 | } | |
875 | ||
876 | if (upper_len) { | |
877 | pci_unmap_page(pdev, rx_buffer_info->page_dma, | |
762f4c57 | 878 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
9a799d71 AK |
879 | rx_buffer_info->page_dma = 0; |
880 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, | |
762f4c57 JB |
881 | rx_buffer_info->page, |
882 | rx_buffer_info->page_offset, | |
883 | upper_len); | |
884 | ||
885 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || | |
886 | (page_count(rx_buffer_info->page) != 1)) | |
887 | rx_buffer_info->page = NULL; | |
888 | else | |
889 | get_page(rx_buffer_info->page); | |
9a799d71 AK |
890 | |
891 | skb->len += upper_len; | |
892 | skb->data_len += upper_len; | |
893 | skb->truesize += upper_len; | |
894 | } | |
895 | ||
896 | i++; | |
897 | if (i == rx_ring->count) | |
898 | i = 0; | |
9a799d71 AK |
899 | |
900 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); | |
901 | prefetch(next_rxd); | |
9a799d71 | 902 | cleaned_count++; |
f8212f97 | 903 | |
0c19d6af | 904 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
f8212f97 AD |
905 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
906 | ||
907 | if (rsc_count) { | |
908 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> | |
909 | IXGBE_RXDADV_NEXTP_SHIFT; | |
910 | next_buffer = &rx_ring->rx_buffer_info[nextp]; | |
f8212f97 AD |
911 | } else { |
912 | next_buffer = &rx_ring->rx_buffer_info[i]; | |
913 | } | |
914 | ||
9a799d71 | 915 | if (staterr & IXGBE_RXD_STAT_EOP) { |
f8212f97 | 916 | if (skb->prev) |
94b982b2 MC |
917 | skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count)); |
918 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { | |
919 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) | |
920 | rx_ring->rsc_count += skb_shinfo(skb)->nr_frags; | |
921 | else | |
922 | rx_ring->rsc_count++; | |
923 | rx_ring->rsc_flush++; | |
924 | } | |
9a799d71 AK |
925 | rx_ring->stats.packets++; |
926 | rx_ring->stats.bytes += skb->len; | |
927 | } else { | |
6e455b89 | 928 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
f8212f97 AD |
929 | rx_buffer_info->skb = next_buffer->skb; |
930 | rx_buffer_info->dma = next_buffer->dma; | |
931 | next_buffer->skb = skb; | |
932 | next_buffer->dma = 0; | |
933 | } else { | |
934 | skb->next = next_buffer->skb; | |
935 | skb->next->prev = skb; | |
936 | } | |
7ca3bc58 | 937 | rx_ring->non_eop_descs++; |
9a799d71 AK |
938 | goto next_desc; |
939 | } | |
940 | ||
941 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { | |
942 | dev_kfree_skb_irq(skb); | |
943 | goto next_desc; | |
944 | } | |
945 | ||
8bae1b2b | 946 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
d2f4fbe2 AV |
947 | |
948 | /* probably a little skewed due to removing CRC */ | |
949 | total_rx_bytes += skb->len; | |
950 | total_rx_packets++; | |
951 | ||
74ce8dd2 | 952 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
332d4a7d YZ |
953 | #ifdef IXGBE_FCOE |
954 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ | |
3d8fd385 YZ |
955 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
956 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); | |
957 | if (!ddp_bytes) | |
332d4a7d | 958 | goto next_desc; |
3d8fd385 | 959 | } |
332d4a7d | 960 | #endif /* IXGBE_FCOE */ |
fdaff1ce | 961 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
9a799d71 AK |
962 | |
963 | next_desc: | |
964 | rx_desc->wb.upper.status_error = 0; | |
965 | ||
966 | /* return some buffers to hardware, one at a time is too slow */ | |
967 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { | |
968 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); | |
969 | cleaned_count = 0; | |
970 | } | |
971 | ||
972 | /* use prefetched values */ | |
973 | rx_desc = next_rxd; | |
f8212f97 | 974 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
9a799d71 AK |
975 | |
976 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); | |
177db6ff MC |
977 | } |
978 | ||
9a799d71 AK |
979 | rx_ring->next_to_clean = i; |
980 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); | |
981 | ||
982 | if (cleaned_count) | |
983 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); | |
984 | ||
3d8fd385 YZ |
985 | #ifdef IXGBE_FCOE |
986 | /* include DDPed FCoE data */ | |
987 | if (ddp_bytes > 0) { | |
988 | unsigned int mss; | |
989 | ||
990 | mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) - | |
991 | sizeof(struct fc_frame_header) - | |
992 | sizeof(struct fcoe_crc_eof); | |
993 | if (mss > 512) | |
994 | mss &= ~511; | |
995 | total_rx_bytes += ddp_bytes; | |
996 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); | |
997 | } | |
998 | #endif /* IXGBE_FCOE */ | |
999 | ||
f494e8fa AV |
1000 | rx_ring->total_packets += total_rx_packets; |
1001 | rx_ring->total_bytes += total_rx_bytes; | |
2d86f139 AK |
1002 | netdev->stats.rx_bytes += total_rx_bytes; |
1003 | netdev->stats.rx_packets += total_rx_packets; | |
f494e8fa | 1004 | |
9a799d71 AK |
1005 | return cleaned; |
1006 | } | |
1007 | ||
021230d4 | 1008 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
9a799d71 AK |
1009 | /** |
1010 | * ixgbe_configure_msix - Configure MSI-X hardware | |
1011 | * @adapter: board private structure | |
1012 | * | |
1013 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X | |
1014 | * interrupts. | |
1015 | **/ | |
1016 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) | |
1017 | { | |
021230d4 AV |
1018 | struct ixgbe_q_vector *q_vector; |
1019 | int i, j, q_vectors, v_idx, r_idx; | |
1020 | u32 mask; | |
9a799d71 | 1021 | |
021230d4 | 1022 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
9a799d71 | 1023 | |
4df10466 JB |
1024 | /* |
1025 | * Populate the IVAR table and set the ITR values to the | |
021230d4 AV |
1026 | * corresponding register. |
1027 | */ | |
1028 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { | |
7a921c93 | 1029 | q_vector = adapter->q_vector[v_idx]; |
021230d4 AV |
1030 | /* XXX for_each_bit(...) */ |
1031 | r_idx = find_first_bit(q_vector->rxr_idx, | |
b4617240 | 1032 | adapter->num_rx_queues); |
021230d4 AV |
1033 | |
1034 | for (i = 0; i < q_vector->rxr_count; i++) { | |
1035 | j = adapter->rx_ring[r_idx].reg_idx; | |
e8e26350 | 1036 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
021230d4 | 1037 | r_idx = find_next_bit(q_vector->rxr_idx, |
b4617240 PW |
1038 | adapter->num_rx_queues, |
1039 | r_idx + 1); | |
021230d4 AV |
1040 | } |
1041 | r_idx = find_first_bit(q_vector->txr_idx, | |
b4617240 | 1042 | adapter->num_tx_queues); |
021230d4 AV |
1043 | |
1044 | for (i = 0; i < q_vector->txr_count; i++) { | |
1045 | j = adapter->tx_ring[r_idx].reg_idx; | |
e8e26350 | 1046 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
021230d4 | 1047 | r_idx = find_next_bit(q_vector->txr_idx, |
b4617240 PW |
1048 | adapter->num_tx_queues, |
1049 | r_idx + 1); | |
021230d4 AV |
1050 | } |
1051 | ||
021230d4 | 1052 | if (q_vector->txr_count && !q_vector->rxr_count) |
f7554a2b NS |
1053 | /* tx only */ |
1054 | q_vector->eitr = adapter->tx_eitr_param; | |
509ee935 | 1055 | else if (q_vector->rxr_count) |
f7554a2b NS |
1056 | /* rx or mixed */ |
1057 | q_vector->eitr = adapter->rx_eitr_param; | |
021230d4 | 1058 | |
fe49f04a | 1059 | ixgbe_write_eitr(q_vector); |
9a799d71 AK |
1060 | } |
1061 | ||
e8e26350 PW |
1062 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
1063 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, | |
1064 | v_idx); | |
1065 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) | |
1066 | ixgbe_set_ivar(adapter, -1, 1, v_idx); | |
021230d4 AV |
1067 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
1068 | ||
41fb9248 | 1069 | /* set up to autoclear timer, and the vectors */ |
021230d4 | 1070 | mask = IXGBE_EIMS_ENABLE_MASK; |
1cdd1ec8 GR |
1071 | if (adapter->num_vfs) |
1072 | mask &= ~(IXGBE_EIMS_OTHER | | |
1073 | IXGBE_EIMS_MAILBOX | | |
1074 | IXGBE_EIMS_LSC); | |
1075 | else | |
1076 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); | |
021230d4 | 1077 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
9a799d71 AK |
1078 | } |
1079 | ||
f494e8fa AV |
1080 | enum latency_range { |
1081 | lowest_latency = 0, | |
1082 | low_latency = 1, | |
1083 | bulk_latency = 2, | |
1084 | latency_invalid = 255 | |
1085 | }; | |
1086 | ||
1087 | /** | |
1088 | * ixgbe_update_itr - update the dynamic ITR value based on statistics | |
1089 | * @adapter: pointer to adapter | |
1090 | * @eitr: eitr setting (ints per sec) to give last timeslice | |
1091 | * @itr_setting: current throttle rate in ints/second | |
1092 | * @packets: the number of packets during this measurement interval | |
1093 | * @bytes: the number of bytes during this measurement interval | |
1094 | * | |
1095 | * Stores a new ITR value based on packets and byte | |
1096 | * counts during the last interrupt. The advantage of per interrupt | |
1097 | * computation is faster updates and more accurate ITR for the current | |
1098 | * traffic pattern. Constants in this function were computed | |
1099 | * based on theoretical maximum wire speed and thresholds were set based | |
1100 | * on testing data as well as attempting to minimize response time | |
1101 | * while increasing bulk throughput. | |
1102 | * this functionality is controlled by the InterruptThrottleRate module | |
1103 | * parameter (see ixgbe_param.c) | |
1104 | **/ | |
1105 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, | |
b4617240 PW |
1106 | u32 eitr, u8 itr_setting, |
1107 | int packets, int bytes) | |
f494e8fa AV |
1108 | { |
1109 | unsigned int retval = itr_setting; | |
1110 | u32 timepassed_us; | |
1111 | u64 bytes_perint; | |
1112 | ||
1113 | if (packets == 0) | |
1114 | goto update_itr_done; | |
1115 | ||
1116 | ||
1117 | /* simple throttlerate management | |
1118 | * 0-20MB/s lowest (100000 ints/s) | |
1119 | * 20-100MB/s low (20000 ints/s) | |
1120 | * 100-1249MB/s bulk (8000 ints/s) | |
1121 | */ | |
1122 | /* what was last interrupt timeslice? */ | |
1123 | timepassed_us = 1000000/eitr; | |
1124 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ | |
1125 | ||
1126 | switch (itr_setting) { | |
1127 | case lowest_latency: | |
1128 | if (bytes_perint > adapter->eitr_low) | |
1129 | retval = low_latency; | |
1130 | break; | |
1131 | case low_latency: | |
1132 | if (bytes_perint > adapter->eitr_high) | |
1133 | retval = bulk_latency; | |
1134 | else if (bytes_perint <= adapter->eitr_low) | |
1135 | retval = lowest_latency; | |
1136 | break; | |
1137 | case bulk_latency: | |
1138 | if (bytes_perint <= adapter->eitr_high) | |
1139 | retval = low_latency; | |
1140 | break; | |
1141 | } | |
1142 | ||
1143 | update_itr_done: | |
1144 | return retval; | |
1145 | } | |
1146 | ||
509ee935 JB |
1147 | /** |
1148 | * ixgbe_write_eitr - write EITR register in hardware specific way | |
fe49f04a | 1149 | * @q_vector: structure containing interrupt and ring information |
509ee935 JB |
1150 | * |
1151 | * This function is made to be called by ethtool and by the driver | |
1152 | * when it needs to update EITR registers at runtime. Hardware | |
1153 | * specific quirks/differences are taken care of here. | |
1154 | */ | |
fe49f04a | 1155 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
509ee935 | 1156 | { |
fe49f04a | 1157 | struct ixgbe_adapter *adapter = q_vector->adapter; |
509ee935 | 1158 | struct ixgbe_hw *hw = &adapter->hw; |
fe49f04a AD |
1159 | int v_idx = q_vector->v_idx; |
1160 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); | |
1161 | ||
509ee935 JB |
1162 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
1163 | /* must write high and low 16 bits to reset counter */ | |
1164 | itr_reg |= (itr_reg << 16); | |
1165 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { | |
1166 | /* | |
1167 | * set the WDIS bit to not clear the timer bits and cause an | |
1168 | * immediate assertion of the interrupt | |
1169 | */ | |
1170 | itr_reg |= IXGBE_EITR_CNT_WDIS; | |
1171 | } | |
1172 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); | |
1173 | } | |
1174 | ||
f494e8fa AV |
1175 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
1176 | { | |
1177 | struct ixgbe_adapter *adapter = q_vector->adapter; | |
f494e8fa AV |
1178 | u32 new_itr; |
1179 | u8 current_itr, ret_itr; | |
fe49f04a | 1180 | int i, r_idx; |
f494e8fa AV |
1181 | struct ixgbe_ring *rx_ring, *tx_ring; |
1182 | ||
1183 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); | |
1184 | for (i = 0; i < q_vector->txr_count; i++) { | |
1185 | tx_ring = &(adapter->tx_ring[r_idx]); | |
1186 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, | |
b4617240 PW |
1187 | q_vector->tx_itr, |
1188 | tx_ring->total_packets, | |
1189 | tx_ring->total_bytes); | |
f494e8fa AV |
1190 | /* if the result for this queue would decrease interrupt |
1191 | * rate for this vector then use that result */ | |
30efa5a3 | 1192 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
b4617240 | 1193 | q_vector->tx_itr - 1 : ret_itr); |
f494e8fa | 1194 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
b4617240 | 1195 | r_idx + 1); |
f494e8fa AV |
1196 | } |
1197 | ||
1198 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); | |
1199 | for (i = 0; i < q_vector->rxr_count; i++) { | |
1200 | rx_ring = &(adapter->rx_ring[r_idx]); | |
1201 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, | |
b4617240 PW |
1202 | q_vector->rx_itr, |
1203 | rx_ring->total_packets, | |
1204 | rx_ring->total_bytes); | |
f494e8fa AV |
1205 | /* if the result for this queue would decrease interrupt |
1206 | * rate for this vector then use that result */ | |
30efa5a3 | 1207 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
b4617240 | 1208 | q_vector->rx_itr - 1 : ret_itr); |
f494e8fa | 1209 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
b4617240 | 1210 | r_idx + 1); |
f494e8fa AV |
1211 | } |
1212 | ||
30efa5a3 | 1213 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
f494e8fa AV |
1214 | |
1215 | switch (current_itr) { | |
1216 | /* counts and packets in update_itr are dependent on these numbers */ | |
1217 | case lowest_latency: | |
1218 | new_itr = 100000; | |
1219 | break; | |
1220 | case low_latency: | |
1221 | new_itr = 20000; /* aka hwitr = ~200 */ | |
1222 | break; | |
1223 | case bulk_latency: | |
1224 | default: | |
1225 | new_itr = 8000; | |
1226 | break; | |
1227 | } | |
1228 | ||
1229 | if (new_itr != q_vector->eitr) { | |
fe49f04a AD |
1230 | /* do an exponential smoothing */ |
1231 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); | |
509ee935 JB |
1232 | |
1233 | /* save the algorithm value here, not the smoothed one */ | |
1234 | q_vector->eitr = new_itr; | |
fe49f04a AD |
1235 | |
1236 | ixgbe_write_eitr(q_vector); | |
f494e8fa AV |
1237 | } |
1238 | ||
1239 | return; | |
1240 | } | |
1241 | ||
0befdb3e JB |
1242 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
1243 | { | |
1244 | struct ixgbe_hw *hw = &adapter->hw; | |
1245 | ||
1246 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && | |
1247 | (eicr & IXGBE_EICR_GPI_SDP1)) { | |
1248 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); | |
1249 | /* write to clear the interrupt */ | |
1250 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); | |
1251 | } | |
1252 | } | |
cf8280ee | 1253 | |
e8e26350 PW |
1254 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
1255 | { | |
1256 | struct ixgbe_hw *hw = &adapter->hw; | |
1257 | ||
1258 | if (eicr & IXGBE_EICR_GPI_SDP1) { | |
1259 | /* Clear the interrupt */ | |
1260 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); | |
1261 | schedule_work(&adapter->multispeed_fiber_task); | |
1262 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { | |
1263 | /* Clear the interrupt */ | |
1264 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); | |
1265 | schedule_work(&adapter->sfp_config_module_task); | |
1266 | } else { | |
1267 | /* Interrupt isn't for us... */ | |
1268 | return; | |
1269 | } | |
1270 | } | |
1271 | ||
cf8280ee JB |
1272 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
1273 | { | |
1274 | struct ixgbe_hw *hw = &adapter->hw; | |
1275 | ||
1276 | adapter->lsc_int++; | |
1277 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; | |
1278 | adapter->link_check_timeout = jiffies; | |
1279 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { | |
1280 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); | |
8a0717f3 | 1281 | IXGBE_WRITE_FLUSH(hw); |
cf8280ee JB |
1282 | schedule_work(&adapter->watchdog_task); |
1283 | } | |
1284 | } | |
1285 | ||
9a799d71 AK |
1286 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
1287 | { | |
1288 | struct net_device *netdev = data; | |
1289 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
1290 | struct ixgbe_hw *hw = &adapter->hw; | |
54037505 DS |
1291 | u32 eicr; |
1292 | ||
1293 | /* | |
1294 | * Workaround for Silicon errata. Use clear-by-write instead | |
1295 | * of clear-by-read. Reading with EICS will return the | |
1296 | * interrupt causes without clearing, which later be done | |
1297 | * with the write to EICR. | |
1298 | */ | |
1299 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); | |
1300 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); | |
9a799d71 | 1301 | |
cf8280ee JB |
1302 | if (eicr & IXGBE_EICR_LSC) |
1303 | ixgbe_check_lsc(adapter); | |
d4f80882 | 1304 | |
1cdd1ec8 GR |
1305 | if (eicr & IXGBE_EICR_MAILBOX) |
1306 | ixgbe_msg_task(adapter); | |
1307 | ||
e8e26350 PW |
1308 | if (hw->mac.type == ixgbe_mac_82598EB) |
1309 | ixgbe_check_fan_failure(adapter, eicr); | |
0befdb3e | 1310 | |
c4cf55e5 | 1311 | if (hw->mac.type == ixgbe_mac_82599EB) { |
e8e26350 | 1312 | ixgbe_check_sfp_event(adapter, eicr); |
c4cf55e5 PWJ |
1313 | |
1314 | /* Handle Flow Director Full threshold interrupt */ | |
1315 | if (eicr & IXGBE_EICR_FLOW_DIR) { | |
1316 | int i; | |
1317 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); | |
1318 | /* Disable transmits before FDIR Re-initialization */ | |
1319 | netif_tx_stop_all_queues(netdev); | |
1320 | for (i = 0; i < adapter->num_tx_queues; i++) { | |
1321 | struct ixgbe_ring *tx_ring = | |
1322 | &adapter->tx_ring[i]; | |
1323 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, | |
1324 | &tx_ring->reinit_state)) | |
1325 | schedule_work(&adapter->fdir_reinit_task); | |
1326 | } | |
1327 | } | |
1328 | } | |
d4f80882 AV |
1329 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
1330 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); | |
9a799d71 AK |
1331 | |
1332 | return IRQ_HANDLED; | |
1333 | } | |
1334 | ||
fe49f04a AD |
1335 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
1336 | u64 qmask) | |
1337 | { | |
1338 | u32 mask; | |
1339 | ||
1340 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { | |
1341 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); | |
1342 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); | |
1343 | } else { | |
1344 | mask = (qmask & 0xFFFFFFFF); | |
1345 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); | |
1346 | mask = (qmask >> 32); | |
1347 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); | |
1348 | } | |
1349 | /* skip the flush */ | |
1350 | } | |
1351 | ||
1352 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, | |
1353 | u64 qmask) | |
1354 | { | |
1355 | u32 mask; | |
1356 | ||
1357 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { | |
1358 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); | |
1359 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); | |
1360 | } else { | |
1361 | mask = (qmask & 0xFFFFFFFF); | |
1362 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); | |
1363 | mask = (qmask >> 32); | |
1364 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); | |
1365 | } | |
1366 | /* skip the flush */ | |
1367 | } | |
1368 | ||
9a799d71 AK |
1369 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
1370 | { | |
021230d4 AV |
1371 | struct ixgbe_q_vector *q_vector = data; |
1372 | struct ixgbe_adapter *adapter = q_vector->adapter; | |
3a581073 | 1373 | struct ixgbe_ring *tx_ring; |
021230d4 AV |
1374 | int i, r_idx; |
1375 | ||
1376 | if (!q_vector->txr_count) | |
1377 | return IRQ_HANDLED; | |
1378 | ||
1379 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); | |
1380 | for (i = 0; i < q_vector->txr_count; i++) { | |
3a581073 | 1381 | tx_ring = &(adapter->tx_ring[r_idx]); |
3a581073 JB |
1382 | tx_ring->total_bytes = 0; |
1383 | tx_ring->total_packets = 0; | |
021230d4 | 1384 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
b4617240 | 1385 | r_idx + 1); |
021230d4 | 1386 | } |
9a799d71 | 1387 | |
9b471446 | 1388 | /* EIAM disabled interrupts (on this vector) for us */ |
91281fd3 AD |
1389 | napi_schedule(&q_vector->napi); |
1390 | ||
9a799d71 AK |
1391 | return IRQ_HANDLED; |
1392 | } | |
1393 | ||
021230d4 AV |
1394 | /** |
1395 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) | |
1396 | * @irq: unused | |
1397 | * @data: pointer to our q_vector struct for this interrupt vector | |
1398 | **/ | |
9a799d71 AK |
1399 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
1400 | { | |
021230d4 AV |
1401 | struct ixgbe_q_vector *q_vector = data; |
1402 | struct ixgbe_adapter *adapter = q_vector->adapter; | |
3a581073 | 1403 | struct ixgbe_ring *rx_ring; |
021230d4 | 1404 | int r_idx; |
30efa5a3 | 1405 | int i; |
021230d4 AV |
1406 | |
1407 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); | |
30efa5a3 JB |
1408 | for (i = 0; i < q_vector->rxr_count; i++) { |
1409 | rx_ring = &(adapter->rx_ring[r_idx]); | |
1410 | rx_ring->total_bytes = 0; | |
1411 | rx_ring->total_packets = 0; | |
1412 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, | |
1413 | r_idx + 1); | |
1414 | } | |
1415 | ||
021230d4 AV |
1416 | if (!q_vector->rxr_count) |
1417 | return IRQ_HANDLED; | |
1418 | ||
021230d4 | 1419 | /* disable interrupts on this vector only */ |
9b471446 | 1420 | /* EIAM disabled interrupts (on this vector) for us */ |
288379f0 | 1421 | napi_schedule(&q_vector->napi); |
021230d4 AV |
1422 | |
1423 | return IRQ_HANDLED; | |
1424 | } | |
1425 | ||
1426 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) | |
1427 | { | |
91281fd3 AD |
1428 | struct ixgbe_q_vector *q_vector = data; |
1429 | struct ixgbe_adapter *adapter = q_vector->adapter; | |
1430 | struct ixgbe_ring *ring; | |
1431 | int r_idx; | |
1432 | int i; | |
1433 | ||
1434 | if (!q_vector->txr_count && !q_vector->rxr_count) | |
1435 | return IRQ_HANDLED; | |
1436 | ||
1437 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); | |
1438 | for (i = 0; i < q_vector->txr_count; i++) { | |
1439 | ring = &(adapter->tx_ring[r_idx]); | |
1440 | ring->total_bytes = 0; | |
1441 | ring->total_packets = 0; | |
1442 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, | |
1443 | r_idx + 1); | |
1444 | } | |
1445 | ||
1446 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); | |
1447 | for (i = 0; i < q_vector->rxr_count; i++) { | |
1448 | ring = &(adapter->rx_ring[r_idx]); | |
1449 | ring->total_bytes = 0; | |
1450 | ring->total_packets = 0; | |
1451 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, | |
1452 | r_idx + 1); | |
1453 | } | |
1454 | ||
9b471446 | 1455 | /* EIAM disabled interrupts (on this vector) for us */ |
91281fd3 | 1456 | napi_schedule(&q_vector->napi); |
9a799d71 | 1457 | |
9a799d71 AK |
1458 | return IRQ_HANDLED; |
1459 | } | |
1460 | ||
021230d4 AV |
1461 | /** |
1462 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine | |
1463 | * @napi: napi struct with our devices info in it | |
1464 | * @budget: amount of work driver is allowed to do this pass, in packets | |
1465 | * | |
f0848276 JB |
1466 | * This function is optimized for cleaning one queue only on a single |
1467 | * q_vector!!! | |
021230d4 | 1468 | **/ |
9a799d71 AK |
1469 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
1470 | { | |
021230d4 | 1471 | struct ixgbe_q_vector *q_vector = |
b4617240 | 1472 | container_of(napi, struct ixgbe_q_vector, napi); |
021230d4 | 1473 | struct ixgbe_adapter *adapter = q_vector->adapter; |
f0848276 | 1474 | struct ixgbe_ring *rx_ring = NULL; |
9a799d71 | 1475 | int work_done = 0; |
021230d4 | 1476 | long r_idx; |
9a799d71 | 1477 | |
021230d4 | 1478 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
3a581073 | 1479 | rx_ring = &(adapter->rx_ring[r_idx]); |
5dd2d332 | 1480 | #ifdef CONFIG_IXGBE_DCA |
bd0362dd | 1481 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
3a581073 | 1482 | ixgbe_update_rx_dca(adapter, rx_ring); |
bd0362dd | 1483 | #endif |
9a799d71 | 1484 | |
78b6f4ce | 1485 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
9a799d71 | 1486 | |
021230d4 AV |
1487 | /* If all Rx work done, exit the polling mode */ |
1488 | if (work_done < budget) { | |
288379f0 | 1489 | napi_complete(napi); |
f7554a2b | 1490 | if (adapter->rx_itr_setting & 1) |
f494e8fa | 1491 | ixgbe_set_itr_msix(q_vector); |
9a799d71 | 1492 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
fe49f04a AD |
1493 | ixgbe_irq_enable_queues(adapter, |
1494 | ((u64)1 << q_vector->v_idx)); | |
9a799d71 AK |
1495 | } |
1496 | ||
1497 | return work_done; | |
1498 | } | |
1499 | ||
f0848276 | 1500 | /** |
91281fd3 | 1501 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
f0848276 JB |
1502 | * @napi: napi struct with our devices info in it |
1503 | * @budget: amount of work driver is allowed to do this pass, in packets | |
1504 | * | |
1505 | * This function will clean more than one rx queue associated with a | |
1506 | * q_vector. | |
1507 | **/ | |
91281fd3 | 1508 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
f0848276 JB |
1509 | { |
1510 | struct ixgbe_q_vector *q_vector = | |
1511 | container_of(napi, struct ixgbe_q_vector, napi); | |
1512 | struct ixgbe_adapter *adapter = q_vector->adapter; | |
91281fd3 | 1513 | struct ixgbe_ring *ring = NULL; |
f0848276 JB |
1514 | int work_done = 0, i; |
1515 | long r_idx; | |
91281fd3 AD |
1516 | bool tx_clean_complete = true; |
1517 | ||
1518 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); | |
1519 | for (i = 0; i < q_vector->txr_count; i++) { | |
1520 | ring = &(adapter->tx_ring[r_idx]); | |
1521 | #ifdef CONFIG_IXGBE_DCA | |
1522 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | |
1523 | ixgbe_update_tx_dca(adapter, ring); | |
1524 | #endif | |
1525 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); | |
1526 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, | |
1527 | r_idx + 1); | |
1528 | } | |
f0848276 JB |
1529 | |
1530 | /* attempt to distribute budget to each queue fairly, but don't allow | |
1531 | * the budget to go below 1 because we'll exit polling */ | |
1532 | budget /= (q_vector->rxr_count ?: 1); | |
1533 | budget = max(budget, 1); | |
1534 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); | |
1535 | for (i = 0; i < q_vector->rxr_count; i++) { | |
91281fd3 | 1536 | ring = &(adapter->rx_ring[r_idx]); |
5dd2d332 | 1537 | #ifdef CONFIG_IXGBE_DCA |
f0848276 | 1538 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
91281fd3 | 1539 | ixgbe_update_rx_dca(adapter, ring); |
f0848276 | 1540 | #endif |
91281fd3 | 1541 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
f0848276 JB |
1542 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
1543 | r_idx + 1); | |
1544 | } | |
1545 | ||
1546 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); | |
91281fd3 | 1547 | ring = &(adapter->rx_ring[r_idx]); |
f0848276 | 1548 | /* If all Rx work done, exit the polling mode */ |
7f821875 | 1549 | if (work_done < budget) { |
288379f0 | 1550 | napi_complete(napi); |
f7554a2b | 1551 | if (adapter->rx_itr_setting & 1) |
f0848276 JB |
1552 | ixgbe_set_itr_msix(q_vector); |
1553 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | |
fe49f04a AD |
1554 | ixgbe_irq_enable_queues(adapter, |
1555 | ((u64)1 << q_vector->v_idx)); | |
f0848276 JB |
1556 | return 0; |
1557 | } | |
1558 | ||
1559 | return work_done; | |
1560 | } | |
91281fd3 AD |
1561 | |
1562 | /** | |
1563 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine | |
1564 | * @napi: napi struct with our devices info in it | |
1565 | * @budget: amount of work driver is allowed to do this pass, in packets | |
1566 | * | |
1567 | * This function is optimized for cleaning one queue only on a single | |
1568 | * q_vector!!! | |
1569 | **/ | |
1570 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) | |
1571 | { | |
1572 | struct ixgbe_q_vector *q_vector = | |
1573 | container_of(napi, struct ixgbe_q_vector, napi); | |
1574 | struct ixgbe_adapter *adapter = q_vector->adapter; | |
1575 | struct ixgbe_ring *tx_ring = NULL; | |
1576 | int work_done = 0; | |
1577 | long r_idx; | |
1578 | ||
1579 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); | |
1580 | tx_ring = &(adapter->tx_ring[r_idx]); | |
1581 | #ifdef CONFIG_IXGBE_DCA | |
1582 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) | |
1583 | ixgbe_update_tx_dca(adapter, tx_ring); | |
1584 | #endif | |
1585 | ||
1586 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) | |
1587 | work_done = budget; | |
1588 | ||
f7554a2b | 1589 | /* If all Tx work done, exit the polling mode */ |
91281fd3 AD |
1590 | if (work_done < budget) { |
1591 | napi_complete(napi); | |
f7554a2b | 1592 | if (adapter->tx_itr_setting & 1) |
91281fd3 AD |
1593 | ixgbe_set_itr_msix(q_vector); |
1594 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | |
1595 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); | |
1596 | } | |
1597 | ||
1598 | return work_done; | |
1599 | } | |
1600 | ||
021230d4 | 1601 | static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx, |
b4617240 | 1602 | int r_idx) |
021230d4 | 1603 | { |
7a921c93 AD |
1604 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
1605 | ||
1606 | set_bit(r_idx, q_vector->rxr_idx); | |
1607 | q_vector->rxr_count++; | |
021230d4 AV |
1608 | } |
1609 | ||
1610 | static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx, | |
7a921c93 | 1611 | int t_idx) |
021230d4 | 1612 | { |
7a921c93 AD |
1613 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
1614 | ||
1615 | set_bit(t_idx, q_vector->txr_idx); | |
1616 | q_vector->txr_count++; | |
021230d4 AV |
1617 | } |
1618 | ||
9a799d71 | 1619 | /** |
021230d4 AV |
1620 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
1621 | * @adapter: board private structure to initialize | |
1622 | * @vectors: allotted vector count for descriptor rings | |
9a799d71 | 1623 | * |
021230d4 AV |
1624 | * This function maps descriptor rings to the queue-specific vectors |
1625 | * we were allotted through the MSI-X enabling code. Ideally, we'd have | |
1626 | * one vector per ring/queue, but on a constrained vector budget, we | |
1627 | * group the rings as "efficiently" as possible. You would add new | |
1628 | * mapping configurations in here. | |
9a799d71 | 1629 | **/ |
021230d4 | 1630 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
b4617240 | 1631 | int vectors) |
021230d4 AV |
1632 | { |
1633 | int v_start = 0; | |
1634 | int rxr_idx = 0, txr_idx = 0; | |
1635 | int rxr_remaining = adapter->num_rx_queues; | |
1636 | int txr_remaining = adapter->num_tx_queues; | |
1637 | int i, j; | |
1638 | int rqpv, tqpv; | |
1639 | int err = 0; | |
1640 | ||
1641 | /* No mapping required if MSI-X is disabled. */ | |
1642 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) | |
1643 | goto out; | |
9a799d71 | 1644 | |
021230d4 AV |
1645 | /* |
1646 | * The ideal configuration... | |
1647 | * We have enough vectors to map one per queue. | |
1648 | */ | |
1649 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { | |
1650 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) | |
1651 | map_vector_to_rxq(adapter, v_start, rxr_idx); | |
9a799d71 | 1652 | |
021230d4 AV |
1653 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
1654 | map_vector_to_txq(adapter, v_start, txr_idx); | |
9a799d71 | 1655 | |
9a799d71 | 1656 | goto out; |
021230d4 | 1657 | } |
9a799d71 | 1658 | |
021230d4 AV |
1659 | /* |
1660 | * If we don't have enough vectors for a 1-to-1 | |
1661 | * mapping, we'll have to group them so there are | |
1662 | * multiple queues per vector. | |
1663 | */ | |
1664 | /* Re-adjusting *qpv takes care of the remainder. */ | |
1665 | for (i = v_start; i < vectors; i++) { | |
1666 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); | |
1667 | for (j = 0; j < rqpv; j++) { | |
1668 | map_vector_to_rxq(adapter, i, rxr_idx); | |
1669 | rxr_idx++; | |
1670 | rxr_remaining--; | |
1671 | } | |
1672 | } | |
1673 | for (i = v_start; i < vectors; i++) { | |
1674 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); | |
1675 | for (j = 0; j < tqpv; j++) { | |
1676 | map_vector_to_txq(adapter, i, txr_idx); | |
1677 | txr_idx++; | |
1678 | txr_remaining--; | |
9a799d71 | 1679 | } |
9a799d71 AK |
1680 | } |
1681 | ||
021230d4 AV |
1682 | out: |
1683 | return err; | |
1684 | } | |
1685 | ||
1686 | /** | |
1687 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts | |
1688 | * @adapter: board private structure | |
1689 | * | |
1690 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests | |
1691 | * interrupts from the kernel. | |
1692 | **/ | |
1693 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) | |
1694 | { | |
1695 | struct net_device *netdev = adapter->netdev; | |
1696 | irqreturn_t (*handler)(int, void *); | |
1697 | int i, vector, q_vectors, err; | |
cb13fc20 | 1698 | int ri=0, ti=0; |
021230d4 AV |
1699 | |
1700 | /* Decrement for Other and TCP Timer vectors */ | |
1701 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | |
1702 | ||
1703 | /* Map the Tx/Rx rings to the vectors we were allotted. */ | |
1704 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); | |
1705 | if (err) | |
1706 | goto out; | |
1707 | ||
1708 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ | |
b4617240 PW |
1709 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
1710 | &ixgbe_msix_clean_many) | |
021230d4 | 1711 | for (vector = 0; vector < q_vectors; vector++) { |
7a921c93 | 1712 | handler = SET_HANDLER(adapter->q_vector[vector]); |
cb13fc20 RO |
1713 | |
1714 | if(handler == &ixgbe_msix_clean_rx) { | |
1715 | sprintf(adapter->name[vector], "%s-%s-%d", | |
1716 | netdev->name, "rx", ri++); | |
1717 | } | |
1718 | else if(handler == &ixgbe_msix_clean_tx) { | |
1719 | sprintf(adapter->name[vector], "%s-%s-%d", | |
1720 | netdev->name, "tx", ti++); | |
1721 | } | |
1722 | else | |
1723 | sprintf(adapter->name[vector], "%s-%s-%d", | |
1724 | netdev->name, "TxRx", vector); | |
1725 | ||
021230d4 | 1726 | err = request_irq(adapter->msix_entries[vector].vector, |
b4617240 | 1727 | handler, 0, adapter->name[vector], |
7a921c93 | 1728 | adapter->q_vector[vector]); |
9a799d71 AK |
1729 | if (err) { |
1730 | DPRINTK(PROBE, ERR, | |
b4617240 PW |
1731 | "request_irq failed for MSIX interrupt " |
1732 | "Error: %d\n", err); | |
021230d4 | 1733 | goto free_queue_irqs; |
9a799d71 | 1734 | } |
9a799d71 AK |
1735 | } |
1736 | ||
021230d4 AV |
1737 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
1738 | err = request_irq(adapter->msix_entries[vector].vector, | |
a0607fd3 | 1739 | ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
9a799d71 AK |
1740 | if (err) { |
1741 | DPRINTK(PROBE, ERR, | |
1742 | "request_irq for msix_lsc failed: %d\n", err); | |
021230d4 | 1743 | goto free_queue_irqs; |
9a799d71 AK |
1744 | } |
1745 | ||
9a799d71 AK |
1746 | return 0; |
1747 | ||
021230d4 AV |
1748 | free_queue_irqs: |
1749 | for (i = vector - 1; i >= 0; i--) | |
1750 | free_irq(adapter->msix_entries[--vector].vector, | |
7a921c93 | 1751 | adapter->q_vector[i]); |
021230d4 AV |
1752 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
1753 | pci_disable_msix(adapter->pdev); | |
9a799d71 AK |
1754 | kfree(adapter->msix_entries); |
1755 | adapter->msix_entries = NULL; | |
021230d4 | 1756 | out: |
9a799d71 AK |
1757 | return err; |
1758 | } | |
1759 | ||
f494e8fa AV |
1760 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
1761 | { | |
7a921c93 | 1762 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
f494e8fa AV |
1763 | u8 current_itr; |
1764 | u32 new_itr = q_vector->eitr; | |
1765 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; | |
1766 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; | |
1767 | ||
30efa5a3 | 1768 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
b4617240 PW |
1769 | q_vector->tx_itr, |
1770 | tx_ring->total_packets, | |
1771 | tx_ring->total_bytes); | |
30efa5a3 | 1772 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
b4617240 PW |
1773 | q_vector->rx_itr, |
1774 | rx_ring->total_packets, | |
1775 | rx_ring->total_bytes); | |
f494e8fa | 1776 | |
30efa5a3 | 1777 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
f494e8fa AV |
1778 | |
1779 | switch (current_itr) { | |
1780 | /* counts and packets in update_itr are dependent on these numbers */ | |
1781 | case lowest_latency: | |
1782 | new_itr = 100000; | |
1783 | break; | |
1784 | case low_latency: | |
1785 | new_itr = 20000; /* aka hwitr = ~200 */ | |
1786 | break; | |
1787 | case bulk_latency: | |
1788 | new_itr = 8000; | |
1789 | break; | |
1790 | default: | |
1791 | break; | |
1792 | } | |
1793 | ||
1794 | if (new_itr != q_vector->eitr) { | |
fe49f04a AD |
1795 | /* do an exponential smoothing */ |
1796 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); | |
509ee935 JB |
1797 | |
1798 | /* save the algorithm value here, not the smoothed one */ | |
1799 | q_vector->eitr = new_itr; | |
fe49f04a AD |
1800 | |
1801 | ixgbe_write_eitr(q_vector); | |
f494e8fa AV |
1802 | } |
1803 | ||
1804 | return; | |
1805 | } | |
1806 | ||
79aefa45 AD |
1807 | /** |
1808 | * ixgbe_irq_enable - Enable default interrupt generation settings | |
1809 | * @adapter: board private structure | |
1810 | **/ | |
1811 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) | |
1812 | { | |
1813 | u32 mask; | |
835462fc NS |
1814 | |
1815 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); | |
6ab33d51 DM |
1816 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
1817 | mask |= IXGBE_EIMS_GPI_SDP1; | |
e8e26350 | 1818 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
2a41ff81 | 1819 | mask |= IXGBE_EIMS_ECC; |
e8e26350 PW |
1820 | mask |= IXGBE_EIMS_GPI_SDP1; |
1821 | mask |= IXGBE_EIMS_GPI_SDP2; | |
1cdd1ec8 GR |
1822 | if (adapter->num_vfs) |
1823 | mask |= IXGBE_EIMS_MAILBOX; | |
e8e26350 | 1824 | } |
c4cf55e5 PWJ |
1825 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
1826 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) | |
1827 | mask |= IXGBE_EIMS_FLOW_DIR; | |
e8e26350 | 1828 | |
79aefa45 | 1829 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
835462fc | 1830 | ixgbe_irq_enable_queues(adapter, ~0); |
79aefa45 | 1831 | IXGBE_WRITE_FLUSH(&adapter->hw); |
1cdd1ec8 GR |
1832 | |
1833 | if (adapter->num_vfs > 32) { | |
1834 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; | |
1835 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); | |
1836 | } | |
79aefa45 | 1837 | } |
021230d4 | 1838 | |
9a799d71 | 1839 | /** |
021230d4 | 1840 | * ixgbe_intr - legacy mode Interrupt Handler |
9a799d71 AK |
1841 | * @irq: interrupt number |
1842 | * @data: pointer to a network interface device structure | |
9a799d71 AK |
1843 | **/ |
1844 | static irqreturn_t ixgbe_intr(int irq, void *data) | |
1845 | { | |
1846 | struct net_device *netdev = data; | |
1847 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
1848 | struct ixgbe_hw *hw = &adapter->hw; | |
7a921c93 | 1849 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
9a799d71 AK |
1850 | u32 eicr; |
1851 | ||
54037505 DS |
1852 | /* |
1853 | * Workaround for silicon errata. Mask the interrupts | |
1854 | * before the read of EICR. | |
1855 | */ | |
1856 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); | |
1857 | ||
021230d4 AV |
1858 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
1859 | * therefore no explict interrupt disable is necessary */ | |
1860 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); | |
f47cf66e JB |
1861 | if (!eicr) { |
1862 | /* shared interrupt alert! | |
1863 | * make sure interrupts are enabled because the read will | |
1864 | * have disabled interrupts due to EIAM */ | |
1865 | ixgbe_irq_enable(adapter); | |
9a799d71 | 1866 | return IRQ_NONE; /* Not our interrupt */ |
f47cf66e | 1867 | } |
9a799d71 | 1868 | |
cf8280ee JB |
1869 | if (eicr & IXGBE_EICR_LSC) |
1870 | ixgbe_check_lsc(adapter); | |
021230d4 | 1871 | |
e8e26350 PW |
1872 | if (hw->mac.type == ixgbe_mac_82599EB) |
1873 | ixgbe_check_sfp_event(adapter, eicr); | |
1874 | ||
0befdb3e JB |
1875 | ixgbe_check_fan_failure(adapter, eicr); |
1876 | ||
7a921c93 | 1877 | if (napi_schedule_prep(&(q_vector->napi))) { |
f494e8fa AV |
1878 | adapter->tx_ring[0].total_packets = 0; |
1879 | adapter->tx_ring[0].total_bytes = 0; | |
1880 | adapter->rx_ring[0].total_packets = 0; | |
1881 | adapter->rx_ring[0].total_bytes = 0; | |
021230d4 | 1882 | /* would disable interrupts here but EIAM disabled it */ |
7a921c93 | 1883 | __napi_schedule(&(q_vector->napi)); |
9a799d71 AK |
1884 | } |
1885 | ||
1886 | return IRQ_HANDLED; | |
1887 | } | |
1888 | ||
021230d4 AV |
1889 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
1890 | { | |
1891 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | |
1892 | ||
1893 | for (i = 0; i < q_vectors; i++) { | |
7a921c93 | 1894 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
021230d4 AV |
1895 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
1896 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); | |
1897 | q_vector->rxr_count = 0; | |
1898 | q_vector->txr_count = 0; | |
1899 | } | |
1900 | } | |
1901 | ||
9a799d71 AK |
1902 | /** |
1903 | * ixgbe_request_irq - initialize interrupts | |
1904 | * @adapter: board private structure | |
1905 | * | |
1906 | * Attempts to configure interrupts using the best available | |
1907 | * capabilities of the hardware and kernel. | |
1908 | **/ | |
021230d4 | 1909 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
9a799d71 AK |
1910 | { |
1911 | struct net_device *netdev = adapter->netdev; | |
021230d4 | 1912 | int err; |
9a799d71 | 1913 | |
021230d4 AV |
1914 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
1915 | err = ixgbe_request_msix_irqs(adapter); | |
1916 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { | |
a0607fd3 | 1917 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
b4617240 | 1918 | netdev->name, netdev); |
021230d4 | 1919 | } else { |
a0607fd3 | 1920 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
b4617240 | 1921 | netdev->name, netdev); |
9a799d71 AK |
1922 | } |
1923 | ||
9a799d71 AK |
1924 | if (err) |
1925 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); | |
1926 | ||
9a799d71 AK |
1927 | return err; |
1928 | } | |
1929 | ||
1930 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) | |
1931 | { | |
1932 | struct net_device *netdev = adapter->netdev; | |
1933 | ||
1934 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | |
021230d4 | 1935 | int i, q_vectors; |
9a799d71 | 1936 | |
021230d4 AV |
1937 | q_vectors = adapter->num_msix_vectors; |
1938 | ||
1939 | i = q_vectors - 1; | |
9a799d71 | 1940 | free_irq(adapter->msix_entries[i].vector, netdev); |
9a799d71 | 1941 | |
021230d4 AV |
1942 | i--; |
1943 | for (; i >= 0; i--) { | |
1944 | free_irq(adapter->msix_entries[i].vector, | |
7a921c93 | 1945 | adapter->q_vector[i]); |
021230d4 AV |
1946 | } |
1947 | ||
1948 | ixgbe_reset_q_vectors(adapter); | |
1949 | } else { | |
1950 | free_irq(adapter->pdev->irq, netdev); | |
9a799d71 AK |
1951 | } |
1952 | } | |
1953 | ||
22d5a71b JB |
1954 | /** |
1955 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC | |
1956 | * @adapter: board private structure | |
1957 | **/ | |
1958 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) | |
1959 | { | |
835462fc NS |
1960 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
1961 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); | |
1962 | } else { | |
1963 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); | |
1964 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); | |
22d5a71b | 1965 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
1cdd1ec8 GR |
1966 | if (adapter->num_vfs > 32) |
1967 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); | |
22d5a71b JB |
1968 | } |
1969 | IXGBE_WRITE_FLUSH(&adapter->hw); | |
1970 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | |
1971 | int i; | |
1972 | for (i = 0; i < adapter->num_msix_vectors; i++) | |
1973 | synchronize_irq(adapter->msix_entries[i].vector); | |
1974 | } else { | |
1975 | synchronize_irq(adapter->pdev->irq); | |
1976 | } | |
1977 | } | |
1978 | ||
9a799d71 AK |
1979 | /** |
1980 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts | |
1981 | * | |
1982 | **/ | |
1983 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) | |
1984 | { | |
9a799d71 AK |
1985 | struct ixgbe_hw *hw = &adapter->hw; |
1986 | ||
021230d4 | 1987 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
f7554a2b | 1988 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
9a799d71 | 1989 | |
e8e26350 PW |
1990 | ixgbe_set_ivar(adapter, 0, 0, 0); |
1991 | ixgbe_set_ivar(adapter, 1, 0, 0); | |
021230d4 AV |
1992 | |
1993 | map_vector_to_rxq(adapter, 0, 0); | |
1994 | map_vector_to_txq(adapter, 0, 0); | |
1995 | ||
1996 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); | |
9a799d71 AK |
1997 | } |
1998 | ||
1999 | /** | |
3a581073 | 2000 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
9a799d71 AK |
2001 | * @adapter: board private structure |
2002 | * | |
2003 | * Configure the Tx unit of the MAC after a reset. | |
2004 | **/ | |
2005 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) | |
2006 | { | |
12207e49 | 2007 | u64 tdba; |
9a799d71 | 2008 | struct ixgbe_hw *hw = &adapter->hw; |
021230d4 | 2009 | u32 i, j, tdlen, txctrl; |
9a799d71 AK |
2010 | |
2011 | /* Setup the HW Tx Head and Tail descriptor pointers */ | |
2012 | for (i = 0; i < adapter->num_tx_queues; i++) { | |
e01c31a5 JB |
2013 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
2014 | j = ring->reg_idx; | |
2015 | tdba = ring->dma; | |
2016 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); | |
021230d4 | 2017 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
284901a9 | 2018 | (tdba & DMA_BIT_MASK(32))); |
021230d4 AV |
2019 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
2020 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); | |
2021 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); | |
2022 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); | |
2023 | adapter->tx_ring[i].head = IXGBE_TDH(j); | |
2024 | adapter->tx_ring[i].tail = IXGBE_TDT(j); | |
84f62d4b PWJ |
2025 | /* |
2026 | * Disable Tx Head Writeback RO bit, since this hoses | |
021230d4 AV |
2027 | * bookkeeping if things aren't delivered in order. |
2028 | */ | |
84f62d4b PWJ |
2029 | switch (hw->mac.type) { |
2030 | case ixgbe_mac_82598EB: | |
2031 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); | |
2032 | break; | |
2033 | case ixgbe_mac_82599EB: | |
2034 | default: | |
2035 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j)); | |
2036 | break; | |
2037 | } | |
021230d4 | 2038 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
84f62d4b PWJ |
2039 | switch (hw->mac.type) { |
2040 | case ixgbe_mac_82598EB: | |
2041 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); | |
2042 | break; | |
2043 | case ixgbe_mac_82599EB: | |
2044 | default: | |
2045 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl); | |
2046 | break; | |
2047 | } | |
9a799d71 | 2048 | } |
ee5f784a | 2049 | |
e8e26350 | 2050 | if (hw->mac.type == ixgbe_mac_82599EB) { |
ee5f784a | 2051 | u32 rttdcs; |
1cdd1ec8 | 2052 | u32 mask; |
ee5f784a DS |
2053 | |
2054 | /* disable the arbiter while setting MTQC */ | |
2055 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); | |
2056 | rttdcs |= IXGBE_RTTDCS_ARBDIS; | |
2057 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); | |
2058 | ||
1cdd1ec8 GR |
2059 | /* set transmit pool layout */ |
2060 | mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED); | |
2061 | switch (adapter->flags & mask) { | |
2062 | ||
2063 | case (IXGBE_FLAG_SRIOV_ENABLED): | |
2064 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, | |
2065 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); | |
2066 | break; | |
2067 | ||
2068 | case (IXGBE_FLAG_DCB_ENABLED): | |
2069 | /* We enable 8 traffic classes, DCB only */ | |
2070 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, | |
2071 | (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ)); | |
2072 | break; | |
2073 | ||
2074 | default: | |
ee5f784a | 2075 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB); |
1cdd1ec8 GR |
2076 | break; |
2077 | } | |
ee5f784a DS |
2078 | |
2079 | /* re-eable the arbiter */ | |
2080 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; | |
2081 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); | |
e8e26350 | 2082 | } |
9a799d71 AK |
2083 | } |
2084 | ||
e8e26350 | 2085 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
cc41ac7c | 2086 | |
a6616b42 YZ |
2087 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
2088 | struct ixgbe_ring *rx_ring) | |
cc41ac7c | 2089 | { |
cc41ac7c | 2090 | u32 srrctl; |
a6616b42 | 2091 | int index; |
0cefafad | 2092 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
3be1adfb | 2093 | |
a6616b42 YZ |
2094 | index = rx_ring->reg_idx; |
2095 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { | |
2096 | unsigned long mask; | |
0cefafad | 2097 | mask = (unsigned long) feature[RING_F_RSS].mask; |
3be1adfb | 2098 | index = index & mask; |
cc41ac7c | 2099 | } |
cc41ac7c JB |
2100 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
2101 | ||
2102 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; | |
2103 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; | |
2104 | ||
afafd5b0 AD |
2105 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
2106 | IXGBE_SRRCTL_BSIZEHDR_MASK; | |
2107 | ||
6e455b89 | 2108 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
afafd5b0 AD |
2109 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
2110 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; | |
2111 | #else | |
2112 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; | |
2113 | #endif | |
cc41ac7c | 2114 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
cc41ac7c | 2115 | } else { |
afafd5b0 AD |
2116 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
2117 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; | |
cc41ac7c | 2118 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
cc41ac7c | 2119 | } |
e8e26350 | 2120 | |
cc41ac7c JB |
2121 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
2122 | } | |
9a799d71 | 2123 | |
0cefafad JB |
2124 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
2125 | { | |
2126 | u32 mrqc = 0; | |
2127 | int mask; | |
2128 | ||
2129 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) | |
2130 | return mrqc; | |
2131 | ||
2132 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED | |
2133 | #ifdef CONFIG_IXGBE_DCB | |
2134 | | IXGBE_FLAG_DCB_ENABLED | |
2135 | #endif | |
1cdd1ec8 | 2136 | | IXGBE_FLAG_SRIOV_ENABLED |
0cefafad JB |
2137 | ); |
2138 | ||
2139 | switch (mask) { | |
2140 | case (IXGBE_FLAG_RSS_ENABLED): | |
2141 | mrqc = IXGBE_MRQC_RSSEN; | |
2142 | break; | |
1cdd1ec8 GR |
2143 | case (IXGBE_FLAG_SRIOV_ENABLED): |
2144 | mrqc = IXGBE_MRQC_VMDQEN; | |
2145 | break; | |
0cefafad JB |
2146 | #ifdef CONFIG_IXGBE_DCB |
2147 | case (IXGBE_FLAG_DCB_ENABLED): | |
2148 | mrqc = IXGBE_MRQC_RT8TCEN; | |
2149 | break; | |
2150 | #endif /* CONFIG_IXGBE_DCB */ | |
2151 | default: | |
2152 | break; | |
2153 | } | |
2154 | ||
2155 | return mrqc; | |
2156 | } | |
2157 | ||
bb5a9ad2 NS |
2158 | /** |
2159 | * ixgbe_configure_rscctl - enable RSC for the indicated ring | |
2160 | * @adapter: address of board private structure | |
2161 | * @index: index of ring to set | |
bb5a9ad2 | 2162 | **/ |
edd2ea55 | 2163 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index) |
bb5a9ad2 NS |
2164 | { |
2165 | struct ixgbe_ring *rx_ring; | |
2166 | struct ixgbe_hw *hw = &adapter->hw; | |
2167 | int j; | |
2168 | u32 rscctrl; | |
edd2ea55 | 2169 | int rx_buf_len; |
bb5a9ad2 NS |
2170 | |
2171 | rx_ring = &adapter->rx_ring[index]; | |
2172 | j = rx_ring->reg_idx; | |
edd2ea55 | 2173 | rx_buf_len = rx_ring->rx_buf_len; |
bb5a9ad2 NS |
2174 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
2175 | rscctrl |= IXGBE_RSCCTL_RSCEN; | |
2176 | /* | |
2177 | * we must limit the number of descriptors so that the | |
2178 | * total size of max desc * buf_len is not greater | |
2179 | * than 65535 | |
2180 | */ | |
2181 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { | |
2182 | #if (MAX_SKB_FRAGS > 16) | |
2183 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; | |
2184 | #elif (MAX_SKB_FRAGS > 8) | |
2185 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; | |
2186 | #elif (MAX_SKB_FRAGS > 4) | |
2187 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; | |
2188 | #else | |
2189 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; | |
2190 | #endif | |
2191 | } else { | |
2192 | if (rx_buf_len < IXGBE_RXBUFFER_4096) | |
2193 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; | |
2194 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) | |
2195 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; | |
2196 | else | |
2197 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; | |
2198 | } | |
2199 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); | |
2200 | } | |
2201 | ||
9a799d71 | 2202 | /** |
3a581073 | 2203 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
9a799d71 AK |
2204 | * @adapter: board private structure |
2205 | * | |
2206 | * Configure the Rx unit of the MAC after a reset. | |
2207 | **/ | |
2208 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) | |
2209 | { | |
2210 | u64 rdba; | |
2211 | struct ixgbe_hw *hw = &adapter->hw; | |
a6616b42 | 2212 | struct ixgbe_ring *rx_ring; |
9a799d71 AK |
2213 | struct net_device *netdev = adapter->netdev; |
2214 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; | |
021230d4 | 2215 | int i, j; |
9a799d71 | 2216 | u32 rdlen, rxctrl, rxcsum; |
7c6e0a43 JB |
2217 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
2218 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, | |
2219 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; | |
9a799d71 | 2220 | u32 fctrl, hlreg0; |
509ee935 | 2221 | u32 reta = 0, mrqc = 0; |
cc41ac7c | 2222 | u32 rdrxctl; |
7c6e0a43 | 2223 | int rx_buf_len; |
9a799d71 AK |
2224 | |
2225 | /* Decide whether to use packet split mode or not */ | |
1cdd1ec8 GR |
2226 | /* Do not use packet split if we're in SR-IOV Mode */ |
2227 | if (!adapter->num_vfs) | |
2228 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; | |
9a799d71 AK |
2229 | |
2230 | /* Set the RX buffer length according to the mode */ | |
2231 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { | |
7c6e0a43 | 2232 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
e8e26350 PW |
2233 | if (hw->mac.type == ixgbe_mac_82599EB) { |
2234 | /* PSRTYPE must be initialized in 82599 */ | |
2235 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | | |
2236 | IXGBE_PSRTYPE_UDPHDR | | |
2237 | IXGBE_PSRTYPE_IPV4HDR | | |
dfa12f05 YZ |
2238 | IXGBE_PSRTYPE_IPV6HDR | |
2239 | IXGBE_PSRTYPE_L2HDR; | |
1cdd1ec8 GR |
2240 | IXGBE_WRITE_REG(hw, |
2241 | IXGBE_PSRTYPE(adapter->num_vfs), | |
2242 | psrtype); | |
e8e26350 | 2243 | } |
9a799d71 | 2244 | } else { |
0c19d6af | 2245 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
f8212f97 | 2246 | (netdev->mtu <= ETH_DATA_LEN)) |
7c6e0a43 | 2247 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
9a799d71 | 2248 | else |
7c6e0a43 | 2249 | rx_buf_len = ALIGN(max_frame, 1024); |
9a799d71 AK |
2250 | } |
2251 | ||
2252 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); | |
2253 | fctrl |= IXGBE_FCTRL_BAM; | |
021230d4 | 2254 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
e8e26350 | 2255 | fctrl |= IXGBE_FCTRL_PMCF; |
9a799d71 AK |
2256 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
2257 | ||
2258 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); | |
2259 | if (adapter->netdev->mtu <= ETH_DATA_LEN) | |
2260 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; | |
2261 | else | |
2262 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; | |
63f39bd1 | 2263 | #ifdef IXGBE_FCOE |
f34c5c82 | 2264 | if (netdev->features & NETIF_F_FCOE_MTU) |
63f39bd1 YZ |
2265 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
2266 | #endif | |
9a799d71 AK |
2267 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
2268 | ||
9a799d71 AK |
2269 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
2270 | /* disable receives while setting up the descriptors */ | |
2271 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); | |
2272 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); | |
2273 | ||
0cefafad JB |
2274 | /* |
2275 | * Setup the HW Rx Head and Tail Descriptor Pointers and | |
2276 | * the Base and Length of the Rx Descriptor Ring | |
2277 | */ | |
9a799d71 | 2278 | for (i = 0; i < adapter->num_rx_queues; i++) { |
a6616b42 YZ |
2279 | rx_ring = &adapter->rx_ring[i]; |
2280 | rdba = rx_ring->dma; | |
2281 | j = rx_ring->reg_idx; | |
284901a9 | 2282 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
7c6e0a43 JB |
2283 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
2284 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); | |
2285 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); | |
2286 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); | |
a6616b42 YZ |
2287 | rx_ring->head = IXGBE_RDH(j); |
2288 | rx_ring->tail = IXGBE_RDT(j); | |
2289 | rx_ring->rx_buf_len = rx_buf_len; | |
cc41ac7c | 2290 | |
6e455b89 YZ |
2291 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
2292 | rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED; | |
1b3ff02e PWJ |
2293 | else |
2294 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; | |
cc41ac7c | 2295 | |
63f39bd1 | 2296 | #ifdef IXGBE_FCOE |
f34c5c82 | 2297 | if (netdev->features & NETIF_F_FCOE_MTU) { |
63f39bd1 YZ |
2298 | struct ixgbe_ring_feature *f; |
2299 | f = &adapter->ring_feature[RING_F_FCOE]; | |
6e455b89 YZ |
2300 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
2301 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; | |
2302 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) | |
2303 | rx_ring->rx_buf_len = | |
2304 | IXGBE_FCOE_JUMBO_FRAME_SIZE; | |
2305 | } | |
63f39bd1 YZ |
2306 | } |
2307 | ||
2308 | #endif /* IXGBE_FCOE */ | |
a6616b42 | 2309 | ixgbe_configure_srrctl(adapter, rx_ring); |
9a799d71 AK |
2310 | } |
2311 | ||
e8e26350 PW |
2312 | if (hw->mac.type == ixgbe_mac_82598EB) { |
2313 | /* | |
2314 | * For VMDq support of different descriptor types or | |
2315 | * buffer sizes through the use of multiple SRRCTL | |
2316 | * registers, RDRXCTL.MVMEN must be set to 1 | |
2317 | * | |
2318 | * also, the manual doesn't mention it clearly but DCA hints | |
2319 | * will only use queue 0's tags unless this bit is set. Side | |
2320 | * effects of setting this bit are only that SRRCTL must be | |
2321 | * fully programmed [0..15] | |
2322 | */ | |
2a41ff81 JB |
2323 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
2324 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; | |
2325 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); | |
2f90b865 | 2326 | } |
177db6ff | 2327 | |
1cdd1ec8 GR |
2328 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
2329 | u32 vt_reg_bits; | |
2330 | u32 reg_offset, vf_shift; | |
2331 | u32 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); | |
2332 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | |
2333 | | IXGBE_VT_CTL_REPLEN; | |
2334 | vt_reg_bits |= (adapter->num_vfs << | |
2335 | IXGBE_VT_CTL_POOL_SHIFT); | |
2336 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); | |
2337 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, 0); | |
2338 | ||
2339 | vf_shift = adapter->num_vfs % 32; | |
2340 | reg_offset = adapter->num_vfs / 32; | |
2341 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); | |
2342 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); | |
2343 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); | |
2344 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); | |
2345 | /* Enable only the PF's pool for Tx/Rx */ | |
2346 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); | |
2347 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); | |
2348 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); | |
2349 | ixgbe_set_vmolr(hw, adapter->num_vfs); | |
2350 | } | |
2351 | ||
e8e26350 | 2352 | /* Program MRQC for the distribution of queues */ |
0cefafad | 2353 | mrqc = ixgbe_setup_mrqc(adapter); |
e8e26350 | 2354 | |
021230d4 | 2355 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
9a799d71 | 2356 | /* Fill out redirection table */ |
021230d4 AV |
2357 | for (i = 0, j = 0; i < 128; i++, j++) { |
2358 | if (j == adapter->ring_feature[RING_F_RSS].indices) | |
2359 | j = 0; | |
2360 | /* reta = 4-byte sliding window of | |
2361 | * 0x00..(indices-1)(indices-1)00..etc. */ | |
2362 | reta = (reta << 8) | (j * 0x11); | |
2363 | if ((i & 3) == 3) | |
2364 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); | |
9a799d71 AK |
2365 | } |
2366 | ||
2367 | /* Fill out hash function seeds */ | |
2368 | for (i = 0; i < 10; i++) | |
7c6e0a43 | 2369 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
9a799d71 | 2370 | |
2a41ff81 JB |
2371 | if (hw->mac.type == ixgbe_mac_82598EB) |
2372 | mrqc |= IXGBE_MRQC_RSSEN; | |
9a799d71 | 2373 | /* Perform hash on these packet types */ |
2a41ff81 JB |
2374 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
2375 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
2376 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP | |
2377 | | IXGBE_MRQC_RSS_FIELD_IPV6 | |
2378 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP | |
2379 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; | |
021230d4 | 2380 | } |
2a41ff81 | 2381 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
9a799d71 | 2382 | |
1cdd1ec8 GR |
2383 | if (adapter->num_vfs) { |
2384 | u32 reg; | |
2385 | ||
2386 | /* Map PF MAC address in RAR Entry 0 to first pool | |
2387 | * following VFs */ | |
2388 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); | |
2389 | ||
2390 | /* Set up VF register offsets for selected VT Mode, i.e. | |
2391 | * 64 VFs for SR-IOV */ | |
2392 | reg = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); | |
2393 | reg |= IXGBE_GCR_EXT_SRIOV; | |
2394 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, reg); | |
2395 | } | |
2396 | ||
021230d4 AV |
2397 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
2398 | ||
2399 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || | |
2400 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { | |
2401 | /* Disable indicating checksum in descriptor, enables | |
2402 | * RSS hash */ | |
9a799d71 | 2403 | rxcsum |= IXGBE_RXCSUM_PCSD; |
9a799d71 | 2404 | } |
021230d4 AV |
2405 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
2406 | /* Enable IPv4 payload checksum for UDP fragments | |
2407 | * if PCSD is not set */ | |
2408 | rxcsum |= IXGBE_RXCSUM_IPPCSE; | |
2409 | } | |
2410 | ||
2411 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); | |
e8e26350 PW |
2412 | |
2413 | if (hw->mac.type == ixgbe_mac_82599EB) { | |
2414 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); | |
2415 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; | |
f8212f97 | 2416 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
e8e26350 PW |
2417 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
2418 | } | |
f8212f97 | 2419 | |
0c19d6af | 2420 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
f8212f97 | 2421 | /* Enable 82599 HW-RSC */ |
bb5a9ad2 | 2422 | for (i = 0; i < adapter->num_rx_queues; i++) |
edd2ea55 | 2423 | ixgbe_configure_rscctl(adapter, i); |
bb5a9ad2 | 2424 | |
f8212f97 AD |
2425 | /* Disable RSC for ACK packets */ |
2426 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, | |
2427 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); | |
2428 | } | |
9a799d71 AK |
2429 | } |
2430 | ||
068c89b0 DS |
2431 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
2432 | { | |
2433 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
2434 | struct ixgbe_hw *hw = &adapter->hw; | |
1ada1b1b | 2435 | int pool_ndx = adapter->num_vfs; |
068c89b0 DS |
2436 | |
2437 | /* add VID to filter table */ | |
1ada1b1b | 2438 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
068c89b0 DS |
2439 | } |
2440 | ||
2441 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) | |
2442 | { | |
2443 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
2444 | struct ixgbe_hw *hw = &adapter->hw; | |
1ada1b1b | 2445 | int pool_ndx = adapter->num_vfs; |
068c89b0 DS |
2446 | |
2447 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | |
2448 | ixgbe_irq_disable(adapter); | |
2449 | ||
2450 | vlan_group_set_device(adapter->vlgrp, vid, NULL); | |
2451 | ||
2452 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) | |
2453 | ixgbe_irq_enable(adapter); | |
2454 | ||
2455 | /* remove VID from filter table */ | |
1ada1b1b | 2456 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
068c89b0 DS |
2457 | } |
2458 | ||
9a799d71 | 2459 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
b4617240 | 2460 | struct vlan_group *grp) |
9a799d71 AK |
2461 | { |
2462 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
2463 | u32 ctrl; | |
e8e26350 | 2464 | int i, j; |
9a799d71 | 2465 | |
d4f80882 AV |
2466 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
2467 | ixgbe_irq_disable(adapter); | |
9a799d71 AK |
2468 | adapter->vlgrp = grp; |
2469 | ||
2f90b865 AD |
2470 | /* |
2471 | * For a DCB driver, always enable VLAN tag stripping so we can | |
2472 | * still receive traffic from a DCB-enabled host even if we're | |
2473 | * not in DCB mode. | |
2474 | */ | |
2475 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); | |
dc63d377 AD |
2476 | |
2477 | /* Disable CFI check */ | |
2478 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; | |
2479 | ||
2480 | /* enable VLAN tag stripping */ | |
e8e26350 | 2481 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
dc63d377 | 2482 | ctrl |= IXGBE_VLNCTRL_VME; |
e8e26350 | 2483 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
e8e26350 | 2484 | for (i = 0; i < adapter->num_rx_queues; i++) { |
dc63d377 | 2485 | u32 ctrl; |
e8e26350 PW |
2486 | j = adapter->rx_ring[i].reg_idx; |
2487 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); | |
2488 | ctrl |= IXGBE_RXDCTL_VME; | |
2489 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); | |
2490 | } | |
9a799d71 | 2491 | } |
dc63d377 AD |
2492 | |
2493 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); | |
2494 | ||
e8e26350 | 2495 | ixgbe_vlan_rx_add_vid(netdev, 0); |
9a799d71 | 2496 | |
d4f80882 AV |
2497 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
2498 | ixgbe_irq_enable(adapter); | |
9a799d71 AK |
2499 | } |
2500 | ||
9a799d71 AK |
2501 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
2502 | { | |
2503 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); | |
2504 | ||
2505 | if (adapter->vlgrp) { | |
2506 | u16 vid; | |
2507 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { | |
2508 | if (!vlan_group_get_device(adapter->vlgrp, vid)) | |
2509 | continue; | |
2510 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); | |
2511 | } | |
2512 | } | |
2513 | } | |
2514 | ||
2c5645cf CL |
2515 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
2516 | { | |
2517 | struct dev_mc_list *mc_ptr; | |
2518 | u8 *addr = *mc_addr_ptr; | |
2519 | *vmdq = 0; | |
2520 | ||
2521 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); | |
2522 | if (mc_ptr->next) | |
2523 | *mc_addr_ptr = mc_ptr->next->dmi_addr; | |
2524 | else | |
2525 | *mc_addr_ptr = NULL; | |
2526 | ||
2527 | return addr; | |
2528 | } | |
2529 | ||
9a799d71 | 2530 | /** |
2c5645cf | 2531 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
9a799d71 AK |
2532 | * @netdev: network interface device structure |
2533 | * | |
2c5645cf CL |
2534 | * The set_rx_method entry point is called whenever the unicast/multicast |
2535 | * address list or the network interface flags are updated. This routine is | |
2536 | * responsible for configuring the hardware for proper unicast, multicast and | |
2537 | * promiscuous mode. | |
9a799d71 | 2538 | **/ |
7f870475 | 2539 | void ixgbe_set_rx_mode(struct net_device *netdev) |
9a799d71 AK |
2540 | { |
2541 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
2542 | struct ixgbe_hw *hw = &adapter->hw; | |
3d01625a | 2543 | u32 fctrl, vlnctrl; |
2c5645cf CL |
2544 | u8 *addr_list = NULL; |
2545 | int addr_count = 0; | |
9a799d71 AK |
2546 | |
2547 | /* Check for Promiscuous and All Multicast modes */ | |
2548 | ||
2549 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); | |
3d01625a | 2550 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
9a799d71 AK |
2551 | |
2552 | if (netdev->flags & IFF_PROMISC) { | |
2c5645cf | 2553 | hw->addr_ctrl.user_set_promisc = 1; |
9a799d71 | 2554 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
3d01625a | 2555 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
9a799d71 | 2556 | } else { |
746b9f02 PM |
2557 | if (netdev->flags & IFF_ALLMULTI) { |
2558 | fctrl |= IXGBE_FCTRL_MPE; | |
2559 | fctrl &= ~IXGBE_FCTRL_UPE; | |
2560 | } else { | |
2561 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); | |
2562 | } | |
3d01625a | 2563 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
2c5645cf | 2564 | hw->addr_ctrl.user_set_promisc = 0; |
9a799d71 AK |
2565 | } |
2566 | ||
2567 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); | |
3d01625a | 2568 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
9a799d71 | 2569 | |
2c5645cf | 2570 | /* reprogram secondary unicast list */ |
31278e71 | 2571 | hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list); |
9a799d71 | 2572 | |
2c5645cf CL |
2573 | /* reprogram multicast list */ |
2574 | addr_count = netdev->mc_count; | |
2575 | if (addr_count) | |
2576 | addr_list = netdev->mc_list->dmi_addr; | |
c44ade9e JB |
2577 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
2578 | ixgbe_addr_list_itr); | |
1cdd1ec8 GR |
2579 | if (adapter->num_vfs) |
2580 | ixgbe_restore_vf_multicasts(adapter); | |
9a799d71 AK |
2581 | } |
2582 | ||
021230d4 AV |
2583 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
2584 | { | |
2585 | int q_idx; | |
2586 | struct ixgbe_q_vector *q_vector; | |
2587 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | |
2588 | ||
2589 | /* legacy and MSI only use one vector */ | |
2590 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) | |
2591 | q_vectors = 1; | |
2592 | ||
2593 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { | |
f0848276 | 2594 | struct napi_struct *napi; |
7a921c93 | 2595 | q_vector = adapter->q_vector[q_idx]; |
f0848276 | 2596 | napi = &q_vector->napi; |
91281fd3 AD |
2597 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
2598 | if (!q_vector->rxr_count || !q_vector->txr_count) { | |
2599 | if (q_vector->txr_count == 1) | |
2600 | napi->poll = &ixgbe_clean_txonly; | |
2601 | else if (q_vector->rxr_count == 1) | |
2602 | napi->poll = &ixgbe_clean_rxonly; | |
2603 | } | |
2604 | } | |
f0848276 JB |
2605 | |
2606 | napi_enable(napi); | |
021230d4 AV |
2607 | } |
2608 | } | |
2609 | ||
2610 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) | |
2611 | { | |
2612 | int q_idx; | |
2613 | struct ixgbe_q_vector *q_vector; | |
2614 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | |
2615 | ||
2616 | /* legacy and MSI only use one vector */ | |
2617 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) | |
2618 | q_vectors = 1; | |
2619 | ||
2620 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { | |
7a921c93 | 2621 | q_vector = adapter->q_vector[q_idx]; |
021230d4 AV |
2622 | napi_disable(&q_vector->napi); |
2623 | } | |
2624 | } | |
2625 | ||
7a6b6f51 | 2626 | #ifdef CONFIG_IXGBE_DCB |
2f90b865 AD |
2627 | /* |
2628 | * ixgbe_configure_dcb - Configure DCB hardware | |
2629 | * @adapter: ixgbe adapter struct | |
2630 | * | |
2631 | * This is called by the driver on open to configure the DCB hardware. | |
2632 | * This is also called by the gennetlink interface when reconfiguring | |
2633 | * the DCB state. | |
2634 | */ | |
2635 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) | |
2636 | { | |
2637 | struct ixgbe_hw *hw = &adapter->hw; | |
2638 | u32 txdctl, vlnctrl; | |
2639 | int i, j; | |
2640 | ||
2641 | ixgbe_dcb_check_config(&adapter->dcb_cfg); | |
2642 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); | |
2643 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); | |
2644 | ||
2645 | /* reconfigure the hardware */ | |
2646 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); | |
2647 | ||
2648 | for (i = 0; i < adapter->num_tx_queues; i++) { | |
2649 | j = adapter->tx_ring[i].reg_idx; | |
2650 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); | |
2651 | /* PThresh workaround for Tx hang with DFP enabled. */ | |
2652 | txdctl |= 32; | |
2653 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); | |
2654 | } | |
2655 | /* Enable VLAN tag insert/strip */ | |
2656 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); | |
e8e26350 PW |
2657 | if (hw->mac.type == ixgbe_mac_82598EB) { |
2658 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; | |
2659 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; | |
2660 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); | |
2661 | } else if (hw->mac.type == ixgbe_mac_82599EB) { | |
2662 | vlnctrl |= IXGBE_VLNCTRL_VFE; | |
2663 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; | |
2664 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); | |
2665 | for (i = 0; i < adapter->num_rx_queues; i++) { | |
2666 | j = adapter->rx_ring[i].reg_idx; | |
2667 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); | |
2668 | vlnctrl |= IXGBE_RXDCTL_VME; | |
2669 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); | |
2670 | } | |
2671 | } | |
2f90b865 AD |
2672 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
2673 | } | |
2674 | ||
2675 | #endif | |
9a799d71 AK |
2676 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
2677 | { | |
2678 | struct net_device *netdev = adapter->netdev; | |
c4cf55e5 | 2679 | struct ixgbe_hw *hw = &adapter->hw; |
9a799d71 AK |
2680 | int i; |
2681 | ||
2c5645cf | 2682 | ixgbe_set_rx_mode(netdev); |
9a799d71 AK |
2683 | |
2684 | ixgbe_restore_vlan(adapter); | |
7a6b6f51 | 2685 | #ifdef CONFIG_IXGBE_DCB |
2f90b865 | 2686 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
b352e40d YZ |
2687 | if (hw->mac.type == ixgbe_mac_82598EB) |
2688 | netif_set_gso_max_size(netdev, 32768); | |
2689 | else | |
2690 | netif_set_gso_max_size(netdev, 65536); | |
2f90b865 AD |
2691 | ixgbe_configure_dcb(adapter); |
2692 | } else { | |
2693 | netif_set_gso_max_size(netdev, 65536); | |
2694 | } | |
2695 | #else | |
2696 | netif_set_gso_max_size(netdev, 65536); | |
2697 | #endif | |
9a799d71 | 2698 | |
eacd73f7 YZ |
2699 | #ifdef IXGBE_FCOE |
2700 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) | |
2701 | ixgbe_configure_fcoe(adapter); | |
2702 | ||
2703 | #endif /* IXGBE_FCOE */ | |
c4cf55e5 PWJ |
2704 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
2705 | for (i = 0; i < adapter->num_tx_queues; i++) | |
2706 | adapter->tx_ring[i].atr_sample_rate = | |
2707 | adapter->atr_sample_rate; | |
2708 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); | |
2709 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { | |
2710 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); | |
2711 | } | |
2712 | ||
9a799d71 AK |
2713 | ixgbe_configure_tx(adapter); |
2714 | ixgbe_configure_rx(adapter); | |
2715 | for (i = 0; i < adapter->num_rx_queues; i++) | |
2716 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], | |
b4617240 | 2717 | (adapter->rx_ring[i].count - 1)); |
9a799d71 AK |
2718 | } |
2719 | ||
e8e26350 PW |
2720 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
2721 | { | |
2722 | switch (hw->phy.type) { | |
2723 | case ixgbe_phy_sfp_avago: | |
2724 | case ixgbe_phy_sfp_ftl: | |
2725 | case ixgbe_phy_sfp_intel: | |
2726 | case ixgbe_phy_sfp_unknown: | |
2727 | case ixgbe_phy_tw_tyco: | |
2728 | case ixgbe_phy_tw_unknown: | |
2729 | return true; | |
2730 | default: | |
2731 | return false; | |
2732 | } | |
2733 | } | |
2734 | ||
0ecc061d | 2735 | /** |
e8e26350 PW |
2736 | * ixgbe_sfp_link_config - set up SFP+ link |
2737 | * @adapter: pointer to private adapter struct | |
2738 | **/ | |
2739 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) | |
2740 | { | |
2741 | struct ixgbe_hw *hw = &adapter->hw; | |
2742 | ||
2743 | if (hw->phy.multispeed_fiber) { | |
2744 | /* | |
2745 | * In multispeed fiber setups, the device may not have | |
2746 | * had a physical connection when the driver loaded. | |
2747 | * If that's the case, the initial link configuration | |
2748 | * couldn't get the MAC into 10G or 1G mode, so we'll | |
2749 | * never have a link status change interrupt fire. | |
2750 | * We need to try and force an autonegotiation | |
2751 | * session, then bring up link. | |
2752 | */ | |
2753 | hw->mac.ops.setup_sfp(hw); | |
2754 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) | |
2755 | schedule_work(&adapter->multispeed_fiber_task); | |
2756 | } else { | |
2757 | /* | |
2758 | * Direct Attach Cu and non-multispeed fiber modules | |
2759 | * still need to be configured properly prior to | |
2760 | * attempting link. | |
2761 | */ | |
2762 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) | |
2763 | schedule_work(&adapter->sfp_config_module_task); | |
2764 | } | |
2765 | } | |
2766 | ||
2767 | /** | |
2768 | * ixgbe_non_sfp_link_config - set up non-SFP+ link | |
0ecc061d PWJ |
2769 | * @hw: pointer to private hardware struct |
2770 | * | |
2771 | * Returns 0 on success, negative on failure | |
2772 | **/ | |
e8e26350 | 2773 | static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw) |
0ecc061d PWJ |
2774 | { |
2775 | u32 autoneg; | |
8620a103 | 2776 | bool negotiation, link_up = false; |
0ecc061d PWJ |
2777 | u32 ret = IXGBE_ERR_LINK_SETUP; |
2778 | ||
2779 | if (hw->mac.ops.check_link) | |
2780 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); | |
2781 | ||
2782 | if (ret) | |
2783 | goto link_cfg_out; | |
2784 | ||
2785 | if (hw->mac.ops.get_link_capabilities) | |
8620a103 | 2786 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
0ecc061d PWJ |
2787 | if (ret) |
2788 | goto link_cfg_out; | |
2789 | ||
8620a103 MC |
2790 | if (hw->mac.ops.setup_link) |
2791 | ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up); | |
0ecc061d PWJ |
2792 | link_cfg_out: |
2793 | return ret; | |
2794 | } | |
2795 | ||
e8e26350 PW |
2796 | #define IXGBE_MAX_RX_DESC_POLL 10 |
2797 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, | |
2798 | int rxr) | |
2799 | { | |
2800 | int j = adapter->rx_ring[rxr].reg_idx; | |
2801 | int k; | |
2802 | ||
2803 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { | |
2804 | if (IXGBE_READ_REG(&adapter->hw, | |
2805 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) | |
2806 | break; | |
2807 | else | |
2808 | msleep(1); | |
2809 | } | |
2810 | if (k >= IXGBE_MAX_RX_DESC_POLL) { | |
2811 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " | |
2812 | "not set within the polling period\n", rxr); | |
2813 | } | |
2814 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], | |
2815 | (adapter->rx_ring[rxr].count - 1)); | |
2816 | } | |
2817 | ||
9a799d71 AK |
2818 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
2819 | { | |
2820 | struct net_device *netdev = adapter->netdev; | |
9a799d71 | 2821 | struct ixgbe_hw *hw = &adapter->hw; |
021230d4 | 2822 | int i, j = 0; |
e8e26350 | 2823 | int num_rx_rings = adapter->num_rx_queues; |
0ecc061d | 2824 | int err; |
9a799d71 | 2825 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
021230d4 | 2826 | u32 txdctl, rxdctl, mhadd; |
e8e26350 | 2827 | u32 dmatxctl; |
021230d4 | 2828 | u32 gpie; |
9a799d71 | 2829 | |
5eba3699 AV |
2830 | ixgbe_get_hw_control(adapter); |
2831 | ||
021230d4 AV |
2832 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
2833 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { | |
9a799d71 AK |
2834 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
2835 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | | |
b4617240 | 2836 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
9a799d71 AK |
2837 | } else { |
2838 | /* MSI only */ | |
021230d4 | 2839 | gpie = 0; |
9a799d71 | 2840 | } |
1cdd1ec8 GR |
2841 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
2842 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; | |
2843 | gpie |= IXGBE_GPIE_VTMODE_64; | |
2844 | } | |
021230d4 AV |
2845 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
2846 | /* gpie |= IXGBE_GPIE_EIMEN; */ | |
2847 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); | |
9a799d71 AK |
2848 | } |
2849 | ||
9b471446 JB |
2850 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
2851 | /* | |
2852 | * use EIAM to auto-mask when MSI-X interrupt is asserted | |
2853 | * this saves a register write for every interrupt | |
2854 | */ | |
2855 | switch (hw->mac.type) { | |
2856 | case ixgbe_mac_82598EB: | |
2857 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); | |
2858 | break; | |
2859 | default: | |
2860 | case ixgbe_mac_82599EB: | |
2861 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); | |
2862 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); | |
2863 | break; | |
2864 | } | |
2865 | } else { | |
021230d4 AV |
2866 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
2867 | * specifically only auto mask tx and rx interrupts */ | |
2868 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); | |
2869 | } | |
9a799d71 | 2870 | |
0befdb3e JB |
2871 | /* Enable fan failure interrupt if media type is copper */ |
2872 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { | |
2873 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); | |
2874 | gpie |= IXGBE_SDP1_GPIEN; | |
2875 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); | |
2876 | } | |
2877 | ||
e8e26350 PW |
2878 | if (hw->mac.type == ixgbe_mac_82599EB) { |
2879 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); | |
2880 | gpie |= IXGBE_SDP1_GPIEN; | |
2881 | gpie |= IXGBE_SDP2_GPIEN; | |
2882 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); | |
2883 | } | |
2884 | ||
63f39bd1 YZ |
2885 | #ifdef IXGBE_FCOE |
2886 | /* adjust max frame to be able to do baby jumbo for FCoE */ | |
f34c5c82 | 2887 | if ((netdev->features & NETIF_F_FCOE_MTU) && |
63f39bd1 YZ |
2888 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
2889 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; | |
2890 | ||
2891 | #endif /* IXGBE_FCOE */ | |
021230d4 | 2892 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
9a799d71 AK |
2893 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
2894 | mhadd &= ~IXGBE_MHADD_MFS_MASK; | |
2895 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; | |
2896 | ||
2897 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); | |
2898 | } | |
2899 | ||
2900 | for (i = 0; i < adapter->num_tx_queues; i++) { | |
021230d4 AV |
2901 | j = adapter->tx_ring[i].reg_idx; |
2902 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); | |
e01c31a5 JB |
2903 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
2904 | txdctl |= (8 << 16); | |
e8e26350 PW |
2905 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
2906 | } | |
2907 | ||
2908 | if (hw->mac.type == ixgbe_mac_82599EB) { | |
2909 | /* DMATXCTL.EN must be set after all Tx queue config is done */ | |
2910 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); | |
2911 | dmatxctl |= IXGBE_DMATXCTL_TE; | |
2912 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); | |
2913 | } | |
2914 | for (i = 0; i < adapter->num_tx_queues; i++) { | |
2915 | j = adapter->tx_ring[i].reg_idx; | |
2916 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); | |
9a799d71 | 2917 | txdctl |= IXGBE_TXDCTL_ENABLE; |
021230d4 | 2918 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
1cdd1ec8 GR |
2919 | if (hw->mac.type == ixgbe_mac_82599EB) { |
2920 | int wait_loop = 10; | |
2921 | /* poll for Tx Enable ready */ | |
2922 | do { | |
2923 | msleep(1); | |
2924 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); | |
2925 | } while (--wait_loop && | |
2926 | !(txdctl & IXGBE_TXDCTL_ENABLE)); | |
2927 | if (!wait_loop) | |
2928 | DPRINTK(DRV, ERR, "Could not enable " | |
2929 | "Tx Queue %d\n", j); | |
2930 | } | |
9a799d71 AK |
2931 | } |
2932 | ||
e8e26350 | 2933 | for (i = 0; i < num_rx_rings; i++) { |
021230d4 AV |
2934 | j = adapter->rx_ring[i].reg_idx; |
2935 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); | |
2936 | /* enable PTHRESH=32 descriptors (half the internal cache) | |
2937 | * and HTHRESH=0 descriptors (to minimize latency on fetch), | |
2938 | * this also removes a pesky rx_no_buffer_count increment */ | |
2939 | rxdctl |= 0x0020; | |
9a799d71 | 2940 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
021230d4 | 2941 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
e8e26350 PW |
2942 | if (hw->mac.type == ixgbe_mac_82599EB) |
2943 | ixgbe_rx_desc_queue_enable(adapter, i); | |
9a799d71 AK |
2944 | } |
2945 | /* enable all receives */ | |
2946 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); | |
e8e26350 PW |
2947 | if (hw->mac.type == ixgbe_mac_82598EB) |
2948 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); | |
2949 | else | |
2950 | rxdctl |= IXGBE_RXCTRL_RXEN; | |
2951 | hw->mac.ops.enable_rx_dma(hw, rxdctl); | |
9a799d71 AK |
2952 | |
2953 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) | |
2954 | ixgbe_configure_msix(adapter); | |
2955 | else | |
2956 | ixgbe_configure_msi_and_legacy(adapter); | |
2957 | ||
2958 | clear_bit(__IXGBE_DOWN, &adapter->state); | |
021230d4 AV |
2959 | ixgbe_napi_enable_all(adapter); |
2960 | ||
2961 | /* clear any pending interrupts, may auto mask */ | |
2962 | IXGBE_READ_REG(hw, IXGBE_EICR); | |
2963 | ||
9a799d71 AK |
2964 | ixgbe_irq_enable(adapter); |
2965 | ||
bf069c97 DS |
2966 | /* |
2967 | * If this adapter has a fan, check to see if we had a failure | |
2968 | * before we enabled the interrupt. | |
2969 | */ | |
2970 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { | |
2971 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); | |
2972 | if (esdp & IXGBE_ESDP_SDP1) | |
2973 | DPRINTK(DRV, CRIT, | |
2974 | "Fan has stopped, replace the adapter\n"); | |
2975 | } | |
2976 | ||
e8e26350 PW |
2977 | /* |
2978 | * For hot-pluggable SFP+ devices, a new SFP+ module may have | |
19343de2 DS |
2979 | * arrived before interrupts were enabled but after probe. Such |
2980 | * devices wouldn't have their type identified yet. We need to | |
2981 | * kick off the SFP+ module setup first, then try to bring up link. | |
e8e26350 PW |
2982 | * If we're not hot-pluggable SFP+, we just need to configure link |
2983 | * and bring it up. | |
2984 | */ | |
19343de2 DS |
2985 | if (hw->phy.type == ixgbe_phy_unknown) { |
2986 | err = hw->phy.ops.identify(hw); | |
2987 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { | |
5da43c1a DS |
2988 | /* |
2989 | * Take the device down and schedule the sfp tasklet | |
2990 | * which will unregister_netdev and log it. | |
2991 | */ | |
19343de2 | 2992 | ixgbe_down(adapter); |
5da43c1a | 2993 | schedule_work(&adapter->sfp_config_module_task); |
19343de2 DS |
2994 | return err; |
2995 | } | |
e8e26350 PW |
2996 | } |
2997 | ||
2998 | if (ixgbe_is_sfp(hw)) { | |
2999 | ixgbe_sfp_link_config(adapter); | |
3000 | } else { | |
3001 | err = ixgbe_non_sfp_link_config(hw); | |
3002 | if (err) | |
3003 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); | |
3004 | } | |
0ecc061d | 3005 | |
c4cf55e5 PWJ |
3006 | for (i = 0; i < adapter->num_tx_queues; i++) |
3007 | set_bit(__IXGBE_FDIR_INIT_DONE, | |
3008 | &(adapter->tx_ring[i].reinit_state)); | |
3009 | ||
1da100bb PWJ |
3010 | /* enable transmits */ |
3011 | netif_tx_start_all_queues(netdev); | |
3012 | ||
9a799d71 AK |
3013 | /* bring the link up in the watchdog, this could race with our first |
3014 | * link up interrupt but shouldn't be a problem */ | |
cf8280ee JB |
3015 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
3016 | adapter->link_check_timeout = jiffies; | |
9a799d71 AK |
3017 | mod_timer(&adapter->watchdog_timer, jiffies); |
3018 | return 0; | |
3019 | } | |
3020 | ||
d4f80882 AV |
3021 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
3022 | { | |
3023 | WARN_ON(in_interrupt()); | |
3024 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) | |
3025 | msleep(1); | |
3026 | ixgbe_down(adapter); | |
3027 | ixgbe_up(adapter); | |
3028 | clear_bit(__IXGBE_RESETTING, &adapter->state); | |
3029 | } | |
3030 | ||
9a799d71 AK |
3031 | int ixgbe_up(struct ixgbe_adapter *adapter) |
3032 | { | |
3033 | /* hardware has been reset, we need to reload some things */ | |
3034 | ixgbe_configure(adapter); | |
3035 | ||
3036 | return ixgbe_up_complete(adapter); | |
3037 | } | |
3038 | ||
3039 | void ixgbe_reset(struct ixgbe_adapter *adapter) | |
3040 | { | |
c44ade9e | 3041 | struct ixgbe_hw *hw = &adapter->hw; |
8ca783ab DS |
3042 | int err; |
3043 | ||
3044 | err = hw->mac.ops.init_hw(hw); | |
da4dd0f7 PWJ |
3045 | switch (err) { |
3046 | case 0: | |
3047 | case IXGBE_ERR_SFP_NOT_PRESENT: | |
3048 | break; | |
3049 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: | |
3050 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); | |
3051 | break; | |
794caeb2 PWJ |
3052 | case IXGBE_ERR_EEPROM_VERSION: |
3053 | /* We are running on a pre-production device, log a warning */ | |
3054 | dev_warn(&adapter->pdev->dev, "This device is a pre-production " | |
3055 | "adapter/LOM. Please be aware there may be issues " | |
3056 | "associated with your hardware. If you are " | |
3057 | "experiencing problems please contact your Intel or " | |
3058 | "hardware representative who provided you with this " | |
3059 | "hardware.\n"); | |
3060 | break; | |
da4dd0f7 PWJ |
3061 | default: |
3062 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); | |
3063 | } | |
9a799d71 AK |
3064 | |
3065 | /* reprogram the RAR[0] in case user changed it. */ | |
1cdd1ec8 GR |
3066 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
3067 | IXGBE_RAH_AV); | |
9a799d71 AK |
3068 | } |
3069 | ||
9a799d71 AK |
3070 | /** |
3071 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue | |
3072 | * @adapter: board private structure | |
3073 | * @rx_ring: ring to free buffers from | |
3074 | **/ | |
3075 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, | |
b4617240 | 3076 | struct ixgbe_ring *rx_ring) |
9a799d71 AK |
3077 | { |
3078 | struct pci_dev *pdev = adapter->pdev; | |
3079 | unsigned long size; | |
3080 | unsigned int i; | |
3081 | ||
3082 | /* Free all the Rx ring sk_buffs */ | |
3083 | ||
3084 | for (i = 0; i < rx_ring->count; i++) { | |
3085 | struct ixgbe_rx_buffer *rx_buffer_info; | |
3086 | ||
3087 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; | |
3088 | if (rx_buffer_info->dma) { | |
3089 | pci_unmap_single(pdev, rx_buffer_info->dma, | |
b4617240 PW |
3090 | rx_ring->rx_buf_len, |
3091 | PCI_DMA_FROMDEVICE); | |
9a799d71 AK |
3092 | rx_buffer_info->dma = 0; |
3093 | } | |
3094 | if (rx_buffer_info->skb) { | |
f8212f97 | 3095 | struct sk_buff *skb = rx_buffer_info->skb; |
9a799d71 | 3096 | rx_buffer_info->skb = NULL; |
f8212f97 AD |
3097 | do { |
3098 | struct sk_buff *this = skb; | |
3099 | skb = skb->prev; | |
3100 | dev_kfree_skb(this); | |
3101 | } while (skb); | |
9a799d71 AK |
3102 | } |
3103 | if (!rx_buffer_info->page) | |
3104 | continue; | |
4f57ca6e JB |
3105 | if (rx_buffer_info->page_dma) { |
3106 | pci_unmap_page(pdev, rx_buffer_info->page_dma, | |
3107 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); | |
3108 | rx_buffer_info->page_dma = 0; | |
3109 | } | |
9a799d71 AK |
3110 | put_page(rx_buffer_info->page); |
3111 | rx_buffer_info->page = NULL; | |
762f4c57 | 3112 | rx_buffer_info->page_offset = 0; |
9a799d71 AK |
3113 | } |
3114 | ||
3115 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; | |
3116 | memset(rx_ring->rx_buffer_info, 0, size); | |
3117 | ||
3118 | /* Zero out the descriptor ring */ | |
3119 | memset(rx_ring->desc, 0, rx_ring->size); | |
3120 | ||
3121 | rx_ring->next_to_clean = 0; | |
3122 | rx_ring->next_to_use = 0; | |
3123 | ||
9891ca7c JB |
3124 | if (rx_ring->head) |
3125 | writel(0, adapter->hw.hw_addr + rx_ring->head); | |
3126 | if (rx_ring->tail) | |
3127 | writel(0, adapter->hw.hw_addr + rx_ring->tail); | |
9a799d71 AK |
3128 | } |
3129 | ||
3130 | /** | |
3131 | * ixgbe_clean_tx_ring - Free Tx Buffers | |
3132 | * @adapter: board private structure | |
3133 | * @tx_ring: ring to be cleaned | |
3134 | **/ | |
3135 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, | |
b4617240 | 3136 | struct ixgbe_ring *tx_ring) |
9a799d71 AK |
3137 | { |
3138 | struct ixgbe_tx_buffer *tx_buffer_info; | |
3139 | unsigned long size; | |
3140 | unsigned int i; | |
3141 | ||
3142 | /* Free all the Tx ring sk_buffs */ | |
3143 | ||
3144 | for (i = 0; i < tx_ring->count; i++) { | |
3145 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | |
3146 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); | |
3147 | } | |
3148 | ||
3149 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; | |
3150 | memset(tx_ring->tx_buffer_info, 0, size); | |
3151 | ||
3152 | /* Zero out the descriptor ring */ | |
3153 | memset(tx_ring->desc, 0, tx_ring->size); | |
3154 | ||
3155 | tx_ring->next_to_use = 0; | |
3156 | tx_ring->next_to_clean = 0; | |
3157 | ||
9891ca7c JB |
3158 | if (tx_ring->head) |
3159 | writel(0, adapter->hw.hw_addr + tx_ring->head); | |
3160 | if (tx_ring->tail) | |
3161 | writel(0, adapter->hw.hw_addr + tx_ring->tail); | |
9a799d71 AK |
3162 | } |
3163 | ||
3164 | /** | |
021230d4 | 3165 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
9a799d71 AK |
3166 | * @adapter: board private structure |
3167 | **/ | |
021230d4 | 3168 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
9a799d71 AK |
3169 | { |
3170 | int i; | |
3171 | ||
021230d4 AV |
3172 | for (i = 0; i < adapter->num_rx_queues; i++) |
3173 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); | |
9a799d71 AK |
3174 | } |
3175 | ||
3176 | /** | |
021230d4 | 3177 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
9a799d71 AK |
3178 | * @adapter: board private structure |
3179 | **/ | |
021230d4 | 3180 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
9a799d71 AK |
3181 | { |
3182 | int i; | |
3183 | ||
021230d4 AV |
3184 | for (i = 0; i < adapter->num_tx_queues; i++) |
3185 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); | |
9a799d71 AK |
3186 | } |
3187 | ||
3188 | void ixgbe_down(struct ixgbe_adapter *adapter) | |
3189 | { | |
3190 | struct net_device *netdev = adapter->netdev; | |
7f821875 | 3191 | struct ixgbe_hw *hw = &adapter->hw; |
9a799d71 | 3192 | u32 rxctrl; |
7f821875 JB |
3193 | u32 txdctl; |
3194 | int i, j; | |
9a799d71 AK |
3195 | |
3196 | /* signal that we are down to the interrupt handler */ | |
3197 | set_bit(__IXGBE_DOWN, &adapter->state); | |
3198 | ||
3199 | /* disable receives */ | |
7f821875 JB |
3200 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
3201 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); | |
9a799d71 AK |
3202 | |
3203 | netif_tx_disable(netdev); | |
3204 | ||
7f821875 | 3205 | IXGBE_WRITE_FLUSH(hw); |
9a799d71 AK |
3206 | msleep(10); |
3207 | ||
7f821875 JB |
3208 | netif_tx_stop_all_queues(netdev); |
3209 | ||
9a799d71 AK |
3210 | ixgbe_irq_disable(adapter); |
3211 | ||
021230d4 | 3212 | ixgbe_napi_disable_all(adapter); |
7f821875 | 3213 | |
0a1f87cb DS |
3214 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
3215 | del_timer_sync(&adapter->sfp_timer); | |
9a799d71 | 3216 | del_timer_sync(&adapter->watchdog_timer); |
cf8280ee | 3217 | cancel_work_sync(&adapter->watchdog_task); |
9a799d71 | 3218 | |
c4cf55e5 PWJ |
3219 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
3220 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) | |
3221 | cancel_work_sync(&adapter->fdir_reinit_task); | |
3222 | ||
7f821875 JB |
3223 | /* disable transmits in the hardware now that interrupts are off */ |
3224 | for (i = 0; i < adapter->num_tx_queues; i++) { | |
3225 | j = adapter->tx_ring[i].reg_idx; | |
3226 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); | |
3227 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), | |
3228 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); | |
3229 | } | |
88512539 PW |
3230 | /* Disable the Tx DMA engine on 82599 */ |
3231 | if (hw->mac.type == ixgbe_mac_82599EB) | |
3232 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, | |
3233 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & | |
3234 | ~IXGBE_DMATXCTL_TE)); | |
7f821875 | 3235 | |
9a799d71 | 3236 | netif_carrier_off(netdev); |
9a799d71 | 3237 | |
6f4a0e45 PL |
3238 | if (!pci_channel_offline(adapter->pdev)) |
3239 | ixgbe_reset(adapter); | |
9a799d71 AK |
3240 | ixgbe_clean_all_tx_rings(adapter); |
3241 | ixgbe_clean_all_rx_rings(adapter); | |
3242 | ||
5dd2d332 | 3243 | #ifdef CONFIG_IXGBE_DCA |
96b0e0f6 | 3244 | /* since we reset the hardware DCA settings were cleared */ |
e35ec126 | 3245 | ixgbe_setup_dca(adapter); |
96b0e0f6 | 3246 | #endif |
9a799d71 AK |
3247 | } |
3248 | ||
9a799d71 | 3249 | /** |
021230d4 AV |
3250 | * ixgbe_poll - NAPI Rx polling callback |
3251 | * @napi: structure for representing this polling device | |
3252 | * @budget: how many packets driver is allowed to clean | |
3253 | * | |
3254 | * This function is used for legacy and MSI, NAPI mode | |
9a799d71 | 3255 | **/ |
021230d4 | 3256 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
9a799d71 | 3257 | { |
9a1a69ad JB |
3258 | struct ixgbe_q_vector *q_vector = |
3259 | container_of(napi, struct ixgbe_q_vector, napi); | |
021230d4 | 3260 | struct ixgbe_adapter *adapter = q_vector->adapter; |
9a1a69ad | 3261 | int tx_clean_complete, work_done = 0; |
9a799d71 | 3262 | |
5dd2d332 | 3263 | #ifdef CONFIG_IXGBE_DCA |
bd0362dd JC |
3264 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
3265 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); | |
3266 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); | |
3267 | } | |
3268 | #endif | |
3269 | ||
fe49f04a | 3270 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring); |
78b6f4ce | 3271 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
9a799d71 | 3272 | |
9a1a69ad | 3273 | if (!tx_clean_complete) |
d2c7ddd6 DM |
3274 | work_done = budget; |
3275 | ||
53e52c72 DM |
3276 | /* If budget not fully consumed, exit the polling mode */ |
3277 | if (work_done < budget) { | |
288379f0 | 3278 | napi_complete(napi); |
f7554a2b | 3279 | if (adapter->rx_itr_setting & 1) |
f494e8fa | 3280 | ixgbe_set_itr(adapter); |
d4f80882 | 3281 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
835462fc | 3282 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
9a799d71 | 3283 | } |
9a799d71 AK |
3284 | return work_done; |
3285 | } | |
3286 | ||
3287 | /** | |
3288 | * ixgbe_tx_timeout - Respond to a Tx Hang | |
3289 | * @netdev: network interface device structure | |
3290 | **/ | |
3291 | static void ixgbe_tx_timeout(struct net_device *netdev) | |
3292 | { | |
3293 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
3294 | ||
3295 | /* Do the reset outside of interrupt context */ | |
3296 | schedule_work(&adapter->reset_task); | |
3297 | } | |
3298 | ||
3299 | static void ixgbe_reset_task(struct work_struct *work) | |
3300 | { | |
3301 | struct ixgbe_adapter *adapter; | |
3302 | adapter = container_of(work, struct ixgbe_adapter, reset_task); | |
3303 | ||
2f90b865 AD |
3304 | /* If we're already down or resetting, just bail */ |
3305 | if (test_bit(__IXGBE_DOWN, &adapter->state) || | |
3306 | test_bit(__IXGBE_RESETTING, &adapter->state)) | |
3307 | return; | |
3308 | ||
9a799d71 AK |
3309 | adapter->tx_timeout_count++; |
3310 | ||
d4f80882 | 3311 | ixgbe_reinit_locked(adapter); |
9a799d71 AK |
3312 | } |
3313 | ||
bc97114d PWJ |
3314 | #ifdef CONFIG_IXGBE_DCB |
3315 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) | |
b9804972 | 3316 | { |
bc97114d | 3317 | bool ret = false; |
0cefafad | 3318 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
b9804972 | 3319 | |
0cefafad JB |
3320 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
3321 | return ret; | |
3322 | ||
3323 | f->mask = 0x7 << 3; | |
3324 | adapter->num_rx_queues = f->indices; | |
3325 | adapter->num_tx_queues = f->indices; | |
3326 | ret = true; | |
2f90b865 | 3327 | |
bc97114d PWJ |
3328 | return ret; |
3329 | } | |
3330 | #endif | |
3331 | ||
4df10466 JB |
3332 | /** |
3333 | * ixgbe_set_rss_queues: Allocate queues for RSS | |
3334 | * @adapter: board private structure to initialize | |
3335 | * | |
3336 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try | |
3337 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. | |
3338 | * | |
3339 | **/ | |
bc97114d PWJ |
3340 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
3341 | { | |
3342 | bool ret = false; | |
0cefafad | 3343 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS]; |
bc97114d PWJ |
3344 | |
3345 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { | |
0cefafad JB |
3346 | f->mask = 0xF; |
3347 | adapter->num_rx_queues = f->indices; | |
3348 | adapter->num_tx_queues = f->indices; | |
bc97114d PWJ |
3349 | ret = true; |
3350 | } else { | |
bc97114d | 3351 | ret = false; |
b9804972 JB |
3352 | } |
3353 | ||
bc97114d PWJ |
3354 | return ret; |
3355 | } | |
3356 | ||
c4cf55e5 PWJ |
3357 | /** |
3358 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director | |
3359 | * @adapter: board private structure to initialize | |
3360 | * | |
3361 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back | |
3362 | * to the original CPU that initiated the Tx session. This runs in addition | |
3363 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the | |
3364 | * Rx load across CPUs using RSS. | |
3365 | * | |
3366 | **/ | |
3367 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) | |
3368 | { | |
3369 | bool ret = false; | |
3370 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; | |
3371 | ||
3372 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); | |
3373 | f_fdir->mask = 0; | |
3374 | ||
3375 | /* Flow Director must have RSS enabled */ | |
3376 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && | |
3377 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || | |
3378 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { | |
3379 | adapter->num_tx_queues = f_fdir->indices; | |
3380 | adapter->num_rx_queues = f_fdir->indices; | |
3381 | ret = true; | |
3382 | } else { | |
3383 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; | |
3384 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; | |
3385 | } | |
3386 | return ret; | |
3387 | } | |
3388 | ||
0331a832 YZ |
3389 | #ifdef IXGBE_FCOE |
3390 | /** | |
3391 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) | |
3392 | * @adapter: board private structure to initialize | |
3393 | * | |
3394 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. | |
3395 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 | |
3396 | * rx queues out of the max number of rx queues, instead, it is used as the | |
3397 | * index of the first rx queue used by FCoE. | |
3398 | * | |
3399 | **/ | |
3400 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) | |
3401 | { | |
3402 | bool ret = false; | |
3403 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; | |
3404 | ||
3405 | f->indices = min((int)num_online_cpus(), f->indices); | |
3406 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { | |
8de8b2e6 YZ |
3407 | adapter->num_rx_queues = 1; |
3408 | adapter->num_tx_queues = 1; | |
0331a832 YZ |
3409 | #ifdef CONFIG_IXGBE_DCB |
3410 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | |
8de8b2e6 | 3411 | DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n"); |
0331a832 YZ |
3412 | ixgbe_set_dcb_queues(adapter); |
3413 | } | |
3414 | #endif | |
3415 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { | |
8de8b2e6 | 3416 | DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n"); |
8faa2a78 YZ |
3417 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
3418 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) | |
3419 | ixgbe_set_fdir_queues(adapter); | |
3420 | else | |
3421 | ixgbe_set_rss_queues(adapter); | |
0331a832 YZ |
3422 | } |
3423 | /* adding FCoE rx rings to the end */ | |
3424 | f->mask = adapter->num_rx_queues; | |
3425 | adapter->num_rx_queues += f->indices; | |
8de8b2e6 | 3426 | adapter->num_tx_queues += f->indices; |
0331a832 YZ |
3427 | |
3428 | ret = true; | |
3429 | } | |
3430 | ||
3431 | return ret; | |
3432 | } | |
3433 | ||
3434 | #endif /* IXGBE_FCOE */ | |
1cdd1ec8 GR |
3435 | /** |
3436 | * ixgbe_set_sriov_queues: Allocate queues for IOV use | |
3437 | * @adapter: board private structure to initialize | |
3438 | * | |
3439 | * IOV doesn't actually use anything, so just NAK the | |
3440 | * request for now and let the other queue routines | |
3441 | * figure out what to do. | |
3442 | */ | |
3443 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) | |
3444 | { | |
3445 | return false; | |
3446 | } | |
3447 | ||
4df10466 JB |
3448 | /* |
3449 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant | |
3450 | * @adapter: board private structure to initialize | |
3451 | * | |
3452 | * This is the top level queue allocation routine. The order here is very | |
3453 | * important, starting with the "most" number of features turned on at once, | |
3454 | * and ending with the smallest set of features. This way large combinations | |
3455 | * can be allocated if they're turned on, and smaller combinations are the | |
3456 | * fallthrough conditions. | |
3457 | * | |
3458 | **/ | |
bc97114d PWJ |
3459 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
3460 | { | |
1cdd1ec8 GR |
3461 | /* Start with base case */ |
3462 | adapter->num_rx_queues = 1; | |
3463 | adapter->num_tx_queues = 1; | |
3464 | adapter->num_rx_pools = adapter->num_rx_queues; | |
3465 | adapter->num_rx_queues_per_pool = 1; | |
3466 | ||
3467 | if (ixgbe_set_sriov_queues(adapter)) | |
3468 | return; | |
3469 | ||
0331a832 YZ |
3470 | #ifdef IXGBE_FCOE |
3471 | if (ixgbe_set_fcoe_queues(adapter)) | |
3472 | goto done; | |
3473 | ||
3474 | #endif /* IXGBE_FCOE */ | |
bc97114d PWJ |
3475 | #ifdef CONFIG_IXGBE_DCB |
3476 | if (ixgbe_set_dcb_queues(adapter)) | |
af22ab1b | 3477 | goto done; |
bc97114d PWJ |
3478 | |
3479 | #endif | |
c4cf55e5 PWJ |
3480 | if (ixgbe_set_fdir_queues(adapter)) |
3481 | goto done; | |
3482 | ||
bc97114d | 3483 | if (ixgbe_set_rss_queues(adapter)) |
af22ab1b WF |
3484 | goto done; |
3485 | ||
3486 | /* fallback to base case */ | |
3487 | adapter->num_rx_queues = 1; | |
3488 | adapter->num_tx_queues = 1; | |
3489 | ||
3490 | done: | |
3491 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ | |
3492 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; | |
b9804972 JB |
3493 | } |
3494 | ||
021230d4 | 3495 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
b4617240 | 3496 | int vectors) |
021230d4 AV |
3497 | { |
3498 | int err, vector_threshold; | |
3499 | ||
3500 | /* We'll want at least 3 (vector_threshold): | |
3501 | * 1) TxQ[0] Cleanup | |
3502 | * 2) RxQ[0] Cleanup | |
3503 | * 3) Other (Link Status Change, etc.) | |
3504 | * 4) TCP Timer (optional) | |
3505 | */ | |
3506 | vector_threshold = MIN_MSIX_COUNT; | |
3507 | ||
3508 | /* The more we get, the more we will assign to Tx/Rx Cleanup | |
3509 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. | |
3510 | * Right now, we simply care about how many we'll get; we'll | |
3511 | * set them up later while requesting irq's. | |
3512 | */ | |
3513 | while (vectors >= vector_threshold) { | |
3514 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, | |
b4617240 | 3515 | vectors); |
021230d4 AV |
3516 | if (!err) /* Success in acquiring all requested vectors. */ |
3517 | break; | |
3518 | else if (err < 0) | |
3519 | vectors = 0; /* Nasty failure, quit now */ | |
3520 | else /* err == number of vectors we should try again with */ | |
3521 | vectors = err; | |
3522 | } | |
3523 | ||
3524 | if (vectors < vector_threshold) { | |
3525 | /* Can't allocate enough MSI-X interrupts? Oh well. | |
3526 | * This just means we'll go with either a single MSI | |
3527 | * vector or fall back to legacy interrupts. | |
3528 | */ | |
3529 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); | |
3530 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; | |
3531 | kfree(adapter->msix_entries); | |
3532 | adapter->msix_entries = NULL; | |
021230d4 AV |
3533 | } else { |
3534 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ | |
eb7f139c PWJ |
3535 | /* |
3536 | * Adjust for only the vectors we'll use, which is minimum | |
3537 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of | |
3538 | * vectors we were allocated. | |
3539 | */ | |
3540 | adapter->num_msix_vectors = min(vectors, | |
3541 | adapter->max_msix_q_vectors + NON_Q_VECTORS); | |
021230d4 AV |
3542 | } |
3543 | } | |
3544 | ||
021230d4 | 3545 | /** |
bc97114d | 3546 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
021230d4 AV |
3547 | * @adapter: board private structure to initialize |
3548 | * | |
bc97114d PWJ |
3549 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
3550 | * | |
021230d4 | 3551 | **/ |
bc97114d | 3552 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
021230d4 | 3553 | { |
bc97114d PWJ |
3554 | int i; |
3555 | bool ret = false; | |
3556 | ||
3557 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { | |
3558 | for (i = 0; i < adapter->num_rx_queues; i++) | |
3559 | adapter->rx_ring[i].reg_idx = i; | |
3560 | for (i = 0; i < adapter->num_tx_queues; i++) | |
3561 | adapter->tx_ring[i].reg_idx = i; | |
3562 | ret = true; | |
3563 | } else { | |
3564 | ret = false; | |
3565 | } | |
3566 | ||
3567 | return ret; | |
3568 | } | |
3569 | ||
3570 | #ifdef CONFIG_IXGBE_DCB | |
3571 | /** | |
3572 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB | |
3573 | * @adapter: board private structure to initialize | |
3574 | * | |
3575 | * Cache the descriptor ring offsets for DCB to the assigned rings. | |
3576 | * | |
3577 | **/ | |
3578 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) | |
3579 | { | |
3580 | int i; | |
3581 | bool ret = false; | |
3582 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; | |
3583 | ||
3584 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | |
3585 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { | |
2f90b865 AD |
3586 | /* the number of queues is assumed to be symmetric */ |
3587 | for (i = 0; i < dcb_i; i++) { | |
3588 | adapter->rx_ring[i].reg_idx = i << 3; | |
3589 | adapter->tx_ring[i].reg_idx = i << 2; | |
3590 | } | |
bc97114d | 3591 | ret = true; |
e8e26350 | 3592 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
f92ef202 PW |
3593 | if (dcb_i == 8) { |
3594 | /* | |
3595 | * Tx TC0 starts at: descriptor queue 0 | |
3596 | * Tx TC1 starts at: descriptor queue 32 | |
3597 | * Tx TC2 starts at: descriptor queue 64 | |
3598 | * Tx TC3 starts at: descriptor queue 80 | |
3599 | * Tx TC4 starts at: descriptor queue 96 | |
3600 | * Tx TC5 starts at: descriptor queue 104 | |
3601 | * Tx TC6 starts at: descriptor queue 112 | |
3602 | * Tx TC7 starts at: descriptor queue 120 | |
3603 | * | |
3604 | * Rx TC0-TC7 are offset by 16 queues each | |
3605 | */ | |
3606 | for (i = 0; i < 3; i++) { | |
3607 | adapter->tx_ring[i].reg_idx = i << 5; | |
3608 | adapter->rx_ring[i].reg_idx = i << 4; | |
3609 | } | |
3610 | for ( ; i < 5; i++) { | |
3611 | adapter->tx_ring[i].reg_idx = | |
3612 | ((i + 2) << 4); | |
3613 | adapter->rx_ring[i].reg_idx = i << 4; | |
3614 | } | |
3615 | for ( ; i < dcb_i; i++) { | |
3616 | adapter->tx_ring[i].reg_idx = | |
3617 | ((i + 8) << 3); | |
3618 | adapter->rx_ring[i].reg_idx = i << 4; | |
3619 | } | |
3620 | ||
3621 | ret = true; | |
3622 | } else if (dcb_i == 4) { | |
3623 | /* | |
3624 | * Tx TC0 starts at: descriptor queue 0 | |
3625 | * Tx TC1 starts at: descriptor queue 64 | |
3626 | * Tx TC2 starts at: descriptor queue 96 | |
3627 | * Tx TC3 starts at: descriptor queue 112 | |
3628 | * | |
3629 | * Rx TC0-TC3 are offset by 32 queues each | |
3630 | */ | |
3631 | adapter->tx_ring[0].reg_idx = 0; | |
3632 | adapter->tx_ring[1].reg_idx = 64; | |
3633 | adapter->tx_ring[2].reg_idx = 96; | |
3634 | adapter->tx_ring[3].reg_idx = 112; | |
3635 | for (i = 0 ; i < dcb_i; i++) | |
3636 | adapter->rx_ring[i].reg_idx = i << 5; | |
3637 | ||
3638 | ret = true; | |
3639 | } else { | |
3640 | ret = false; | |
e8e26350 | 3641 | } |
bc97114d PWJ |
3642 | } else { |
3643 | ret = false; | |
021230d4 | 3644 | } |
bc97114d PWJ |
3645 | } else { |
3646 | ret = false; | |
021230d4 | 3647 | } |
bc97114d PWJ |
3648 | |
3649 | return ret; | |
3650 | } | |
3651 | #endif | |
3652 | ||
c4cf55e5 PWJ |
3653 | /** |
3654 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director | |
3655 | * @adapter: board private structure to initialize | |
3656 | * | |
3657 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. | |
3658 | * | |
3659 | **/ | |
3660 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) | |
3661 | { | |
3662 | int i; | |
3663 | bool ret = false; | |
3664 | ||
3665 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && | |
3666 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || | |
3667 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { | |
3668 | for (i = 0; i < adapter->num_rx_queues; i++) | |
3669 | adapter->rx_ring[i].reg_idx = i; | |
3670 | for (i = 0; i < adapter->num_tx_queues; i++) | |
3671 | adapter->tx_ring[i].reg_idx = i; | |
3672 | ret = true; | |
3673 | } | |
3674 | ||
3675 | return ret; | |
3676 | } | |
3677 | ||
0331a832 YZ |
3678 | #ifdef IXGBE_FCOE |
3679 | /** | |
3680 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE | |
3681 | * @adapter: board private structure to initialize | |
3682 | * | |
3683 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. | |
3684 | * | |
3685 | */ | |
3686 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) | |
3687 | { | |
8de8b2e6 | 3688 | int i, fcoe_rx_i = 0, fcoe_tx_i = 0; |
0331a832 YZ |
3689 | bool ret = false; |
3690 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; | |
3691 | ||
3692 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { | |
3693 | #ifdef CONFIG_IXGBE_DCB | |
3694 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | |
8de8b2e6 YZ |
3695 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
3696 | ||
0331a832 | 3697 | ixgbe_cache_ring_dcb(adapter); |
8de8b2e6 YZ |
3698 | /* find out queues in TC for FCoE */ |
3699 | fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1; | |
3700 | fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1; | |
3701 | /* | |
3702 | * In 82599, the number of Tx queues for each traffic | |
3703 | * class for both 8-TC and 4-TC modes are: | |
3704 | * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7 | |
3705 | * 8 TCs: 32 32 16 16 8 8 8 8 | |
3706 | * 4 TCs: 64 64 32 32 | |
3707 | * We have max 8 queues for FCoE, where 8 the is | |
3708 | * FCoE redirection table size. If TC for FCoE is | |
3709 | * less than or equal to TC3, we have enough queues | |
3710 | * to add max of 8 queues for FCoE, so we start FCoE | |
3711 | * tx descriptor from the next one, i.e., reg_idx + 1. | |
3712 | * If TC for FCoE is above TC3, implying 8 TC mode, | |
3713 | * and we need 8 for FCoE, we have to take all queues | |
3714 | * in that traffic class for FCoE. | |
3715 | */ | |
3716 | if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3)) | |
3717 | fcoe_tx_i--; | |
0331a832 YZ |
3718 | } |
3719 | #endif /* CONFIG_IXGBE_DCB */ | |
3720 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { | |
8faa2a78 YZ |
3721 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
3722 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) | |
3723 | ixgbe_cache_ring_fdir(adapter); | |
3724 | else | |
3725 | ixgbe_cache_ring_rss(adapter); | |
3726 | ||
8de8b2e6 YZ |
3727 | fcoe_rx_i = f->mask; |
3728 | fcoe_tx_i = f->mask; | |
3729 | } | |
3730 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { | |
3731 | adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i; | |
3732 | adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i; | |
0331a832 | 3733 | } |
0331a832 YZ |
3734 | ret = true; |
3735 | } | |
3736 | return ret; | |
3737 | } | |
3738 | ||
3739 | #endif /* IXGBE_FCOE */ | |
1cdd1ec8 GR |
3740 | /** |
3741 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov | |
3742 | * @adapter: board private structure to initialize | |
3743 | * | |
3744 | * SR-IOV doesn't use any descriptor rings but changes the default if | |
3745 | * no other mapping is used. | |
3746 | * | |
3747 | */ | |
3748 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) | |
3749 | { | |
3750 | adapter->rx_ring[0].reg_idx = adapter->num_vfs * 2; | |
3751 | adapter->tx_ring[0].reg_idx = adapter->num_vfs * 2; | |
3752 | if (adapter->num_vfs) | |
3753 | return true; | |
3754 | else | |
3755 | return false; | |
3756 | } | |
3757 | ||
bc97114d PWJ |
3758 | /** |
3759 | * ixgbe_cache_ring_register - Descriptor ring to register mapping | |
3760 | * @adapter: board private structure to initialize | |
3761 | * | |
3762 | * Once we know the feature-set enabled for the device, we'll cache | |
3763 | * the register offset the descriptor ring is assigned to. | |
3764 | * | |
3765 | * Note, the order the various feature calls is important. It must start with | |
3766 | * the "most" features enabled at the same time, then trickle down to the | |
3767 | * least amount of features turned on at once. | |
3768 | **/ | |
3769 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) | |
3770 | { | |
3771 | /* start with default case */ | |
3772 | adapter->rx_ring[0].reg_idx = 0; | |
3773 | adapter->tx_ring[0].reg_idx = 0; | |
3774 | ||
1cdd1ec8 GR |
3775 | if (ixgbe_cache_ring_sriov(adapter)) |
3776 | return; | |
3777 | ||
0331a832 YZ |
3778 | #ifdef IXGBE_FCOE |
3779 | if (ixgbe_cache_ring_fcoe(adapter)) | |
3780 | return; | |
3781 | ||
3782 | #endif /* IXGBE_FCOE */ | |
bc97114d PWJ |
3783 | #ifdef CONFIG_IXGBE_DCB |
3784 | if (ixgbe_cache_ring_dcb(adapter)) | |
3785 | return; | |
3786 | ||
3787 | #endif | |
c4cf55e5 PWJ |
3788 | if (ixgbe_cache_ring_fdir(adapter)) |
3789 | return; | |
3790 | ||
bc97114d PWJ |
3791 | if (ixgbe_cache_ring_rss(adapter)) |
3792 | return; | |
021230d4 AV |
3793 | } |
3794 | ||
9a799d71 AK |
3795 | /** |
3796 | * ixgbe_alloc_queues - Allocate memory for all rings | |
3797 | * @adapter: board private structure to initialize | |
3798 | * | |
3799 | * We allocate one ring per queue at run-time since we don't know the | |
4df10466 JB |
3800 | * number of queues at compile-time. The polling_netdev array is |
3801 | * intended for Multiqueue, but should work fine with a single queue. | |
9a799d71 | 3802 | **/ |
2f90b865 | 3803 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
9a799d71 AK |
3804 | { |
3805 | int i; | |
3806 | ||
3807 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, | |
b4617240 | 3808 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
9a799d71 | 3809 | if (!adapter->tx_ring) |
021230d4 | 3810 | goto err_tx_ring_allocation; |
9a799d71 AK |
3811 | |
3812 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, | |
b4617240 | 3813 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
021230d4 AV |
3814 | if (!adapter->rx_ring) |
3815 | goto err_rx_ring_allocation; | |
9a799d71 | 3816 | |
021230d4 | 3817 | for (i = 0; i < adapter->num_tx_queues; i++) { |
b9804972 | 3818 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
021230d4 AV |
3819 | adapter->tx_ring[i].queue_index = i; |
3820 | } | |
b9804972 | 3821 | |
9a799d71 | 3822 | for (i = 0; i < adapter->num_rx_queues; i++) { |
b9804972 | 3823 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
021230d4 AV |
3824 | adapter->rx_ring[i].queue_index = i; |
3825 | } | |
3826 | ||
3827 | ixgbe_cache_ring_register(adapter); | |
3828 | ||
3829 | return 0; | |
3830 | ||
3831 | err_rx_ring_allocation: | |
3832 | kfree(adapter->tx_ring); | |
3833 | err_tx_ring_allocation: | |
3834 | return -ENOMEM; | |
3835 | } | |
3836 | ||
3837 | /** | |
3838 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported | |
3839 | * @adapter: board private structure to initialize | |
3840 | * | |
3841 | * Attempt to configure the interrupts using the best available | |
3842 | * capabilities of the hardware and the kernel. | |
3843 | **/ | |
feea6a57 | 3844 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
021230d4 | 3845 | { |
8be0e467 | 3846 | struct ixgbe_hw *hw = &adapter->hw; |
021230d4 AV |
3847 | int err = 0; |
3848 | int vector, v_budget; | |
3849 | ||
3850 | /* | |
3851 | * It's easy to be greedy for MSI-X vectors, but it really | |
3852 | * doesn't do us much good if we have a lot more vectors | |
3853 | * than CPU's. So let's be conservative and only ask for | |
342bde1b | 3854 | * (roughly) the same number of vectors as there are CPU's. |
021230d4 AV |
3855 | */ |
3856 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, | |
342bde1b | 3857 | (int)num_online_cpus()) + NON_Q_VECTORS; |
021230d4 AV |
3858 | |
3859 | /* | |
3860 | * At the same time, hardware can only support a maximum of | |
8be0e467 PW |
3861 | * hw.mac->max_msix_vectors vectors. With features |
3862 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx | |
3863 | * descriptor queues supported by our device. Thus, we cap it off in | |
3864 | * those rare cases where the cpu count also exceeds our vector limit. | |
021230d4 | 3865 | */ |
8be0e467 | 3866 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
021230d4 AV |
3867 | |
3868 | /* A failure in MSI-X entry allocation isn't fatal, but it does | |
3869 | * mean we disable MSI-X capabilities of the adapter. */ | |
3870 | adapter->msix_entries = kcalloc(v_budget, | |
b4617240 | 3871 | sizeof(struct msix_entry), GFP_KERNEL); |
7a921c93 AD |
3872 | if (adapter->msix_entries) { |
3873 | for (vector = 0; vector < v_budget; vector++) | |
3874 | adapter->msix_entries[vector].entry = vector; | |
021230d4 | 3875 | |
7a921c93 | 3876 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
021230d4 | 3877 | |
7a921c93 AD |
3878 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
3879 | goto out; | |
3880 | } | |
021230d4 | 3881 | |
7a921c93 AD |
3882 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
3883 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; | |
c4cf55e5 PWJ |
3884 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
3885 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; | |
3886 | adapter->atr_sample_rate = 0; | |
1cdd1ec8 GR |
3887 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
3888 | ixgbe_disable_sriov(adapter); | |
3889 | ||
7a921c93 | 3890 | ixgbe_set_num_queues(adapter); |
021230d4 | 3891 | |
021230d4 AV |
3892 | err = pci_enable_msi(adapter->pdev); |
3893 | if (!err) { | |
3894 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; | |
3895 | } else { | |
3896 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " | |
b4617240 | 3897 | "falling back to legacy. Error: %d\n", err); |
021230d4 AV |
3898 | /* reset err */ |
3899 | err = 0; | |
3900 | } | |
3901 | ||
3902 | out: | |
021230d4 AV |
3903 | return err; |
3904 | } | |
3905 | ||
7a921c93 AD |
3906 | /** |
3907 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors | |
3908 | * @adapter: board private structure to initialize | |
3909 | * | |
3910 | * We allocate one q_vector per queue interrupt. If allocation fails we | |
3911 | * return -ENOMEM. | |
3912 | **/ | |
3913 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) | |
3914 | { | |
3915 | int q_idx, num_q_vectors; | |
3916 | struct ixgbe_q_vector *q_vector; | |
3917 | int napi_vectors; | |
3918 | int (*poll)(struct napi_struct *, int); | |
3919 | ||
3920 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | |
3921 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | |
3922 | napi_vectors = adapter->num_rx_queues; | |
91281fd3 | 3923 | poll = &ixgbe_clean_rxtx_many; |
7a921c93 AD |
3924 | } else { |
3925 | num_q_vectors = 1; | |
3926 | napi_vectors = 1; | |
3927 | poll = &ixgbe_poll; | |
3928 | } | |
3929 | ||
3930 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { | |
3931 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL); | |
3932 | if (!q_vector) | |
3933 | goto err_out; | |
3934 | q_vector->adapter = adapter; | |
f7554a2b NS |
3935 | if (q_vector->txr_count && !q_vector->rxr_count) |
3936 | q_vector->eitr = adapter->tx_eitr_param; | |
3937 | else | |
3938 | q_vector->eitr = adapter->rx_eitr_param; | |
fe49f04a | 3939 | q_vector->v_idx = q_idx; |
91281fd3 | 3940 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
7a921c93 AD |
3941 | adapter->q_vector[q_idx] = q_vector; |
3942 | } | |
3943 | ||
3944 | return 0; | |
3945 | ||
3946 | err_out: | |
3947 | while (q_idx) { | |
3948 | q_idx--; | |
3949 | q_vector = adapter->q_vector[q_idx]; | |
3950 | netif_napi_del(&q_vector->napi); | |
3951 | kfree(q_vector); | |
3952 | adapter->q_vector[q_idx] = NULL; | |
3953 | } | |
3954 | return -ENOMEM; | |
3955 | } | |
3956 | ||
3957 | /** | |
3958 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors | |
3959 | * @adapter: board private structure to initialize | |
3960 | * | |
3961 | * This function frees the memory allocated to the q_vectors. In addition if | |
3962 | * NAPI is enabled it will delete any references to the NAPI struct prior | |
3963 | * to freeing the q_vector. | |
3964 | **/ | |
3965 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) | |
3966 | { | |
3967 | int q_idx, num_q_vectors; | |
7a921c93 | 3968 | |
91281fd3 | 3969 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
7a921c93 | 3970 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
91281fd3 | 3971 | else |
7a921c93 | 3972 | num_q_vectors = 1; |
7a921c93 AD |
3973 | |
3974 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { | |
3975 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; | |
7a921c93 | 3976 | adapter->q_vector[q_idx] = NULL; |
91281fd3 | 3977 | netif_napi_del(&q_vector->napi); |
7a921c93 AD |
3978 | kfree(q_vector); |
3979 | } | |
3980 | } | |
3981 | ||
7b25cdba | 3982 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
021230d4 AV |
3983 | { |
3984 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { | |
3985 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; | |
3986 | pci_disable_msix(adapter->pdev); | |
3987 | kfree(adapter->msix_entries); | |
3988 | adapter->msix_entries = NULL; | |
3989 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { | |
3990 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; | |
3991 | pci_disable_msi(adapter->pdev); | |
3992 | } | |
3993 | return; | |
3994 | } | |
3995 | ||
3996 | /** | |
3997 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme | |
3998 | * @adapter: board private structure to initialize | |
3999 | * | |
4000 | * We determine which interrupt scheme to use based on... | |
4001 | * - Kernel support (MSI, MSI-X) | |
4002 | * - which can be user-defined (via MODULE_PARAM) | |
4003 | * - Hardware queue count (num_*_queues) | |
4004 | * - defined by miscellaneous hardware support/features (RSS, etc.) | |
4005 | **/ | |
2f90b865 | 4006 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
021230d4 AV |
4007 | { |
4008 | int err; | |
4009 | ||
4010 | /* Number of supported queues */ | |
4011 | ixgbe_set_num_queues(adapter); | |
4012 | ||
021230d4 AV |
4013 | err = ixgbe_set_interrupt_capability(adapter); |
4014 | if (err) { | |
4015 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); | |
4016 | goto err_set_interrupt; | |
9a799d71 AK |
4017 | } |
4018 | ||
7a921c93 AD |
4019 | err = ixgbe_alloc_q_vectors(adapter); |
4020 | if (err) { | |
4021 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " | |
4022 | "vectors\n"); | |
4023 | goto err_alloc_q_vectors; | |
4024 | } | |
4025 | ||
4026 | err = ixgbe_alloc_queues(adapter); | |
4027 | if (err) { | |
4028 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); | |
4029 | goto err_alloc_queues; | |
4030 | } | |
4031 | ||
021230d4 | 4032 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
b4617240 PW |
4033 | "Tx Queue count = %u\n", |
4034 | (adapter->num_rx_queues > 1) ? "Enabled" : | |
4035 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); | |
021230d4 AV |
4036 | |
4037 | set_bit(__IXGBE_DOWN, &adapter->state); | |
4038 | ||
9a799d71 | 4039 | return 0; |
021230d4 | 4040 | |
7a921c93 AD |
4041 | err_alloc_queues: |
4042 | ixgbe_free_q_vectors(adapter); | |
4043 | err_alloc_q_vectors: | |
4044 | ixgbe_reset_interrupt_capability(adapter); | |
021230d4 | 4045 | err_set_interrupt: |
7a921c93 AD |
4046 | return err; |
4047 | } | |
4048 | ||
4049 | /** | |
4050 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings | |
4051 | * @adapter: board private structure to clear interrupt scheme on | |
4052 | * | |
4053 | * We go through and clear interrupt specific resources and reset the structure | |
4054 | * to pre-load conditions | |
4055 | **/ | |
4056 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) | |
4057 | { | |
021230d4 AV |
4058 | kfree(adapter->tx_ring); |
4059 | kfree(adapter->rx_ring); | |
7a921c93 AD |
4060 | adapter->tx_ring = NULL; |
4061 | adapter->rx_ring = NULL; | |
4062 | ||
4063 | ixgbe_free_q_vectors(adapter); | |
4064 | ixgbe_reset_interrupt_capability(adapter); | |
9a799d71 AK |
4065 | } |
4066 | ||
c4900be0 DS |
4067 | /** |
4068 | * ixgbe_sfp_timer - worker thread to find a missing module | |
4069 | * @data: pointer to our adapter struct | |
4070 | **/ | |
4071 | static void ixgbe_sfp_timer(unsigned long data) | |
4072 | { | |
4073 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; | |
4074 | ||
4df10466 JB |
4075 | /* |
4076 | * Do the sfp_timer outside of interrupt context due to the | |
c4900be0 DS |
4077 | * delays that sfp+ detection requires |
4078 | */ | |
4079 | schedule_work(&adapter->sfp_task); | |
4080 | } | |
4081 | ||
4082 | /** | |
4083 | * ixgbe_sfp_task - worker thread to find a missing module | |
4084 | * @work: pointer to work_struct containing our data | |
4085 | **/ | |
4086 | static void ixgbe_sfp_task(struct work_struct *work) | |
4087 | { | |
4088 | struct ixgbe_adapter *adapter = container_of(work, | |
4089 | struct ixgbe_adapter, | |
4090 | sfp_task); | |
4091 | struct ixgbe_hw *hw = &adapter->hw; | |
4092 | ||
4093 | if ((hw->phy.type == ixgbe_phy_nl) && | |
4094 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { | |
4095 | s32 ret = hw->phy.ops.identify_sfp(hw); | |
63d6e1d8 | 4096 | if (ret == IXGBE_ERR_SFP_NOT_PRESENT) |
c4900be0 DS |
4097 | goto reschedule; |
4098 | ret = hw->phy.ops.reset(hw); | |
4099 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { | |
88d2b81f DS |
4100 | dev_err(&adapter->pdev->dev, "failed to initialize " |
4101 | "because an unsupported SFP+ module type " | |
4102 | "was detected.\n" | |
4103 | "Reload the driver after installing a " | |
4104 | "supported module.\n"); | |
c4900be0 DS |
4105 | unregister_netdev(adapter->netdev); |
4106 | } else { | |
4107 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", | |
4108 | hw->phy.sfp_type); | |
4109 | } | |
4110 | /* don't need this routine any more */ | |
4111 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); | |
4112 | } | |
4113 | return; | |
4114 | reschedule: | |
4115 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) | |
4116 | mod_timer(&adapter->sfp_timer, | |
4117 | round_jiffies(jiffies + (2 * HZ))); | |
4118 | } | |
4119 | ||
9a799d71 AK |
4120 | /** |
4121 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) | |
4122 | * @adapter: board private structure to initialize | |
4123 | * | |
4124 | * ixgbe_sw_init initializes the Adapter private data structure. | |
4125 | * Fields are initialized based on PCI device information and | |
4126 | * OS network device settings (MTU size). | |
4127 | **/ | |
4128 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) | |
4129 | { | |
4130 | struct ixgbe_hw *hw = &adapter->hw; | |
4131 | struct pci_dev *pdev = adapter->pdev; | |
021230d4 | 4132 | unsigned int rss; |
7a6b6f51 | 4133 | #ifdef CONFIG_IXGBE_DCB |
2f90b865 AD |
4134 | int j; |
4135 | struct tc_configuration *tc; | |
4136 | #endif | |
021230d4 | 4137 | |
c44ade9e JB |
4138 | /* PCI config space info */ |
4139 | ||
4140 | hw->vendor_id = pdev->vendor; | |
4141 | hw->device_id = pdev->device; | |
4142 | hw->revision_id = pdev->revision; | |
4143 | hw->subsystem_vendor_id = pdev->subsystem_vendor; | |
4144 | hw->subsystem_device_id = pdev->subsystem_device; | |
4145 | ||
021230d4 AV |
4146 | /* Set capability flags */ |
4147 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); | |
4148 | adapter->ring_feature[RING_F_RSS].indices = rss; | |
4149 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; | |
2f90b865 | 4150 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
bf069c97 DS |
4151 | if (hw->mac.type == ixgbe_mac_82598EB) { |
4152 | if (hw->device_id == IXGBE_DEV_ID_82598AT) | |
4153 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; | |
e8e26350 | 4154 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
bf069c97 | 4155 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
e8e26350 | 4156 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
0c19d6af PWJ |
4157 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
4158 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; | |
c4cf55e5 PWJ |
4159 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
4160 | adapter->ring_feature[RING_F_FDIR].indices = | |
4161 | IXGBE_MAX_FDIR_INDICES; | |
4162 | adapter->atr_sample_rate = 20; | |
4163 | adapter->fdir_pballoc = 0; | |
eacd73f7 | 4164 | #ifdef IXGBE_FCOE |
0d551589 YZ |
4165 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
4166 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; | |
4167 | adapter->ring_feature[RING_F_FCOE].indices = 0; | |
61a0f421 | 4168 | #ifdef CONFIG_IXGBE_DCB |
6ee16520 YZ |
4169 | /* Default traffic class to use for FCoE */ |
4170 | adapter->fcoe.tc = IXGBE_FCOE_DEFTC; | |
61a0f421 | 4171 | #endif |
eacd73f7 | 4172 | #endif /* IXGBE_FCOE */ |
f8212f97 | 4173 | } |
2f90b865 | 4174 | |
7a6b6f51 | 4175 | #ifdef CONFIG_IXGBE_DCB |
2f90b865 AD |
4176 | /* Configure DCB traffic classes */ |
4177 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { | |
4178 | tc = &adapter->dcb_cfg.tc_config[j]; | |
4179 | tc->path[DCB_TX_CONFIG].bwg_id = 0; | |
4180 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); | |
4181 | tc->path[DCB_RX_CONFIG].bwg_id = 0; | |
4182 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); | |
4183 | tc->dcb_pfc = pfc_disabled; | |
4184 | } | |
4185 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; | |
4186 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; | |
4187 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; | |
264857b8 | 4188 | adapter->dcb_cfg.pfc_mode_enable = false; |
2f90b865 AD |
4189 | adapter->dcb_cfg.round_robin_enable = false; |
4190 | adapter->dcb_set_bitmap = 0x00; | |
4191 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, | |
4192 | adapter->ring_feature[RING_F_DCB].indices); | |
4193 | ||
4194 | #endif | |
9a799d71 AK |
4195 | |
4196 | /* default flow control settings */ | |
cd7664f6 | 4197 | hw->fc.requested_mode = ixgbe_fc_full; |
71fd570b | 4198 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
264857b8 PWJ |
4199 | #ifdef CONFIG_DCB |
4200 | adapter->last_lfc_mode = hw->fc.current_mode; | |
4201 | #endif | |
2b9ade93 JB |
4202 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
4203 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; | |
4204 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; | |
4205 | hw->fc.send_xon = true; | |
71fd570b | 4206 | hw->fc.disable_fc_autoneg = false; |
9a799d71 | 4207 | |
30efa5a3 | 4208 | /* enable itr by default in dynamic mode */ |
f7554a2b NS |
4209 | adapter->rx_itr_setting = 1; |
4210 | adapter->rx_eitr_param = 20000; | |
4211 | adapter->tx_itr_setting = 1; | |
4212 | adapter->tx_eitr_param = 10000; | |
30efa5a3 JB |
4213 | |
4214 | /* set defaults for eitr in MegaBytes */ | |
4215 | adapter->eitr_low = 10; | |
4216 | adapter->eitr_high = 20; | |
4217 | ||
4218 | /* set default ring sizes */ | |
4219 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; | |
4220 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; | |
4221 | ||
9a799d71 | 4222 | /* initialize eeprom parameters */ |
c44ade9e | 4223 | if (ixgbe_init_eeprom_params_generic(hw)) { |
9a799d71 AK |
4224 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
4225 | return -EIO; | |
4226 | } | |
4227 | ||
021230d4 | 4228 | /* enable rx csum by default */ |
9a799d71 AK |
4229 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
4230 | ||
9a799d71 AK |
4231 | set_bit(__IXGBE_DOWN, &adapter->state); |
4232 | ||
4233 | return 0; | |
4234 | } | |
4235 | ||
4236 | /** | |
4237 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) | |
4238 | * @adapter: board private structure | |
3a581073 | 4239 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
9a799d71 AK |
4240 | * |
4241 | * Return 0 on success, negative on failure | |
4242 | **/ | |
4243 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, | |
e01c31a5 | 4244 | struct ixgbe_ring *tx_ring) |
9a799d71 AK |
4245 | { |
4246 | struct pci_dev *pdev = adapter->pdev; | |
4247 | int size; | |
4248 | ||
3a581073 JB |
4249 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
4250 | tx_ring->tx_buffer_info = vmalloc(size); | |
e01c31a5 JB |
4251 | if (!tx_ring->tx_buffer_info) |
4252 | goto err; | |
3a581073 | 4253 | memset(tx_ring->tx_buffer_info, 0, size); |
9a799d71 AK |
4254 | |
4255 | /* round up to nearest 4K */ | |
12207e49 | 4256 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
3a581073 | 4257 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
9a799d71 | 4258 | |
3a581073 JB |
4259 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
4260 | &tx_ring->dma); | |
e01c31a5 JB |
4261 | if (!tx_ring->desc) |
4262 | goto err; | |
9a799d71 | 4263 | |
3a581073 JB |
4264 | tx_ring->next_to_use = 0; |
4265 | tx_ring->next_to_clean = 0; | |
4266 | tx_ring->work_limit = tx_ring->count; | |
9a799d71 | 4267 | return 0; |
e01c31a5 JB |
4268 | |
4269 | err: | |
4270 | vfree(tx_ring->tx_buffer_info); | |
4271 | tx_ring->tx_buffer_info = NULL; | |
4272 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " | |
4273 | "descriptor ring\n"); | |
4274 | return -ENOMEM; | |
9a799d71 AK |
4275 | } |
4276 | ||
69888674 AD |
4277 | /** |
4278 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources | |
4279 | * @adapter: board private structure | |
4280 | * | |
4281 | * If this function returns with an error, then it's possible one or | |
4282 | * more of the rings is populated (while the rest are not). It is the | |
4283 | * callers duty to clean those orphaned rings. | |
4284 | * | |
4285 | * Return 0 on success, negative on failure | |
4286 | **/ | |
4287 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) | |
4288 | { | |
4289 | int i, err = 0; | |
4290 | ||
4291 | for (i = 0; i < adapter->num_tx_queues; i++) { | |
4292 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); | |
4293 | if (!err) | |
4294 | continue; | |
4295 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); | |
4296 | break; | |
4297 | } | |
4298 | ||
4299 | return err; | |
4300 | } | |
4301 | ||
9a799d71 AK |
4302 | /** |
4303 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) | |
4304 | * @adapter: board private structure | |
3a581073 | 4305 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
9a799d71 AK |
4306 | * |
4307 | * Returns 0 on success, negative on failure | |
4308 | **/ | |
4309 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, | |
b4617240 | 4310 | struct ixgbe_ring *rx_ring) |
9a799d71 AK |
4311 | { |
4312 | struct pci_dev *pdev = adapter->pdev; | |
021230d4 | 4313 | int size; |
9a799d71 | 4314 | |
3a581073 JB |
4315 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
4316 | rx_ring->rx_buffer_info = vmalloc(size); | |
4317 | if (!rx_ring->rx_buffer_info) { | |
9a799d71 | 4318 | DPRINTK(PROBE, ERR, |
b4617240 | 4319 | "vmalloc allocation failed for the rx desc ring\n"); |
177db6ff | 4320 | goto alloc_failed; |
9a799d71 | 4321 | } |
3a581073 | 4322 | memset(rx_ring->rx_buffer_info, 0, size); |
9a799d71 | 4323 | |
9a799d71 | 4324 | /* Round up to nearest 4K */ |
3a581073 JB |
4325 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
4326 | rx_ring->size = ALIGN(rx_ring->size, 4096); | |
9a799d71 | 4327 | |
3a581073 | 4328 | rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma); |
9a799d71 | 4329 | |
3a581073 | 4330 | if (!rx_ring->desc) { |
9a799d71 | 4331 | DPRINTK(PROBE, ERR, |
b4617240 | 4332 | "Memory allocation failed for the rx desc ring\n"); |
3a581073 | 4333 | vfree(rx_ring->rx_buffer_info); |
177db6ff | 4334 | goto alloc_failed; |
9a799d71 AK |
4335 | } |
4336 | ||
3a581073 JB |
4337 | rx_ring->next_to_clean = 0; |
4338 | rx_ring->next_to_use = 0; | |
9a799d71 AK |
4339 | |
4340 | return 0; | |
177db6ff MC |
4341 | |
4342 | alloc_failed: | |
177db6ff | 4343 | return -ENOMEM; |
9a799d71 AK |
4344 | } |
4345 | ||
69888674 AD |
4346 | /** |
4347 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources | |
4348 | * @adapter: board private structure | |
4349 | * | |
4350 | * If this function returns with an error, then it's possible one or | |
4351 | * more of the rings is populated (while the rest are not). It is the | |
4352 | * callers duty to clean those orphaned rings. | |
4353 | * | |
4354 | * Return 0 on success, negative on failure | |
4355 | **/ | |
4356 | ||
4357 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) | |
4358 | { | |
4359 | int i, err = 0; | |
4360 | ||
4361 | for (i = 0; i < adapter->num_rx_queues; i++) { | |
4362 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); | |
4363 | if (!err) | |
4364 | continue; | |
4365 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); | |
4366 | break; | |
4367 | } | |
4368 | ||
4369 | return err; | |
4370 | } | |
4371 | ||
9a799d71 AK |
4372 | /** |
4373 | * ixgbe_free_tx_resources - Free Tx Resources per Queue | |
4374 | * @adapter: board private structure | |
4375 | * @tx_ring: Tx descriptor ring for a specific queue | |
4376 | * | |
4377 | * Free all transmit software resources | |
4378 | **/ | |
c431f97e JB |
4379 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
4380 | struct ixgbe_ring *tx_ring) | |
9a799d71 AK |
4381 | { |
4382 | struct pci_dev *pdev = adapter->pdev; | |
4383 | ||
4384 | ixgbe_clean_tx_ring(adapter, tx_ring); | |
4385 | ||
4386 | vfree(tx_ring->tx_buffer_info); | |
4387 | tx_ring->tx_buffer_info = NULL; | |
4388 | ||
4389 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); | |
4390 | ||
4391 | tx_ring->desc = NULL; | |
4392 | } | |
4393 | ||
4394 | /** | |
4395 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues | |
4396 | * @adapter: board private structure | |
4397 | * | |
4398 | * Free all transmit software resources | |
4399 | **/ | |
4400 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) | |
4401 | { | |
4402 | int i; | |
4403 | ||
4404 | for (i = 0; i < adapter->num_tx_queues; i++) | |
9891ca7c JB |
4405 | if (adapter->tx_ring[i].desc) |
4406 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); | |
9a799d71 AK |
4407 | } |
4408 | ||
4409 | /** | |
b4617240 | 4410 | * ixgbe_free_rx_resources - Free Rx Resources |
9a799d71 AK |
4411 | * @adapter: board private structure |
4412 | * @rx_ring: ring to clean the resources from | |
4413 | * | |
4414 | * Free all receive software resources | |
4415 | **/ | |
c431f97e JB |
4416 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
4417 | struct ixgbe_ring *rx_ring) | |
9a799d71 AK |
4418 | { |
4419 | struct pci_dev *pdev = adapter->pdev; | |
4420 | ||
4421 | ixgbe_clean_rx_ring(adapter, rx_ring); | |
4422 | ||
4423 | vfree(rx_ring->rx_buffer_info); | |
4424 | rx_ring->rx_buffer_info = NULL; | |
4425 | ||
4426 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); | |
4427 | ||
4428 | rx_ring->desc = NULL; | |
4429 | } | |
4430 | ||
4431 | /** | |
4432 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues | |
4433 | * @adapter: board private structure | |
4434 | * | |
4435 | * Free all receive software resources | |
4436 | **/ | |
4437 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) | |
4438 | { | |
4439 | int i; | |
4440 | ||
4441 | for (i = 0; i < adapter->num_rx_queues; i++) | |
9891ca7c JB |
4442 | if (adapter->rx_ring[i].desc) |
4443 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); | |
9a799d71 AK |
4444 | } |
4445 | ||
9a799d71 AK |
4446 | /** |
4447 | * ixgbe_change_mtu - Change the Maximum Transfer Unit | |
4448 | * @netdev: network interface device structure | |
4449 | * @new_mtu: new value for maximum frame size | |
4450 | * | |
4451 | * Returns 0 on success, negative on failure | |
4452 | **/ | |
4453 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) | |
4454 | { | |
4455 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
4456 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | |
4457 | ||
42c783c5 JB |
4458 | /* MTU < 68 is an error and causes problems on some kernels */ |
4459 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) | |
9a799d71 AK |
4460 | return -EINVAL; |
4461 | ||
021230d4 | 4462 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
b4617240 | 4463 | netdev->mtu, new_mtu); |
021230d4 | 4464 | /* must set new MTU before calling down or up */ |
9a799d71 AK |
4465 | netdev->mtu = new_mtu; |
4466 | ||
d4f80882 AV |
4467 | if (netif_running(netdev)) |
4468 | ixgbe_reinit_locked(adapter); | |
9a799d71 AK |
4469 | |
4470 | return 0; | |
4471 | } | |
4472 | ||
4473 | /** | |
4474 | * ixgbe_open - Called when a network interface is made active | |
4475 | * @netdev: network interface device structure | |
4476 | * | |
4477 | * Returns 0 on success, negative value on failure | |
4478 | * | |
4479 | * The open entry point is called when a network interface is made | |
4480 | * active by the system (IFF_UP). At this point all resources needed | |
4481 | * for transmit and receive operations are allocated, the interrupt | |
4482 | * handler is registered with the OS, the watchdog timer is started, | |
4483 | * and the stack is notified that the interface is ready. | |
4484 | **/ | |
4485 | static int ixgbe_open(struct net_device *netdev) | |
4486 | { | |
4487 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
4488 | int err; | |
4bebfaa5 AK |
4489 | |
4490 | /* disallow open during test */ | |
4491 | if (test_bit(__IXGBE_TESTING, &adapter->state)) | |
4492 | return -EBUSY; | |
9a799d71 | 4493 | |
54386467 JB |
4494 | netif_carrier_off(netdev); |
4495 | ||
9a799d71 AK |
4496 | /* allocate transmit descriptors */ |
4497 | err = ixgbe_setup_all_tx_resources(adapter); | |
4498 | if (err) | |
4499 | goto err_setup_tx; | |
4500 | ||
9a799d71 AK |
4501 | /* allocate receive descriptors */ |
4502 | err = ixgbe_setup_all_rx_resources(adapter); | |
4503 | if (err) | |
4504 | goto err_setup_rx; | |
4505 | ||
4506 | ixgbe_configure(adapter); | |
4507 | ||
021230d4 | 4508 | err = ixgbe_request_irq(adapter); |
9a799d71 AK |
4509 | if (err) |
4510 | goto err_req_irq; | |
4511 | ||
9a799d71 AK |
4512 | err = ixgbe_up_complete(adapter); |
4513 | if (err) | |
4514 | goto err_up; | |
4515 | ||
d55b53ff JK |
4516 | netif_tx_start_all_queues(netdev); |
4517 | ||
9a799d71 AK |
4518 | return 0; |
4519 | ||
4520 | err_up: | |
5eba3699 | 4521 | ixgbe_release_hw_control(adapter); |
9a799d71 AK |
4522 | ixgbe_free_irq(adapter); |
4523 | err_req_irq: | |
9a799d71 | 4524 | err_setup_rx: |
a20a1199 | 4525 | ixgbe_free_all_rx_resources(adapter); |
9a799d71 | 4526 | err_setup_tx: |
a20a1199 | 4527 | ixgbe_free_all_tx_resources(adapter); |
9a799d71 AK |
4528 | ixgbe_reset(adapter); |
4529 | ||
4530 | return err; | |
4531 | } | |
4532 | ||
4533 | /** | |
4534 | * ixgbe_close - Disables a network interface | |
4535 | * @netdev: network interface device structure | |
4536 | * | |
4537 | * Returns 0, this is not allowed to fail | |
4538 | * | |
4539 | * The close entry point is called when an interface is de-activated | |
4540 | * by the OS. The hardware is still under the drivers control, but | |
4541 | * needs to be disabled. A global MAC reset is issued to stop the | |
4542 | * hardware, and all transmit and receive resources are freed. | |
4543 | **/ | |
4544 | static int ixgbe_close(struct net_device *netdev) | |
4545 | { | |
4546 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
9a799d71 AK |
4547 | |
4548 | ixgbe_down(adapter); | |
4549 | ixgbe_free_irq(adapter); | |
4550 | ||
4551 | ixgbe_free_all_tx_resources(adapter); | |
4552 | ixgbe_free_all_rx_resources(adapter); | |
4553 | ||
5eba3699 | 4554 | ixgbe_release_hw_control(adapter); |
9a799d71 AK |
4555 | |
4556 | return 0; | |
4557 | } | |
4558 | ||
b3c8b4ba AD |
4559 | #ifdef CONFIG_PM |
4560 | static int ixgbe_resume(struct pci_dev *pdev) | |
4561 | { | |
4562 | struct net_device *netdev = pci_get_drvdata(pdev); | |
4563 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
4564 | u32 err; | |
4565 | ||
4566 | pci_set_power_state(pdev, PCI_D0); | |
4567 | pci_restore_state(pdev); | |
656ab817 DS |
4568 | /* |
4569 | * pci_restore_state clears dev->state_saved so call | |
4570 | * pci_save_state to restore it. | |
4571 | */ | |
4572 | pci_save_state(pdev); | |
9ce77666 | 4573 | |
4574 | err = pci_enable_device_mem(pdev); | |
b3c8b4ba | 4575 | if (err) { |
69888674 | 4576 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
b3c8b4ba AD |
4577 | "suspend\n"); |
4578 | return err; | |
4579 | } | |
4580 | pci_set_master(pdev); | |
4581 | ||
dd4d8ca6 | 4582 | pci_wake_from_d3(pdev, false); |
b3c8b4ba AD |
4583 | |
4584 | err = ixgbe_init_interrupt_scheme(adapter); | |
4585 | if (err) { | |
4586 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " | |
4587 | "device\n"); | |
4588 | return err; | |
4589 | } | |
4590 | ||
b3c8b4ba AD |
4591 | ixgbe_reset(adapter); |
4592 | ||
495dce12 WJP |
4593 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
4594 | ||
b3c8b4ba AD |
4595 | if (netif_running(netdev)) { |
4596 | err = ixgbe_open(adapter->netdev); | |
4597 | if (err) | |
4598 | return err; | |
4599 | } | |
4600 | ||
4601 | netif_device_attach(netdev); | |
4602 | ||
4603 | return 0; | |
4604 | } | |
b3c8b4ba | 4605 | #endif /* CONFIG_PM */ |
9d8d05ae RW |
4606 | |
4607 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) | |
b3c8b4ba AD |
4608 | { |
4609 | struct net_device *netdev = pci_get_drvdata(pdev); | |
4610 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
e8e26350 PW |
4611 | struct ixgbe_hw *hw = &adapter->hw; |
4612 | u32 ctrl, fctrl; | |
4613 | u32 wufc = adapter->wol; | |
b3c8b4ba AD |
4614 | #ifdef CONFIG_PM |
4615 | int retval = 0; | |
4616 | #endif | |
4617 | ||
4618 | netif_device_detach(netdev); | |
4619 | ||
4620 | if (netif_running(netdev)) { | |
4621 | ixgbe_down(adapter); | |
4622 | ixgbe_free_irq(adapter); | |
4623 | ixgbe_free_all_tx_resources(adapter); | |
4624 | ixgbe_free_all_rx_resources(adapter); | |
4625 | } | |
7a921c93 | 4626 | ixgbe_clear_interrupt_scheme(adapter); |
b3c8b4ba AD |
4627 | |
4628 | #ifdef CONFIG_PM | |
4629 | retval = pci_save_state(pdev); | |
4630 | if (retval) | |
4631 | return retval; | |
4df10466 | 4632 | |
b3c8b4ba | 4633 | #endif |
e8e26350 PW |
4634 | if (wufc) { |
4635 | ixgbe_set_rx_mode(netdev); | |
b3c8b4ba | 4636 | |
e8e26350 PW |
4637 | /* turn on all-multi mode if wake on multicast is enabled */ |
4638 | if (wufc & IXGBE_WUFC_MC) { | |
4639 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); | |
4640 | fctrl |= IXGBE_FCTRL_MPE; | |
4641 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); | |
4642 | } | |
4643 | ||
4644 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); | |
4645 | ctrl |= IXGBE_CTRL_GIO_DIS; | |
4646 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); | |
4647 | ||
4648 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); | |
4649 | } else { | |
4650 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); | |
4651 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); | |
4652 | } | |
4653 | ||
dd4d8ca6 DS |
4654 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
4655 | pci_wake_from_d3(pdev, true); | |
4656 | else | |
4657 | pci_wake_from_d3(pdev, false); | |
b3c8b4ba | 4658 | |
9d8d05ae RW |
4659 | *enable_wake = !!wufc; |
4660 | ||
b3c8b4ba AD |
4661 | ixgbe_release_hw_control(adapter); |
4662 | ||
4663 | pci_disable_device(pdev); | |
4664 | ||
9d8d05ae RW |
4665 | return 0; |
4666 | } | |
4667 | ||
4668 | #ifdef CONFIG_PM | |
4669 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) | |
4670 | { | |
4671 | int retval; | |
4672 | bool wake; | |
4673 | ||
4674 | retval = __ixgbe_shutdown(pdev, &wake); | |
4675 | if (retval) | |
4676 | return retval; | |
4677 | ||
4678 | if (wake) { | |
4679 | pci_prepare_to_sleep(pdev); | |
4680 | } else { | |
4681 | pci_wake_from_d3(pdev, false); | |
4682 | pci_set_power_state(pdev, PCI_D3hot); | |
4683 | } | |
b3c8b4ba AD |
4684 | |
4685 | return 0; | |
4686 | } | |
9d8d05ae | 4687 | #endif /* CONFIG_PM */ |
b3c8b4ba AD |
4688 | |
4689 | static void ixgbe_shutdown(struct pci_dev *pdev) | |
4690 | { | |
9d8d05ae RW |
4691 | bool wake; |
4692 | ||
4693 | __ixgbe_shutdown(pdev, &wake); | |
4694 | ||
4695 | if (system_state == SYSTEM_POWER_OFF) { | |
4696 | pci_wake_from_d3(pdev, wake); | |
4697 | pci_set_power_state(pdev, PCI_D3hot); | |
4698 | } | |
b3c8b4ba AD |
4699 | } |
4700 | ||
9a799d71 AK |
4701 | /** |
4702 | * ixgbe_update_stats - Update the board statistics counters. | |
4703 | * @adapter: board private structure | |
4704 | **/ | |
4705 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) | |
4706 | { | |
2d86f139 | 4707 | struct net_device *netdev = adapter->netdev; |
9a799d71 | 4708 | struct ixgbe_hw *hw = &adapter->hw; |
6f11eef7 AV |
4709 | u64 total_mpc = 0; |
4710 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; | |
eb985f09 | 4711 | u64 non_eop_descs = 0, restart_queue = 0; |
9a799d71 | 4712 | |
94b982b2 | 4713 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
f8212f97 | 4714 | u64 rsc_count = 0; |
94b982b2 | 4715 | u64 rsc_flush = 0; |
d51019a4 PW |
4716 | for (i = 0; i < 16; i++) |
4717 | adapter->hw_rx_no_dma_resources += | |
4718 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); | |
94b982b2 | 4719 | for (i = 0; i < adapter->num_rx_queues; i++) { |
f8212f97 | 4720 | rsc_count += adapter->rx_ring[i].rsc_count; |
94b982b2 MC |
4721 | rsc_flush += adapter->rx_ring[i].rsc_flush; |
4722 | } | |
4723 | adapter->rsc_total_count = rsc_count; | |
4724 | adapter->rsc_total_flush = rsc_flush; | |
d51019a4 PW |
4725 | } |
4726 | ||
7ca3bc58 JB |
4727 | /* gather some stats to the adapter struct that are per queue */ |
4728 | for (i = 0; i < adapter->num_tx_queues; i++) | |
eb985f09 MC |
4729 | restart_queue += adapter->tx_ring[i].restart_queue; |
4730 | adapter->restart_queue = restart_queue; | |
7ca3bc58 JB |
4731 | |
4732 | for (i = 0; i < adapter->num_rx_queues; i++) | |
eb985f09 MC |
4733 | non_eop_descs += adapter->rx_ring[i].non_eop_descs; |
4734 | adapter->non_eop_descs = non_eop_descs; | |
7ca3bc58 | 4735 | |
9a799d71 | 4736 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
6f11eef7 AV |
4737 | for (i = 0; i < 8; i++) { |
4738 | /* for packet buffers not used, the register should read 0 */ | |
4739 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); | |
4740 | missed_rx += mpc; | |
4741 | adapter->stats.mpc[i] += mpc; | |
4742 | total_mpc += adapter->stats.mpc[i]; | |
e8e26350 PW |
4743 | if (hw->mac.type == ixgbe_mac_82598EB) |
4744 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); | |
2f90b865 AD |
4745 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
4746 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); | |
4747 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); | |
4748 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); | |
e8e26350 PW |
4749 | if (hw->mac.type == ixgbe_mac_82599EB) { |
4750 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, | |
4751 | IXGBE_PXONRXCNT(i)); | |
4752 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, | |
4753 | IXGBE_PXOFFRXCNT(i)); | |
4754 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); | |
e8e26350 PW |
4755 | } else { |
4756 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, | |
4757 | IXGBE_PXONRXC(i)); | |
4758 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, | |
4759 | IXGBE_PXOFFRXC(i)); | |
4760 | } | |
2f90b865 AD |
4761 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
4762 | IXGBE_PXONTXC(i)); | |
2f90b865 | 4763 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
e8e26350 | 4764 | IXGBE_PXOFFTXC(i)); |
6f11eef7 AV |
4765 | } |
4766 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); | |
4767 | /* work around hardware counting issue */ | |
4768 | adapter->stats.gprc -= missed_rx; | |
4769 | ||
4770 | /* 82598 hardware only has a 32 bit counter in the high register */ | |
e8e26350 | 4771 | if (hw->mac.type == ixgbe_mac_82599EB) { |
aad71918 | 4772 | u64 tmp; |
e8e26350 | 4773 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
aad71918 BG |
4774 | tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */ |
4775 | adapter->stats.gorc += (tmp << 32); | |
e8e26350 | 4776 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
aad71918 BG |
4777 | tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */ |
4778 | adapter->stats.gotc += (tmp << 32); | |
e8e26350 PW |
4779 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
4780 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ | |
4781 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); | |
4782 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); | |
c4cf55e5 PWJ |
4783 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
4784 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); | |
6d45522c YZ |
4785 | #ifdef IXGBE_FCOE |
4786 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); | |
4787 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); | |
4788 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); | |
4789 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); | |
4790 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); | |
4791 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); | |
4792 | #endif /* IXGBE_FCOE */ | |
e8e26350 PW |
4793 | } else { |
4794 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); | |
4795 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); | |
4796 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); | |
4797 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); | |
4798 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); | |
4799 | } | |
9a799d71 AK |
4800 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
4801 | adapter->stats.bprc += bprc; | |
4802 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); | |
e8e26350 PW |
4803 | if (hw->mac.type == ixgbe_mac_82598EB) |
4804 | adapter->stats.mprc -= bprc; | |
9a799d71 AK |
4805 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
4806 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); | |
4807 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); | |
4808 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); | |
4809 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); | |
4810 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); | |
4811 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); | |
9a799d71 | 4812 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
6f11eef7 AV |
4813 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
4814 | adapter->stats.lxontxc += lxon; | |
4815 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); | |
4816 | adapter->stats.lxofftxc += lxoff; | |
9a799d71 AK |
4817 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
4818 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); | |
6f11eef7 AV |
4819 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
4820 | /* | |
4821 | * 82598 errata - tx of flow control packets is included in tx counters | |
4822 | */ | |
4823 | xon_off_tot = lxon + lxoff; | |
4824 | adapter->stats.gptc -= xon_off_tot; | |
4825 | adapter->stats.mptc -= xon_off_tot; | |
4826 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); | |
9a799d71 AK |
4827 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
4828 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); | |
4829 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); | |
9a799d71 AK |
4830 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
4831 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); | |
6f11eef7 | 4832 | adapter->stats.ptc64 -= xon_off_tot; |
9a799d71 AK |
4833 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
4834 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); | |
4835 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); | |
4836 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); | |
4837 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); | |
9a799d71 AK |
4838 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
4839 | ||
4840 | /* Fill out the OS statistics structure */ | |
2d86f139 | 4841 | netdev->stats.multicast = adapter->stats.mprc; |
9a799d71 AK |
4842 | |
4843 | /* Rx Errors */ | |
2d86f139 | 4844 | netdev->stats.rx_errors = adapter->stats.crcerrs + |
b4617240 | 4845 | adapter->stats.rlec; |
2d86f139 AK |
4846 | netdev->stats.rx_dropped = 0; |
4847 | netdev->stats.rx_length_errors = adapter->stats.rlec; | |
4848 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; | |
4849 | netdev->stats.rx_missed_errors = total_mpc; | |
9a799d71 AK |
4850 | } |
4851 | ||
4852 | /** | |
4853 | * ixgbe_watchdog - Timer Call-back | |
4854 | * @data: pointer to adapter cast into an unsigned long | |
4855 | **/ | |
4856 | static void ixgbe_watchdog(unsigned long data) | |
4857 | { | |
4858 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; | |
cf8280ee | 4859 | struct ixgbe_hw *hw = &adapter->hw; |
fe49f04a AD |
4860 | u64 eics = 0; |
4861 | int i; | |
cf8280ee | 4862 | |
fe49f04a AD |
4863 | /* |
4864 | * Do the watchdog outside of interrupt context due to the lovely | |
4865 | * delays that some of the newer hardware requires | |
4866 | */ | |
22d5a71b | 4867 | |
fe49f04a AD |
4868 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
4869 | goto watchdog_short_circuit; | |
22d5a71b | 4870 | |
fe49f04a AD |
4871 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
4872 | /* | |
4873 | * for legacy and MSI interrupts don't set any bits | |
4874 | * that are enabled for EIAM, because this operation | |
4875 | * would set *both* EIMS and EICS for any bit in EIAM | |
4876 | */ | |
4877 | IXGBE_WRITE_REG(hw, IXGBE_EICS, | |
4878 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); | |
4879 | goto watchdog_reschedule; | |
4880 | } | |
4881 | ||
4882 | /* get one bit for every active tx/rx interrupt vector */ | |
4883 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { | |
4884 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; | |
4885 | if (qv->rxr_count || qv->txr_count) | |
4886 | eics |= ((u64)1 << i); | |
cf8280ee | 4887 | } |
9a799d71 | 4888 | |
fe49f04a AD |
4889 | /* Cause software interrupt to ensure rx rings are cleaned */ |
4890 | ixgbe_irq_rearm_queues(adapter, eics); | |
4891 | ||
4892 | watchdog_reschedule: | |
4893 | /* Reset the timer */ | |
4894 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); | |
4895 | ||
4896 | watchdog_short_circuit: | |
cf8280ee JB |
4897 | schedule_work(&adapter->watchdog_task); |
4898 | } | |
4899 | ||
e8e26350 PW |
4900 | /** |
4901 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber | |
4902 | * @work: pointer to work_struct containing our data | |
4903 | **/ | |
4904 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) | |
4905 | { | |
4906 | struct ixgbe_adapter *adapter = container_of(work, | |
4907 | struct ixgbe_adapter, | |
4908 | multispeed_fiber_task); | |
4909 | struct ixgbe_hw *hw = &adapter->hw; | |
4910 | u32 autoneg; | |
8620a103 | 4911 | bool negotiation; |
e8e26350 PW |
4912 | |
4913 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; | |
a1f25324 MC |
4914 | autoneg = hw->phy.autoneg_advertised; |
4915 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) | |
8620a103 MC |
4916 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
4917 | if (hw->mac.ops.setup_link) | |
4918 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); | |
e8e26350 PW |
4919 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
4920 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; | |
4921 | } | |
4922 | ||
4923 | /** | |
4924 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module | |
4925 | * @work: pointer to work_struct containing our data | |
4926 | **/ | |
4927 | static void ixgbe_sfp_config_module_task(struct work_struct *work) | |
4928 | { | |
4929 | struct ixgbe_adapter *adapter = container_of(work, | |
4930 | struct ixgbe_adapter, | |
4931 | sfp_config_module_task); | |
4932 | struct ixgbe_hw *hw = &adapter->hw; | |
4933 | u32 err; | |
4934 | ||
4935 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; | |
63d6e1d8 DS |
4936 | |
4937 | /* Time for electrical oscillations to settle down */ | |
4938 | msleep(100); | |
e8e26350 | 4939 | err = hw->phy.ops.identify_sfp(hw); |
63d6e1d8 | 4940 | |
e8e26350 | 4941 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
88d2b81f DS |
4942 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
4943 | "an unsupported SFP+ module type was detected.\n" | |
4944 | "Reload the driver after installing a supported " | |
4945 | "module.\n"); | |
63d6e1d8 | 4946 | unregister_netdev(adapter->netdev); |
e8e26350 PW |
4947 | return; |
4948 | } | |
4949 | hw->mac.ops.setup_sfp(hw); | |
4950 | ||
8d1c3c07 | 4951 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
e8e26350 PW |
4952 | /* This will also work for DA Twinax connections */ |
4953 | schedule_work(&adapter->multispeed_fiber_task); | |
4954 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; | |
4955 | } | |
4956 | ||
c4cf55e5 PWJ |
4957 | /** |
4958 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table | |
4959 | * @work: pointer to work_struct containing our data | |
4960 | **/ | |
4961 | static void ixgbe_fdir_reinit_task(struct work_struct *work) | |
4962 | { | |
4963 | struct ixgbe_adapter *adapter = container_of(work, | |
4964 | struct ixgbe_adapter, | |
4965 | fdir_reinit_task); | |
4966 | struct ixgbe_hw *hw = &adapter->hw; | |
4967 | int i; | |
4968 | ||
4969 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { | |
4970 | for (i = 0; i < adapter->num_tx_queues; i++) | |
4971 | set_bit(__IXGBE_FDIR_INIT_DONE, | |
4972 | &(adapter->tx_ring[i].reinit_state)); | |
4973 | } else { | |
4974 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " | |
4975 | "ignored adding FDIR ATR filters \n"); | |
4976 | } | |
4977 | /* Done FDIR Re-initialization, enable transmits */ | |
4978 | netif_tx_start_all_queues(adapter->netdev); | |
4979 | } | |
4980 | ||
cf8280ee | 4981 | /** |
69888674 AD |
4982 | * ixgbe_watchdog_task - worker thread to bring link up |
4983 | * @work: pointer to work_struct containing our data | |
cf8280ee JB |
4984 | **/ |
4985 | static void ixgbe_watchdog_task(struct work_struct *work) | |
4986 | { | |
4987 | struct ixgbe_adapter *adapter = container_of(work, | |
4988 | struct ixgbe_adapter, | |
4989 | watchdog_task); | |
4990 | struct net_device *netdev = adapter->netdev; | |
4991 | struct ixgbe_hw *hw = &adapter->hw; | |
4992 | u32 link_speed = adapter->link_speed; | |
4993 | bool link_up = adapter->link_up; | |
bc59fcda NS |
4994 | int i; |
4995 | struct ixgbe_ring *tx_ring; | |
4996 | int some_tx_pending = 0; | |
cf8280ee JB |
4997 | |
4998 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; | |
4999 | ||
5000 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { | |
5001 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); | |
264857b8 PWJ |
5002 | if (link_up) { |
5003 | #ifdef CONFIG_DCB | |
5004 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | |
5005 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) | |
620fa036 | 5006 | hw->mac.ops.fc_enable(hw, i); |
264857b8 | 5007 | } else { |
620fa036 | 5008 | hw->mac.ops.fc_enable(hw, 0); |
264857b8 PWJ |
5009 | } |
5010 | #else | |
620fa036 | 5011 | hw->mac.ops.fc_enable(hw, 0); |
264857b8 PWJ |
5012 | #endif |
5013 | } | |
5014 | ||
cf8280ee JB |
5015 | if (link_up || |
5016 | time_after(jiffies, (adapter->link_check_timeout + | |
5017 | IXGBE_TRY_LINK_TIMEOUT))) { | |
cf8280ee | 5018 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
264857b8 | 5019 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
cf8280ee JB |
5020 | } |
5021 | adapter->link_up = link_up; | |
5022 | adapter->link_speed = link_speed; | |
5023 | } | |
9a799d71 AK |
5024 | |
5025 | if (link_up) { | |
5026 | if (!netif_carrier_ok(netdev)) { | |
e8e26350 PW |
5027 | bool flow_rx, flow_tx; |
5028 | ||
5029 | if (hw->mac.type == ixgbe_mac_82599EB) { | |
5030 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); | |
5031 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); | |
078788b6 PWJ |
5032 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
5033 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); | |
e8e26350 PW |
5034 | } else { |
5035 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); | |
5036 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); | |
078788b6 PWJ |
5037 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
5038 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); | |
e8e26350 PW |
5039 | } |
5040 | ||
a46e534b JK |
5041 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
5042 | "Flow Control: %s\n", | |
5043 | netdev->name, | |
5044 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? | |
5045 | "10 Gbps" : | |
5046 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? | |
5047 | "1 Gbps" : "unknown speed")), | |
e8e26350 PW |
5048 | ((flow_rx && flow_tx) ? "RX/TX" : |
5049 | (flow_rx ? "RX" : | |
5050 | (flow_tx ? "TX" : "None")))); | |
9a799d71 AK |
5051 | |
5052 | netif_carrier_on(netdev); | |
9a799d71 AK |
5053 | } else { |
5054 | /* Force detection of hung controller */ | |
5055 | adapter->detect_tx_hung = true; | |
5056 | } | |
5057 | } else { | |
cf8280ee JB |
5058 | adapter->link_up = false; |
5059 | adapter->link_speed = 0; | |
9a799d71 | 5060 | if (netif_carrier_ok(netdev)) { |
a46e534b JK |
5061 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
5062 | netdev->name); | |
9a799d71 | 5063 | netif_carrier_off(netdev); |
9a799d71 AK |
5064 | } |
5065 | } | |
5066 | ||
bc59fcda NS |
5067 | if (!netif_carrier_ok(netdev)) { |
5068 | for (i = 0; i < adapter->num_tx_queues; i++) { | |
5069 | tx_ring = &adapter->tx_ring[i]; | |
5070 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { | |
5071 | some_tx_pending = 1; | |
5072 | break; | |
5073 | } | |
5074 | } | |
5075 | ||
5076 | if (some_tx_pending) { | |
5077 | /* We've lost link, so the controller stops DMA, | |
5078 | * but we've got queued Tx work that's never going | |
5079 | * to get done, so reset controller to flush Tx. | |
5080 | * (Do the reset outside of interrupt context). | |
5081 | */ | |
5082 | schedule_work(&adapter->reset_task); | |
5083 | } | |
5084 | } | |
5085 | ||
9a799d71 | 5086 | ixgbe_update_stats(adapter); |
cf8280ee | 5087 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
9a799d71 AK |
5088 | } |
5089 | ||
9a799d71 | 5090 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
b4617240 PW |
5091 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
5092 | u32 tx_flags, u8 *hdr_len) | |
9a799d71 AK |
5093 | { |
5094 | struct ixgbe_adv_tx_context_desc *context_desc; | |
5095 | unsigned int i; | |
5096 | int err; | |
5097 | struct ixgbe_tx_buffer *tx_buffer_info; | |
9f8cdf4f JB |
5098 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
5099 | u32 mss_l4len_idx, l4len; | |
9a799d71 AK |
5100 | |
5101 | if (skb_is_gso(skb)) { | |
5102 | if (skb_header_cloned(skb)) { | |
5103 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); | |
5104 | if (err) | |
5105 | return err; | |
5106 | } | |
5107 | l4len = tcp_hdrlen(skb); | |
5108 | *hdr_len += l4len; | |
5109 | ||
8327d000 | 5110 | if (skb->protocol == htons(ETH_P_IP)) { |
9a799d71 AK |
5111 | struct iphdr *iph = ip_hdr(skb); |
5112 | iph->tot_len = 0; | |
5113 | iph->check = 0; | |
5114 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, | |
b4617240 PW |
5115 | iph->daddr, 0, |
5116 | IPPROTO_TCP, | |
5117 | 0); | |
9a799d71 AK |
5118 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
5119 | ipv6_hdr(skb)->payload_len = 0; | |
5120 | tcp_hdr(skb)->check = | |
5121 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, | |
b4617240 PW |
5122 | &ipv6_hdr(skb)->daddr, |
5123 | 0, IPPROTO_TCP, 0); | |
9a799d71 AK |
5124 | } |
5125 | ||
5126 | i = tx_ring->next_to_use; | |
5127 | ||
5128 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | |
5129 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); | |
5130 | ||
5131 | /* VLAN MACLEN IPLEN */ | |
5132 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) | |
5133 | vlan_macip_lens |= | |
5134 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); | |
5135 | vlan_macip_lens |= ((skb_network_offset(skb)) << | |
b4617240 | 5136 | IXGBE_ADVTXD_MACLEN_SHIFT); |
9a799d71 AK |
5137 | *hdr_len += skb_network_offset(skb); |
5138 | vlan_macip_lens |= | |
5139 | (skb_transport_header(skb) - skb_network_header(skb)); | |
5140 | *hdr_len += | |
5141 | (skb_transport_header(skb) - skb_network_header(skb)); | |
5142 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); | |
5143 | context_desc->seqnum_seed = 0; | |
5144 | ||
5145 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ | |
9f8cdf4f | 5146 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
b4617240 | 5147 | IXGBE_ADVTXD_DTYP_CTXT); |
9a799d71 | 5148 | |
8327d000 | 5149 | if (skb->protocol == htons(ETH_P_IP)) |
9a799d71 AK |
5150 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
5151 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; | |
5152 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); | |
5153 | ||
5154 | /* MSS L4LEN IDX */ | |
9f8cdf4f | 5155 | mss_l4len_idx = |
9a799d71 AK |
5156 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
5157 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); | |
4eeae6fd PW |
5158 | /* use index 1 for TSO */ |
5159 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); | |
9a799d71 AK |
5160 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
5161 | ||
5162 | tx_buffer_info->time_stamp = jiffies; | |
5163 | tx_buffer_info->next_to_watch = i; | |
5164 | ||
5165 | i++; | |
5166 | if (i == tx_ring->count) | |
5167 | i = 0; | |
5168 | tx_ring->next_to_use = i; | |
5169 | ||
5170 | return true; | |
5171 | } | |
5172 | return false; | |
5173 | } | |
5174 | ||
5175 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, | |
b4617240 PW |
5176 | struct ixgbe_ring *tx_ring, |
5177 | struct sk_buff *skb, u32 tx_flags) | |
9a799d71 AK |
5178 | { |
5179 | struct ixgbe_adv_tx_context_desc *context_desc; | |
5180 | unsigned int i; | |
5181 | struct ixgbe_tx_buffer *tx_buffer_info; | |
5182 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; | |
5183 | ||
5184 | if (skb->ip_summed == CHECKSUM_PARTIAL || | |
5185 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { | |
5186 | i = tx_ring->next_to_use; | |
5187 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | |
5188 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); | |
5189 | ||
5190 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) | |
5191 | vlan_macip_lens |= | |
5192 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); | |
5193 | vlan_macip_lens |= (skb_network_offset(skb) << | |
b4617240 | 5194 | IXGBE_ADVTXD_MACLEN_SHIFT); |
9a799d71 AK |
5195 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
5196 | vlan_macip_lens |= (skb_transport_header(skb) - | |
b4617240 | 5197 | skb_network_header(skb)); |
9a799d71 AK |
5198 | |
5199 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); | |
5200 | context_desc->seqnum_seed = 0; | |
5201 | ||
5202 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | | |
b4617240 | 5203 | IXGBE_ADVTXD_DTYP_CTXT); |
9a799d71 AK |
5204 | |
5205 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | |
ca553980 GS |
5206 | __be16 protocol; |
5207 | ||
5208 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) { | |
5209 | const struct vlan_ethhdr *vhdr = | |
5210 | (const struct vlan_ethhdr *)skb->data; | |
5211 | ||
5212 | protocol = vhdr->h_vlan_encapsulated_proto; | |
5213 | } else { | |
5214 | protocol = skb->protocol; | |
5215 | } | |
5216 | ||
5217 | switch (protocol) { | |
09640e63 | 5218 | case cpu_to_be16(ETH_P_IP): |
9a799d71 | 5219 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
41825d71 AK |
5220 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
5221 | type_tucmd_mlhl |= | |
b4617240 | 5222 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
45a5ead0 JB |
5223 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
5224 | type_tucmd_mlhl |= | |
5225 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; | |
41825d71 | 5226 | break; |
09640e63 | 5227 | case cpu_to_be16(ETH_P_IPV6): |
41825d71 AK |
5228 | /* XXX what about other V6 headers?? */ |
5229 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) | |
5230 | type_tucmd_mlhl |= | |
b4617240 | 5231 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
45a5ead0 JB |
5232 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
5233 | type_tucmd_mlhl |= | |
5234 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; | |
41825d71 | 5235 | break; |
41825d71 AK |
5236 | default: |
5237 | if (unlikely(net_ratelimit())) { | |
5238 | DPRINTK(PROBE, WARNING, | |
5239 | "partial checksum but proto=%x!\n", | |
5240 | skb->protocol); | |
5241 | } | |
5242 | break; | |
5243 | } | |
9a799d71 AK |
5244 | } |
5245 | ||
5246 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); | |
4eeae6fd | 5247 | /* use index zero for tx checksum offload */ |
9a799d71 AK |
5248 | context_desc->mss_l4len_idx = 0; |
5249 | ||
5250 | tx_buffer_info->time_stamp = jiffies; | |
5251 | tx_buffer_info->next_to_watch = i; | |
9f8cdf4f | 5252 | |
9a799d71 AK |
5253 | i++; |
5254 | if (i == tx_ring->count) | |
5255 | i = 0; | |
5256 | tx_ring->next_to_use = i; | |
5257 | ||
5258 | return true; | |
5259 | } | |
9f8cdf4f | 5260 | |
9a799d71 AK |
5261 | return false; |
5262 | } | |
5263 | ||
5264 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, | |
b4617240 | 5265 | struct ixgbe_ring *tx_ring, |
eacd73f7 YZ |
5266 | struct sk_buff *skb, u32 tx_flags, |
5267 | unsigned int first) | |
9a799d71 | 5268 | { |
e5a43549 | 5269 | struct pci_dev *pdev = adapter->pdev; |
9a799d71 | 5270 | struct ixgbe_tx_buffer *tx_buffer_info; |
eacd73f7 YZ |
5271 | unsigned int len; |
5272 | unsigned int total = skb->len; | |
9a799d71 AK |
5273 | unsigned int offset = 0, size, count = 0, i; |
5274 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; | |
5275 | unsigned int f; | |
9a799d71 AK |
5276 | |
5277 | i = tx_ring->next_to_use; | |
5278 | ||
eacd73f7 YZ |
5279 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
5280 | /* excluding fcoe_crc_eof for FCoE */ | |
5281 | total -= sizeof(struct fcoe_crc_eof); | |
5282 | ||
5283 | len = min(skb_headlen(skb), total); | |
9a799d71 AK |
5284 | while (len) { |
5285 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | |
5286 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); | |
5287 | ||
5288 | tx_buffer_info->length = size; | |
e5a43549 AD |
5289 | tx_buffer_info->mapped_as_page = false; |
5290 | tx_buffer_info->dma = pci_map_single(pdev, | |
5291 | skb->data + offset, | |
5292 | size, PCI_DMA_TODEVICE); | |
5293 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) | |
5294 | goto dma_error; | |
9a799d71 AK |
5295 | tx_buffer_info->time_stamp = jiffies; |
5296 | tx_buffer_info->next_to_watch = i; | |
5297 | ||
5298 | len -= size; | |
eacd73f7 | 5299 | total -= size; |
9a799d71 AK |
5300 | offset += size; |
5301 | count++; | |
44df32c5 AD |
5302 | |
5303 | if (len) { | |
5304 | i++; | |
5305 | if (i == tx_ring->count) | |
5306 | i = 0; | |
5307 | } | |
9a799d71 AK |
5308 | } |
5309 | ||
5310 | for (f = 0; f < nr_frags; f++) { | |
5311 | struct skb_frag_struct *frag; | |
5312 | ||
5313 | frag = &skb_shinfo(skb)->frags[f]; | |
eacd73f7 | 5314 | len = min((unsigned int)frag->size, total); |
e5a43549 | 5315 | offset = frag->page_offset; |
9a799d71 AK |
5316 | |
5317 | while (len) { | |
44df32c5 AD |
5318 | i++; |
5319 | if (i == tx_ring->count) | |
5320 | i = 0; | |
5321 | ||
9a799d71 AK |
5322 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
5323 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); | |
5324 | ||
5325 | tx_buffer_info->length = size; | |
e5a43549 AD |
5326 | tx_buffer_info->dma = pci_map_page(adapter->pdev, |
5327 | frag->page, | |
5328 | offset, size, | |
5329 | PCI_DMA_TODEVICE); | |
5330 | tx_buffer_info->mapped_as_page = true; | |
5331 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) | |
5332 | goto dma_error; | |
9a799d71 AK |
5333 | tx_buffer_info->time_stamp = jiffies; |
5334 | tx_buffer_info->next_to_watch = i; | |
5335 | ||
5336 | len -= size; | |
eacd73f7 | 5337 | total -= size; |
9a799d71 AK |
5338 | offset += size; |
5339 | count++; | |
9a799d71 | 5340 | } |
eacd73f7 YZ |
5341 | if (total == 0) |
5342 | break; | |
9a799d71 | 5343 | } |
44df32c5 | 5344 | |
9a799d71 AK |
5345 | tx_ring->tx_buffer_info[i].skb = skb; |
5346 | tx_ring->tx_buffer_info[first].next_to_watch = i; | |
5347 | ||
e5a43549 AD |
5348 | return count; |
5349 | ||
5350 | dma_error: | |
5351 | dev_err(&pdev->dev, "TX DMA map failed\n"); | |
5352 | ||
5353 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ | |
5354 | tx_buffer_info->dma = 0; | |
5355 | tx_buffer_info->time_stamp = 0; | |
5356 | tx_buffer_info->next_to_watch = 0; | |
c1fa347f RK |
5357 | if (count) |
5358 | count--; | |
e5a43549 AD |
5359 | |
5360 | /* clear timestamp and dma mappings for remaining portion of packet */ | |
c1fa347f RK |
5361 | while (count--) { |
5362 | if (i==0) | |
e5a43549 | 5363 | i += tx_ring->count; |
c1fa347f | 5364 | i--; |
e5a43549 AD |
5365 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
5366 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); | |
5367 | } | |
5368 | ||
9a799d71 AK |
5369 | return count; |
5370 | } | |
5371 | ||
5372 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, | |
b4617240 PW |
5373 | struct ixgbe_ring *tx_ring, |
5374 | int tx_flags, int count, u32 paylen, u8 hdr_len) | |
9a799d71 AK |
5375 | { |
5376 | union ixgbe_adv_tx_desc *tx_desc = NULL; | |
5377 | struct ixgbe_tx_buffer *tx_buffer_info; | |
5378 | u32 olinfo_status = 0, cmd_type_len = 0; | |
5379 | unsigned int i; | |
5380 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; | |
5381 | ||
5382 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; | |
5383 | ||
5384 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; | |
5385 | ||
5386 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) | |
5387 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; | |
5388 | ||
5389 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { | |
5390 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; | |
5391 | ||
5392 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << | |
b4617240 | 5393 | IXGBE_ADVTXD_POPTS_SHIFT; |
9a799d71 | 5394 | |
4eeae6fd PW |
5395 | /* use index 1 context for tso */ |
5396 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); | |
9a799d71 AK |
5397 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
5398 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << | |
b4617240 | 5399 | IXGBE_ADVTXD_POPTS_SHIFT; |
9a799d71 AK |
5400 | |
5401 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) | |
5402 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << | |
b4617240 | 5403 | IXGBE_ADVTXD_POPTS_SHIFT; |
9a799d71 | 5404 | |
eacd73f7 YZ |
5405 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
5406 | olinfo_status |= IXGBE_ADVTXD_CC; | |
5407 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); | |
5408 | if (tx_flags & IXGBE_TX_FLAGS_FSO) | |
5409 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; | |
5410 | } | |
5411 | ||
9a799d71 AK |
5412 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
5413 | ||
5414 | i = tx_ring->next_to_use; | |
5415 | while (count--) { | |
5416 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | |
5417 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); | |
5418 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); | |
5419 | tx_desc->read.cmd_type_len = | |
b4617240 | 5420 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
9a799d71 | 5421 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
9a799d71 AK |
5422 | i++; |
5423 | if (i == tx_ring->count) | |
5424 | i = 0; | |
5425 | } | |
5426 | ||
5427 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); | |
5428 | ||
5429 | /* | |
5430 | * Force memory writes to complete before letting h/w | |
5431 | * know there are new descriptors to fetch. (Only | |
5432 | * applicable for weak-ordered memory model archs, | |
5433 | * such as IA-64). | |
5434 | */ | |
5435 | wmb(); | |
5436 | ||
5437 | tx_ring->next_to_use = i; | |
5438 | writel(i, adapter->hw.hw_addr + tx_ring->tail); | |
5439 | } | |
5440 | ||
c4cf55e5 PWJ |
5441 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
5442 | int queue, u32 tx_flags) | |
5443 | { | |
5444 | /* Right now, we support IPv4 only */ | |
5445 | struct ixgbe_atr_input atr_input; | |
5446 | struct tcphdr *th; | |
c4cf55e5 PWJ |
5447 | struct iphdr *iph = ip_hdr(skb); |
5448 | struct ethhdr *eth = (struct ethhdr *)skb->data; | |
5449 | u16 vlan_id, src_port, dst_port, flex_bytes; | |
5450 | u32 src_ipv4_addr, dst_ipv4_addr; | |
5451 | u8 l4type = 0; | |
5452 | ||
5453 | /* check if we're UDP or TCP */ | |
5454 | if (iph->protocol == IPPROTO_TCP) { | |
5455 | th = tcp_hdr(skb); | |
5456 | src_port = th->source; | |
5457 | dst_port = th->dest; | |
5458 | l4type |= IXGBE_ATR_L4TYPE_TCP; | |
5459 | /* l4type IPv4 type is 0, no need to assign */ | |
c4cf55e5 PWJ |
5460 | } else { |
5461 | /* Unsupported L4 header, just bail here */ | |
5462 | return; | |
5463 | } | |
5464 | ||
5465 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); | |
5466 | ||
5467 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> | |
5468 | IXGBE_TX_FLAGS_VLAN_SHIFT; | |
5469 | src_ipv4_addr = iph->saddr; | |
5470 | dst_ipv4_addr = iph->daddr; | |
5471 | flex_bytes = eth->h_proto; | |
5472 | ||
5473 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); | |
5474 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); | |
5475 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); | |
5476 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); | |
5477 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); | |
5478 | /* src and dst are inverted, think how the receiver sees them */ | |
5479 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); | |
5480 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); | |
5481 | ||
5482 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ | |
5483 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); | |
5484 | } | |
5485 | ||
e092be60 | 5486 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
b4617240 | 5487 | struct ixgbe_ring *tx_ring, int size) |
e092be60 | 5488 | { |
30eba97a | 5489 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
e092be60 AV |
5490 | /* Herbert's original patch had: |
5491 | * smp_mb__after_netif_stop_queue(); | |
5492 | * but since that doesn't exist yet, just open code it. */ | |
5493 | smp_mb(); | |
5494 | ||
5495 | /* We need to check again in a case another CPU has just | |
5496 | * made room available. */ | |
5497 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) | |
5498 | return -EBUSY; | |
5499 | ||
5500 | /* A reprieve! - use start_queue because it doesn't call schedule */ | |
af72166f | 5501 | netif_start_subqueue(netdev, tx_ring->queue_index); |
7ca3bc58 | 5502 | ++tx_ring->restart_queue; |
e092be60 AV |
5503 | return 0; |
5504 | } | |
5505 | ||
5506 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, | |
b4617240 | 5507 | struct ixgbe_ring *tx_ring, int size) |
e092be60 AV |
5508 | { |
5509 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) | |
5510 | return 0; | |
5511 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); | |
5512 | } | |
5513 | ||
09a3b1f8 SH |
5514 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
5515 | { | |
5516 | struct ixgbe_adapter *adapter = netdev_priv(dev); | |
5f715823 | 5517 | int txq = smp_processor_id(); |
09a3b1f8 | 5518 | |
c4cf55e5 | 5519 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
5f715823 | 5520 | return txq; |
c4cf55e5 | 5521 | |
5f715823 YZ |
5522 | #ifdef IXGBE_FCOE |
5523 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && | |
5524 | (skb->protocol == htons(ETH_P_FCOE))) { | |
5525 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); | |
5526 | txq += adapter->ring_feature[RING_F_FCOE].mask; | |
5527 | return txq; | |
5528 | } | |
5529 | #endif | |
09a3b1f8 | 5530 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
36e89d73 | 5531 | return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13; |
09a3b1f8 SH |
5532 | |
5533 | return skb_tx_hash(dev, skb); | |
5534 | } | |
5535 | ||
3b29a56d SH |
5536 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
5537 | struct net_device *netdev) | |
9a799d71 AK |
5538 | { |
5539 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
5540 | struct ixgbe_ring *tx_ring; | |
60d51134 | 5541 | struct netdev_queue *txq; |
9a799d71 AK |
5542 | unsigned int first; |
5543 | unsigned int tx_flags = 0; | |
30eba97a | 5544 | u8 hdr_len = 0; |
5f715823 | 5545 | int tso; |
9a799d71 AK |
5546 | int count = 0; |
5547 | unsigned int f; | |
9f8cdf4f | 5548 | |
9f8cdf4f JB |
5549 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
5550 | tx_flags |= vlan_tx_tag_get(skb); | |
2f90b865 AD |
5551 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
5552 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; | |
5f715823 | 5553 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
2f90b865 AD |
5554 | } |
5555 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; | |
5556 | tx_flags |= IXGBE_TX_FLAGS_VLAN; | |
5557 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { | |
60127865 | 5558 | if (skb->priority != TC_PRIO_CONTROL) { |
5f715823 | 5559 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
60127865 LL |
5560 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
5561 | tx_flags |= IXGBE_TX_FLAGS_VLAN; | |
5562 | } else { | |
5563 | skb->queue_mapping = | |
5564 | adapter->ring_feature[RING_F_DCB].indices-1; | |
5565 | } | |
9a799d71 | 5566 | } |
eacd73f7 | 5567 | |
5f715823 | 5568 | tx_ring = &adapter->tx_ring[skb->queue_mapping]; |
60127865 | 5569 | |
eacd73f7 | 5570 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
09ad1cc0 | 5571 | (skb->protocol == htons(ETH_P_FCOE))) { |
eacd73f7 | 5572 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
09ad1cc0 | 5573 | #ifdef IXGBE_FCOE |
61a0f421 YZ |
5574 | #ifdef CONFIG_IXGBE_DCB |
5575 | tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK | |
5576 | << IXGBE_TX_FLAGS_VLAN_SHIFT); | |
5577 | tx_flags |= ((adapter->fcoe.up << 13) | |
5578 | << IXGBE_TX_FLAGS_VLAN_SHIFT); | |
5579 | #endif | |
09ad1cc0 YZ |
5580 | #endif |
5581 | } | |
eacd73f7 | 5582 | /* four things can cause us to need a context descriptor */ |
9f8cdf4f JB |
5583 | if (skb_is_gso(skb) || |
5584 | (skb->ip_summed == CHECKSUM_PARTIAL) || | |
eacd73f7 YZ |
5585 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
5586 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) | |
9a799d71 AK |
5587 | count++; |
5588 | ||
9f8cdf4f JB |
5589 | count += TXD_USE_COUNT(skb_headlen(skb)); |
5590 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) | |
9a799d71 AK |
5591 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
5592 | ||
e092be60 | 5593 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
9a799d71 | 5594 | adapter->tx_busy++; |
9a799d71 AK |
5595 | return NETDEV_TX_BUSY; |
5596 | } | |
9a799d71 | 5597 | |
9a799d71 | 5598 | first = tx_ring->next_to_use; |
eacd73f7 YZ |
5599 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
5600 | #ifdef IXGBE_FCOE | |
5601 | /* setup tx offload for FCoE */ | |
5602 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); | |
5603 | if (tso < 0) { | |
5604 | dev_kfree_skb_any(skb); | |
5605 | return NETDEV_TX_OK; | |
5606 | } | |
5607 | if (tso) | |
5608 | tx_flags |= IXGBE_TX_FLAGS_FSO; | |
5609 | #endif /* IXGBE_FCOE */ | |
5610 | } else { | |
5611 | if (skb->protocol == htons(ETH_P_IP)) | |
5612 | tx_flags |= IXGBE_TX_FLAGS_IPV4; | |
5613 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); | |
5614 | if (tso < 0) { | |
5615 | dev_kfree_skb_any(skb); | |
5616 | return NETDEV_TX_OK; | |
5617 | } | |
9a799d71 | 5618 | |
eacd73f7 YZ |
5619 | if (tso) |
5620 | tx_flags |= IXGBE_TX_FLAGS_TSO; | |
5621 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && | |
5622 | (skb->ip_summed == CHECKSUM_PARTIAL)) | |
5623 | tx_flags |= IXGBE_TX_FLAGS_CSUM; | |
5624 | } | |
9a799d71 | 5625 | |
eacd73f7 | 5626 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
44df32c5 | 5627 | if (count) { |
c4cf55e5 PWJ |
5628 | /* add the ATR filter if ATR is on */ |
5629 | if (tx_ring->atr_sample_rate) { | |
5630 | ++tx_ring->atr_count; | |
5631 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && | |
5632 | test_bit(__IXGBE_FDIR_INIT_DONE, | |
5633 | &tx_ring->reinit_state)) { | |
5634 | ixgbe_atr(adapter, skb, tx_ring->queue_index, | |
5635 | tx_flags); | |
5636 | tx_ring->atr_count = 0; | |
5637 | } | |
5638 | } | |
60d51134 ED |
5639 | txq = netdev_get_tx_queue(netdev, tx_ring->queue_index); |
5640 | txq->tx_bytes += skb->len; | |
5641 | txq->tx_packets++; | |
44df32c5 AD |
5642 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
5643 | hdr_len); | |
44df32c5 | 5644 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
9a799d71 | 5645 | |
44df32c5 AD |
5646 | } else { |
5647 | dev_kfree_skb_any(skb); | |
5648 | tx_ring->tx_buffer_info[first].time_stamp = 0; | |
5649 | tx_ring->next_to_use = first; | |
5650 | } | |
9a799d71 AK |
5651 | |
5652 | return NETDEV_TX_OK; | |
5653 | } | |
5654 | ||
9a799d71 AK |
5655 | /** |
5656 | * ixgbe_set_mac - Change the Ethernet Address of the NIC | |
5657 | * @netdev: network interface device structure | |
5658 | * @p: pointer to an address structure | |
5659 | * | |
5660 | * Returns 0 on success, negative on failure | |
5661 | **/ | |
5662 | static int ixgbe_set_mac(struct net_device *netdev, void *p) | |
5663 | { | |
5664 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
b4617240 | 5665 | struct ixgbe_hw *hw = &adapter->hw; |
9a799d71 AK |
5666 | struct sockaddr *addr = p; |
5667 | ||
5668 | if (!is_valid_ether_addr(addr->sa_data)) | |
5669 | return -EADDRNOTAVAIL; | |
5670 | ||
5671 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | |
b4617240 | 5672 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
9a799d71 | 5673 | |
1cdd1ec8 GR |
5674 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
5675 | IXGBE_RAH_AV); | |
9a799d71 AK |
5676 | |
5677 | return 0; | |
5678 | } | |
5679 | ||
6b73e10d BH |
5680 | static int |
5681 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) | |
5682 | { | |
5683 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
5684 | struct ixgbe_hw *hw = &adapter->hw; | |
5685 | u16 value; | |
5686 | int rc; | |
5687 | ||
5688 | if (prtad != hw->phy.mdio.prtad) | |
5689 | return -EINVAL; | |
5690 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); | |
5691 | if (!rc) | |
5692 | rc = value; | |
5693 | return rc; | |
5694 | } | |
5695 | ||
5696 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, | |
5697 | u16 addr, u16 value) | |
5698 | { | |
5699 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
5700 | struct ixgbe_hw *hw = &adapter->hw; | |
5701 | ||
5702 | if (prtad != hw->phy.mdio.prtad) | |
5703 | return -EINVAL; | |
5704 | return hw->phy.ops.write_reg(hw, addr, devad, value); | |
5705 | } | |
5706 | ||
5707 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) | |
5708 | { | |
5709 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
5710 | ||
5711 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); | |
5712 | } | |
5713 | ||
0365e6e4 PW |
5714 | /** |
5715 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding | |
31278e71 | 5716 | * netdev->dev_addrs |
0365e6e4 PW |
5717 | * @netdev: network interface device structure |
5718 | * | |
5719 | * Returns non-zero on failure | |
5720 | **/ | |
5721 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) | |
5722 | { | |
5723 | int err = 0; | |
5724 | struct ixgbe_adapter *adapter = netdev_priv(dev); | |
5725 | struct ixgbe_mac_info *mac = &adapter->hw.mac; | |
5726 | ||
5727 | if (is_valid_ether_addr(mac->san_addr)) { | |
5728 | rtnl_lock(); | |
5729 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); | |
5730 | rtnl_unlock(); | |
5731 | } | |
5732 | return err; | |
5733 | } | |
5734 | ||
5735 | /** | |
5736 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding | |
31278e71 | 5737 | * netdev->dev_addrs |
0365e6e4 PW |
5738 | * @netdev: network interface device structure |
5739 | * | |
5740 | * Returns non-zero on failure | |
5741 | **/ | |
5742 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) | |
5743 | { | |
5744 | int err = 0; | |
5745 | struct ixgbe_adapter *adapter = netdev_priv(dev); | |
5746 | struct ixgbe_mac_info *mac = &adapter->hw.mac; | |
5747 | ||
5748 | if (is_valid_ether_addr(mac->san_addr)) { | |
5749 | rtnl_lock(); | |
5750 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); | |
5751 | rtnl_unlock(); | |
5752 | } | |
5753 | return err; | |
5754 | } | |
5755 | ||
9a799d71 AK |
5756 | #ifdef CONFIG_NET_POLL_CONTROLLER |
5757 | /* | |
5758 | * Polling 'interrupt' - used by things like netconsole to send skbs | |
5759 | * without having to re-enable interrupts. It's not called while | |
5760 | * the interrupt routine is executing. | |
5761 | */ | |
5762 | static void ixgbe_netpoll(struct net_device *netdev) | |
5763 | { | |
5764 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
8f9a7167 | 5765 | int i; |
9a799d71 | 5766 | |
1a647bd2 AD |
5767 | /* if interface is down do nothing */ |
5768 | if (test_bit(__IXGBE_DOWN, &adapter->state)) | |
5769 | return; | |
5770 | ||
9a799d71 | 5771 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
8f9a7167 PWJ |
5772 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
5773 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; | |
5774 | for (i = 0; i < num_q_vectors; i++) { | |
5775 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; | |
5776 | ixgbe_msix_clean_many(0, q_vector); | |
5777 | } | |
5778 | } else { | |
5779 | ixgbe_intr(adapter->pdev->irq, netdev); | |
5780 | } | |
9a799d71 | 5781 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
9a799d71 AK |
5782 | } |
5783 | #endif | |
5784 | ||
0edc3527 SH |
5785 | static const struct net_device_ops ixgbe_netdev_ops = { |
5786 | .ndo_open = ixgbe_open, | |
5787 | .ndo_stop = ixgbe_close, | |
00829823 | 5788 | .ndo_start_xmit = ixgbe_xmit_frame, |
09a3b1f8 | 5789 | .ndo_select_queue = ixgbe_select_queue, |
e90d400c | 5790 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
0edc3527 SH |
5791 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
5792 | .ndo_validate_addr = eth_validate_addr, | |
5793 | .ndo_set_mac_address = ixgbe_set_mac, | |
5794 | .ndo_change_mtu = ixgbe_change_mtu, | |
5795 | .ndo_tx_timeout = ixgbe_tx_timeout, | |
5796 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, | |
5797 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, | |
5798 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, | |
6b73e10d | 5799 | .ndo_do_ioctl = ixgbe_ioctl, |
0edc3527 SH |
5800 | #ifdef CONFIG_NET_POLL_CONTROLLER |
5801 | .ndo_poll_controller = ixgbe_netpoll, | |
5802 | #endif | |
332d4a7d YZ |
5803 | #ifdef IXGBE_FCOE |
5804 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, | |
5805 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, | |
8450ff8c YZ |
5806 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
5807 | .ndo_fcoe_disable = ixgbe_fcoe_disable, | |
61a1fa10 | 5808 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
332d4a7d | 5809 | #endif /* IXGBE_FCOE */ |
0edc3527 SH |
5810 | }; |
5811 | ||
1cdd1ec8 GR |
5812 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
5813 | const struct ixgbe_info *ii) | |
5814 | { | |
5815 | #ifdef CONFIG_PCI_IOV | |
5816 | struct ixgbe_hw *hw = &adapter->hw; | |
5817 | int err; | |
5818 | ||
5819 | if (hw->mac.type != ixgbe_mac_82599EB || !max_vfs) | |
5820 | return; | |
5821 | ||
5822 | /* The 82599 supports up to 64 VFs per physical function | |
5823 | * but this implementation limits allocation to 63 so that | |
5824 | * basic networking resources are still available to the | |
5825 | * physical function | |
5826 | */ | |
5827 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; | |
5828 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; | |
5829 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); | |
5830 | if (err) { | |
5831 | DPRINTK(PROBE, ERR, | |
5832 | "Failed to enable PCI sriov: %d\n", err); | |
5833 | goto err_novfs; | |
5834 | } | |
5835 | /* If call to enable VFs succeeded then allocate memory | |
5836 | * for per VF control structures. | |
5837 | */ | |
5838 | adapter->vfinfo = | |
5839 | kcalloc(adapter->num_vfs, | |
5840 | sizeof(struct vf_data_storage), GFP_KERNEL); | |
5841 | if (adapter->vfinfo) { | |
5842 | /* Now that we're sure SR-IOV is enabled | |
5843 | * and memory allocated set up the mailbox parameters | |
5844 | */ | |
5845 | ixgbe_init_mbx_params_pf(hw); | |
5846 | memcpy(&hw->mbx.ops, ii->mbx_ops, | |
5847 | sizeof(hw->mbx.ops)); | |
5848 | ||
5849 | /* Disable RSC when in SR-IOV mode */ | |
5850 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | | |
5851 | IXGBE_FLAG2_RSC_ENABLED); | |
5852 | return; | |
5853 | } | |
5854 | ||
5855 | /* Oh oh */ | |
5856 | DPRINTK(PROBE, ERR, | |
5857 | "Unable to allocate memory for VF " | |
5858 | "Data Storage - SRIOV disabled\n"); | |
5859 | pci_disable_sriov(adapter->pdev); | |
5860 | ||
5861 | err_novfs: | |
5862 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; | |
5863 | adapter->num_vfs = 0; | |
5864 | #endif /* CONFIG_PCI_IOV */ | |
5865 | } | |
5866 | ||
9a799d71 AK |
5867 | /** |
5868 | * ixgbe_probe - Device Initialization Routine | |
5869 | * @pdev: PCI device information struct | |
5870 | * @ent: entry in ixgbe_pci_tbl | |
5871 | * | |
5872 | * Returns 0 on success, negative on failure | |
5873 | * | |
5874 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. | |
5875 | * The OS initialization, configuring of the adapter private structure, | |
5876 | * and a hardware reset occur. | |
5877 | **/ | |
5878 | static int __devinit ixgbe_probe(struct pci_dev *pdev, | |
b4617240 | 5879 | const struct pci_device_id *ent) |
9a799d71 AK |
5880 | { |
5881 | struct net_device *netdev; | |
5882 | struct ixgbe_adapter *adapter = NULL; | |
5883 | struct ixgbe_hw *hw; | |
5884 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; | |
9a799d71 AK |
5885 | static int cards_found; |
5886 | int i, err, pci_using_dac; | |
eacd73f7 YZ |
5887 | #ifdef IXGBE_FCOE |
5888 | u16 device_caps; | |
5889 | #endif | |
c44ade9e | 5890 | u32 part_num, eec; |
9a799d71 | 5891 | |
9ce77666 | 5892 | err = pci_enable_device_mem(pdev); |
9a799d71 AK |
5893 | if (err) |
5894 | return err; | |
5895 | ||
6a35528a YH |
5896 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
5897 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { | |
9a799d71 AK |
5898 | pci_using_dac = 1; |
5899 | } else { | |
284901a9 | 5900 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
9a799d71 | 5901 | if (err) { |
284901a9 | 5902 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
9a799d71 | 5903 | if (err) { |
b4617240 PW |
5904 | dev_err(&pdev->dev, "No usable DMA " |
5905 | "configuration, aborting\n"); | |
9a799d71 AK |
5906 | goto err_dma; |
5907 | } | |
5908 | } | |
5909 | pci_using_dac = 0; | |
5910 | } | |
5911 | ||
9ce77666 | 5912 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
5913 | IORESOURCE_MEM), ixgbe_driver_name); | |
9a799d71 | 5914 | if (err) { |
9ce77666 | 5915 | dev_err(&pdev->dev, |
5916 | "pci_request_selected_regions failed 0x%x\n", err); | |
9a799d71 AK |
5917 | goto err_pci_reg; |
5918 | } | |
5919 | ||
19d5afd4 | 5920 | pci_enable_pcie_error_reporting(pdev); |
6fabd715 | 5921 | |
9a799d71 | 5922 | pci_set_master(pdev); |
fb3b27bc | 5923 | pci_save_state(pdev); |
9a799d71 | 5924 | |
30eba97a | 5925 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
9a799d71 AK |
5926 | if (!netdev) { |
5927 | err = -ENOMEM; | |
5928 | goto err_alloc_etherdev; | |
5929 | } | |
5930 | ||
9a799d71 AK |
5931 | SET_NETDEV_DEV(netdev, &pdev->dev); |
5932 | ||
5933 | pci_set_drvdata(pdev, netdev); | |
5934 | adapter = netdev_priv(netdev); | |
5935 | ||
5936 | adapter->netdev = netdev; | |
5937 | adapter->pdev = pdev; | |
5938 | hw = &adapter->hw; | |
5939 | hw->back = adapter; | |
5940 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; | |
5941 | ||
05857980 JK |
5942 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
5943 | pci_resource_len(pdev, 0)); | |
9a799d71 AK |
5944 | if (!hw->hw_addr) { |
5945 | err = -EIO; | |
5946 | goto err_ioremap; | |
5947 | } | |
5948 | ||
5949 | for (i = 1; i <= 5; i++) { | |
5950 | if (pci_resource_len(pdev, i) == 0) | |
5951 | continue; | |
5952 | } | |
5953 | ||
0edc3527 | 5954 | netdev->netdev_ops = &ixgbe_netdev_ops; |
9a799d71 | 5955 | ixgbe_set_ethtool_ops(netdev); |
9a799d71 | 5956 | netdev->watchdog_timeo = 5 * HZ; |
9a799d71 AK |
5957 | strcpy(netdev->name, pci_name(pdev)); |
5958 | ||
9a799d71 AK |
5959 | adapter->bd_number = cards_found; |
5960 | ||
9a799d71 AK |
5961 | /* Setup hw api */ |
5962 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); | |
021230d4 | 5963 | hw->mac.type = ii->mac; |
9a799d71 | 5964 | |
c44ade9e JB |
5965 | /* EEPROM */ |
5966 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); | |
5967 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); | |
5968 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ | |
5969 | if (!(eec & (1 << 8))) | |
5970 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; | |
5971 | ||
5972 | /* PHY */ | |
5973 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); | |
c4900be0 | 5974 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
6b73e10d BH |
5975 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
5976 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; | |
5977 | hw->phy.mdio.mmds = 0; | |
5978 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; | |
5979 | hw->phy.mdio.dev = netdev; | |
5980 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; | |
5981 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; | |
c4900be0 DS |
5982 | |
5983 | /* set up this timer and work struct before calling get_invariants | |
5984 | * which might start the timer | |
5985 | */ | |
5986 | init_timer(&adapter->sfp_timer); | |
5987 | adapter->sfp_timer.function = &ixgbe_sfp_timer; | |
5988 | adapter->sfp_timer.data = (unsigned long) adapter; | |
5989 | ||
5990 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); | |
c44ade9e | 5991 | |
e8e26350 PW |
5992 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
5993 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); | |
5994 | ||
5995 | /* a new SFP+ module arrival, called from GPI SDP2 context */ | |
5996 | INIT_WORK(&adapter->sfp_config_module_task, | |
5997 | ixgbe_sfp_config_module_task); | |
5998 | ||
8ca783ab | 5999 | ii->get_invariants(hw); |
9a799d71 AK |
6000 | |
6001 | /* setup the private structure */ | |
6002 | err = ixgbe_sw_init(adapter); | |
6003 | if (err) | |
6004 | goto err_sw_init; | |
6005 | ||
bf069c97 DS |
6006 | /* |
6007 | * If there is a fan on this device and it has failed log the | |
6008 | * failure. | |
6009 | */ | |
6010 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { | |
6011 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); | |
6012 | if (esdp & IXGBE_ESDP_SDP1) | |
6013 | DPRINTK(PROBE, CRIT, | |
6014 | "Fan has stopped, replace the adapter\n"); | |
6015 | } | |
6016 | ||
c44ade9e JB |
6017 | /* reset_hw fills in the perm_addr as well */ |
6018 | err = hw->mac.ops.reset_hw(hw); | |
8ca783ab DS |
6019 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
6020 | hw->mac.type == ixgbe_mac_82598EB) { | |
6021 | /* | |
6022 | * Start a kernel thread to watch for a module to arrive. | |
6023 | * Only do this for 82598, since 82599 will generate | |
6024 | * interrupts on module arrival. | |
6025 | */ | |
6026 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); | |
6027 | mod_timer(&adapter->sfp_timer, | |
6028 | round_jiffies(jiffies + (2 * HZ))); | |
6029 | err = 0; | |
6030 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { | |
88d2b81f DS |
6031 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
6032 | "an unsupported SFP+ module type was detected.\n" | |
6033 | "Reload the driver after installing a supported " | |
6034 | "module.\n"); | |
04f165ef PW |
6035 | goto err_sw_init; |
6036 | } else if (err) { | |
c44ade9e JB |
6037 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
6038 | goto err_sw_init; | |
6039 | } | |
6040 | ||
1cdd1ec8 GR |
6041 | ixgbe_probe_vf(adapter, ii); |
6042 | ||
9a799d71 | 6043 | netdev->features = NETIF_F_SG | |
b4617240 PW |
6044 | NETIF_F_IP_CSUM | |
6045 | NETIF_F_HW_VLAN_TX | | |
6046 | NETIF_F_HW_VLAN_RX | | |
6047 | NETIF_F_HW_VLAN_FILTER; | |
9a799d71 | 6048 | |
e9990a9c | 6049 | netdev->features |= NETIF_F_IPV6_CSUM; |
9a799d71 | 6050 | netdev->features |= NETIF_F_TSO; |
9a799d71 | 6051 | netdev->features |= NETIF_F_TSO6; |
78b6f4ce | 6052 | netdev->features |= NETIF_F_GRO; |
ad31c402 | 6053 | |
45a5ead0 JB |
6054 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
6055 | netdev->features |= NETIF_F_SCTP_CSUM; | |
6056 | ||
ad31c402 JK |
6057 | netdev->vlan_features |= NETIF_F_TSO; |
6058 | netdev->vlan_features |= NETIF_F_TSO6; | |
22f32b7a | 6059 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
cd1da503 | 6060 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
ad31c402 JK |
6061 | netdev->vlan_features |= NETIF_F_SG; |
6062 | ||
1cdd1ec8 GR |
6063 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
6064 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | | |
6065 | IXGBE_FLAG_DCB_ENABLED); | |
2f90b865 AD |
6066 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
6067 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; | |
6068 | ||
7a6b6f51 | 6069 | #ifdef CONFIG_IXGBE_DCB |
2f90b865 AD |
6070 | netdev->dcbnl_ops = &dcbnl_ops; |
6071 | #endif | |
6072 | ||
eacd73f7 | 6073 | #ifdef IXGBE_FCOE |
0d551589 | 6074 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
eacd73f7 YZ |
6075 | if (hw->mac.ops.get_device_caps) { |
6076 | hw->mac.ops.get_device_caps(hw, &device_caps); | |
0d551589 YZ |
6077 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
6078 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; | |
eacd73f7 YZ |
6079 | } |
6080 | } | |
6081 | #endif /* IXGBE_FCOE */ | |
9a799d71 AK |
6082 | if (pci_using_dac) |
6083 | netdev->features |= NETIF_F_HIGHDMA; | |
6084 | ||
0c19d6af | 6085 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
f8212f97 AD |
6086 | netdev->features |= NETIF_F_LRO; |
6087 | ||
9a799d71 | 6088 | /* make sure the EEPROM is good */ |
c44ade9e | 6089 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
9a799d71 AK |
6090 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
6091 | err = -EIO; | |
6092 | goto err_eeprom; | |
6093 | } | |
6094 | ||
6095 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); | |
6096 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); | |
6097 | ||
c44ade9e JB |
6098 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
6099 | dev_err(&pdev->dev, "invalid MAC address\n"); | |
9a799d71 AK |
6100 | err = -EIO; |
6101 | goto err_eeprom; | |
6102 | } | |
6103 | ||
6104 | init_timer(&adapter->watchdog_timer); | |
6105 | adapter->watchdog_timer.function = &ixgbe_watchdog; | |
6106 | adapter->watchdog_timer.data = (unsigned long)adapter; | |
6107 | ||
6108 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); | |
cf8280ee | 6109 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
9a799d71 | 6110 | |
021230d4 AV |
6111 | err = ixgbe_init_interrupt_scheme(adapter); |
6112 | if (err) | |
6113 | goto err_sw_init; | |
9a799d71 | 6114 | |
e8e26350 PW |
6115 | switch (pdev->device) { |
6116 | case IXGBE_DEV_ID_82599_KX4: | |
495dce12 WJP |
6117 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
6118 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); | |
bdf0a550 PWJ |
6119 | /* Enable ACPI wakeup in GRC */ |
6120 | IXGBE_WRITE_REG(hw, IXGBE_GRC, | |
6121 | (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME)); | |
e8e26350 PW |
6122 | break; |
6123 | default: | |
6124 | adapter->wol = 0; | |
6125 | break; | |
6126 | } | |
e8e26350 PW |
6127 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
6128 | ||
04f165ef PW |
6129 | /* pick up the PCI bus settings for reporting later */ |
6130 | hw->mac.ops.get_bus_info(hw); | |
6131 | ||
9a799d71 | 6132 | /* print bus type/speed/width info */ |
7c510e4b | 6133 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
e8e26350 PW |
6134 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
6135 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), | |
6136 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : | |
6137 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : | |
6138 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : | |
b4617240 | 6139 | "Unknown"), |
7c510e4b | 6140 | netdev->dev_addr); |
c44ade9e | 6141 | ixgbe_read_pba_num_generic(hw, &part_num); |
e8e26350 PW |
6142 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
6143 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", | |
6144 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, | |
6145 | (part_num >> 8), (part_num & 0xff)); | |
6146 | else | |
6147 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", | |
6148 | hw->mac.type, hw->phy.type, | |
6149 | (part_num >> 8), (part_num & 0xff)); | |
9a799d71 | 6150 | |
e8e26350 | 6151 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
0c254d86 | 6152 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
b4617240 PW |
6153 | "this card is not sufficient for optimal " |
6154 | "performance.\n"); | |
0c254d86 | 6155 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
b4617240 | 6156 | "PCI-Express slot is required.\n"); |
0c254d86 AK |
6157 | } |
6158 | ||
34b0368c PWJ |
6159 | /* save off EEPROM version number */ |
6160 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); | |
6161 | ||
9a799d71 | 6162 | /* reset the hardware with the new settings */ |
794caeb2 | 6163 | err = hw->mac.ops.start_hw(hw); |
c44ade9e | 6164 | |
794caeb2 PWJ |
6165 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
6166 | /* We are running on a pre-production device, log a warning */ | |
6167 | dev_warn(&pdev->dev, "This device is a pre-production " | |
6168 | "adapter/LOM. Please be aware there may be issues " | |
6169 | "associated with your hardware. If you are " | |
6170 | "experiencing problems please contact your Intel or " | |
6171 | "hardware representative who provided you with this " | |
6172 | "hardware.\n"); | |
6173 | } | |
9a799d71 AK |
6174 | strcpy(netdev->name, "eth%d"); |
6175 | err = register_netdev(netdev); | |
6176 | if (err) | |
6177 | goto err_register; | |
6178 | ||
54386467 JB |
6179 | /* carrier off reporting is important to ethtool even BEFORE open */ |
6180 | netif_carrier_off(netdev); | |
6181 | ||
c4cf55e5 PWJ |
6182 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
6183 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) | |
6184 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); | |
6185 | ||
5dd2d332 | 6186 | #ifdef CONFIG_IXGBE_DCA |
652f093f | 6187 | if (dca_add_requester(&pdev->dev) == 0) { |
bd0362dd | 6188 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
bd0362dd JC |
6189 | ixgbe_setup_dca(adapter); |
6190 | } | |
6191 | #endif | |
1cdd1ec8 GR |
6192 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
6193 | DPRINTK(PROBE, INFO, "IOV is enabled with %d VFs\n", | |
6194 | adapter->num_vfs); | |
6195 | for (i = 0; i < adapter->num_vfs; i++) | |
6196 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); | |
6197 | } | |
6198 | ||
0365e6e4 PW |
6199 | /* add san mac addr to netdev */ |
6200 | ixgbe_add_sanmac_netdev(netdev); | |
9a799d71 AK |
6201 | |
6202 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); | |
6203 | cards_found++; | |
6204 | return 0; | |
6205 | ||
6206 | err_register: | |
5eba3699 | 6207 | ixgbe_release_hw_control(adapter); |
7a921c93 | 6208 | ixgbe_clear_interrupt_scheme(adapter); |
9a799d71 AK |
6209 | err_sw_init: |
6210 | err_eeprom: | |
1cdd1ec8 GR |
6211 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
6212 | ixgbe_disable_sriov(adapter); | |
c4900be0 DS |
6213 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
6214 | del_timer_sync(&adapter->sfp_timer); | |
6215 | cancel_work_sync(&adapter->sfp_task); | |
e8e26350 PW |
6216 | cancel_work_sync(&adapter->multispeed_fiber_task); |
6217 | cancel_work_sync(&adapter->sfp_config_module_task); | |
9a799d71 AK |
6218 | iounmap(hw->hw_addr); |
6219 | err_ioremap: | |
6220 | free_netdev(netdev); | |
6221 | err_alloc_etherdev: | |
9ce77666 | 6222 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
6223 | IORESOURCE_MEM)); | |
9a799d71 AK |
6224 | err_pci_reg: |
6225 | err_dma: | |
6226 | pci_disable_device(pdev); | |
6227 | return err; | |
6228 | } | |
6229 | ||
6230 | /** | |
6231 | * ixgbe_remove - Device Removal Routine | |
6232 | * @pdev: PCI device information struct | |
6233 | * | |
6234 | * ixgbe_remove is called by the PCI subsystem to alert the driver | |
6235 | * that it should release a PCI device. The could be caused by a | |
6236 | * Hot-Plug event, or because the driver is going to be removed from | |
6237 | * memory. | |
6238 | **/ | |
6239 | static void __devexit ixgbe_remove(struct pci_dev *pdev) | |
6240 | { | |
6241 | struct net_device *netdev = pci_get_drvdata(pdev); | |
6242 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
6243 | ||
6244 | set_bit(__IXGBE_DOWN, &adapter->state); | |
c4900be0 DS |
6245 | /* clear the module not found bit to make sure the worker won't |
6246 | * reschedule | |
6247 | */ | |
6248 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); | |
9a799d71 AK |
6249 | del_timer_sync(&adapter->watchdog_timer); |
6250 | ||
c4900be0 DS |
6251 | del_timer_sync(&adapter->sfp_timer); |
6252 | cancel_work_sync(&adapter->watchdog_task); | |
6253 | cancel_work_sync(&adapter->sfp_task); | |
e8e26350 PW |
6254 | cancel_work_sync(&adapter->multispeed_fiber_task); |
6255 | cancel_work_sync(&adapter->sfp_config_module_task); | |
c4cf55e5 PWJ |
6256 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
6257 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) | |
6258 | cancel_work_sync(&adapter->fdir_reinit_task); | |
9a799d71 AK |
6259 | flush_scheduled_work(); |
6260 | ||
5dd2d332 | 6261 | #ifdef CONFIG_IXGBE_DCA |
bd0362dd JC |
6262 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
6263 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; | |
6264 | dca_remove_requester(&pdev->dev); | |
6265 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); | |
6266 | } | |
6267 | ||
6268 | #endif | |
332d4a7d YZ |
6269 | #ifdef IXGBE_FCOE |
6270 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) | |
6271 | ixgbe_cleanup_fcoe(adapter); | |
6272 | ||
6273 | #endif /* IXGBE_FCOE */ | |
0365e6e4 PW |
6274 | |
6275 | /* remove the added san mac */ | |
6276 | ixgbe_del_sanmac_netdev(netdev); | |
6277 | ||
c4900be0 DS |
6278 | if (netdev->reg_state == NETREG_REGISTERED) |
6279 | unregister_netdev(netdev); | |
9a799d71 | 6280 | |
1cdd1ec8 GR |
6281 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
6282 | ixgbe_disable_sriov(adapter); | |
6283 | ||
7a921c93 | 6284 | ixgbe_clear_interrupt_scheme(adapter); |
5eba3699 | 6285 | |
021230d4 | 6286 | ixgbe_release_hw_control(adapter); |
9a799d71 AK |
6287 | |
6288 | iounmap(adapter->hw.hw_addr); | |
9ce77666 | 6289 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
6290 | IORESOURCE_MEM)); | |
9a799d71 | 6291 | |
021230d4 | 6292 | DPRINTK(PROBE, INFO, "complete\n"); |
021230d4 | 6293 | |
9a799d71 AK |
6294 | free_netdev(netdev); |
6295 | ||
19d5afd4 | 6296 | pci_disable_pcie_error_reporting(pdev); |
6fabd715 | 6297 | |
9a799d71 AK |
6298 | pci_disable_device(pdev); |
6299 | } | |
6300 | ||
6301 | /** | |
6302 | * ixgbe_io_error_detected - called when PCI error is detected | |
6303 | * @pdev: Pointer to PCI device | |
6304 | * @state: The current pci connection state | |
6305 | * | |
6306 | * This function is called after a PCI bus error affecting | |
6307 | * this device has been detected. | |
6308 | */ | |
6309 | static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev, | |
b4617240 | 6310 | pci_channel_state_t state) |
9a799d71 AK |
6311 | { |
6312 | struct net_device *netdev = pci_get_drvdata(pdev); | |
454d7c9b | 6313 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
9a799d71 AK |
6314 | |
6315 | netif_device_detach(netdev); | |
6316 | ||
3044b8d1 BL |
6317 | if (state == pci_channel_io_perm_failure) |
6318 | return PCI_ERS_RESULT_DISCONNECT; | |
6319 | ||
9a799d71 AK |
6320 | if (netif_running(netdev)) |
6321 | ixgbe_down(adapter); | |
6322 | pci_disable_device(pdev); | |
6323 | ||
b4617240 | 6324 | /* Request a slot reset. */ |
9a799d71 AK |
6325 | return PCI_ERS_RESULT_NEED_RESET; |
6326 | } | |
6327 | ||
6328 | /** | |
6329 | * ixgbe_io_slot_reset - called after the pci bus has been reset. | |
6330 | * @pdev: Pointer to PCI device | |
6331 | * | |
6332 | * Restart the card from scratch, as if from a cold-boot. | |
6333 | */ | |
6334 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) | |
6335 | { | |
6336 | struct net_device *netdev = pci_get_drvdata(pdev); | |
454d7c9b | 6337 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
6fabd715 PWJ |
6338 | pci_ers_result_t result; |
6339 | int err; | |
9a799d71 | 6340 | |
9ce77666 | 6341 | if (pci_enable_device_mem(pdev)) { |
9a799d71 | 6342 | DPRINTK(PROBE, ERR, |
b4617240 | 6343 | "Cannot re-enable PCI device after reset.\n"); |
6fabd715 PWJ |
6344 | result = PCI_ERS_RESULT_DISCONNECT; |
6345 | } else { | |
6346 | pci_set_master(pdev); | |
6347 | pci_restore_state(pdev); | |
c0e1f68b | 6348 | pci_save_state(pdev); |
9a799d71 | 6349 | |
dd4d8ca6 | 6350 | pci_wake_from_d3(pdev, false); |
9a799d71 | 6351 | |
6fabd715 | 6352 | ixgbe_reset(adapter); |
88512539 | 6353 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
6fabd715 PWJ |
6354 | result = PCI_ERS_RESULT_RECOVERED; |
6355 | } | |
6356 | ||
6357 | err = pci_cleanup_aer_uncorrect_error_status(pdev); | |
6358 | if (err) { | |
6359 | dev_err(&pdev->dev, | |
6360 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); | |
6361 | /* non-fatal, continue */ | |
6362 | } | |
9a799d71 | 6363 | |
6fabd715 | 6364 | return result; |
9a799d71 AK |
6365 | } |
6366 | ||
6367 | /** | |
6368 | * ixgbe_io_resume - called when traffic can start flowing again. | |
6369 | * @pdev: Pointer to PCI device | |
6370 | * | |
6371 | * This callback is called when the error recovery driver tells us that | |
6372 | * its OK to resume normal operation. | |
6373 | */ | |
6374 | static void ixgbe_io_resume(struct pci_dev *pdev) | |
6375 | { | |
6376 | struct net_device *netdev = pci_get_drvdata(pdev); | |
454d7c9b | 6377 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
9a799d71 AK |
6378 | |
6379 | if (netif_running(netdev)) { | |
6380 | if (ixgbe_up(adapter)) { | |
6381 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); | |
6382 | return; | |
6383 | } | |
6384 | } | |
6385 | ||
6386 | netif_device_attach(netdev); | |
9a799d71 AK |
6387 | } |
6388 | ||
6389 | static struct pci_error_handlers ixgbe_err_handler = { | |
6390 | .error_detected = ixgbe_io_error_detected, | |
6391 | .slot_reset = ixgbe_io_slot_reset, | |
6392 | .resume = ixgbe_io_resume, | |
6393 | }; | |
6394 | ||
6395 | static struct pci_driver ixgbe_driver = { | |
6396 | .name = ixgbe_driver_name, | |
6397 | .id_table = ixgbe_pci_tbl, | |
6398 | .probe = ixgbe_probe, | |
6399 | .remove = __devexit_p(ixgbe_remove), | |
6400 | #ifdef CONFIG_PM | |
6401 | .suspend = ixgbe_suspend, | |
6402 | .resume = ixgbe_resume, | |
6403 | #endif | |
6404 | .shutdown = ixgbe_shutdown, | |
6405 | .err_handler = &ixgbe_err_handler | |
6406 | }; | |
6407 | ||
6408 | /** | |
6409 | * ixgbe_init_module - Driver Registration Routine | |
6410 | * | |
6411 | * ixgbe_init_module is the first routine called when the driver is | |
6412 | * loaded. All it does is register with the PCI subsystem. | |
6413 | **/ | |
6414 | static int __init ixgbe_init_module(void) | |
6415 | { | |
6416 | int ret; | |
6417 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, | |
6418 | ixgbe_driver_string, ixgbe_driver_version); | |
6419 | ||
6420 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); | |
6421 | ||
5dd2d332 | 6422 | #ifdef CONFIG_IXGBE_DCA |
bd0362dd | 6423 | dca_register_notify(&dca_notifier); |
bd0362dd | 6424 | #endif |
5dd2d332 | 6425 | |
9a799d71 AK |
6426 | ret = pci_register_driver(&ixgbe_driver); |
6427 | return ret; | |
6428 | } | |
b4617240 | 6429 | |
9a799d71 AK |
6430 | module_init(ixgbe_init_module); |
6431 | ||
6432 | /** | |
6433 | * ixgbe_exit_module - Driver Exit Cleanup Routine | |
6434 | * | |
6435 | * ixgbe_exit_module is called just before the driver is removed | |
6436 | * from memory. | |
6437 | **/ | |
6438 | static void __exit ixgbe_exit_module(void) | |
6439 | { | |
5dd2d332 | 6440 | #ifdef CONFIG_IXGBE_DCA |
bd0362dd JC |
6441 | dca_unregister_notify(&dca_notifier); |
6442 | #endif | |
9a799d71 AK |
6443 | pci_unregister_driver(&ixgbe_driver); |
6444 | } | |
bd0362dd | 6445 | |
5dd2d332 | 6446 | #ifdef CONFIG_IXGBE_DCA |
bd0362dd | 6447 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
b4617240 | 6448 | void *p) |
bd0362dd JC |
6449 | { |
6450 | int ret_val; | |
6451 | ||
6452 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, | |
b4617240 | 6453 | __ixgbe_notify_dca); |
bd0362dd JC |
6454 | |
6455 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; | |
6456 | } | |
b453368d | 6457 | |
5dd2d332 | 6458 | #endif /* CONFIG_IXGBE_DCA */ |
b453368d AD |
6459 | #ifdef DEBUG |
6460 | /** | |
6461 | * ixgbe_get_hw_dev_name - return device name string | |
6462 | * used by hardware layer to print debugging information | |
6463 | **/ | |
6464 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) | |
6465 | { | |
6466 | struct ixgbe_adapter *adapter = hw->back; | |
6467 | return adapter->netdev->name; | |
6468 | } | |
bd0362dd | 6469 | |
b453368d | 6470 | #endif |
9a799d71 AK |
6471 | module_exit(ixgbe_exit_module); |
6472 | ||
6473 | /* ixgbe_main.c */ |