blob: 3b880a27f8d118eb6b08fcd5e23678bdf2c27653 [file] [log] [blame]
Greg Rose92915f72010-01-09 02:24:10 +00001/*******************************************************************************
2
3 Intel 82599 Virtual Function driver
Greg Rose66c87bd2010-11-16 19:26:43 -08004 Copyright(c) 1999 - 2010 Intel Corporation.
Greg Rose92915f72010-01-09 02:24:10 +00005
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:
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
29/******************************************************************************
30 Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
31******************************************************************************/
32#include <linux/types.h>
Jiri Pirkodadcd652011-07-21 03:25:09 +000033#include <linux/bitops.h>
Greg Rose92915f72010-01-09 02:24:10 +000034#include <linux/module.h>
35#include <linux/pci.h>
36#include <linux/netdevice.h>
37#include <linux/vmalloc.h>
38#include <linux/string.h>
39#include <linux/in.h>
40#include <linux/ip.h>
41#include <linux/tcp.h>
42#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090043#include <linux/slab.h>
Greg Rose92915f72010-01-09 02:24:10 +000044#include <net/checksum.h>
45#include <net/ip6_checksum.h>
46#include <linux/ethtool.h>
47#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040048#include <linux/prefetch.h>
Greg Rose92915f72010-01-09 02:24:10 +000049
50#include "ixgbevf.h"
51
52char ixgbevf_driver_name[] = "ixgbevf";
53static const char ixgbevf_driver_string[] =
Greg Rose422e05d2011-03-12 02:01:29 +000054 "Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver";
Greg Rose92915f72010-01-09 02:24:10 +000055
Greg Rose1057c422011-05-19 02:11:45 +000056#define DRV_VERSION "2.1.0-k"
Greg Rose92915f72010-01-09 02:24:10 +000057const char ixgbevf_driver_version[] = DRV_VERSION;
Greg Rose66c87bd2010-11-16 19:26:43 -080058static char ixgbevf_copyright[] =
59 "Copyright (c) 2009 - 2010 Intel Corporation.";
Greg Rose92915f72010-01-09 02:24:10 +000060
61static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
Greg Rose2316aa22010-12-02 07:12:26 +000062 [board_82599_vf] = &ixgbevf_82599_vf_info,
63 [board_X540_vf] = &ixgbevf_X540_vf_info,
Greg Rose92915f72010-01-09 02:24:10 +000064};
65
66/* ixgbevf_pci_tbl - PCI Device ID Table
67 *
68 * Wildcard entries (PCI_ANY_ID) should come last
69 * Last entry must be all 0s
70 *
71 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
72 * Class, Class Mask, private data (not used) }
73 */
74static struct pci_device_id ixgbevf_pci_tbl[] = {
75 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF),
76 board_82599_vf},
Greg Rose2316aa22010-12-02 07:12:26 +000077 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF),
78 board_X540_vf},
Greg Rose92915f72010-01-09 02:24:10 +000079
80 /* required last entry */
81 {0, }
82};
83MODULE_DEVICE_TABLE(pci, ixgbevf_pci_tbl);
84
85MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
86MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
87MODULE_LICENSE("GPL");
88MODULE_VERSION(DRV_VERSION);
89
90#define DEFAULT_DEBUG_LEVEL_SHIFT 3
91
92/* forward decls */
93static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector *q_vector);
94static void ixgbevf_write_eitr(struct ixgbevf_adapter *adapter, int v_idx,
95 u32 itr_reg);
96
97static inline void ixgbevf_release_rx_desc(struct ixgbe_hw *hw,
98 struct ixgbevf_ring *rx_ring,
99 u32 val)
100{
101 /*
102 * Force memory writes to complete before letting h/w
103 * know there are new descriptors to fetch. (Only
104 * applicable for weak-ordered memory model archs,
105 * such as IA-64).
106 */
107 wmb();
108 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rx_ring->reg_idx), val);
109}
110
111/*
Greg Rose65d676c2011-02-03 06:54:13 +0000112 * ixgbevf_set_ivar - set IVAR registers - maps interrupt causes to vectors
Greg Rose92915f72010-01-09 02:24:10 +0000113 * @adapter: pointer to adapter struct
114 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
115 * @queue: queue to map the corresponding interrupt to
116 * @msix_vector: the vector to map to the corresponding queue
117 *
118 */
119static void ixgbevf_set_ivar(struct ixgbevf_adapter *adapter, s8 direction,
120 u8 queue, u8 msix_vector)
121{
122 u32 ivar, index;
123 struct ixgbe_hw *hw = &adapter->hw;
124 if (direction == -1) {
125 /* other causes */
126 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
127 ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
128 ivar &= ~0xFF;
129 ivar |= msix_vector;
130 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar);
131 } else {
132 /* tx or rx causes */
133 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
134 index = ((16 * (queue & 1)) + (8 * direction));
135 ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
136 ivar &= ~(0xFF << index);
137 ivar |= (msix_vector << index);
138 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), ivar);
139 }
140}
141
142static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_adapter *adapter,
143 struct ixgbevf_tx_buffer
144 *tx_buffer_info)
145{
146 if (tx_buffer_info->dma) {
147 if (tx_buffer_info->mapped_as_page)
Nick Nunley2a1f8792010-04-27 13:10:50 +0000148 dma_unmap_page(&adapter->pdev->dev,
Greg Rose92915f72010-01-09 02:24:10 +0000149 tx_buffer_info->dma,
150 tx_buffer_info->length,
Nick Nunley2a1f8792010-04-27 13:10:50 +0000151 DMA_TO_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +0000152 else
Nick Nunley2a1f8792010-04-27 13:10:50 +0000153 dma_unmap_single(&adapter->pdev->dev,
Greg Rose92915f72010-01-09 02:24:10 +0000154 tx_buffer_info->dma,
155 tx_buffer_info->length,
Nick Nunley2a1f8792010-04-27 13:10:50 +0000156 DMA_TO_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +0000157 tx_buffer_info->dma = 0;
158 }
159 if (tx_buffer_info->skb) {
160 dev_kfree_skb_any(tx_buffer_info->skb);
161 tx_buffer_info->skb = NULL;
162 }
163 tx_buffer_info->time_stamp = 0;
164 /* tx_buffer_info must be completely set up in the transmit path */
165}
166
Greg Rose92915f72010-01-09 02:24:10 +0000167#define IXGBE_MAX_TXD_PWR 14
168#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
169
170/* Tx Descriptors needed, worst case */
171#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
172 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
173#ifdef MAX_SKB_FRAGS
174#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
175 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
176#else
177#define DESC_NEEDED TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD)
178#endif
179
180static void ixgbevf_tx_timeout(struct net_device *netdev);
181
182/**
183 * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
184 * @adapter: board private structure
185 * @tx_ring: tx ring to clean
186 **/
187static bool ixgbevf_clean_tx_irq(struct ixgbevf_adapter *adapter,
188 struct ixgbevf_ring *tx_ring)
189{
190 struct net_device *netdev = adapter->netdev;
191 struct ixgbe_hw *hw = &adapter->hw;
192 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
193 struct ixgbevf_tx_buffer *tx_buffer_info;
194 unsigned int i, eop, count = 0;
195 unsigned int total_bytes = 0, total_packets = 0;
196
197 i = tx_ring->next_to_clean;
198 eop = tx_ring->tx_buffer_info[i].next_to_watch;
199 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
200
201 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
202 (count < tx_ring->work_limit)) {
203 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000204 rmb(); /* read buffer_info after eop_desc */
Greg Rose92915f72010-01-09 02:24:10 +0000205 for ( ; !cleaned; count++) {
206 struct sk_buff *skb;
207 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
208 tx_buffer_info = &tx_ring->tx_buffer_info[i];
209 cleaned = (i == eop);
210 skb = tx_buffer_info->skb;
211
212 if (cleaned && skb) {
213 unsigned int segs, bytecount;
214
215 /* gso_segs is currently only valid for tcp */
216 segs = skb_shinfo(skb)->gso_segs ?: 1;
217 /* multiply data chunks by size of headers */
218 bytecount = ((segs - 1) * skb_headlen(skb)) +
219 skb->len;
220 total_packets += segs;
221 total_bytes += bytecount;
222 }
223
224 ixgbevf_unmap_and_free_tx_resource(adapter,
225 tx_buffer_info);
226
227 tx_desc->wb.status = 0;
228
229 i++;
230 if (i == tx_ring->count)
231 i = 0;
232 }
233
234 eop = tx_ring->tx_buffer_info[i].next_to_watch;
235 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
236 }
237
238 tx_ring->next_to_clean = i;
239
240#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
241 if (unlikely(count && netif_carrier_ok(netdev) &&
242 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
243 /* Make sure that anybody stopping the queue after this
244 * sees the new next_to_clean.
245 */
246 smp_mb();
247#ifdef HAVE_TX_MQ
248 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
249 !test_bit(__IXGBEVF_DOWN, &adapter->state)) {
250 netif_wake_subqueue(netdev, tx_ring->queue_index);
251 ++adapter->restart_queue;
252 }
253#else
254 if (netif_queue_stopped(netdev) &&
255 !test_bit(__IXGBEVF_DOWN, &adapter->state)) {
256 netif_wake_queue(netdev);
257 ++adapter->restart_queue;
258 }
259#endif
260 }
261
Greg Rose92915f72010-01-09 02:24:10 +0000262 /* re-arm the interrupt */
263 if ((count >= tx_ring->work_limit) &&
264 (!test_bit(__IXGBEVF_DOWN, &adapter->state))) {
265 IXGBE_WRITE_REG(hw, IXGBE_VTEICS, tx_ring->v_idx);
266 }
267
268 tx_ring->total_bytes += total_bytes;
269 tx_ring->total_packets += total_packets;
270
Eric Dumazetfb621ba2010-09-08 22:48:31 +0000271 netdev->stats.tx_bytes += total_bytes;
272 netdev->stats.tx_packets += total_packets;
Greg Rose92915f72010-01-09 02:24:10 +0000273
Eric Dumazet807540b2010-09-23 05:40:09 +0000274 return count < tx_ring->work_limit;
Greg Rose92915f72010-01-09 02:24:10 +0000275}
276
277/**
278 * ixgbevf_receive_skb - Send a completed packet up the stack
279 * @q_vector: structure containing interrupt and ring information
280 * @skb: packet to send up
281 * @status: hardware indication of status of receive
282 * @rx_ring: rx descriptor ring (for a specific queue) to setup
283 * @rx_desc: rx descriptor
284 **/
285static void ixgbevf_receive_skb(struct ixgbevf_q_vector *q_vector,
286 struct sk_buff *skb, u8 status,
287 struct ixgbevf_ring *ring,
288 union ixgbe_adv_rx_desc *rx_desc)
289{
290 struct ixgbevf_adapter *adapter = q_vector->adapter;
291 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
Greg Rose92915f72010-01-09 02:24:10 +0000292
Jiri Pirkodadcd652011-07-21 03:25:09 +0000293 if (is_vlan) {
294 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
295
296 __vlan_hwaccel_put_tag(skb, tag);
Greg Rose92915f72010-01-09 02:24:10 +0000297 }
Jiri Pirkodadcd652011-07-21 03:25:09 +0000298
299 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
300 napi_gro_receive(&q_vector->napi, skb);
301 else
302 netif_rx(skb);
Greg Rose92915f72010-01-09 02:24:10 +0000303}
304
305/**
306 * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
307 * @adapter: address of board private structure
308 * @status_err: hardware indication of status of receive
309 * @skb: skb currently being received and modified
310 **/
311static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter *adapter,
312 u32 status_err, struct sk_buff *skb)
313{
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700314 skb_checksum_none_assert(skb);
Greg Rose92915f72010-01-09 02:24:10 +0000315
316 /* Rx csum disabled */
317 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
318 return;
319
320 /* if IP and error */
321 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
322 (status_err & IXGBE_RXDADV_ERR_IPE)) {
323 adapter->hw_csum_rx_error++;
324 return;
325 }
326
327 if (!(status_err & IXGBE_RXD_STAT_L4CS))
328 return;
329
330 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
331 adapter->hw_csum_rx_error++;
332 return;
333 }
334
335 /* It must be a TCP or UDP packet with a valid checksum */
336 skb->ip_summed = CHECKSUM_UNNECESSARY;
337 adapter->hw_csum_rx_good++;
338}
339
340/**
341 * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
342 * @adapter: address of board private structure
343 **/
344static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter *adapter,
345 struct ixgbevf_ring *rx_ring,
346 int cleaned_count)
347{
348 struct pci_dev *pdev = adapter->pdev;
349 union ixgbe_adv_rx_desc *rx_desc;
350 struct ixgbevf_rx_buffer *bi;
351 struct sk_buff *skb;
352 unsigned int i;
353 unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN;
354
355 i = rx_ring->next_to_use;
356 bi = &rx_ring->rx_buffer_info[i];
357
358 while (cleaned_count--) {
359 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
360
361 if (!bi->page_dma &&
362 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
363 if (!bi->page) {
364 bi->page = netdev_alloc_page(adapter->netdev);
365 if (!bi->page) {
366 adapter->alloc_rx_page_failed++;
367 goto no_buffers;
368 }
369 bi->page_offset = 0;
370 } else {
371 /* use a half page if we're re-using */
372 bi->page_offset ^= (PAGE_SIZE / 2);
373 }
374
Nick Nunley2a1f8792010-04-27 13:10:50 +0000375 bi->page_dma = dma_map_page(&pdev->dev, bi->page,
Greg Rose92915f72010-01-09 02:24:10 +0000376 bi->page_offset,
377 (PAGE_SIZE / 2),
Nick Nunley2a1f8792010-04-27 13:10:50 +0000378 DMA_FROM_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +0000379 }
380
381 skb = bi->skb;
382 if (!skb) {
383 skb = netdev_alloc_skb(adapter->netdev,
384 bufsz);
385
386 if (!skb) {
387 adapter->alloc_rx_buff_failed++;
388 goto no_buffers;
389 }
390
391 /*
392 * Make buffer alignment 2 beyond a 16 byte boundary
393 * this will result in a 16 byte aligned IP header after
394 * the 14 byte MAC header is removed
395 */
396 skb_reserve(skb, NET_IP_ALIGN);
397
398 bi->skb = skb;
399 }
400 if (!bi->dma) {
Nick Nunley2a1f8792010-04-27 13:10:50 +0000401 bi->dma = dma_map_single(&pdev->dev, skb->data,
Greg Rose92915f72010-01-09 02:24:10 +0000402 rx_ring->rx_buf_len,
Nick Nunley2a1f8792010-04-27 13:10:50 +0000403 DMA_FROM_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +0000404 }
405 /* Refresh the desc even if buffer_addrs didn't change because
406 * each write-back erases this info. */
407 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
408 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
409 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
410 } else {
411 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
412 }
413
414 i++;
415 if (i == rx_ring->count)
416 i = 0;
417 bi = &rx_ring->rx_buffer_info[i];
418 }
419
420no_buffers:
421 if (rx_ring->next_to_use != i) {
422 rx_ring->next_to_use = i;
423 if (i-- == 0)
424 i = (rx_ring->count - 1);
425
426 ixgbevf_release_rx_desc(&adapter->hw, rx_ring, i);
427 }
428}
429
430static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter *adapter,
431 u64 qmask)
432{
433 u32 mask;
434 struct ixgbe_hw *hw = &adapter->hw;
435
436 mask = (qmask & 0xFFFFFFFF);
437 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
438}
439
440static inline u16 ixgbevf_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
441{
442 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
443}
444
445static inline u16 ixgbevf_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
446{
447 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
448}
449
450static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector,
451 struct ixgbevf_ring *rx_ring,
452 int *work_done, int work_to_do)
453{
454 struct ixgbevf_adapter *adapter = q_vector->adapter;
455 struct pci_dev *pdev = adapter->pdev;
456 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
457 struct ixgbevf_rx_buffer *rx_buffer_info, *next_buffer;
458 struct sk_buff *skb;
459 unsigned int i;
460 u32 len, staterr;
461 u16 hdr_info;
462 bool cleaned = false;
463 int cleaned_count = 0;
464 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
465
466 i = rx_ring->next_to_clean;
467 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
468 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
469 rx_buffer_info = &rx_ring->rx_buffer_info[i];
470
471 while (staterr & IXGBE_RXD_STAT_DD) {
472 u32 upper_len = 0;
473 if (*work_done >= work_to_do)
474 break;
475 (*work_done)++;
476
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000477 rmb(); /* read descriptor and rx_buffer_info after status DD */
Greg Rose92915f72010-01-09 02:24:10 +0000478 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
479 hdr_info = le16_to_cpu(ixgbevf_get_hdr_info(rx_desc));
480 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
481 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
482 if (hdr_info & IXGBE_RXDADV_SPH)
483 adapter->rx_hdr_split++;
484 if (len > IXGBEVF_RX_HDR_SIZE)
485 len = IXGBEVF_RX_HDR_SIZE;
486 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
487 } else {
488 len = le16_to_cpu(rx_desc->wb.upper.length);
489 }
490 cleaned = true;
491 skb = rx_buffer_info->skb;
492 prefetch(skb->data - NET_IP_ALIGN);
493 rx_buffer_info->skb = NULL;
494
495 if (rx_buffer_info->dma) {
Nick Nunley2a1f8792010-04-27 13:10:50 +0000496 dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
Greg Rose92915f72010-01-09 02:24:10 +0000497 rx_ring->rx_buf_len,
Nick Nunley2a1f8792010-04-27 13:10:50 +0000498 DMA_FROM_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +0000499 rx_buffer_info->dma = 0;
500 skb_put(skb, len);
501 }
502
503 if (upper_len) {
Nick Nunley2a1f8792010-04-27 13:10:50 +0000504 dma_unmap_page(&pdev->dev, rx_buffer_info->page_dma,
505 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +0000506 rx_buffer_info->page_dma = 0;
507 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
508 rx_buffer_info->page,
509 rx_buffer_info->page_offset,
510 upper_len);
511
512 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
513 (page_count(rx_buffer_info->page) != 1))
514 rx_buffer_info->page = NULL;
515 else
516 get_page(rx_buffer_info->page);
517
518 skb->len += upper_len;
519 skb->data_len += upper_len;
520 skb->truesize += upper_len;
521 }
522
523 i++;
524 if (i == rx_ring->count)
525 i = 0;
526
527 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
528 prefetch(next_rxd);
529 cleaned_count++;
530
531 next_buffer = &rx_ring->rx_buffer_info[i];
532
533 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
534 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
535 rx_buffer_info->skb = next_buffer->skb;
536 rx_buffer_info->dma = next_buffer->dma;
537 next_buffer->skb = skb;
538 next_buffer->dma = 0;
539 } else {
540 skb->next = next_buffer->skb;
541 skb->next->prev = skb;
542 }
543 adapter->non_eop_descs++;
544 goto next_desc;
545 }
546
547 /* ERR_MASK will only have valid bits if EOP set */
548 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
549 dev_kfree_skb_irq(skb);
550 goto next_desc;
551 }
552
553 ixgbevf_rx_checksum(adapter, staterr, skb);
554
555 /* probably a little skewed due to removing CRC */
556 total_rx_bytes += skb->len;
557 total_rx_packets++;
558
559 /*
560 * Work around issue of some types of VM to VM loop back
561 * packets not getting split correctly
562 */
563 if (staterr & IXGBE_RXD_STAT_LB) {
Eric Dumazete743d312010-04-14 15:59:40 -0700564 u32 header_fixup_len = skb_headlen(skb);
Greg Rose92915f72010-01-09 02:24:10 +0000565 if (header_fixup_len < 14)
566 skb_push(skb, header_fixup_len);
567 }
568 skb->protocol = eth_type_trans(skb, adapter->netdev);
569
570 ixgbevf_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Greg Rose92915f72010-01-09 02:24:10 +0000571
572next_desc:
573 rx_desc->wb.upper.status_error = 0;
574
575 /* return some buffers to hardware, one at a time is too slow */
576 if (cleaned_count >= IXGBEVF_RX_BUFFER_WRITE) {
577 ixgbevf_alloc_rx_buffers(adapter, rx_ring,
578 cleaned_count);
579 cleaned_count = 0;
580 }
581
582 /* use prefetched values */
583 rx_desc = next_rxd;
584 rx_buffer_info = &rx_ring->rx_buffer_info[i];
585
586 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
587 }
588
589 rx_ring->next_to_clean = i;
590 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
591
592 if (cleaned_count)
593 ixgbevf_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
594
595 rx_ring->total_packets += total_rx_packets;
596 rx_ring->total_bytes += total_rx_bytes;
Eric Dumazetfb621ba2010-09-08 22:48:31 +0000597 adapter->netdev->stats.rx_bytes += total_rx_bytes;
598 adapter->netdev->stats.rx_packets += total_rx_packets;
Greg Rose92915f72010-01-09 02:24:10 +0000599
600 return cleaned;
601}
602
603/**
604 * ixgbevf_clean_rxonly - msix (aka one shot) rx clean routine
605 * @napi: napi struct with our devices info in it
606 * @budget: amount of work driver is allowed to do this pass, in packets
607 *
608 * This function is optimized for cleaning one queue only on a single
609 * q_vector!!!
610 **/
611static int ixgbevf_clean_rxonly(struct napi_struct *napi, int budget)
612{
613 struct ixgbevf_q_vector *q_vector =
614 container_of(napi, struct ixgbevf_q_vector, napi);
615 struct ixgbevf_adapter *adapter = q_vector->adapter;
616 struct ixgbevf_ring *rx_ring = NULL;
617 int work_done = 0;
618 long r_idx;
619
620 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
621 rx_ring = &(adapter->rx_ring[r_idx]);
622
623 ixgbevf_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
624
625 /* If all Rx work done, exit the polling mode */
626 if (work_done < budget) {
627 napi_complete(napi);
628 if (adapter->itr_setting & 1)
629 ixgbevf_set_itr_msix(q_vector);
630 if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
631 ixgbevf_irq_enable_queues(adapter, rx_ring->v_idx);
632 }
633
634 return work_done;
635}
636
637/**
638 * ixgbevf_clean_rxonly_many - msix (aka one shot) rx clean routine
639 * @napi: napi struct with our devices info in it
640 * @budget: amount of work driver is allowed to do this pass, in packets
641 *
642 * This function will clean more than one rx queue associated with a
643 * q_vector.
644 **/
645static int ixgbevf_clean_rxonly_many(struct napi_struct *napi, int budget)
646{
647 struct ixgbevf_q_vector *q_vector =
648 container_of(napi, struct ixgbevf_q_vector, napi);
649 struct ixgbevf_adapter *adapter = q_vector->adapter;
650 struct ixgbevf_ring *rx_ring = NULL;
651 int work_done = 0, i;
652 long r_idx;
653 u64 enable_mask = 0;
654
655 /* attempt to distribute budget to each queue fairly, but don't allow
656 * the budget to go below 1 because we'll exit polling */
657 budget /= (q_vector->rxr_count ?: 1);
658 budget = max(budget, 1);
659 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
660 for (i = 0; i < q_vector->rxr_count; i++) {
661 rx_ring = &(adapter->rx_ring[r_idx]);
662 ixgbevf_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
663 enable_mask |= rx_ring->v_idx;
664 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
665 r_idx + 1);
666 }
667
668#ifndef HAVE_NETDEV_NAPI_LIST
669 if (!netif_running(adapter->netdev))
670 work_done = 0;
671
672#endif
673 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
674 rx_ring = &(adapter->rx_ring[r_idx]);
675
676 /* If all Rx work done, exit the polling mode */
677 if (work_done < budget) {
678 napi_complete(napi);
679 if (adapter->itr_setting & 1)
680 ixgbevf_set_itr_msix(q_vector);
681 if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
682 ixgbevf_irq_enable_queues(adapter, enable_mask);
683 }
684
685 return work_done;
686}
687
688
689/**
690 * ixgbevf_configure_msix - Configure MSI-X hardware
691 * @adapter: board private structure
692 *
693 * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X
694 * interrupts.
695 **/
696static void ixgbevf_configure_msix(struct ixgbevf_adapter *adapter)
697{
698 struct ixgbevf_q_vector *q_vector;
699 struct ixgbe_hw *hw = &adapter->hw;
700 int i, j, q_vectors, v_idx, r_idx;
701 u32 mask;
702
703 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
704
705 /*
706 * Populate the IVAR table and set the ITR values to the
707 * corresponding register.
708 */
709 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
710 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -0800711 /* XXX for_each_set_bit(...) */
Greg Rose92915f72010-01-09 02:24:10 +0000712 r_idx = find_first_bit(q_vector->rxr_idx,
713 adapter->num_rx_queues);
714
715 for (i = 0; i < q_vector->rxr_count; i++) {
716 j = adapter->rx_ring[r_idx].reg_idx;
717 ixgbevf_set_ivar(adapter, 0, j, v_idx);
718 r_idx = find_next_bit(q_vector->rxr_idx,
719 adapter->num_rx_queues,
720 r_idx + 1);
721 }
722 r_idx = find_first_bit(q_vector->txr_idx,
723 adapter->num_tx_queues);
724
725 for (i = 0; i < q_vector->txr_count; i++) {
726 j = adapter->tx_ring[r_idx].reg_idx;
727 ixgbevf_set_ivar(adapter, 1, j, v_idx);
728 r_idx = find_next_bit(q_vector->txr_idx,
729 adapter->num_tx_queues,
730 r_idx + 1);
731 }
732
733 /* if this is a tx only vector halve the interrupt rate */
734 if (q_vector->txr_count && !q_vector->rxr_count)
735 q_vector->eitr = (adapter->eitr_param >> 1);
736 else if (q_vector->rxr_count)
737 /* rx only */
738 q_vector->eitr = adapter->eitr_param;
739
740 ixgbevf_write_eitr(adapter, v_idx, q_vector->eitr);
741 }
742
743 ixgbevf_set_ivar(adapter, -1, 1, v_idx);
744
745 /* set up to autoclear timer, and the vectors */
746 mask = IXGBE_EIMS_ENABLE_MASK;
747 mask &= ~IXGBE_EIMS_OTHER;
748 IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, mask);
749}
750
751enum latency_range {
752 lowest_latency = 0,
753 low_latency = 1,
754 bulk_latency = 2,
755 latency_invalid = 255
756};
757
758/**
759 * ixgbevf_update_itr - update the dynamic ITR value based on statistics
760 * @adapter: pointer to adapter
761 * @eitr: eitr setting (ints per sec) to give last timeslice
762 * @itr_setting: current throttle rate in ints/second
763 * @packets: the number of packets during this measurement interval
764 * @bytes: the number of bytes during this measurement interval
765 *
766 * Stores a new ITR value based on packets and byte
767 * counts during the last interrupt. The advantage of per interrupt
768 * computation is faster updates and more accurate ITR for the current
769 * traffic pattern. Constants in this function were computed
770 * based on theoretical maximum wire speed and thresholds were set based
771 * on testing data as well as attempting to minimize response time
772 * while increasing bulk throughput.
773 **/
774static u8 ixgbevf_update_itr(struct ixgbevf_adapter *adapter,
775 u32 eitr, u8 itr_setting,
776 int packets, int bytes)
777{
778 unsigned int retval = itr_setting;
779 u32 timepassed_us;
780 u64 bytes_perint;
781
782 if (packets == 0)
783 goto update_itr_done;
784
785
786 /* simple throttlerate management
787 * 0-20MB/s lowest (100000 ints/s)
788 * 20-100MB/s low (20000 ints/s)
789 * 100-1249MB/s bulk (8000 ints/s)
790 */
791 /* what was last interrupt timeslice? */
792 timepassed_us = 1000000/eitr;
793 bytes_perint = bytes / timepassed_us; /* bytes/usec */
794
795 switch (itr_setting) {
796 case lowest_latency:
797 if (bytes_perint > adapter->eitr_low)
798 retval = low_latency;
799 break;
800 case low_latency:
801 if (bytes_perint > adapter->eitr_high)
802 retval = bulk_latency;
803 else if (bytes_perint <= adapter->eitr_low)
804 retval = lowest_latency;
805 break;
806 case bulk_latency:
807 if (bytes_perint <= adapter->eitr_high)
808 retval = low_latency;
809 break;
810 }
811
812update_itr_done:
813 return retval;
814}
815
816/**
817 * ixgbevf_write_eitr - write VTEITR register in hardware specific way
818 * @adapter: pointer to adapter struct
819 * @v_idx: vector index into q_vector array
820 * @itr_reg: new value to be written in *register* format, not ints/s
821 *
822 * This function is made to be called by ethtool and by the driver
823 * when it needs to update VTEITR registers at runtime. Hardware
824 * specific quirks/differences are taken care of here.
825 */
826static void ixgbevf_write_eitr(struct ixgbevf_adapter *adapter, int v_idx,
827 u32 itr_reg)
828{
829 struct ixgbe_hw *hw = &adapter->hw;
830
831 itr_reg = EITR_INTS_PER_SEC_TO_REG(itr_reg);
832
833 /*
834 * set the WDIS bit to not clear the timer bits and cause an
835 * immediate assertion of the interrupt
836 */
837 itr_reg |= IXGBE_EITR_CNT_WDIS;
838
839 IXGBE_WRITE_REG(hw, IXGBE_VTEITR(v_idx), itr_reg);
840}
841
842static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector *q_vector)
843{
844 struct ixgbevf_adapter *adapter = q_vector->adapter;
845 u32 new_itr;
846 u8 current_itr, ret_itr;
847 int i, r_idx, v_idx = q_vector->v_idx;
848 struct ixgbevf_ring *rx_ring, *tx_ring;
849
850 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
851 for (i = 0; i < q_vector->txr_count; i++) {
852 tx_ring = &(adapter->tx_ring[r_idx]);
853 ret_itr = ixgbevf_update_itr(adapter, q_vector->eitr,
854 q_vector->tx_itr,
855 tx_ring->total_packets,
856 tx_ring->total_bytes);
857 /* if the result for this queue would decrease interrupt
858 * rate for this vector then use that result */
859 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
860 q_vector->tx_itr - 1 : ret_itr);
861 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
862 r_idx + 1);
863 }
864
865 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
866 for (i = 0; i < q_vector->rxr_count; i++) {
867 rx_ring = &(adapter->rx_ring[r_idx]);
868 ret_itr = ixgbevf_update_itr(adapter, q_vector->eitr,
869 q_vector->rx_itr,
870 rx_ring->total_packets,
871 rx_ring->total_bytes);
872 /* if the result for this queue would decrease interrupt
873 * rate for this vector then use that result */
874 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
875 q_vector->rx_itr - 1 : ret_itr);
876 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
877 r_idx + 1);
878 }
879
880 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
881
882 switch (current_itr) {
883 /* counts and packets in update_itr are dependent on these numbers */
884 case lowest_latency:
885 new_itr = 100000;
886 break;
887 case low_latency:
888 new_itr = 20000; /* aka hwitr = ~200 */
889 break;
890 case bulk_latency:
891 default:
892 new_itr = 8000;
893 break;
894 }
895
896 if (new_itr != q_vector->eitr) {
897 u32 itr_reg;
898
899 /* save the algorithm value here, not the smoothed one */
900 q_vector->eitr = new_itr;
901 /* do an exponential smoothing */
902 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
903 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
904 ixgbevf_write_eitr(adapter, v_idx, itr_reg);
905 }
Greg Rose92915f72010-01-09 02:24:10 +0000906}
907
908static irqreturn_t ixgbevf_msix_mbx(int irq, void *data)
909{
910 struct net_device *netdev = data;
911 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
912 struct ixgbe_hw *hw = &adapter->hw;
913 u32 eicr;
Greg Rosea9ee25a2010-01-22 22:47:00 +0000914 u32 msg;
Greg Rose92915f72010-01-09 02:24:10 +0000915
916 eicr = IXGBE_READ_REG(hw, IXGBE_VTEICS);
917 IXGBE_WRITE_REG(hw, IXGBE_VTEICR, eicr);
918
Greg Rose08259592010-05-05 19:57:49 +0000919 if (!hw->mbx.ops.check_for_ack(hw)) {
920 /*
921 * checking for the ack clears the PFACK bit. Place
922 * it back in the v2p_mailbox cache so that anyone
923 * polling for an ack will not miss it. Also
924 * avoid the read below because the code to read
925 * the mailbox will also clear the ack bit. This was
926 * causing lost acks. Just cache the bit and exit
927 * the IRQ handler.
928 */
929 hw->mbx.v2p_mailbox |= IXGBE_VFMAILBOX_PFACK;
930 goto out;
931 }
932
933 /* Not an ack interrupt, go ahead and read the message */
Greg Rosea9ee25a2010-01-22 22:47:00 +0000934 hw->mbx.ops.read(hw, &msg, 1);
935
936 if ((msg & IXGBE_MBVFICR_VFREQ_MASK) == IXGBE_PF_CONTROL_MSG)
937 mod_timer(&adapter->watchdog_timer,
Greg Rose4c3a8222010-03-19 03:00:12 +0000938 round_jiffies(jiffies + 1));
Greg Rosea9ee25a2010-01-22 22:47:00 +0000939
Greg Rose08259592010-05-05 19:57:49 +0000940out:
Greg Rose92915f72010-01-09 02:24:10 +0000941 return IRQ_HANDLED;
942}
943
944static irqreturn_t ixgbevf_msix_clean_tx(int irq, void *data)
945{
946 struct ixgbevf_q_vector *q_vector = data;
947 struct ixgbevf_adapter *adapter = q_vector->adapter;
948 struct ixgbevf_ring *tx_ring;
949 int i, r_idx;
950
951 if (!q_vector->txr_count)
952 return IRQ_HANDLED;
953
954 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
955 for (i = 0; i < q_vector->txr_count; i++) {
956 tx_ring = &(adapter->tx_ring[r_idx]);
957 tx_ring->total_bytes = 0;
958 tx_ring->total_packets = 0;
959 ixgbevf_clean_tx_irq(adapter, tx_ring);
960 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
961 r_idx + 1);
962 }
963
964 if (adapter->itr_setting & 1)
965 ixgbevf_set_itr_msix(q_vector);
966
967 return IRQ_HANDLED;
968}
969
970/**
Greg Rose65d676c2011-02-03 06:54:13 +0000971 * ixgbevf_msix_clean_rx - single unshared vector rx clean (all queues)
Greg Rose92915f72010-01-09 02:24:10 +0000972 * @irq: unused
973 * @data: pointer to our q_vector struct for this interrupt vector
974 **/
975static irqreturn_t ixgbevf_msix_clean_rx(int irq, void *data)
976{
977 struct ixgbevf_q_vector *q_vector = data;
978 struct ixgbevf_adapter *adapter = q_vector->adapter;
979 struct ixgbe_hw *hw = &adapter->hw;
980 struct ixgbevf_ring *rx_ring;
981 int r_idx;
982 int i;
983
984 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
985 for (i = 0; i < q_vector->rxr_count; i++) {
986 rx_ring = &(adapter->rx_ring[r_idx]);
987 rx_ring->total_bytes = 0;
988 rx_ring->total_packets = 0;
989 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
990 r_idx + 1);
991 }
992
993 if (!q_vector->rxr_count)
994 return IRQ_HANDLED;
995
996 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
997 rx_ring = &(adapter->rx_ring[r_idx]);
998 /* disable interrupts on this vector only */
999 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, rx_ring->v_idx);
1000 napi_schedule(&q_vector->napi);
1001
1002
1003 return IRQ_HANDLED;
1004}
1005
1006static irqreturn_t ixgbevf_msix_clean_many(int irq, void *data)
1007{
1008 ixgbevf_msix_clean_rx(irq, data);
1009 ixgbevf_msix_clean_tx(irq, data);
1010
1011 return IRQ_HANDLED;
1012}
1013
1014static inline void map_vector_to_rxq(struct ixgbevf_adapter *a, int v_idx,
1015 int r_idx)
1016{
1017 struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx];
1018
1019 set_bit(r_idx, q_vector->rxr_idx);
1020 q_vector->rxr_count++;
1021 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1022}
1023
1024static inline void map_vector_to_txq(struct ixgbevf_adapter *a, int v_idx,
1025 int t_idx)
1026{
1027 struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx];
1028
1029 set_bit(t_idx, q_vector->txr_idx);
1030 q_vector->txr_count++;
1031 a->tx_ring[t_idx].v_idx = 1 << v_idx;
1032}
1033
1034/**
1035 * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
1036 * @adapter: board private structure to initialize
1037 *
1038 * This function maps descriptor rings to the queue-specific vectors
1039 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1040 * one vector per ring/queue, but on a constrained vector budget, we
1041 * group the rings as "efficiently" as possible. You would add new
1042 * mapping configurations in here.
1043 **/
1044static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter *adapter)
1045{
1046 int q_vectors;
1047 int v_start = 0;
1048 int rxr_idx = 0, txr_idx = 0;
1049 int rxr_remaining = adapter->num_rx_queues;
1050 int txr_remaining = adapter->num_tx_queues;
1051 int i, j;
1052 int rqpv, tqpv;
1053 int err = 0;
1054
1055 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1056
1057 /*
1058 * The ideal configuration...
1059 * We have enough vectors to map one per queue.
1060 */
1061 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1062 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1063 map_vector_to_rxq(adapter, v_start, rxr_idx);
1064
1065 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1066 map_vector_to_txq(adapter, v_start, txr_idx);
1067 goto out;
1068 }
1069
1070 /*
1071 * If we don't have enough vectors for a 1-to-1
1072 * mapping, we'll have to group them so there are
1073 * multiple queues per vector.
1074 */
1075 /* Re-adjusting *qpv takes care of the remainder. */
1076 for (i = v_start; i < q_vectors; i++) {
1077 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
1078 for (j = 0; j < rqpv; j++) {
1079 map_vector_to_rxq(adapter, i, rxr_idx);
1080 rxr_idx++;
1081 rxr_remaining--;
1082 }
1083 }
1084 for (i = v_start; i < q_vectors; i++) {
1085 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
1086 for (j = 0; j < tqpv; j++) {
1087 map_vector_to_txq(adapter, i, txr_idx);
1088 txr_idx++;
1089 txr_remaining--;
1090 }
1091 }
1092
1093out:
1094 return err;
1095}
1096
1097/**
1098 * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
1099 * @adapter: board private structure
1100 *
1101 * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
1102 * interrupts from the kernel.
1103 **/
1104static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter *adapter)
1105{
1106 struct net_device *netdev = adapter->netdev;
1107 irqreturn_t (*handler)(int, void *);
1108 int i, vector, q_vectors, err;
1109 int ri = 0, ti = 0;
1110
1111 /* Decrement for Other and TCP Timer vectors */
1112 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1113
1114#define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
1115 ? &ixgbevf_msix_clean_many : \
1116 (_v)->rxr_count ? &ixgbevf_msix_clean_rx : \
1117 (_v)->txr_count ? &ixgbevf_msix_clean_tx : \
1118 NULL)
1119 for (vector = 0; vector < q_vectors; vector++) {
1120 handler = SET_HANDLER(adapter->q_vector[vector]);
1121
1122 if (handler == &ixgbevf_msix_clean_rx) {
1123 sprintf(adapter->name[vector], "%s-%s-%d",
1124 netdev->name, "rx", ri++);
1125 } else if (handler == &ixgbevf_msix_clean_tx) {
1126 sprintf(adapter->name[vector], "%s-%s-%d",
1127 netdev->name, "tx", ti++);
1128 } else if (handler == &ixgbevf_msix_clean_many) {
1129 sprintf(adapter->name[vector], "%s-%s-%d",
1130 netdev->name, "TxRx", vector);
1131 } else {
1132 /* skip this unused q_vector */
1133 continue;
1134 }
1135 err = request_irq(adapter->msix_entries[vector].vector,
1136 handler, 0, adapter->name[vector],
1137 adapter->q_vector[vector]);
1138 if (err) {
1139 hw_dbg(&adapter->hw,
1140 "request_irq failed for MSIX interrupt "
1141 "Error: %d\n", err);
1142 goto free_queue_irqs;
1143 }
1144 }
1145
1146 sprintf(adapter->name[vector], "%s:mbx", netdev->name);
1147 err = request_irq(adapter->msix_entries[vector].vector,
1148 &ixgbevf_msix_mbx, 0, adapter->name[vector], netdev);
1149 if (err) {
1150 hw_dbg(&adapter->hw,
1151 "request_irq for msix_mbx failed: %d\n", err);
1152 goto free_queue_irqs;
1153 }
1154
1155 return 0;
1156
1157free_queue_irqs:
1158 for (i = vector - 1; i >= 0; i--)
1159 free_irq(adapter->msix_entries[--vector].vector,
1160 &(adapter->q_vector[i]));
1161 pci_disable_msix(adapter->pdev);
1162 kfree(adapter->msix_entries);
1163 adapter->msix_entries = NULL;
1164 return err;
1165}
1166
1167static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter *adapter)
1168{
1169 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1170
1171 for (i = 0; i < q_vectors; i++) {
1172 struct ixgbevf_q_vector *q_vector = adapter->q_vector[i];
1173 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1174 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1175 q_vector->rxr_count = 0;
1176 q_vector->txr_count = 0;
1177 q_vector->eitr = adapter->eitr_param;
1178 }
1179}
1180
1181/**
1182 * ixgbevf_request_irq - initialize interrupts
1183 * @adapter: board private structure
1184 *
1185 * Attempts to configure interrupts using the best available
1186 * capabilities of the hardware and kernel.
1187 **/
1188static int ixgbevf_request_irq(struct ixgbevf_adapter *adapter)
1189{
1190 int err = 0;
1191
1192 err = ixgbevf_request_msix_irqs(adapter);
1193
1194 if (err)
1195 hw_dbg(&adapter->hw,
1196 "request_irq failed, Error %d\n", err);
1197
1198 return err;
1199}
1200
1201static void ixgbevf_free_irq(struct ixgbevf_adapter *adapter)
1202{
1203 struct net_device *netdev = adapter->netdev;
1204 int i, q_vectors;
1205
1206 q_vectors = adapter->num_msix_vectors;
1207
1208 i = q_vectors - 1;
1209
1210 free_irq(adapter->msix_entries[i].vector, netdev);
1211 i--;
1212
1213 for (; i >= 0; i--) {
1214 free_irq(adapter->msix_entries[i].vector,
1215 adapter->q_vector[i]);
1216 }
1217
1218 ixgbevf_reset_q_vectors(adapter);
1219}
1220
1221/**
1222 * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
1223 * @adapter: board private structure
1224 **/
1225static inline void ixgbevf_irq_disable(struct ixgbevf_adapter *adapter)
1226{
1227 int i;
1228 struct ixgbe_hw *hw = &adapter->hw;
1229
1230 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, ~0);
1231
1232 IXGBE_WRITE_FLUSH(hw);
1233
1234 for (i = 0; i < adapter->num_msix_vectors; i++)
1235 synchronize_irq(adapter->msix_entries[i].vector);
1236}
1237
1238/**
1239 * ixgbevf_irq_enable - Enable default interrupt generation settings
1240 * @adapter: board private structure
1241 **/
1242static inline void ixgbevf_irq_enable(struct ixgbevf_adapter *adapter,
1243 bool queues, bool flush)
1244{
1245 struct ixgbe_hw *hw = &adapter->hw;
1246 u32 mask;
1247 u64 qmask;
1248
1249 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
1250 qmask = ~0;
1251
1252 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
1253
1254 if (queues)
1255 ixgbevf_irq_enable_queues(adapter, qmask);
1256
1257 if (flush)
1258 IXGBE_WRITE_FLUSH(hw);
1259}
1260
1261/**
1262 * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
1263 * @adapter: board private structure
1264 *
1265 * Configure the Tx unit of the MAC after a reset.
1266 **/
1267static void ixgbevf_configure_tx(struct ixgbevf_adapter *adapter)
1268{
1269 u64 tdba;
1270 struct ixgbe_hw *hw = &adapter->hw;
1271 u32 i, j, tdlen, txctrl;
1272
1273 /* Setup the HW Tx Head and Tail descriptor pointers */
1274 for (i = 0; i < adapter->num_tx_queues; i++) {
1275 struct ixgbevf_ring *ring = &adapter->tx_ring[i];
1276 j = ring->reg_idx;
1277 tdba = ring->dma;
1278 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
1279 IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(j),
1280 (tdba & DMA_BIT_MASK(32)));
1281 IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(j), (tdba >> 32));
1282 IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(j), tdlen);
1283 IXGBE_WRITE_REG(hw, IXGBE_VFTDH(j), 0);
1284 IXGBE_WRITE_REG(hw, IXGBE_VFTDT(j), 0);
1285 adapter->tx_ring[i].head = IXGBE_VFTDH(j);
1286 adapter->tx_ring[i].tail = IXGBE_VFTDT(j);
1287 /* Disable Tx Head Writeback RO bit, since this hoses
1288 * bookkeeping if things aren't delivered in order.
1289 */
1290 txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(j));
1291 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
1292 IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(j), txctrl);
1293 }
1294}
1295
1296#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1297
1298static void ixgbevf_configure_srrctl(struct ixgbevf_adapter *adapter, int index)
1299{
1300 struct ixgbevf_ring *rx_ring;
1301 struct ixgbe_hw *hw = &adapter->hw;
1302 u32 srrctl;
1303
1304 rx_ring = &adapter->rx_ring[index];
1305
1306 srrctl = IXGBE_SRRCTL_DROP_EN;
1307
1308 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1309 u16 bufsz = IXGBEVF_RXBUFFER_2048;
1310 /* grow the amount we can receive on large page machines */
1311 if (bufsz < (PAGE_SIZE / 2))
1312 bufsz = (PAGE_SIZE / 2);
1313 /* cap the bufsz at our largest descriptor size */
1314 bufsz = min((u16)IXGBEVF_MAX_RXBUFFER, bufsz);
1315
1316 srrctl |= bufsz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1317 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1318 srrctl |= ((IXGBEVF_RX_HDR_SIZE <<
1319 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1320 IXGBE_SRRCTL_BSIZEHDR_MASK);
1321 } else {
1322 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1323
1324 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1325 srrctl |= IXGBEVF_RXBUFFER_2048 >>
1326 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1327 else
1328 srrctl |= rx_ring->rx_buf_len >>
1329 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1330 }
1331 IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(index), srrctl);
1332}
1333
1334/**
1335 * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
1336 * @adapter: board private structure
1337 *
1338 * Configure the Rx unit of the MAC after a reset.
1339 **/
1340static void ixgbevf_configure_rx(struct ixgbevf_adapter *adapter)
1341{
1342 u64 rdba;
1343 struct ixgbe_hw *hw = &adapter->hw;
1344 struct net_device *netdev = adapter->netdev;
1345 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1346 int i, j;
1347 u32 rdlen;
1348 int rx_buf_len;
1349
1350 /* Decide whether to use packet split mode or not */
1351 if (netdev->mtu > ETH_DATA_LEN) {
1352 if (adapter->flags & IXGBE_FLAG_RX_PS_CAPABLE)
1353 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
1354 else
1355 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
1356 } else {
1357 if (adapter->flags & IXGBE_FLAG_RX_1BUF_CAPABLE)
1358 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
1359 else
1360 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
1361 }
1362
1363 /* Set the RX buffer length according to the mode */
1364 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1365 /* PSRTYPE must be initialized in 82599 */
1366 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
1367 IXGBE_PSRTYPE_UDPHDR |
1368 IXGBE_PSRTYPE_IPV4HDR |
1369 IXGBE_PSRTYPE_IPV6HDR |
1370 IXGBE_PSRTYPE_L2HDR;
1371 IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype);
1372 rx_buf_len = IXGBEVF_RX_HDR_SIZE;
1373 } else {
1374 IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, 0);
1375 if (netdev->mtu <= ETH_DATA_LEN)
1376 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1377 else
1378 rx_buf_len = ALIGN(max_frame, 1024);
1379 }
1380
1381 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1382 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1383 * the Base and Length of the Rx Descriptor Ring */
1384 for (i = 0; i < adapter->num_rx_queues; i++) {
1385 rdba = adapter->rx_ring[i].dma;
1386 j = adapter->rx_ring[i].reg_idx;
1387 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(j),
1388 (rdba & DMA_BIT_MASK(32)));
1389 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(j), (rdba >> 32));
1390 IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(j), rdlen);
1391 IXGBE_WRITE_REG(hw, IXGBE_VFRDH(j), 0);
1392 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(j), 0);
1393 adapter->rx_ring[i].head = IXGBE_VFRDH(j);
1394 adapter->rx_ring[i].tail = IXGBE_VFRDT(j);
1395 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
1396
1397 ixgbevf_configure_srrctl(adapter, j);
1398 }
1399}
1400
Greg Rose92915f72010-01-09 02:24:10 +00001401static void ixgbevf_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1402{
1403 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
1404 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose92915f72010-01-09 02:24:10 +00001405
1406 /* add VID to filter table */
1407 if (hw->mac.ops.set_vfta)
1408 hw->mac.ops.set_vfta(hw, vid, 0, true);
Jiri Pirkodadcd652011-07-21 03:25:09 +00001409 set_bit(vid, adapter->active_vlans);
Greg Rose92915f72010-01-09 02:24:10 +00001410}
1411
1412static void ixgbevf_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1413{
1414 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
1415 struct ixgbe_hw *hw = &adapter->hw;
1416
Greg Rose92915f72010-01-09 02:24:10 +00001417 /* remove VID from filter table */
1418 if (hw->mac.ops.set_vfta)
1419 hw->mac.ops.set_vfta(hw, vid, 0, false);
Jiri Pirkodadcd652011-07-21 03:25:09 +00001420 clear_bit(vid, adapter->active_vlans);
Greg Rose92915f72010-01-09 02:24:10 +00001421}
1422
1423static void ixgbevf_restore_vlan(struct ixgbevf_adapter *adapter)
1424{
Jiri Pirkodadcd652011-07-21 03:25:09 +00001425 u16 vid;
Greg Rose92915f72010-01-09 02:24:10 +00001426
Jiri Pirkodadcd652011-07-21 03:25:09 +00001427 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
1428 ixgbevf_vlan_rx_add_vid(adapter->netdev, vid);
Greg Rose92915f72010-01-09 02:24:10 +00001429}
1430
Greg Rose46ec20f2011-05-13 01:33:42 +00001431static int ixgbevf_write_uc_addr_list(struct net_device *netdev)
1432{
1433 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
1434 struct ixgbe_hw *hw = &adapter->hw;
1435 int count = 0;
1436
1437 if ((netdev_uc_count(netdev)) > 10) {
1438 printk(KERN_ERR "Too many unicast filters - No Space\n");
1439 return -ENOSPC;
1440 }
1441
1442 if (!netdev_uc_empty(netdev)) {
1443 struct netdev_hw_addr *ha;
1444 netdev_for_each_uc_addr(ha, netdev) {
1445 hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
1446 udelay(200);
1447 }
1448 } else {
1449 /*
1450 * If the list is empty then send message to PF driver to
1451 * clear all macvlans on this VF.
1452 */
1453 hw->mac.ops.set_uc_addr(hw, 0, NULL);
1454 }
1455
1456 return count;
1457}
1458
Greg Rose92915f72010-01-09 02:24:10 +00001459/**
1460 * ixgbevf_set_rx_mode - Multicast set
1461 * @netdev: network interface device structure
1462 *
1463 * The set_rx_method entry point is called whenever the multicast address
1464 * list or the network interface flags are updated. This routine is
1465 * responsible for configuring the hardware for proper multicast mode.
1466 **/
1467static void ixgbevf_set_rx_mode(struct net_device *netdev)
1468{
1469 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
1470 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose92915f72010-01-09 02:24:10 +00001471
1472 /* reprogram multicast list */
Greg Rose92915f72010-01-09 02:24:10 +00001473 if (hw->mac.ops.update_mc_addr_list)
Jiri Pirko5c58c472010-03-23 22:58:20 +00001474 hw->mac.ops.update_mc_addr_list(hw, netdev);
Greg Rose46ec20f2011-05-13 01:33:42 +00001475
1476 ixgbevf_write_uc_addr_list(netdev);
Greg Rose92915f72010-01-09 02:24:10 +00001477}
1478
1479static void ixgbevf_napi_enable_all(struct ixgbevf_adapter *adapter)
1480{
1481 int q_idx;
1482 struct ixgbevf_q_vector *q_vector;
1483 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1484
1485 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1486 struct napi_struct *napi;
1487 q_vector = adapter->q_vector[q_idx];
1488 if (!q_vector->rxr_count)
1489 continue;
1490 napi = &q_vector->napi;
1491 if (q_vector->rxr_count > 1)
1492 napi->poll = &ixgbevf_clean_rxonly_many;
1493
1494 napi_enable(napi);
1495 }
1496}
1497
1498static void ixgbevf_napi_disable_all(struct ixgbevf_adapter *adapter)
1499{
1500 int q_idx;
1501 struct ixgbevf_q_vector *q_vector;
1502 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1503
1504 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1505 q_vector = adapter->q_vector[q_idx];
1506 if (!q_vector->rxr_count)
1507 continue;
1508 napi_disable(&q_vector->napi);
1509 }
1510}
1511
1512static void ixgbevf_configure(struct ixgbevf_adapter *adapter)
1513{
1514 struct net_device *netdev = adapter->netdev;
1515 int i;
1516
1517 ixgbevf_set_rx_mode(netdev);
1518
1519 ixgbevf_restore_vlan(adapter);
1520
1521 ixgbevf_configure_tx(adapter);
1522 ixgbevf_configure_rx(adapter);
1523 for (i = 0; i < adapter->num_rx_queues; i++) {
1524 struct ixgbevf_ring *ring = &adapter->rx_ring[i];
1525 ixgbevf_alloc_rx_buffers(adapter, ring, ring->count);
1526 ring->next_to_use = ring->count - 1;
1527 writel(ring->next_to_use, adapter->hw.hw_addr + ring->tail);
1528 }
1529}
1530
1531#define IXGBE_MAX_RX_DESC_POLL 10
1532static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter *adapter,
1533 int rxr)
1534{
1535 struct ixgbe_hw *hw = &adapter->hw;
1536 int j = adapter->rx_ring[rxr].reg_idx;
1537 int k;
1538
1539 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
1540 if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
1541 break;
1542 else
1543 msleep(1);
1544 }
1545 if (k >= IXGBE_MAX_RX_DESC_POLL) {
1546 hw_dbg(hw, "RXDCTL.ENABLE on Rx queue %d "
1547 "not set within the polling period\n", rxr);
1548 }
1549
1550 ixgbevf_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
1551 (adapter->rx_ring[rxr].count - 1));
1552}
1553
Greg Rose33bd9f62010-03-19 02:59:52 +00001554static void ixgbevf_save_reset_stats(struct ixgbevf_adapter *adapter)
1555{
1556 /* Only save pre-reset stats if there are some */
1557 if (adapter->stats.vfgprc || adapter->stats.vfgptc) {
1558 adapter->stats.saved_reset_vfgprc += adapter->stats.vfgprc -
1559 adapter->stats.base_vfgprc;
1560 adapter->stats.saved_reset_vfgptc += adapter->stats.vfgptc -
1561 adapter->stats.base_vfgptc;
1562 adapter->stats.saved_reset_vfgorc += adapter->stats.vfgorc -
1563 adapter->stats.base_vfgorc;
1564 adapter->stats.saved_reset_vfgotc += adapter->stats.vfgotc -
1565 adapter->stats.base_vfgotc;
1566 adapter->stats.saved_reset_vfmprc += adapter->stats.vfmprc -
1567 adapter->stats.base_vfmprc;
1568 }
1569}
1570
1571static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter *adapter)
1572{
1573 struct ixgbe_hw *hw = &adapter->hw;
1574
1575 adapter->stats.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC);
1576 adapter->stats.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB);
1577 adapter->stats.last_vfgorc |=
1578 (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32);
1579 adapter->stats.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC);
1580 adapter->stats.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB);
1581 adapter->stats.last_vfgotc |=
1582 (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32);
1583 adapter->stats.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC);
1584
1585 adapter->stats.base_vfgprc = adapter->stats.last_vfgprc;
1586 adapter->stats.base_vfgorc = adapter->stats.last_vfgorc;
1587 adapter->stats.base_vfgptc = adapter->stats.last_vfgptc;
1588 adapter->stats.base_vfgotc = adapter->stats.last_vfgotc;
1589 adapter->stats.base_vfmprc = adapter->stats.last_vfmprc;
1590}
1591
Greg Rose92915f72010-01-09 02:24:10 +00001592static int ixgbevf_up_complete(struct ixgbevf_adapter *adapter)
1593{
1594 struct net_device *netdev = adapter->netdev;
1595 struct ixgbe_hw *hw = &adapter->hw;
1596 int i, j = 0;
1597 int num_rx_rings = adapter->num_rx_queues;
1598 u32 txdctl, rxdctl;
1599
1600 for (i = 0; i < adapter->num_tx_queues; i++) {
1601 j = adapter->tx_ring[i].reg_idx;
1602 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
1603 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
1604 txdctl |= (8 << 16);
1605 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
1606 }
1607
1608 for (i = 0; i < adapter->num_tx_queues; i++) {
1609 j = adapter->tx_ring[i].reg_idx;
1610 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
1611 txdctl |= IXGBE_TXDCTL_ENABLE;
1612 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
1613 }
1614
1615 for (i = 0; i < num_rx_rings; i++) {
1616 j = adapter->rx_ring[i].reg_idx;
1617 rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j));
Jiri Pirkodadcd652011-07-21 03:25:09 +00001618 rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME;
Greg Rose69bfbec2011-01-26 01:06:12 +00001619 if (hw->mac.type == ixgbe_mac_X540_vf) {
1620 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
1621 rxdctl |= ((netdev->mtu + ETH_HLEN + ETH_FCS_LEN) |
1622 IXGBE_RXDCTL_RLPML_EN);
1623 }
Greg Rose92915f72010-01-09 02:24:10 +00001624 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(j), rxdctl);
1625 ixgbevf_rx_desc_queue_enable(adapter, i);
1626 }
1627
1628 ixgbevf_configure_msix(adapter);
1629
1630 if (hw->mac.ops.set_rar) {
1631 if (is_valid_ether_addr(hw->mac.addr))
1632 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
1633 else
1634 hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
1635 }
1636
1637 clear_bit(__IXGBEVF_DOWN, &adapter->state);
1638 ixgbevf_napi_enable_all(adapter);
1639
1640 /* enable transmits */
1641 netif_tx_start_all_queues(netdev);
1642
Greg Rose33bd9f62010-03-19 02:59:52 +00001643 ixgbevf_save_reset_stats(adapter);
1644 ixgbevf_init_last_counter_stats(adapter);
1645
Greg Rose92915f72010-01-09 02:24:10 +00001646 /* bring the link up in the watchdog, this could race with our first
1647 * link up interrupt but shouldn't be a problem */
1648 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1649 adapter->link_check_timeout = jiffies;
1650 mod_timer(&adapter->watchdog_timer, jiffies);
1651 return 0;
1652}
1653
1654int ixgbevf_up(struct ixgbevf_adapter *adapter)
1655{
1656 int err;
1657 struct ixgbe_hw *hw = &adapter->hw;
1658
1659 ixgbevf_configure(adapter);
1660
1661 err = ixgbevf_up_complete(adapter);
1662
1663 /* clear any pending interrupts, may auto mask */
1664 IXGBE_READ_REG(hw, IXGBE_VTEICR);
1665
1666 ixgbevf_irq_enable(adapter, true, true);
1667
1668 return err;
1669}
1670
1671/**
1672 * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
1673 * @adapter: board private structure
1674 * @rx_ring: ring to free buffers from
1675 **/
1676static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter *adapter,
1677 struct ixgbevf_ring *rx_ring)
1678{
1679 struct pci_dev *pdev = adapter->pdev;
1680 unsigned long size;
1681 unsigned int i;
1682
Greg Rosec0456c22010-01-22 22:47:18 +00001683 if (!rx_ring->rx_buffer_info)
1684 return;
Greg Rose92915f72010-01-09 02:24:10 +00001685
Greg Rosec0456c22010-01-22 22:47:18 +00001686 /* Free all the Rx ring sk_buffs */
Greg Rose92915f72010-01-09 02:24:10 +00001687 for (i = 0; i < rx_ring->count; i++) {
1688 struct ixgbevf_rx_buffer *rx_buffer_info;
1689
1690 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1691 if (rx_buffer_info->dma) {
Nick Nunley2a1f8792010-04-27 13:10:50 +00001692 dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
Greg Rose92915f72010-01-09 02:24:10 +00001693 rx_ring->rx_buf_len,
Nick Nunley2a1f8792010-04-27 13:10:50 +00001694 DMA_FROM_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +00001695 rx_buffer_info->dma = 0;
1696 }
1697 if (rx_buffer_info->skb) {
1698 struct sk_buff *skb = rx_buffer_info->skb;
1699 rx_buffer_info->skb = NULL;
1700 do {
1701 struct sk_buff *this = skb;
1702 skb = skb->prev;
1703 dev_kfree_skb(this);
1704 } while (skb);
1705 }
1706 if (!rx_buffer_info->page)
1707 continue;
Nick Nunley2a1f8792010-04-27 13:10:50 +00001708 dma_unmap_page(&pdev->dev, rx_buffer_info->page_dma,
1709 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +00001710 rx_buffer_info->page_dma = 0;
1711 put_page(rx_buffer_info->page);
1712 rx_buffer_info->page = NULL;
1713 rx_buffer_info->page_offset = 0;
1714 }
1715
1716 size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count;
1717 memset(rx_ring->rx_buffer_info, 0, size);
1718
1719 /* Zero out the descriptor ring */
1720 memset(rx_ring->desc, 0, rx_ring->size);
1721
1722 rx_ring->next_to_clean = 0;
1723 rx_ring->next_to_use = 0;
1724
1725 if (rx_ring->head)
1726 writel(0, adapter->hw.hw_addr + rx_ring->head);
1727 if (rx_ring->tail)
1728 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1729}
1730
1731/**
1732 * ixgbevf_clean_tx_ring - Free Tx Buffers
1733 * @adapter: board private structure
1734 * @tx_ring: ring to be cleaned
1735 **/
1736static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter *adapter,
1737 struct ixgbevf_ring *tx_ring)
1738{
1739 struct ixgbevf_tx_buffer *tx_buffer_info;
1740 unsigned long size;
1741 unsigned int i;
1742
Greg Rosec0456c22010-01-22 22:47:18 +00001743 if (!tx_ring->tx_buffer_info)
1744 return;
1745
Greg Rose92915f72010-01-09 02:24:10 +00001746 /* Free all the Tx ring sk_buffs */
1747
1748 for (i = 0; i < tx_ring->count; i++) {
1749 tx_buffer_info = &tx_ring->tx_buffer_info[i];
1750 ixgbevf_unmap_and_free_tx_resource(adapter, tx_buffer_info);
1751 }
1752
1753 size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count;
1754 memset(tx_ring->tx_buffer_info, 0, size);
1755
1756 memset(tx_ring->desc, 0, tx_ring->size);
1757
1758 tx_ring->next_to_use = 0;
1759 tx_ring->next_to_clean = 0;
1760
1761 if (tx_ring->head)
1762 writel(0, adapter->hw.hw_addr + tx_ring->head);
1763 if (tx_ring->tail)
1764 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1765}
1766
1767/**
1768 * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
1769 * @adapter: board private structure
1770 **/
1771static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter *adapter)
1772{
1773 int i;
1774
1775 for (i = 0; i < adapter->num_rx_queues; i++)
1776 ixgbevf_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1777}
1778
1779/**
1780 * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
1781 * @adapter: board private structure
1782 **/
1783static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter *adapter)
1784{
1785 int i;
1786
1787 for (i = 0; i < adapter->num_tx_queues; i++)
1788 ixgbevf_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1789}
1790
1791void ixgbevf_down(struct ixgbevf_adapter *adapter)
1792{
1793 struct net_device *netdev = adapter->netdev;
1794 struct ixgbe_hw *hw = &adapter->hw;
1795 u32 txdctl;
1796 int i, j;
1797
1798 /* signal that we are down to the interrupt handler */
1799 set_bit(__IXGBEVF_DOWN, &adapter->state);
1800 /* disable receives */
1801
1802 netif_tx_disable(netdev);
1803
1804 msleep(10);
1805
1806 netif_tx_stop_all_queues(netdev);
1807
1808 ixgbevf_irq_disable(adapter);
1809
1810 ixgbevf_napi_disable_all(adapter);
1811
1812 del_timer_sync(&adapter->watchdog_timer);
1813 /* can't call flush scheduled work here because it can deadlock
1814 * if linkwatch_event tries to acquire the rtnl_lock which we are
1815 * holding */
1816 while (adapter->flags & IXGBE_FLAG_IN_WATCHDOG_TASK)
1817 msleep(1);
1818
1819 /* disable transmits in the hardware now that interrupts are off */
1820 for (i = 0; i < adapter->num_tx_queues; i++) {
1821 j = adapter->tx_ring[i].reg_idx;
1822 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
1823 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j),
1824 (txdctl & ~IXGBE_TXDCTL_ENABLE));
1825 }
1826
1827 netif_carrier_off(netdev);
1828
1829 if (!pci_channel_offline(adapter->pdev))
1830 ixgbevf_reset(adapter);
1831
1832 ixgbevf_clean_all_tx_rings(adapter);
1833 ixgbevf_clean_all_rx_rings(adapter);
1834}
1835
1836void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter)
1837{
Greg Rosec0456c22010-01-22 22:47:18 +00001838 struct ixgbe_hw *hw = &adapter->hw;
1839
Greg Rose92915f72010-01-09 02:24:10 +00001840 WARN_ON(in_interrupt());
Greg Rosec0456c22010-01-22 22:47:18 +00001841
Greg Rose92915f72010-01-09 02:24:10 +00001842 while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state))
1843 msleep(1);
1844
Greg Rosec0456c22010-01-22 22:47:18 +00001845 /*
1846 * Check if PF is up before re-init. If not then skip until
1847 * later when the PF is up and ready to service requests from
1848 * the VF via mailbox. If the VF is up and running then the
1849 * watchdog task will continue to schedule reset tasks until
1850 * the PF is up and running.
1851 */
1852 if (!hw->mac.ops.reset_hw(hw)) {
1853 ixgbevf_down(adapter);
1854 ixgbevf_up(adapter);
1855 }
Greg Rose92915f72010-01-09 02:24:10 +00001856
1857 clear_bit(__IXGBEVF_RESETTING, &adapter->state);
1858}
1859
1860void ixgbevf_reset(struct ixgbevf_adapter *adapter)
1861{
1862 struct ixgbe_hw *hw = &adapter->hw;
1863 struct net_device *netdev = adapter->netdev;
1864
1865 if (hw->mac.ops.reset_hw(hw))
1866 hw_dbg(hw, "PF still resetting\n");
1867 else
1868 hw->mac.ops.init_hw(hw);
1869
1870 if (is_valid_ether_addr(adapter->hw.mac.addr)) {
1871 memcpy(netdev->dev_addr, adapter->hw.mac.addr,
1872 netdev->addr_len);
1873 memcpy(netdev->perm_addr, adapter->hw.mac.addr,
1874 netdev->addr_len);
1875 }
1876}
1877
1878static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter *adapter,
1879 int vectors)
1880{
1881 int err, vector_threshold;
1882
1883 /* We'll want at least 3 (vector_threshold):
1884 * 1) TxQ[0] Cleanup
1885 * 2) RxQ[0] Cleanup
1886 * 3) Other (Link Status Change, etc.)
1887 */
1888 vector_threshold = MIN_MSIX_COUNT;
1889
1890 /* The more we get, the more we will assign to Tx/Rx Cleanup
1891 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1892 * Right now, we simply care about how many we'll get; we'll
1893 * set them up later while requesting irq's.
1894 */
1895 while (vectors >= vector_threshold) {
1896 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
1897 vectors);
1898 if (!err) /* Success in acquiring all requested vectors. */
1899 break;
1900 else if (err < 0)
1901 vectors = 0; /* Nasty failure, quit now */
1902 else /* err == number of vectors we should try again with */
1903 vectors = err;
1904 }
1905
1906 if (vectors < vector_threshold) {
1907 /* Can't allocate enough MSI-X interrupts? Oh well.
1908 * This just means we'll go with either a single MSI
1909 * vector or fall back to legacy interrupts.
1910 */
1911 hw_dbg(&adapter->hw,
1912 "Unable to allocate MSI-X interrupts\n");
1913 kfree(adapter->msix_entries);
1914 adapter->msix_entries = NULL;
1915 } else {
1916 /*
1917 * Adjust for only the vectors we'll use, which is minimum
1918 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
1919 * vectors we were allocated.
1920 */
1921 adapter->num_msix_vectors = vectors;
1922 }
1923}
1924
1925/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001926 * ixgbevf_set_num_queues: Allocate queues for device, feature dependent
Greg Rose92915f72010-01-09 02:24:10 +00001927 * @adapter: board private structure to initialize
1928 *
1929 * This is the top level queue allocation routine. The order here is very
1930 * important, starting with the "most" number of features turned on at once,
1931 * and ending with the smallest set of features. This way large combinations
1932 * can be allocated if they're turned on, and smaller combinations are the
1933 * fallthrough conditions.
1934 *
1935 **/
1936static void ixgbevf_set_num_queues(struct ixgbevf_adapter *adapter)
1937{
1938 /* Start with base case */
1939 adapter->num_rx_queues = 1;
1940 adapter->num_tx_queues = 1;
1941 adapter->num_rx_pools = adapter->num_rx_queues;
1942 adapter->num_rx_queues_per_pool = 1;
1943}
1944
1945/**
1946 * ixgbevf_alloc_queues - Allocate memory for all rings
1947 * @adapter: board private structure to initialize
1948 *
1949 * We allocate one ring per queue at run-time since we don't know the
1950 * number of queues at compile-time. The polling_netdev array is
1951 * intended for Multiqueue, but should work fine with a single queue.
1952 **/
1953static int ixgbevf_alloc_queues(struct ixgbevf_adapter *adapter)
1954{
1955 int i;
1956
1957 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1958 sizeof(struct ixgbevf_ring), GFP_KERNEL);
1959 if (!adapter->tx_ring)
1960 goto err_tx_ring_allocation;
1961
1962 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1963 sizeof(struct ixgbevf_ring), GFP_KERNEL);
1964 if (!adapter->rx_ring)
1965 goto err_rx_ring_allocation;
1966
1967 for (i = 0; i < adapter->num_tx_queues; i++) {
1968 adapter->tx_ring[i].count = adapter->tx_ring_count;
1969 adapter->tx_ring[i].queue_index = i;
1970 adapter->tx_ring[i].reg_idx = i;
1971 }
1972
1973 for (i = 0; i < adapter->num_rx_queues; i++) {
1974 adapter->rx_ring[i].count = adapter->rx_ring_count;
1975 adapter->rx_ring[i].queue_index = i;
1976 adapter->rx_ring[i].reg_idx = i;
1977 }
1978
1979 return 0;
1980
1981err_rx_ring_allocation:
1982 kfree(adapter->tx_ring);
1983err_tx_ring_allocation:
1984 return -ENOMEM;
1985}
1986
1987/**
1988 * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
1989 * @adapter: board private structure to initialize
1990 *
1991 * Attempt to configure the interrupts using the best available
1992 * capabilities of the hardware and the kernel.
1993 **/
1994static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter *adapter)
1995{
1996 int err = 0;
1997 int vector, v_budget;
1998
1999 /*
2000 * It's easy to be greedy for MSI-X vectors, but it really
2001 * doesn't do us much good if we have a lot more vectors
2002 * than CPU's. So let's be conservative and only ask for
2003 * (roughly) twice the number of vectors as there are CPU's.
2004 */
2005 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
2006 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
2007
2008 /* A failure in MSI-X entry allocation isn't fatal, but it does
2009 * mean we disable MSI-X capabilities of the adapter. */
2010 adapter->msix_entries = kcalloc(v_budget,
2011 sizeof(struct msix_entry), GFP_KERNEL);
2012 if (!adapter->msix_entries) {
2013 err = -ENOMEM;
2014 goto out;
2015 }
2016
2017 for (vector = 0; vector < v_budget; vector++)
2018 adapter->msix_entries[vector].entry = vector;
2019
2020 ixgbevf_acquire_msix_vectors(adapter, v_budget);
2021
2022out:
2023 return err;
2024}
2025
2026/**
2027 * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
2028 * @adapter: board private structure to initialize
2029 *
2030 * We allocate one q_vector per queue interrupt. If allocation fails we
2031 * return -ENOMEM.
2032 **/
2033static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter *adapter)
2034{
2035 int q_idx, num_q_vectors;
2036 struct ixgbevf_q_vector *q_vector;
2037 int napi_vectors;
2038 int (*poll)(struct napi_struct *, int);
2039
2040 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2041 napi_vectors = adapter->num_rx_queues;
2042 poll = &ixgbevf_clean_rxonly;
2043
2044 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
2045 q_vector = kzalloc(sizeof(struct ixgbevf_q_vector), GFP_KERNEL);
2046 if (!q_vector)
2047 goto err_out;
2048 q_vector->adapter = adapter;
2049 q_vector->v_idx = q_idx;
2050 q_vector->eitr = adapter->eitr_param;
2051 if (q_idx < napi_vectors)
2052 netif_napi_add(adapter->netdev, &q_vector->napi,
2053 (*poll), 64);
2054 adapter->q_vector[q_idx] = q_vector;
2055 }
2056
2057 return 0;
2058
2059err_out:
2060 while (q_idx) {
2061 q_idx--;
2062 q_vector = adapter->q_vector[q_idx];
2063 netif_napi_del(&q_vector->napi);
2064 kfree(q_vector);
2065 adapter->q_vector[q_idx] = NULL;
2066 }
2067 return -ENOMEM;
2068}
2069
2070/**
2071 * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
2072 * @adapter: board private structure to initialize
2073 *
2074 * This function frees the memory allocated to the q_vectors. In addition if
2075 * NAPI is enabled it will delete any references to the NAPI struct prior
2076 * to freeing the q_vector.
2077 **/
2078static void ixgbevf_free_q_vectors(struct ixgbevf_adapter *adapter)
2079{
2080 int q_idx, num_q_vectors;
2081 int napi_vectors;
2082
2083 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2084 napi_vectors = adapter->num_rx_queues;
2085
2086 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
2087 struct ixgbevf_q_vector *q_vector = adapter->q_vector[q_idx];
2088
2089 adapter->q_vector[q_idx] = NULL;
2090 if (q_idx < napi_vectors)
2091 netif_napi_del(&q_vector->napi);
2092 kfree(q_vector);
2093 }
2094}
2095
2096/**
2097 * ixgbevf_reset_interrupt_capability - Reset MSIX setup
2098 * @adapter: board private structure
2099 *
2100 **/
2101static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter *adapter)
2102{
2103 pci_disable_msix(adapter->pdev);
2104 kfree(adapter->msix_entries);
2105 adapter->msix_entries = NULL;
Greg Rose92915f72010-01-09 02:24:10 +00002106}
2107
2108/**
2109 * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
2110 * @adapter: board private structure to initialize
2111 *
2112 **/
2113static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter *adapter)
2114{
2115 int err;
2116
2117 /* Number of supported queues */
2118 ixgbevf_set_num_queues(adapter);
2119
2120 err = ixgbevf_set_interrupt_capability(adapter);
2121 if (err) {
2122 hw_dbg(&adapter->hw,
2123 "Unable to setup interrupt capabilities\n");
2124 goto err_set_interrupt;
2125 }
2126
2127 err = ixgbevf_alloc_q_vectors(adapter);
2128 if (err) {
2129 hw_dbg(&adapter->hw, "Unable to allocate memory for queue "
2130 "vectors\n");
2131 goto err_alloc_q_vectors;
2132 }
2133
2134 err = ixgbevf_alloc_queues(adapter);
2135 if (err) {
2136 printk(KERN_ERR "Unable to allocate memory for queues\n");
2137 goto err_alloc_queues;
2138 }
2139
2140 hw_dbg(&adapter->hw, "Multiqueue %s: Rx Queue count = %u, "
2141 "Tx Queue count = %u\n",
2142 (adapter->num_rx_queues > 1) ? "Enabled" :
2143 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
2144
2145 set_bit(__IXGBEVF_DOWN, &adapter->state);
2146
2147 return 0;
2148err_alloc_queues:
2149 ixgbevf_free_q_vectors(adapter);
2150err_alloc_q_vectors:
2151 ixgbevf_reset_interrupt_capability(adapter);
2152err_set_interrupt:
2153 return err;
2154}
2155
2156/**
2157 * ixgbevf_sw_init - Initialize general software structures
2158 * (struct ixgbevf_adapter)
2159 * @adapter: board private structure to initialize
2160 *
2161 * ixgbevf_sw_init initializes the Adapter private data structure.
2162 * Fields are initialized based on PCI device information and
2163 * OS network device settings (MTU size).
2164 **/
2165static int __devinit ixgbevf_sw_init(struct ixgbevf_adapter *adapter)
2166{
2167 struct ixgbe_hw *hw = &adapter->hw;
2168 struct pci_dev *pdev = adapter->pdev;
2169 int err;
2170
2171 /* PCI config space info */
2172
2173 hw->vendor_id = pdev->vendor;
2174 hw->device_id = pdev->device;
Sergei Shtylyovff938e42011-02-28 11:57:33 -08002175 hw->revision_id = pdev->revision;
Greg Rose92915f72010-01-09 02:24:10 +00002176 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2177 hw->subsystem_device_id = pdev->subsystem_device;
2178
2179 hw->mbx.ops.init_params(hw);
2180 hw->mac.max_tx_queues = MAX_TX_QUEUES;
2181 hw->mac.max_rx_queues = MAX_RX_QUEUES;
2182 err = hw->mac.ops.reset_hw(hw);
2183 if (err) {
2184 dev_info(&pdev->dev,
2185 "PF still in reset state, assigning new address\n");
Stefan Assmann2c6952d2010-07-26 23:24:50 +00002186 dev_hw_addr_random(adapter->netdev, hw->mac.addr);
Greg Rose92915f72010-01-09 02:24:10 +00002187 } else {
2188 err = hw->mac.ops.init_hw(hw);
2189 if (err) {
2190 printk(KERN_ERR "init_shared_code failed: %d\n", err);
2191 goto out;
2192 }
2193 }
2194
2195 /* Enable dynamic interrupt throttling rates */
2196 adapter->eitr_param = 20000;
2197 adapter->itr_setting = 1;
2198
2199 /* set defaults for eitr in MegaBytes */
2200 adapter->eitr_low = 10;
2201 adapter->eitr_high = 20;
2202
2203 /* set default ring sizes */
2204 adapter->tx_ring_count = IXGBEVF_DEFAULT_TXD;
2205 adapter->rx_ring_count = IXGBEVF_DEFAULT_RXD;
2206
2207 /* enable rx csum by default */
2208 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2209
2210 set_bit(__IXGBEVF_DOWN, &adapter->state);
2211
2212out:
2213 return err;
2214}
2215
Greg Rose92915f72010-01-09 02:24:10 +00002216#define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
2217 { \
2218 u32 current_counter = IXGBE_READ_REG(hw, reg); \
2219 if (current_counter < last_counter) \
2220 counter += 0x100000000LL; \
2221 last_counter = current_counter; \
2222 counter &= 0xFFFFFFFF00000000LL; \
2223 counter |= current_counter; \
2224 }
2225
2226#define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
2227 { \
2228 u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
2229 u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
2230 u64 current_counter = (current_counter_msb << 32) | \
2231 current_counter_lsb; \
2232 if (current_counter < last_counter) \
2233 counter += 0x1000000000LL; \
2234 last_counter = current_counter; \
2235 counter &= 0xFFFFFFF000000000LL; \
2236 counter |= current_counter; \
2237 }
2238/**
2239 * ixgbevf_update_stats - Update the board statistics counters.
2240 * @adapter: board private structure
2241 **/
2242void ixgbevf_update_stats(struct ixgbevf_adapter *adapter)
2243{
2244 struct ixgbe_hw *hw = &adapter->hw;
2245
2246 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC, adapter->stats.last_vfgprc,
2247 adapter->stats.vfgprc);
2248 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC, adapter->stats.last_vfgptc,
2249 adapter->stats.vfgptc);
2250 UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
2251 adapter->stats.last_vfgorc,
2252 adapter->stats.vfgorc);
2253 UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
2254 adapter->stats.last_vfgotc,
2255 adapter->stats.vfgotc);
2256 UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC, adapter->stats.last_vfmprc,
2257 adapter->stats.vfmprc);
2258
2259 /* Fill out the OS statistics structure */
Eric Dumazetfb621ba2010-09-08 22:48:31 +00002260 adapter->netdev->stats.multicast = adapter->stats.vfmprc -
Greg Rose92915f72010-01-09 02:24:10 +00002261 adapter->stats.base_vfmprc;
2262}
2263
2264/**
2265 * ixgbevf_watchdog - Timer Call-back
2266 * @data: pointer to adapter cast into an unsigned long
2267 **/
2268static void ixgbevf_watchdog(unsigned long data)
2269{
2270 struct ixgbevf_adapter *adapter = (struct ixgbevf_adapter *)data;
2271 struct ixgbe_hw *hw = &adapter->hw;
2272 u64 eics = 0;
2273 int i;
2274
2275 /*
2276 * Do the watchdog outside of interrupt context due to the lovely
2277 * delays that some of the newer hardware requires
2278 */
2279
2280 if (test_bit(__IXGBEVF_DOWN, &adapter->state))
2281 goto watchdog_short_circuit;
2282
2283 /* get one bit for every active tx/rx interrupt vector */
2284 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
2285 struct ixgbevf_q_vector *qv = adapter->q_vector[i];
2286 if (qv->rxr_count || qv->txr_count)
2287 eics |= (1 << i);
2288 }
2289
2290 IXGBE_WRITE_REG(hw, IXGBE_VTEICS, (u32)eics);
2291
2292watchdog_short_circuit:
2293 schedule_work(&adapter->watchdog_task);
2294}
2295
2296/**
2297 * ixgbevf_tx_timeout - Respond to a Tx Hang
2298 * @netdev: network interface device structure
2299 **/
2300static void ixgbevf_tx_timeout(struct net_device *netdev)
2301{
2302 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
2303
2304 /* Do the reset outside of interrupt context */
2305 schedule_work(&adapter->reset_task);
2306}
2307
2308static void ixgbevf_reset_task(struct work_struct *work)
2309{
2310 struct ixgbevf_adapter *adapter;
2311 adapter = container_of(work, struct ixgbevf_adapter, reset_task);
2312
2313 /* If we're already down or resetting, just bail */
2314 if (test_bit(__IXGBEVF_DOWN, &adapter->state) ||
2315 test_bit(__IXGBEVF_RESETTING, &adapter->state))
2316 return;
2317
2318 adapter->tx_timeout_count++;
2319
2320 ixgbevf_reinit_locked(adapter);
2321}
2322
2323/**
2324 * ixgbevf_watchdog_task - worker thread to bring link up
2325 * @work: pointer to work_struct containing our data
2326 **/
2327static void ixgbevf_watchdog_task(struct work_struct *work)
2328{
2329 struct ixgbevf_adapter *adapter = container_of(work,
2330 struct ixgbevf_adapter,
2331 watchdog_task);
2332 struct net_device *netdev = adapter->netdev;
2333 struct ixgbe_hw *hw = &adapter->hw;
2334 u32 link_speed = adapter->link_speed;
2335 bool link_up = adapter->link_up;
2336
2337 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
2338
2339 /*
2340 * Always check the link on the watchdog because we have
2341 * no LSC interrupt
2342 */
2343 if (hw->mac.ops.check_link) {
2344 if ((hw->mac.ops.check_link(hw, &link_speed,
2345 &link_up, false)) != 0) {
2346 adapter->link_up = link_up;
2347 adapter->link_speed = link_speed;
Greg Roseda6b3332010-01-22 22:47:37 +00002348 netif_carrier_off(netdev);
2349 netif_tx_stop_all_queues(netdev);
Greg Rose92915f72010-01-09 02:24:10 +00002350 schedule_work(&adapter->reset_task);
2351 goto pf_has_reset;
2352 }
2353 } else {
2354 /* always assume link is up, if no check link
2355 * function */
2356 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
2357 link_up = true;
2358 }
2359 adapter->link_up = link_up;
2360 adapter->link_speed = link_speed;
2361
2362 if (link_up) {
2363 if (!netif_carrier_ok(netdev)) {
Joe Perches300bc062010-03-22 20:08:04 -07002364 hw_dbg(&adapter->hw, "NIC Link is Up, %u Gbps\n",
2365 (link_speed == IXGBE_LINK_SPEED_10GB_FULL) ?
2366 10 : 1);
Greg Rose92915f72010-01-09 02:24:10 +00002367 netif_carrier_on(netdev);
2368 netif_tx_wake_all_queues(netdev);
Greg Rose92915f72010-01-09 02:24:10 +00002369 }
2370 } else {
2371 adapter->link_up = false;
2372 adapter->link_speed = 0;
2373 if (netif_carrier_ok(netdev)) {
2374 hw_dbg(&adapter->hw, "NIC Link is Down\n");
2375 netif_carrier_off(netdev);
2376 netif_tx_stop_all_queues(netdev);
2377 }
2378 }
2379
Greg Rose92915f72010-01-09 02:24:10 +00002380 ixgbevf_update_stats(adapter);
2381
Greg Rose33bd9f62010-03-19 02:59:52 +00002382pf_has_reset:
Greg Rose92915f72010-01-09 02:24:10 +00002383 /* Reset the timer */
2384 if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
2385 mod_timer(&adapter->watchdog_timer,
2386 round_jiffies(jiffies + (2 * HZ)));
2387
2388 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
2389}
2390
2391/**
2392 * ixgbevf_free_tx_resources - Free Tx Resources per Queue
2393 * @adapter: board private structure
2394 * @tx_ring: Tx descriptor ring for a specific queue
2395 *
2396 * Free all transmit software resources
2397 **/
2398void ixgbevf_free_tx_resources(struct ixgbevf_adapter *adapter,
2399 struct ixgbevf_ring *tx_ring)
2400{
2401 struct pci_dev *pdev = adapter->pdev;
2402
Greg Rose92915f72010-01-09 02:24:10 +00002403 ixgbevf_clean_tx_ring(adapter, tx_ring);
2404
2405 vfree(tx_ring->tx_buffer_info);
2406 tx_ring->tx_buffer_info = NULL;
2407
Nick Nunley2a1f8792010-04-27 13:10:50 +00002408 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2409 tx_ring->dma);
Greg Rose92915f72010-01-09 02:24:10 +00002410
2411 tx_ring->desc = NULL;
2412}
2413
2414/**
2415 * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
2416 * @adapter: board private structure
2417 *
2418 * Free all transmit software resources
2419 **/
2420static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter *adapter)
2421{
2422 int i;
2423
2424 for (i = 0; i < adapter->num_tx_queues; i++)
2425 if (adapter->tx_ring[i].desc)
2426 ixgbevf_free_tx_resources(adapter,
2427 &adapter->tx_ring[i]);
2428
2429}
2430
2431/**
2432 * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
2433 * @adapter: board private structure
2434 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2435 *
2436 * Return 0 on success, negative on failure
2437 **/
2438int ixgbevf_setup_tx_resources(struct ixgbevf_adapter *adapter,
2439 struct ixgbevf_ring *tx_ring)
2440{
2441 struct pci_dev *pdev = adapter->pdev;
2442 int size;
2443
2444 size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002445 tx_ring->tx_buffer_info = vzalloc(size);
Greg Rose92915f72010-01-09 02:24:10 +00002446 if (!tx_ring->tx_buffer_info)
2447 goto err;
Greg Rose92915f72010-01-09 02:24:10 +00002448
2449 /* round up to nearest 4K */
2450 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
2451 tx_ring->size = ALIGN(tx_ring->size, 4096);
2452
Nick Nunley2a1f8792010-04-27 13:10:50 +00002453 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
2454 &tx_ring->dma, GFP_KERNEL);
Greg Rose92915f72010-01-09 02:24:10 +00002455 if (!tx_ring->desc)
2456 goto err;
2457
2458 tx_ring->next_to_use = 0;
2459 tx_ring->next_to_clean = 0;
2460 tx_ring->work_limit = tx_ring->count;
2461 return 0;
2462
2463err:
2464 vfree(tx_ring->tx_buffer_info);
2465 tx_ring->tx_buffer_info = NULL;
2466 hw_dbg(&adapter->hw, "Unable to allocate memory for the transmit "
2467 "descriptor ring\n");
2468 return -ENOMEM;
2469}
2470
2471/**
2472 * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
2473 * @adapter: board private structure
2474 *
2475 * If this function returns with an error, then it's possible one or
2476 * more of the rings is populated (while the rest are not). It is the
2477 * callers duty to clean those orphaned rings.
2478 *
2479 * Return 0 on success, negative on failure
2480 **/
2481static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter *adapter)
2482{
2483 int i, err = 0;
2484
2485 for (i = 0; i < adapter->num_tx_queues; i++) {
2486 err = ixgbevf_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2487 if (!err)
2488 continue;
2489 hw_dbg(&adapter->hw,
2490 "Allocation for Tx Queue %u failed\n", i);
2491 break;
2492 }
2493
2494 return err;
2495}
2496
2497/**
2498 * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
2499 * @adapter: board private structure
2500 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2501 *
2502 * Returns 0 on success, negative on failure
2503 **/
2504int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter,
2505 struct ixgbevf_ring *rx_ring)
2506{
2507 struct pci_dev *pdev = adapter->pdev;
2508 int size;
2509
2510 size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002511 rx_ring->rx_buffer_info = vzalloc(size);
Greg Rose92915f72010-01-09 02:24:10 +00002512 if (!rx_ring->rx_buffer_info) {
2513 hw_dbg(&adapter->hw,
2514 "Unable to vmalloc buffer memory for "
2515 "the receive descriptor ring\n");
2516 goto alloc_failed;
2517 }
Greg Rose92915f72010-01-09 02:24:10 +00002518
2519 /* Round up to nearest 4K */
2520 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2521 rx_ring->size = ALIGN(rx_ring->size, 4096);
2522
Nick Nunley2a1f8792010-04-27 13:10:50 +00002523 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
2524 &rx_ring->dma, GFP_KERNEL);
Greg Rose92915f72010-01-09 02:24:10 +00002525
2526 if (!rx_ring->desc) {
2527 hw_dbg(&adapter->hw,
2528 "Unable to allocate memory for "
2529 "the receive descriptor ring\n");
2530 vfree(rx_ring->rx_buffer_info);
2531 rx_ring->rx_buffer_info = NULL;
2532 goto alloc_failed;
2533 }
2534
2535 rx_ring->next_to_clean = 0;
2536 rx_ring->next_to_use = 0;
2537
2538 return 0;
2539alloc_failed:
2540 return -ENOMEM;
2541}
2542
2543/**
2544 * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
2545 * @adapter: board private structure
2546 *
2547 * If this function returns with an error, then it's possible one or
2548 * more of the rings is populated (while the rest are not). It is the
2549 * callers duty to clean those orphaned rings.
2550 *
2551 * Return 0 on success, negative on failure
2552 **/
2553static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter *adapter)
2554{
2555 int i, err = 0;
2556
2557 for (i = 0; i < adapter->num_rx_queues; i++) {
2558 err = ixgbevf_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2559 if (!err)
2560 continue;
2561 hw_dbg(&adapter->hw,
2562 "Allocation for Rx Queue %u failed\n", i);
2563 break;
2564 }
2565 return err;
2566}
2567
2568/**
2569 * ixgbevf_free_rx_resources - Free Rx Resources
2570 * @adapter: board private structure
2571 * @rx_ring: ring to clean the resources from
2572 *
2573 * Free all receive software resources
2574 **/
2575void ixgbevf_free_rx_resources(struct ixgbevf_adapter *adapter,
2576 struct ixgbevf_ring *rx_ring)
2577{
2578 struct pci_dev *pdev = adapter->pdev;
2579
2580 ixgbevf_clean_rx_ring(adapter, rx_ring);
2581
2582 vfree(rx_ring->rx_buffer_info);
2583 rx_ring->rx_buffer_info = NULL;
2584
Nick Nunley2a1f8792010-04-27 13:10:50 +00002585 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2586 rx_ring->dma);
Greg Rose92915f72010-01-09 02:24:10 +00002587
2588 rx_ring->desc = NULL;
2589}
2590
2591/**
2592 * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
2593 * @adapter: board private structure
2594 *
2595 * Free all receive software resources
2596 **/
2597static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter)
2598{
2599 int i;
2600
2601 for (i = 0; i < adapter->num_rx_queues; i++)
2602 if (adapter->rx_ring[i].desc)
2603 ixgbevf_free_rx_resources(adapter,
2604 &adapter->rx_ring[i]);
2605}
2606
2607/**
2608 * ixgbevf_open - Called when a network interface is made active
2609 * @netdev: network interface device structure
2610 *
2611 * Returns 0 on success, negative value on failure
2612 *
2613 * The open entry point is called when a network interface is made
2614 * active by the system (IFF_UP). At this point all resources needed
2615 * for transmit and receive operations are allocated, the interrupt
2616 * handler is registered with the OS, the watchdog timer is started,
2617 * and the stack is notified that the interface is ready.
2618 **/
2619static int ixgbevf_open(struct net_device *netdev)
2620{
2621 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
2622 struct ixgbe_hw *hw = &adapter->hw;
2623 int err;
2624
2625 /* disallow open during test */
2626 if (test_bit(__IXGBEVF_TESTING, &adapter->state))
2627 return -EBUSY;
2628
2629 if (hw->adapter_stopped) {
2630 ixgbevf_reset(adapter);
2631 /* if adapter is still stopped then PF isn't up and
2632 * the vf can't start. */
2633 if (hw->adapter_stopped) {
2634 err = IXGBE_ERR_MBX;
2635 printk(KERN_ERR "Unable to start - perhaps the PF"
Greg Rose29b8dd02010-03-19 03:00:31 +00002636 " Driver isn't up yet\n");
Greg Rose92915f72010-01-09 02:24:10 +00002637 goto err_setup_reset;
2638 }
2639 }
2640
2641 /* allocate transmit descriptors */
2642 err = ixgbevf_setup_all_tx_resources(adapter);
2643 if (err)
2644 goto err_setup_tx;
2645
2646 /* allocate receive descriptors */
2647 err = ixgbevf_setup_all_rx_resources(adapter);
2648 if (err)
2649 goto err_setup_rx;
2650
2651 ixgbevf_configure(adapter);
2652
2653 /*
2654 * Map the Tx/Rx rings to the vectors we were allotted.
2655 * if request_irq will be called in this function map_rings
2656 * must be called *before* up_complete
2657 */
2658 ixgbevf_map_rings_to_vectors(adapter);
2659
2660 err = ixgbevf_up_complete(adapter);
2661 if (err)
2662 goto err_up;
2663
2664 /* clear any pending interrupts, may auto mask */
2665 IXGBE_READ_REG(hw, IXGBE_VTEICR);
2666 err = ixgbevf_request_irq(adapter);
2667 if (err)
2668 goto err_req_irq;
2669
2670 ixgbevf_irq_enable(adapter, true, true);
2671
2672 return 0;
2673
2674err_req_irq:
2675 ixgbevf_down(adapter);
2676err_up:
2677 ixgbevf_free_irq(adapter);
2678err_setup_rx:
2679 ixgbevf_free_all_rx_resources(adapter);
2680err_setup_tx:
2681 ixgbevf_free_all_tx_resources(adapter);
2682 ixgbevf_reset(adapter);
2683
2684err_setup_reset:
2685
2686 return err;
2687}
2688
2689/**
2690 * ixgbevf_close - Disables a network interface
2691 * @netdev: network interface device structure
2692 *
2693 * Returns 0, this is not allowed to fail
2694 *
2695 * The close entry point is called when an interface is de-activated
2696 * by the OS. The hardware is still under the drivers control, but
2697 * needs to be disabled. A global MAC reset is issued to stop the
2698 * hardware, and all transmit and receive resources are freed.
2699 **/
2700static int ixgbevf_close(struct net_device *netdev)
2701{
2702 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
2703
2704 ixgbevf_down(adapter);
2705 ixgbevf_free_irq(adapter);
2706
2707 ixgbevf_free_all_tx_resources(adapter);
2708 ixgbevf_free_all_rx_resources(adapter);
2709
2710 return 0;
2711}
2712
2713static int ixgbevf_tso(struct ixgbevf_adapter *adapter,
2714 struct ixgbevf_ring *tx_ring,
2715 struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
2716{
2717 struct ixgbe_adv_tx_context_desc *context_desc;
2718 unsigned int i;
2719 int err;
2720 struct ixgbevf_tx_buffer *tx_buffer_info;
2721 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
2722 u32 mss_l4len_idx, l4len;
2723
2724 if (skb_is_gso(skb)) {
2725 if (skb_header_cloned(skb)) {
2726 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2727 if (err)
2728 return err;
2729 }
2730 l4len = tcp_hdrlen(skb);
2731 *hdr_len += l4len;
2732
2733 if (skb->protocol == htons(ETH_P_IP)) {
2734 struct iphdr *iph = ip_hdr(skb);
2735 iph->tot_len = 0;
2736 iph->check = 0;
2737 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2738 iph->daddr, 0,
2739 IPPROTO_TCP,
2740 0);
2741 adapter->hw_tso_ctxt++;
Jeff Kirsher9010bc32010-01-23 02:06:26 -08002742 } else if (skb_is_gso_v6(skb)) {
Greg Rose92915f72010-01-09 02:24:10 +00002743 ipv6_hdr(skb)->payload_len = 0;
2744 tcp_hdr(skb)->check =
2745 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2746 &ipv6_hdr(skb)->daddr,
2747 0, IPPROTO_TCP, 0);
2748 adapter->hw_tso6_ctxt++;
2749 }
2750
2751 i = tx_ring->next_to_use;
2752
2753 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2754 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
2755
2756 /* VLAN MACLEN IPLEN */
2757 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
2758 vlan_macip_lens |=
2759 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
2760 vlan_macip_lens |= ((skb_network_offset(skb)) <<
2761 IXGBE_ADVTXD_MACLEN_SHIFT);
2762 *hdr_len += skb_network_offset(skb);
2763 vlan_macip_lens |=
2764 (skb_transport_header(skb) - skb_network_header(skb));
2765 *hdr_len +=
2766 (skb_transport_header(skb) - skb_network_header(skb));
2767 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
2768 context_desc->seqnum_seed = 0;
2769
2770 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2771 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
2772 IXGBE_ADVTXD_DTYP_CTXT);
2773
2774 if (skb->protocol == htons(ETH_P_IP))
2775 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
2776 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
2777 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
2778
2779 /* MSS L4LEN IDX */
2780 mss_l4len_idx =
2781 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
2782 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
2783 /* use index 1 for TSO */
2784 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
2785 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
2786
2787 tx_buffer_info->time_stamp = jiffies;
2788 tx_buffer_info->next_to_watch = i;
2789
2790 i++;
2791 if (i == tx_ring->count)
2792 i = 0;
2793 tx_ring->next_to_use = i;
2794
2795 return true;
2796 }
2797
2798 return false;
2799}
2800
2801static bool ixgbevf_tx_csum(struct ixgbevf_adapter *adapter,
2802 struct ixgbevf_ring *tx_ring,
2803 struct sk_buff *skb, u32 tx_flags)
2804{
2805 struct ixgbe_adv_tx_context_desc *context_desc;
2806 unsigned int i;
2807 struct ixgbevf_tx_buffer *tx_buffer_info;
2808 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
2809
2810 if (skb->ip_summed == CHECKSUM_PARTIAL ||
2811 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
2812 i = tx_ring->next_to_use;
2813 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2814 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
2815
2816 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
2817 vlan_macip_lens |= (tx_flags &
2818 IXGBE_TX_FLAGS_VLAN_MASK);
2819 vlan_macip_lens |= (skb_network_offset(skb) <<
2820 IXGBE_ADVTXD_MACLEN_SHIFT);
2821 if (skb->ip_summed == CHECKSUM_PARTIAL)
2822 vlan_macip_lens |= (skb_transport_header(skb) -
2823 skb_network_header(skb));
2824
2825 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
2826 context_desc->seqnum_seed = 0;
2827
2828 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
2829 IXGBE_ADVTXD_DTYP_CTXT);
2830
2831 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2832 switch (skb->protocol) {
2833 case __constant_htons(ETH_P_IP):
2834 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
2835 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2836 type_tucmd_mlhl |=
2837 IXGBE_ADVTXD_TUCMD_L4T_TCP;
2838 break;
2839 case __constant_htons(ETH_P_IPV6):
2840 /* XXX what about other V6 headers?? */
2841 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2842 type_tucmd_mlhl |=
2843 IXGBE_ADVTXD_TUCMD_L4T_TCP;
2844 break;
2845 default:
2846 if (unlikely(net_ratelimit())) {
2847 printk(KERN_WARNING
2848 "partial checksum but "
2849 "proto=%x!\n",
2850 skb->protocol);
2851 }
2852 break;
2853 }
2854 }
2855
2856 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
2857 /* use index zero for tx checksum offload */
2858 context_desc->mss_l4len_idx = 0;
2859
2860 tx_buffer_info->time_stamp = jiffies;
2861 tx_buffer_info->next_to_watch = i;
2862
2863 adapter->hw_csum_tx_good++;
2864 i++;
2865 if (i == tx_ring->count)
2866 i = 0;
2867 tx_ring->next_to_use = i;
2868
2869 return true;
2870 }
2871
2872 return false;
2873}
2874
2875static int ixgbevf_tx_map(struct ixgbevf_adapter *adapter,
2876 struct ixgbevf_ring *tx_ring,
2877 struct sk_buff *skb, u32 tx_flags,
2878 unsigned int first)
2879{
2880 struct pci_dev *pdev = adapter->pdev;
2881 struct ixgbevf_tx_buffer *tx_buffer_info;
2882 unsigned int len;
2883 unsigned int total = skb->len;
Kulikov Vasiliy2540ddb2010-07-15 08:45:57 +00002884 unsigned int offset = 0, size;
2885 int count = 0;
Greg Rose92915f72010-01-09 02:24:10 +00002886 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
2887 unsigned int f;
Greg Rose65deeed2010-03-24 09:35:42 +00002888 int i;
Greg Rose92915f72010-01-09 02:24:10 +00002889
2890 i = tx_ring->next_to_use;
2891
2892 len = min(skb_headlen(skb), total);
2893 while (len) {
2894 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2895 size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD);
2896
2897 tx_buffer_info->length = size;
2898 tx_buffer_info->mapped_as_page = false;
Nick Nunley2a1f8792010-04-27 13:10:50 +00002899 tx_buffer_info->dma = dma_map_single(&adapter->pdev->dev,
Greg Rose92915f72010-01-09 02:24:10 +00002900 skb->data + offset,
Nick Nunley2a1f8792010-04-27 13:10:50 +00002901 size, DMA_TO_DEVICE);
2902 if (dma_mapping_error(&pdev->dev, tx_buffer_info->dma))
Greg Rose92915f72010-01-09 02:24:10 +00002903 goto dma_error;
2904 tx_buffer_info->time_stamp = jiffies;
2905 tx_buffer_info->next_to_watch = i;
2906
2907 len -= size;
2908 total -= size;
2909 offset += size;
2910 count++;
2911 i++;
2912 if (i == tx_ring->count)
2913 i = 0;
2914 }
2915
2916 for (f = 0; f < nr_frags; f++) {
2917 struct skb_frag_struct *frag;
2918
2919 frag = &skb_shinfo(skb)->frags[f];
2920 len = min((unsigned int)frag->size, total);
2921 offset = frag->page_offset;
2922
2923 while (len) {
2924 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2925 size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD);
2926
2927 tx_buffer_info->length = size;
Nick Nunley2a1f8792010-04-27 13:10:50 +00002928 tx_buffer_info->dma = dma_map_page(&adapter->pdev->dev,
Greg Rose92915f72010-01-09 02:24:10 +00002929 frag->page,
2930 offset,
2931 size,
Nick Nunley2a1f8792010-04-27 13:10:50 +00002932 DMA_TO_DEVICE);
Greg Rose92915f72010-01-09 02:24:10 +00002933 tx_buffer_info->mapped_as_page = true;
Nick Nunley2a1f8792010-04-27 13:10:50 +00002934 if (dma_mapping_error(&pdev->dev, tx_buffer_info->dma))
Greg Rose92915f72010-01-09 02:24:10 +00002935 goto dma_error;
2936 tx_buffer_info->time_stamp = jiffies;
2937 tx_buffer_info->next_to_watch = i;
2938
2939 len -= size;
2940 total -= size;
2941 offset += size;
2942 count++;
2943 i++;
2944 if (i == tx_ring->count)
2945 i = 0;
2946 }
2947 if (total == 0)
2948 break;
2949 }
2950
2951 if (i == 0)
2952 i = tx_ring->count - 1;
2953 else
2954 i = i - 1;
2955 tx_ring->tx_buffer_info[i].skb = skb;
2956 tx_ring->tx_buffer_info[first].next_to_watch = i;
2957
2958 return count;
2959
2960dma_error:
2961 dev_err(&pdev->dev, "TX DMA map failed\n");
2962
2963 /* clear timestamp and dma mappings for failed tx_buffer_info map */
2964 tx_buffer_info->dma = 0;
2965 tx_buffer_info->time_stamp = 0;
2966 tx_buffer_info->next_to_watch = 0;
2967 count--;
2968
2969 /* clear timestamp and dma mappings for remaining portion of packet */
2970 while (count >= 0) {
2971 count--;
2972 i--;
2973 if (i < 0)
2974 i += tx_ring->count;
2975 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2976 ixgbevf_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2977 }
2978
2979 return count;
2980}
2981
2982static void ixgbevf_tx_queue(struct ixgbevf_adapter *adapter,
2983 struct ixgbevf_ring *tx_ring, int tx_flags,
2984 int count, u32 paylen, u8 hdr_len)
2985{
2986 union ixgbe_adv_tx_desc *tx_desc = NULL;
2987 struct ixgbevf_tx_buffer *tx_buffer_info;
2988 u32 olinfo_status = 0, cmd_type_len = 0;
2989 unsigned int i;
2990
2991 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
2992
2993 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
2994
2995 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
2996
2997 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
2998 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
2999
3000 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3001 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3002
3003 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3004 IXGBE_ADVTXD_POPTS_SHIFT;
3005
3006 /* use index 1 context for tso */
3007 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
3008 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3009 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
3010 IXGBE_ADVTXD_POPTS_SHIFT;
3011
3012 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3013 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
3014 IXGBE_ADVTXD_POPTS_SHIFT;
3015
3016 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3017
3018 i = tx_ring->next_to_use;
3019 while (count--) {
3020 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3021 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3022 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3023 tx_desc->read.cmd_type_len =
3024 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
3025 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
3026 i++;
3027 if (i == tx_ring->count)
3028 i = 0;
3029 }
3030
3031 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3032
3033 /*
3034 * Force memory writes to complete before letting h/w
3035 * know there are new descriptors to fetch. (Only
3036 * applicable for weak-ordered memory model archs,
3037 * such as IA-64).
3038 */
3039 wmb();
3040
3041 tx_ring->next_to_use = i;
3042 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3043}
3044
3045static int __ixgbevf_maybe_stop_tx(struct net_device *netdev,
3046 struct ixgbevf_ring *tx_ring, int size)
3047{
3048 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3049
3050 netif_stop_subqueue(netdev, tx_ring->queue_index);
3051 /* Herbert's original patch had:
3052 * smp_mb__after_netif_stop_queue();
3053 * but since that doesn't exist yet, just open code it. */
3054 smp_mb();
3055
3056 /* We need to check again in a case another CPU has just
3057 * made room available. */
3058 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3059 return -EBUSY;
3060
3061 /* A reprieve! - use start_queue because it doesn't call schedule */
3062 netif_start_subqueue(netdev, tx_ring->queue_index);
3063 ++adapter->restart_queue;
3064 return 0;
3065}
3066
3067static int ixgbevf_maybe_stop_tx(struct net_device *netdev,
3068 struct ixgbevf_ring *tx_ring, int size)
3069{
3070 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3071 return 0;
3072 return __ixgbevf_maybe_stop_tx(netdev, tx_ring, size);
3073}
3074
3075static int ixgbevf_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3076{
3077 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3078 struct ixgbevf_ring *tx_ring;
3079 unsigned int first;
3080 unsigned int tx_flags = 0;
3081 u8 hdr_len = 0;
3082 int r_idx = 0, tso;
3083 int count = 0;
3084
3085 unsigned int f;
3086
3087 tx_ring = &adapter->tx_ring[r_idx];
3088
Jesse Grosseab6d182010-10-20 13:56:03 +00003089 if (vlan_tx_tag_present(skb)) {
Greg Rose92915f72010-01-09 02:24:10 +00003090 tx_flags |= vlan_tx_tag_get(skb);
3091 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3092 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3093 }
3094
3095 /* four things can cause us to need a context descriptor */
3096 if (skb_is_gso(skb) ||
3097 (skb->ip_summed == CHECKSUM_PARTIAL) ||
3098 (tx_flags & IXGBE_TX_FLAGS_VLAN))
3099 count++;
3100
3101 count += TXD_USE_COUNT(skb_headlen(skb));
3102 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
3103 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3104
3105 if (ixgbevf_maybe_stop_tx(netdev, tx_ring, count)) {
3106 adapter->tx_busy++;
3107 return NETDEV_TX_BUSY;
3108 }
3109
3110 first = tx_ring->next_to_use;
3111
3112 if (skb->protocol == htons(ETH_P_IP))
3113 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3114 tso = ixgbevf_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3115 if (tso < 0) {
3116 dev_kfree_skb_any(skb);
3117 return NETDEV_TX_OK;
3118 }
3119
3120 if (tso)
3121 tx_flags |= IXGBE_TX_FLAGS_TSO;
3122 else if (ixgbevf_tx_csum(adapter, tx_ring, skb, tx_flags) &&
3123 (skb->ip_summed == CHECKSUM_PARTIAL))
3124 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3125
3126 ixgbevf_tx_queue(adapter, tx_ring, tx_flags,
3127 ixgbevf_tx_map(adapter, tx_ring, skb, tx_flags, first),
3128 skb->len, hdr_len);
3129
Greg Rose92915f72010-01-09 02:24:10 +00003130 ixgbevf_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
3131
3132 return NETDEV_TX_OK;
3133}
3134
3135/**
Greg Rose92915f72010-01-09 02:24:10 +00003136 * ixgbevf_set_mac - Change the Ethernet Address of the NIC
3137 * @netdev: network interface device structure
3138 * @p: pointer to an address structure
3139 *
3140 * Returns 0 on success, negative on failure
3141 **/
3142static int ixgbevf_set_mac(struct net_device *netdev, void *p)
3143{
3144 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3145 struct ixgbe_hw *hw = &adapter->hw;
3146 struct sockaddr *addr = p;
3147
3148 if (!is_valid_ether_addr(addr->sa_data))
3149 return -EADDRNOTAVAIL;
3150
3151 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3152 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
3153
3154 if (hw->mac.ops.set_rar)
3155 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
3156
3157 return 0;
3158}
3159
3160/**
3161 * ixgbevf_change_mtu - Change the Maximum Transfer Unit
3162 * @netdev: network interface device structure
3163 * @new_mtu: new value for maximum frame size
3164 *
3165 * Returns 0 on success, negative on failure
3166 **/
3167static int ixgbevf_change_mtu(struct net_device *netdev, int new_mtu)
3168{
3169 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
Greg Rose69bfbec2011-01-26 01:06:12 +00003170 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose92915f72010-01-09 02:24:10 +00003171 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
Greg Rose69bfbec2011-01-26 01:06:12 +00003172 int max_possible_frame = MAXIMUM_ETHERNET_VLAN_SIZE;
3173 u32 msg[2];
3174
3175 if (adapter->hw.mac.type == ixgbe_mac_X540_vf)
3176 max_possible_frame = IXGBE_MAX_JUMBO_FRAME_SIZE;
Greg Rose92915f72010-01-09 02:24:10 +00003177
3178 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rose69bfbec2011-01-26 01:06:12 +00003179 if ((new_mtu < 68) || (max_frame > max_possible_frame))
Greg Rose92915f72010-01-09 02:24:10 +00003180 return -EINVAL;
3181
3182 hw_dbg(&adapter->hw, "changing MTU from %d to %d\n",
3183 netdev->mtu, new_mtu);
3184 /* must set new MTU before calling down or up */
3185 netdev->mtu = new_mtu;
3186
Greg Rose69bfbec2011-01-26 01:06:12 +00003187 msg[0] = IXGBE_VF_SET_LPE;
3188 msg[1] = max_frame;
3189 hw->mbx.ops.write_posted(hw, msg, 2);
3190
Greg Rose92915f72010-01-09 02:24:10 +00003191 if (netif_running(netdev))
3192 ixgbevf_reinit_locked(adapter);
3193
3194 return 0;
3195}
3196
3197static void ixgbevf_shutdown(struct pci_dev *pdev)
3198{
3199 struct net_device *netdev = pci_get_drvdata(pdev);
3200 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3201
3202 netif_device_detach(netdev);
3203
3204 if (netif_running(netdev)) {
3205 ixgbevf_down(adapter);
3206 ixgbevf_free_irq(adapter);
3207 ixgbevf_free_all_tx_resources(adapter);
3208 ixgbevf_free_all_rx_resources(adapter);
3209 }
3210
3211#ifdef CONFIG_PM
3212 pci_save_state(pdev);
3213#endif
3214
3215 pci_disable_device(pdev);
3216}
3217
Greg Rose92915f72010-01-09 02:24:10 +00003218static const struct net_device_ops ixgbe_netdev_ops = {
Stephen Hemmingerc12db762011-06-09 02:58:39 +00003219 .ndo_open = ixgbevf_open,
3220 .ndo_stop = ixgbevf_close,
3221 .ndo_start_xmit = ixgbevf_xmit_frame,
3222 .ndo_set_rx_mode = ixgbevf_set_rx_mode,
3223 .ndo_set_multicast_list = ixgbevf_set_rx_mode,
Greg Rose92915f72010-01-09 02:24:10 +00003224 .ndo_validate_addr = eth_validate_addr,
Stephen Hemmingerc12db762011-06-09 02:58:39 +00003225 .ndo_set_mac_address = ixgbevf_set_mac,
3226 .ndo_change_mtu = ixgbevf_change_mtu,
3227 .ndo_tx_timeout = ixgbevf_tx_timeout,
Stephen Hemmingerc12db762011-06-09 02:58:39 +00003228 .ndo_vlan_rx_add_vid = ixgbevf_vlan_rx_add_vid,
3229 .ndo_vlan_rx_kill_vid = ixgbevf_vlan_rx_kill_vid,
Greg Rose92915f72010-01-09 02:24:10 +00003230};
Greg Rose92915f72010-01-09 02:24:10 +00003231
3232static void ixgbevf_assign_netdev_ops(struct net_device *dev)
3233{
Greg Rose92915f72010-01-09 02:24:10 +00003234 dev->netdev_ops = &ixgbe_netdev_ops;
Greg Rose92915f72010-01-09 02:24:10 +00003235 ixgbevf_set_ethtool_ops(dev);
3236 dev->watchdog_timeo = 5 * HZ;
3237}
3238
3239/**
3240 * ixgbevf_probe - Device Initialization Routine
3241 * @pdev: PCI device information struct
3242 * @ent: entry in ixgbevf_pci_tbl
3243 *
3244 * Returns 0 on success, negative on failure
3245 *
3246 * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
3247 * The OS initialization, configuring of the adapter private structure,
3248 * and a hardware reset occur.
3249 **/
3250static int __devinit ixgbevf_probe(struct pci_dev *pdev,
3251 const struct pci_device_id *ent)
3252{
3253 struct net_device *netdev;
3254 struct ixgbevf_adapter *adapter = NULL;
3255 struct ixgbe_hw *hw = NULL;
3256 const struct ixgbevf_info *ii = ixgbevf_info_tbl[ent->driver_data];
3257 static int cards_found;
3258 int err, pci_using_dac;
3259
3260 err = pci_enable_device(pdev);
3261 if (err)
3262 return err;
3263
Nick Nunley2a1f8792010-04-27 13:10:50 +00003264 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
3265 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Greg Rose92915f72010-01-09 02:24:10 +00003266 pci_using_dac = 1;
3267 } else {
Nick Nunley2a1f8792010-04-27 13:10:50 +00003268 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Greg Rose92915f72010-01-09 02:24:10 +00003269 if (err) {
Nick Nunley2a1f8792010-04-27 13:10:50 +00003270 err = dma_set_coherent_mask(&pdev->dev,
3271 DMA_BIT_MASK(32));
Greg Rose92915f72010-01-09 02:24:10 +00003272 if (err) {
3273 dev_err(&pdev->dev, "No usable DMA "
3274 "configuration, aborting\n");
3275 goto err_dma;
3276 }
3277 }
3278 pci_using_dac = 0;
3279 }
3280
3281 err = pci_request_regions(pdev, ixgbevf_driver_name);
3282 if (err) {
3283 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
3284 goto err_pci_reg;
3285 }
3286
3287 pci_set_master(pdev);
3288
3289#ifdef HAVE_TX_MQ
3290 netdev = alloc_etherdev_mq(sizeof(struct ixgbevf_adapter),
3291 MAX_TX_QUEUES);
3292#else
3293 netdev = alloc_etherdev(sizeof(struct ixgbevf_adapter));
3294#endif
3295 if (!netdev) {
3296 err = -ENOMEM;
3297 goto err_alloc_etherdev;
3298 }
3299
3300 SET_NETDEV_DEV(netdev, &pdev->dev);
3301
3302 pci_set_drvdata(pdev, netdev);
3303 adapter = netdev_priv(netdev);
3304
3305 adapter->netdev = netdev;
3306 adapter->pdev = pdev;
3307 hw = &adapter->hw;
3308 hw->back = adapter;
3309 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
3310
3311 /*
3312 * call save state here in standalone driver because it relies on
3313 * adapter struct to exist, and needs to call netdev_priv
3314 */
3315 pci_save_state(pdev);
3316
3317 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
3318 pci_resource_len(pdev, 0));
3319 if (!hw->hw_addr) {
3320 err = -EIO;
3321 goto err_ioremap;
3322 }
3323
3324 ixgbevf_assign_netdev_ops(netdev);
3325
3326 adapter->bd_number = cards_found;
3327
3328 /* Setup hw api */
3329 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
3330 hw->mac.type = ii->mac;
3331
3332 memcpy(&hw->mbx.ops, &ixgbevf_mbx_ops,
Greg Rosef416dfc2011-06-08 07:32:38 +00003333 sizeof(struct ixgbe_mbx_operations));
Greg Rose92915f72010-01-09 02:24:10 +00003334
3335 adapter->flags &= ~IXGBE_FLAG_RX_PS_CAPABLE;
3336 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3337 adapter->flags |= IXGBE_FLAG_RX_1BUF_CAPABLE;
3338
3339 /* setup the private structure */
3340 err = ixgbevf_sw_init(adapter);
3341
Greg Rose92915f72010-01-09 02:24:10 +00003342 netdev->features = NETIF_F_SG |
3343 NETIF_F_IP_CSUM |
3344 NETIF_F_HW_VLAN_TX |
3345 NETIF_F_HW_VLAN_RX |
3346 NETIF_F_HW_VLAN_FILTER;
3347
3348 netdev->features |= NETIF_F_IPV6_CSUM;
3349 netdev->features |= NETIF_F_TSO;
3350 netdev->features |= NETIF_F_TSO6;
Shirley Mae59d44d2010-06-05 03:04:50 -07003351 netdev->features |= NETIF_F_GRO;
Greg Rose92915f72010-01-09 02:24:10 +00003352 netdev->vlan_features |= NETIF_F_TSO;
3353 netdev->vlan_features |= NETIF_F_TSO6;
3354 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyck3bfacf92010-08-02 14:59:04 +00003355 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Greg Rose92915f72010-01-09 02:24:10 +00003356 netdev->vlan_features |= NETIF_F_SG;
3357
3358 if (pci_using_dac)
3359 netdev->features |= NETIF_F_HIGHDMA;
3360
Greg Rose92915f72010-01-09 02:24:10 +00003361 /* The HW MAC address was set and/or determined in sw_init */
3362 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
3363 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
3364
3365 if (!is_valid_ether_addr(netdev->dev_addr)) {
3366 printk(KERN_ERR "invalid MAC address\n");
3367 err = -EIO;
3368 goto err_sw_init;
3369 }
3370
3371 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00003372 adapter->watchdog_timer.function = ixgbevf_watchdog;
Greg Rose92915f72010-01-09 02:24:10 +00003373 adapter->watchdog_timer.data = (unsigned long)adapter;
3374
3375 INIT_WORK(&adapter->reset_task, ixgbevf_reset_task);
3376 INIT_WORK(&adapter->watchdog_task, ixgbevf_watchdog_task);
3377
3378 err = ixgbevf_init_interrupt_scheme(adapter);
3379 if (err)
3380 goto err_sw_init;
3381
3382 /* pick up the PCI bus settings for reporting later */
3383 if (hw->mac.ops.get_bus_info)
3384 hw->mac.ops.get_bus_info(hw);
3385
Greg Rose92915f72010-01-09 02:24:10 +00003386 strcpy(netdev->name, "eth%d");
3387
3388 err = register_netdev(netdev);
3389 if (err)
3390 goto err_register;
3391
3392 adapter->netdev_registered = true;
3393
Greg Rose5d426ad2010-11-16 19:27:19 -08003394 netif_carrier_off(netdev);
3395
Greg Rose33bd9f62010-03-19 02:59:52 +00003396 ixgbevf_init_last_counter_stats(adapter);
3397
Greg Rose92915f72010-01-09 02:24:10 +00003398 /* print the MAC address */
3399 hw_dbg(hw, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
3400 netdev->dev_addr[0],
3401 netdev->dev_addr[1],
3402 netdev->dev_addr[2],
3403 netdev->dev_addr[3],
3404 netdev->dev_addr[4],
3405 netdev->dev_addr[5]);
3406
3407 hw_dbg(hw, "MAC: %d\n", hw->mac.type);
3408
Frans Popd6dbee82010-03-24 07:57:35 +00003409 hw_dbg(hw, "LRO is disabled\n");
Greg Rose92915f72010-01-09 02:24:10 +00003410
3411 hw_dbg(hw, "Intel(R) 82599 Virtual Function\n");
3412 cards_found++;
3413 return 0;
3414
3415err_register:
3416err_sw_init:
3417 ixgbevf_reset_interrupt_capability(adapter);
3418 iounmap(hw->hw_addr);
3419err_ioremap:
3420 free_netdev(netdev);
3421err_alloc_etherdev:
3422 pci_release_regions(pdev);
3423err_pci_reg:
3424err_dma:
3425 pci_disable_device(pdev);
3426 return err;
3427}
3428
3429/**
3430 * ixgbevf_remove - Device Removal Routine
3431 * @pdev: PCI device information struct
3432 *
3433 * ixgbevf_remove is called by the PCI subsystem to alert the driver
3434 * that it should release a PCI device. The could be caused by a
3435 * Hot-Plug event, or because the driver is going to be removed from
3436 * memory.
3437 **/
3438static void __devexit ixgbevf_remove(struct pci_dev *pdev)
3439{
3440 struct net_device *netdev = pci_get_drvdata(pdev);
3441 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3442
3443 set_bit(__IXGBEVF_DOWN, &adapter->state);
3444
3445 del_timer_sync(&adapter->watchdog_timer);
3446
Tejun Heo23f333a2010-12-12 16:45:14 +01003447 cancel_work_sync(&adapter->reset_task);
Greg Rose92915f72010-01-09 02:24:10 +00003448 cancel_work_sync(&adapter->watchdog_task);
3449
Greg Rose92915f72010-01-09 02:24:10 +00003450 if (adapter->netdev_registered) {
3451 unregister_netdev(netdev);
3452 adapter->netdev_registered = false;
3453 }
3454
3455 ixgbevf_reset_interrupt_capability(adapter);
3456
3457 iounmap(adapter->hw.hw_addr);
3458 pci_release_regions(pdev);
3459
3460 hw_dbg(&adapter->hw, "Remove complete\n");
3461
3462 kfree(adapter->tx_ring);
3463 kfree(adapter->rx_ring);
3464
3465 free_netdev(netdev);
3466
3467 pci_disable_device(pdev);
3468}
3469
3470static struct pci_driver ixgbevf_driver = {
3471 .name = ixgbevf_driver_name,
3472 .id_table = ixgbevf_pci_tbl,
3473 .probe = ixgbevf_probe,
3474 .remove = __devexit_p(ixgbevf_remove),
3475 .shutdown = ixgbevf_shutdown,
3476};
3477
3478/**
Greg Rose65d676c2011-02-03 06:54:13 +00003479 * ixgbevf_init_module - Driver Registration Routine
Greg Rose92915f72010-01-09 02:24:10 +00003480 *
Greg Rose65d676c2011-02-03 06:54:13 +00003481 * ixgbevf_init_module is the first routine called when the driver is
Greg Rose92915f72010-01-09 02:24:10 +00003482 * loaded. All it does is register with the PCI subsystem.
3483 **/
3484static int __init ixgbevf_init_module(void)
3485{
3486 int ret;
3487 printk(KERN_INFO "ixgbevf: %s - version %s\n", ixgbevf_driver_string,
3488 ixgbevf_driver_version);
3489
3490 printk(KERN_INFO "%s\n", ixgbevf_copyright);
3491
3492 ret = pci_register_driver(&ixgbevf_driver);
3493 return ret;
3494}
3495
3496module_init(ixgbevf_init_module);
3497
3498/**
Greg Rose65d676c2011-02-03 06:54:13 +00003499 * ixgbevf_exit_module - Driver Exit Cleanup Routine
Greg Rose92915f72010-01-09 02:24:10 +00003500 *
Greg Rose65d676c2011-02-03 06:54:13 +00003501 * ixgbevf_exit_module is called just before the driver is removed
Greg Rose92915f72010-01-09 02:24:10 +00003502 * from memory.
3503 **/
3504static void __exit ixgbevf_exit_module(void)
3505{
3506 pci_unregister_driver(&ixgbevf_driver);
3507}
3508
3509#ifdef DEBUG
3510/**
Greg Rose65d676c2011-02-03 06:54:13 +00003511 * ixgbevf_get_hw_dev_name - return device name string
Greg Rose92915f72010-01-09 02:24:10 +00003512 * used by hardware layer to print debugging information
3513 **/
3514char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw)
3515{
3516 struct ixgbevf_adapter *adapter = hw->back;
3517 return adapter->netdev->name;
3518}
3519
3520#endif
3521module_exit(ixgbevf_exit_module);
3522
3523/* ixgbevf_main.c */