blob: ebfaa68ee630404addca4607b4dffa2e3fe6bc33 [file] [log] [blame]
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001/*******************************************************************************
2
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 2009 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/module.h>
29#include <linux/types.h>
30#include <linux/init.h>
31#include <linux/pci.h>
32#include <linux/vmalloc.h>
33#include <linux/pagemap.h>
34#include <linux/delay.h>
35#include <linux/netdevice.h>
36#include <linux/tcp.h>
37#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000039#include <net/checksum.h>
40#include <net/ip6_checksum.h>
41#include <linux/mii.h>
42#include <linux/ethtool.h>
43#include <linux/if_vlan.h>
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000044
45#include "igbvf.h"
46
47#define DRV_VERSION "1.0.0-k0"
48char igbvf_driver_name[] = "igbvf";
49const char igbvf_driver_version[] = DRV_VERSION;
50static const char igbvf_driver_string[] =
51 "Intel(R) Virtual Function Network Driver";
52static const char igbvf_copyright[] = "Copyright (c) 2009 Intel Corporation.";
53
54static int igbvf_poll(struct napi_struct *napi, int budget);
Alexander Duyck2d165772009-04-09 22:49:20 +000055static void igbvf_reset(struct igbvf_adapter *);
56static void igbvf_set_interrupt_capability(struct igbvf_adapter *);
57static void igbvf_reset_interrupt_capability(struct igbvf_adapter *);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000058
59static struct igbvf_info igbvf_vf_info = {
60 .mac = e1000_vfadapt,
Alexander Duyck0364d6f2009-05-06 10:25:01 +000061 .flags = 0,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000062 .pba = 10,
63 .init_ops = e1000_init_function_pointers_vf,
64};
65
66static const struct igbvf_info *igbvf_info_tbl[] = {
67 [board_vf] = &igbvf_vf_info,
68};
69
70/**
71 * igbvf_desc_unused - calculate if we have unused descriptors
72 **/
73static int igbvf_desc_unused(struct igbvf_ring *ring)
74{
75 if (ring->next_to_clean > ring->next_to_use)
76 return ring->next_to_clean - ring->next_to_use - 1;
77
78 return ring->count + ring->next_to_clean - ring->next_to_use - 1;
79}
80
81/**
82 * igbvf_receive_skb - helper function to handle Rx indications
83 * @adapter: board private structure
84 * @status: descriptor status field as written by hardware
85 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
86 * @skb: pointer to sk_buff to be indicated to stack
87 **/
88static void igbvf_receive_skb(struct igbvf_adapter *adapter,
89 struct net_device *netdev,
90 struct sk_buff *skb,
91 u32 status, u16 vlan)
92{
93 if (adapter->vlgrp && (status & E1000_RXD_STAT_VP))
94 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
95 le16_to_cpu(vlan) &
96 E1000_RXD_SPC_VLAN_MASK);
97 else
98 netif_receive_skb(skb);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000099}
100
101static inline void igbvf_rx_checksum_adv(struct igbvf_adapter *adapter,
102 u32 status_err, struct sk_buff *skb)
103{
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700104 skb_checksum_none_assert(skb);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000105
106 /* Ignore Checksum bit is set or checksum is disabled through ethtool */
Alexander Duyck0364d6f2009-05-06 10:25:01 +0000107 if ((status_err & E1000_RXD_STAT_IXSM) ||
108 (adapter->flags & IGBVF_FLAG_RX_CSUM_DISABLED))
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000109 return;
Alexander Duyck0364d6f2009-05-06 10:25:01 +0000110
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000111 /* TCP/UDP checksum error bit is set */
112 if (status_err &
113 (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
114 /* let the stack verify checksum errors */
115 adapter->hw_csum_err++;
116 return;
117 }
Alexander Duyck0364d6f2009-05-06 10:25:01 +0000118
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000119 /* It must be a TCP or UDP packet with a valid checksum */
120 if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
121 skb->ip_summed = CHECKSUM_UNNECESSARY;
122
123 adapter->hw_csum_good++;
124}
125
126/**
127 * igbvf_alloc_rx_buffers - Replace used receive buffers; packet split
128 * @rx_ring: address of ring structure to repopulate
129 * @cleaned_count: number of buffers to repopulate
130 **/
131static void igbvf_alloc_rx_buffers(struct igbvf_ring *rx_ring,
132 int cleaned_count)
133{
134 struct igbvf_adapter *adapter = rx_ring->adapter;
135 struct net_device *netdev = adapter->netdev;
136 struct pci_dev *pdev = adapter->pdev;
137 union e1000_adv_rx_desc *rx_desc;
138 struct igbvf_buffer *buffer_info;
139 struct sk_buff *skb;
140 unsigned int i;
141 int bufsz;
142
143 i = rx_ring->next_to_use;
144 buffer_info = &rx_ring->buffer_info[i];
145
146 if (adapter->rx_ps_hdr_size)
147 bufsz = adapter->rx_ps_hdr_size;
148 else
149 bufsz = adapter->rx_buffer_len;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000150
151 while (cleaned_count--) {
152 rx_desc = IGBVF_RX_DESC_ADV(*rx_ring, i);
153
154 if (adapter->rx_ps_hdr_size && !buffer_info->page_dma) {
155 if (!buffer_info->page) {
156 buffer_info->page = alloc_page(GFP_ATOMIC);
157 if (!buffer_info->page) {
158 adapter->alloc_rx_buff_failed++;
159 goto no_buffers;
160 }
161 buffer_info->page_offset = 0;
162 } else {
163 buffer_info->page_offset ^= PAGE_SIZE / 2;
164 }
165 buffer_info->page_dma =
Nick Nunley123e9f12010-04-27 13:09:44 +0000166 dma_map_page(&pdev->dev, buffer_info->page,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000167 buffer_info->page_offset,
168 PAGE_SIZE / 2,
Nick Nunley123e9f12010-04-27 13:09:44 +0000169 DMA_FROM_DEVICE);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000170 }
171
172 if (!buffer_info->skb) {
Eric Dumazet89d71a62009-10-13 05:34:20 +0000173 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000174 if (!skb) {
175 adapter->alloc_rx_buff_failed++;
176 goto no_buffers;
177 }
178
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000179 buffer_info->skb = skb;
Nick Nunley123e9f12010-04-27 13:09:44 +0000180 buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000181 bufsz,
Nick Nunley123e9f12010-04-27 13:09:44 +0000182 DMA_FROM_DEVICE);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000183 }
184 /* Refresh the desc even if buffer_addrs didn't change because
185 * each write-back erases this info. */
186 if (adapter->rx_ps_hdr_size) {
187 rx_desc->read.pkt_addr =
188 cpu_to_le64(buffer_info->page_dma);
189 rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
190 } else {
191 rx_desc->read.pkt_addr =
192 cpu_to_le64(buffer_info->dma);
193 rx_desc->read.hdr_addr = 0;
194 }
195
196 i++;
197 if (i == rx_ring->count)
198 i = 0;
199 buffer_info = &rx_ring->buffer_info[i];
200 }
201
202no_buffers:
203 if (rx_ring->next_to_use != i) {
204 rx_ring->next_to_use = i;
205 if (i == 0)
206 i = (rx_ring->count - 1);
207 else
208 i--;
209
210 /* Force memory writes to complete before letting h/w
211 * know there are new descriptors to fetch. (Only
212 * applicable for weak-ordered memory model archs,
213 * such as IA-64). */
214 wmb();
215 writel(i, adapter->hw.hw_addr + rx_ring->tail);
216 }
217}
218
219/**
220 * igbvf_clean_rx_irq - Send received data up the network stack; legacy
221 * @adapter: board private structure
222 *
223 * the return value indicates whether actual cleaning was done, there
224 * is no guarantee that everything was cleaned
225 **/
226static bool igbvf_clean_rx_irq(struct igbvf_adapter *adapter,
227 int *work_done, int work_to_do)
228{
229 struct igbvf_ring *rx_ring = adapter->rx_ring;
230 struct net_device *netdev = adapter->netdev;
231 struct pci_dev *pdev = adapter->pdev;
232 union e1000_adv_rx_desc *rx_desc, *next_rxd;
233 struct igbvf_buffer *buffer_info, *next_buffer;
234 struct sk_buff *skb;
235 bool cleaned = false;
236 int cleaned_count = 0;
237 unsigned int total_bytes = 0, total_packets = 0;
238 unsigned int i;
239 u32 length, hlen, staterr;
240
241 i = rx_ring->next_to_clean;
242 rx_desc = IGBVF_RX_DESC_ADV(*rx_ring, i);
243 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
244
245 while (staterr & E1000_RXD_STAT_DD) {
246 if (*work_done >= work_to_do)
247 break;
248 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000249 rmb(); /* read descriptor and rx_buffer_info after status DD */
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000250
251 buffer_info = &rx_ring->buffer_info[i];
252
253 /* HW will not DMA in data larger than the given buffer, even
254 * if it parses the (NFS, of course) header to be larger. In
255 * that case, it fills the header buffer and spills the rest
256 * into the page.
257 */
258 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info) &
259 E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
260 if (hlen > adapter->rx_ps_hdr_size)
261 hlen = adapter->rx_ps_hdr_size;
262
263 length = le16_to_cpu(rx_desc->wb.upper.length);
264 cleaned = true;
265 cleaned_count++;
266
267 skb = buffer_info->skb;
268 prefetch(skb->data - NET_IP_ALIGN);
269 buffer_info->skb = NULL;
270 if (!adapter->rx_ps_hdr_size) {
Nick Nunley123e9f12010-04-27 13:09:44 +0000271 dma_unmap_single(&pdev->dev, buffer_info->dma,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000272 adapter->rx_buffer_len,
Nick Nunley123e9f12010-04-27 13:09:44 +0000273 DMA_FROM_DEVICE);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000274 buffer_info->dma = 0;
275 skb_put(skb, length);
276 goto send_up;
277 }
278
279 if (!skb_shinfo(skb)->nr_frags) {
Nick Nunley123e9f12010-04-27 13:09:44 +0000280 dma_unmap_single(&pdev->dev, buffer_info->dma,
Alexander Duyck92d947b2009-07-23 18:11:01 +0000281 adapter->rx_ps_hdr_size,
Nick Nunley123e9f12010-04-27 13:09:44 +0000282 DMA_FROM_DEVICE);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000283 skb_put(skb, hlen);
284 }
285
286 if (length) {
Nick Nunley123e9f12010-04-27 13:09:44 +0000287 dma_unmap_page(&pdev->dev, buffer_info->page_dma,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000288 PAGE_SIZE / 2,
Nick Nunley123e9f12010-04-27 13:09:44 +0000289 DMA_FROM_DEVICE);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000290 buffer_info->page_dma = 0;
291
Koki Sanagiec857fd2010-04-27 01:01:39 +0000292 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000293 buffer_info->page,
294 buffer_info->page_offset,
295 length);
296
297 if ((adapter->rx_buffer_len > (PAGE_SIZE / 2)) ||
298 (page_count(buffer_info->page) != 1))
299 buffer_info->page = NULL;
300 else
301 get_page(buffer_info->page);
302
303 skb->len += length;
304 skb->data_len += length;
305 skb->truesize += length;
306 }
307send_up:
308 i++;
309 if (i == rx_ring->count)
310 i = 0;
311 next_rxd = IGBVF_RX_DESC_ADV(*rx_ring, i);
312 prefetch(next_rxd);
313 next_buffer = &rx_ring->buffer_info[i];
314
315 if (!(staterr & E1000_RXD_STAT_EOP)) {
316 buffer_info->skb = next_buffer->skb;
317 buffer_info->dma = next_buffer->dma;
318 next_buffer->skb = skb;
319 next_buffer->dma = 0;
320 goto next_desc;
321 }
322
323 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
324 dev_kfree_skb_irq(skb);
325 goto next_desc;
326 }
327
328 total_bytes += skb->len;
329 total_packets++;
330
331 igbvf_rx_checksum_adv(adapter, staterr, skb);
332
333 skb->protocol = eth_type_trans(skb, netdev);
334
335 igbvf_receive_skb(adapter, netdev, skb, staterr,
336 rx_desc->wb.upper.vlan);
337
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000338next_desc:
339 rx_desc->wb.upper.status_error = 0;
340
341 /* return some buffers to hardware, one at a time is too slow */
342 if (cleaned_count >= IGBVF_RX_BUFFER_WRITE) {
343 igbvf_alloc_rx_buffers(rx_ring, cleaned_count);
344 cleaned_count = 0;
345 }
346
347 /* use prefetched values */
348 rx_desc = next_rxd;
349 buffer_info = next_buffer;
350
351 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
352 }
353
354 rx_ring->next_to_clean = i;
355 cleaned_count = igbvf_desc_unused(rx_ring);
356
357 if (cleaned_count)
358 igbvf_alloc_rx_buffers(rx_ring, cleaned_count);
359
360 adapter->total_rx_packets += total_packets;
361 adapter->total_rx_bytes += total_bytes;
362 adapter->net_stats.rx_bytes += total_bytes;
363 adapter->net_stats.rx_packets += total_packets;
364 return cleaned;
365}
366
367static void igbvf_put_txbuf(struct igbvf_adapter *adapter,
368 struct igbvf_buffer *buffer_info)
369{
Alexander Duycka7d5ca42009-12-02 16:47:37 +0000370 if (buffer_info->dma) {
371 if (buffer_info->mapped_as_page)
Nick Nunley123e9f12010-04-27 13:09:44 +0000372 dma_unmap_page(&adapter->pdev->dev,
Alexander Duycka7d5ca42009-12-02 16:47:37 +0000373 buffer_info->dma,
374 buffer_info->length,
Nick Nunley123e9f12010-04-27 13:09:44 +0000375 DMA_TO_DEVICE);
Alexander Duycka7d5ca42009-12-02 16:47:37 +0000376 else
Nick Nunley123e9f12010-04-27 13:09:44 +0000377 dma_unmap_single(&adapter->pdev->dev,
Alexander Duycka7d5ca42009-12-02 16:47:37 +0000378 buffer_info->dma,
379 buffer_info->length,
Nick Nunley123e9f12010-04-27 13:09:44 +0000380 DMA_TO_DEVICE);
Alexander Duycka7d5ca42009-12-02 16:47:37 +0000381 buffer_info->dma = 0;
382 }
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000383 if (buffer_info->skb) {
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000384 dev_kfree_skb_any(buffer_info->skb);
385 buffer_info->skb = NULL;
386 }
387 buffer_info->time_stamp = 0;
388}
389
390static void igbvf_print_tx_hang(struct igbvf_adapter *adapter)
391{
392 struct igbvf_ring *tx_ring = adapter->tx_ring;
393 unsigned int i = tx_ring->next_to_clean;
394 unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
395 union e1000_adv_tx_desc *eop_desc = IGBVF_TX_DESC_ADV(*tx_ring, eop);
396
397 /* detected Tx unit hang */
398 dev_err(&adapter->pdev->dev,
399 "Detected Tx Unit Hang:\n"
400 " TDH <%x>\n"
401 " TDT <%x>\n"
402 " next_to_use <%x>\n"
403 " next_to_clean <%x>\n"
404 "buffer_info[next_to_clean]:\n"
405 " time_stamp <%lx>\n"
406 " next_to_watch <%x>\n"
407 " jiffies <%lx>\n"
408 " next_to_watch.status <%x>\n",
409 readl(adapter->hw.hw_addr + tx_ring->head),
410 readl(adapter->hw.hw_addr + tx_ring->tail),
411 tx_ring->next_to_use,
412 tx_ring->next_to_clean,
413 tx_ring->buffer_info[eop].time_stamp,
414 eop,
415 jiffies,
416 eop_desc->wb.status);
417}
418
419/**
420 * igbvf_setup_tx_resources - allocate Tx resources (Descriptors)
421 * @adapter: board private structure
422 *
423 * Return 0 on success, negative on failure
424 **/
425int igbvf_setup_tx_resources(struct igbvf_adapter *adapter,
426 struct igbvf_ring *tx_ring)
427{
428 struct pci_dev *pdev = adapter->pdev;
429 int size;
430
431 size = sizeof(struct igbvf_buffer) * tx_ring->count;
432 tx_ring->buffer_info = vmalloc(size);
433 if (!tx_ring->buffer_info)
434 goto err;
435 memset(tx_ring->buffer_info, 0, size);
436
437 /* round up to nearest 4K */
438 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
439 tx_ring->size = ALIGN(tx_ring->size, 4096);
440
Nick Nunley123e9f12010-04-27 13:09:44 +0000441 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
442 &tx_ring->dma, GFP_KERNEL);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000443
444 if (!tx_ring->desc)
445 goto err;
446
447 tx_ring->adapter = adapter;
448 tx_ring->next_to_use = 0;
449 tx_ring->next_to_clean = 0;
450
451 return 0;
452err:
453 vfree(tx_ring->buffer_info);
454 dev_err(&adapter->pdev->dev,
455 "Unable to allocate memory for the transmit descriptor ring\n");
456 return -ENOMEM;
457}
458
459/**
460 * igbvf_setup_rx_resources - allocate Rx resources (Descriptors)
461 * @adapter: board private structure
462 *
463 * Returns 0 on success, negative on failure
464 **/
465int igbvf_setup_rx_resources(struct igbvf_adapter *adapter,
466 struct igbvf_ring *rx_ring)
467{
468 struct pci_dev *pdev = adapter->pdev;
469 int size, desc_len;
470
471 size = sizeof(struct igbvf_buffer) * rx_ring->count;
472 rx_ring->buffer_info = vmalloc(size);
473 if (!rx_ring->buffer_info)
474 goto err;
475 memset(rx_ring->buffer_info, 0, size);
476
477 desc_len = sizeof(union e1000_adv_rx_desc);
478
479 /* Round up to nearest 4K */
480 rx_ring->size = rx_ring->count * desc_len;
481 rx_ring->size = ALIGN(rx_ring->size, 4096);
482
Nick Nunley123e9f12010-04-27 13:09:44 +0000483 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
484 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000485
486 if (!rx_ring->desc)
487 goto err;
488
489 rx_ring->next_to_clean = 0;
490 rx_ring->next_to_use = 0;
491
492 rx_ring->adapter = adapter;
493
494 return 0;
495
496err:
497 vfree(rx_ring->buffer_info);
498 rx_ring->buffer_info = NULL;
499 dev_err(&adapter->pdev->dev,
500 "Unable to allocate memory for the receive descriptor ring\n");
501 return -ENOMEM;
502}
503
504/**
505 * igbvf_clean_tx_ring - Free Tx Buffers
506 * @tx_ring: ring to be cleaned
507 **/
508static void igbvf_clean_tx_ring(struct igbvf_ring *tx_ring)
509{
510 struct igbvf_adapter *adapter = tx_ring->adapter;
511 struct igbvf_buffer *buffer_info;
512 unsigned long size;
513 unsigned int i;
514
515 if (!tx_ring->buffer_info)
516 return;
517
518 /* Free all the Tx ring sk_buffs */
519 for (i = 0; i < tx_ring->count; i++) {
520 buffer_info = &tx_ring->buffer_info[i];
521 igbvf_put_txbuf(adapter, buffer_info);
522 }
523
524 size = sizeof(struct igbvf_buffer) * tx_ring->count;
525 memset(tx_ring->buffer_info, 0, size);
526
527 /* Zero out the descriptor ring */
528 memset(tx_ring->desc, 0, tx_ring->size);
529
530 tx_ring->next_to_use = 0;
531 tx_ring->next_to_clean = 0;
532
533 writel(0, adapter->hw.hw_addr + tx_ring->head);
534 writel(0, adapter->hw.hw_addr + tx_ring->tail);
535}
536
537/**
538 * igbvf_free_tx_resources - Free Tx Resources per Queue
539 * @tx_ring: ring to free resources from
540 *
541 * Free all transmit software resources
542 **/
543void igbvf_free_tx_resources(struct igbvf_ring *tx_ring)
544{
545 struct pci_dev *pdev = tx_ring->adapter->pdev;
546
547 igbvf_clean_tx_ring(tx_ring);
548
549 vfree(tx_ring->buffer_info);
550 tx_ring->buffer_info = NULL;
551
Nick Nunley123e9f12010-04-27 13:09:44 +0000552 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
553 tx_ring->dma);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000554
555 tx_ring->desc = NULL;
556}
557
558/**
559 * igbvf_clean_rx_ring - Free Rx Buffers per Queue
560 * @adapter: board private structure
561 **/
562static void igbvf_clean_rx_ring(struct igbvf_ring *rx_ring)
563{
564 struct igbvf_adapter *adapter = rx_ring->adapter;
565 struct igbvf_buffer *buffer_info;
566 struct pci_dev *pdev = adapter->pdev;
567 unsigned long size;
568 unsigned int i;
569
570 if (!rx_ring->buffer_info)
571 return;
572
573 /* Free all the Rx ring sk_buffs */
574 for (i = 0; i < rx_ring->count; i++) {
575 buffer_info = &rx_ring->buffer_info[i];
576 if (buffer_info->dma) {
577 if (adapter->rx_ps_hdr_size){
Nick Nunley123e9f12010-04-27 13:09:44 +0000578 dma_unmap_single(&pdev->dev, buffer_info->dma,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000579 adapter->rx_ps_hdr_size,
Nick Nunley123e9f12010-04-27 13:09:44 +0000580 DMA_FROM_DEVICE);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000581 } else {
Nick Nunley123e9f12010-04-27 13:09:44 +0000582 dma_unmap_single(&pdev->dev, buffer_info->dma,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000583 adapter->rx_buffer_len,
Nick Nunley123e9f12010-04-27 13:09:44 +0000584 DMA_FROM_DEVICE);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000585 }
586 buffer_info->dma = 0;
587 }
588
589 if (buffer_info->skb) {
590 dev_kfree_skb(buffer_info->skb);
591 buffer_info->skb = NULL;
592 }
593
594 if (buffer_info->page) {
595 if (buffer_info->page_dma)
Nick Nunley123e9f12010-04-27 13:09:44 +0000596 dma_unmap_page(&pdev->dev,
597 buffer_info->page_dma,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000598 PAGE_SIZE / 2,
Nick Nunley123e9f12010-04-27 13:09:44 +0000599 DMA_FROM_DEVICE);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000600 put_page(buffer_info->page);
601 buffer_info->page = NULL;
602 buffer_info->page_dma = 0;
603 buffer_info->page_offset = 0;
604 }
605 }
606
607 size = sizeof(struct igbvf_buffer) * rx_ring->count;
608 memset(rx_ring->buffer_info, 0, size);
609
610 /* Zero out the descriptor ring */
611 memset(rx_ring->desc, 0, rx_ring->size);
612
613 rx_ring->next_to_clean = 0;
614 rx_ring->next_to_use = 0;
615
616 writel(0, adapter->hw.hw_addr + rx_ring->head);
617 writel(0, adapter->hw.hw_addr + rx_ring->tail);
618}
619
620/**
621 * igbvf_free_rx_resources - Free Rx Resources
622 * @rx_ring: ring to clean the resources from
623 *
624 * Free all receive software resources
625 **/
626
627void igbvf_free_rx_resources(struct igbvf_ring *rx_ring)
628{
629 struct pci_dev *pdev = rx_ring->adapter->pdev;
630
631 igbvf_clean_rx_ring(rx_ring);
632
633 vfree(rx_ring->buffer_info);
634 rx_ring->buffer_info = NULL;
635
636 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
637 rx_ring->dma);
638 rx_ring->desc = NULL;
639}
640
641/**
642 * igbvf_update_itr - update the dynamic ITR value based on statistics
643 * @adapter: pointer to adapter
644 * @itr_setting: current adapter->itr
645 * @packets: the number of packets during this measurement interval
646 * @bytes: the number of bytes during this measurement interval
647 *
648 * Stores a new ITR value based on packets and byte
649 * counts during the last interrupt. The advantage of per interrupt
650 * computation is faster updates and more accurate ITR for the current
651 * traffic pattern. Constants in this function were computed
652 * based on theoretical maximum wire speed and thresholds were set based
653 * on testing data as well as attempting to minimize response time
654 * while increasing bulk throughput. This functionality is controlled
655 * by the InterruptThrottleRate module parameter.
656 **/
657static unsigned int igbvf_update_itr(struct igbvf_adapter *adapter,
658 u16 itr_setting, int packets,
659 int bytes)
660{
661 unsigned int retval = itr_setting;
662
663 if (packets == 0)
664 goto update_itr_done;
665
666 switch (itr_setting) {
667 case lowest_latency:
668 /* handle TSO and jumbo frames */
669 if (bytes/packets > 8000)
670 retval = bulk_latency;
671 else if ((packets < 5) && (bytes > 512))
672 retval = low_latency;
673 break;
674 case low_latency: /* 50 usec aka 20000 ints/s */
675 if (bytes > 10000) {
676 /* this if handles the TSO accounting */
677 if (bytes/packets > 8000)
678 retval = bulk_latency;
679 else if ((packets < 10) || ((bytes/packets) > 1200))
680 retval = bulk_latency;
681 else if ((packets > 35))
682 retval = lowest_latency;
683 } else if (bytes/packets > 2000) {
684 retval = bulk_latency;
685 } else if (packets <= 2 && bytes < 512) {
686 retval = lowest_latency;
687 }
688 break;
689 case bulk_latency: /* 250 usec aka 4000 ints/s */
690 if (bytes > 25000) {
691 if (packets > 35)
692 retval = low_latency;
693 } else if (bytes < 6000) {
694 retval = low_latency;
695 }
696 break;
697 }
698
699update_itr_done:
700 return retval;
701}
702
703static void igbvf_set_itr(struct igbvf_adapter *adapter)
704{
705 struct e1000_hw *hw = &adapter->hw;
706 u16 current_itr;
707 u32 new_itr = adapter->itr;
708
709 adapter->tx_itr = igbvf_update_itr(adapter, adapter->tx_itr,
710 adapter->total_tx_packets,
711 adapter->total_tx_bytes);
712 /* conservative mode (itr 3) eliminates the lowest_latency setting */
713 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
714 adapter->tx_itr = low_latency;
715
716 adapter->rx_itr = igbvf_update_itr(adapter, adapter->rx_itr,
717 adapter->total_rx_packets,
718 adapter->total_rx_bytes);
719 /* conservative mode (itr 3) eliminates the lowest_latency setting */
720 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
721 adapter->rx_itr = low_latency;
722
723 current_itr = max(adapter->rx_itr, adapter->tx_itr);
724
725 switch (current_itr) {
726 /* counts and packets in update_itr are dependent on these numbers */
727 case lowest_latency:
728 new_itr = 70000;
729 break;
730 case low_latency:
731 new_itr = 20000; /* aka hwitr = ~200 */
732 break;
733 case bulk_latency:
734 new_itr = 4000;
735 break;
736 default:
737 break;
738 }
739
740 if (new_itr != adapter->itr) {
741 /*
742 * this attempts to bias the interrupt rate towards Bulk
743 * by adding intermediate steps when interrupt rate is
744 * increasing
745 */
746 new_itr = new_itr > adapter->itr ?
747 min(adapter->itr + (new_itr >> 2), new_itr) :
748 new_itr;
749 adapter->itr = new_itr;
750 adapter->rx_ring->itr_val = 1952;
751
752 if (adapter->msix_entries)
753 adapter->rx_ring->set_itr = 1;
754 else
755 ew32(ITR, 1952);
756 }
757}
758
759/**
760 * igbvf_clean_tx_irq - Reclaim resources after transmit completes
761 * @adapter: board private structure
762 * returns true if ring is completely cleaned
763 **/
764static bool igbvf_clean_tx_irq(struct igbvf_ring *tx_ring)
765{
766 struct igbvf_adapter *adapter = tx_ring->adapter;
767 struct e1000_hw *hw = &adapter->hw;
768 struct net_device *netdev = adapter->netdev;
769 struct igbvf_buffer *buffer_info;
770 struct sk_buff *skb;
771 union e1000_adv_tx_desc *tx_desc, *eop_desc;
772 unsigned int total_bytes = 0, total_packets = 0;
773 unsigned int i, eop, count = 0;
774 bool cleaned = false;
775
776 i = tx_ring->next_to_clean;
777 eop = tx_ring->buffer_info[i].next_to_watch;
778 eop_desc = IGBVF_TX_DESC_ADV(*tx_ring, eop);
779
780 while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
781 (count < tx_ring->count)) {
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000782 rmb(); /* read buffer_info after eop_desc status */
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000783 for (cleaned = false; !cleaned; count++) {
784 tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i);
785 buffer_info = &tx_ring->buffer_info[i];
786 cleaned = (i == eop);
787 skb = buffer_info->skb;
788
789 if (skb) {
790 unsigned int segs, bytecount;
791
792 /* gso_segs is currently only valid for tcp */
793 segs = skb_shinfo(skb)->gso_segs ?: 1;
794 /* multiply data chunks by size of headers */
795 bytecount = ((segs - 1) * skb_headlen(skb)) +
796 skb->len;
797 total_packets += segs;
798 total_bytes += bytecount;
799 }
800
801 igbvf_put_txbuf(adapter, buffer_info);
802 tx_desc->wb.status = 0;
803
804 i++;
805 if (i == tx_ring->count)
806 i = 0;
807 }
808 eop = tx_ring->buffer_info[i].next_to_watch;
809 eop_desc = IGBVF_TX_DESC_ADV(*tx_ring, eop);
810 }
811
812 tx_ring->next_to_clean = i;
813
814 if (unlikely(count &&
815 netif_carrier_ok(netdev) &&
816 igbvf_desc_unused(tx_ring) >= IGBVF_TX_QUEUE_WAKE)) {
817 /* Make sure that anybody stopping the queue after this
818 * sees the new next_to_clean.
819 */
820 smp_mb();
821 if (netif_queue_stopped(netdev) &&
822 !(test_bit(__IGBVF_DOWN, &adapter->state))) {
823 netif_wake_queue(netdev);
824 ++adapter->restart_queue;
825 }
826 }
827
828 if (adapter->detect_tx_hung) {
829 /* Detect a transmit hang in hardware, this serializes the
830 * check with the clearing of time_stamp and movement of i */
831 adapter->detect_tx_hung = false;
832 if (tx_ring->buffer_info[i].time_stamp &&
833 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
Joe Perches8e95a202009-12-03 07:58:21 +0000834 (adapter->tx_timeout_factor * HZ)) &&
835 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000836
837 tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i);
838 /* detected Tx unit hang */
839 igbvf_print_tx_hang(adapter);
840
841 netif_stop_queue(netdev);
842 }
843 }
844 adapter->net_stats.tx_bytes += total_bytes;
845 adapter->net_stats.tx_packets += total_packets;
Eric Dumazet807540b2010-09-23 05:40:09 +0000846 return count < tx_ring->count;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000847}
848
849static irqreturn_t igbvf_msix_other(int irq, void *data)
850{
851 struct net_device *netdev = data;
852 struct igbvf_adapter *adapter = netdev_priv(netdev);
853 struct e1000_hw *hw = &adapter->hw;
854
855 adapter->int_counter1++;
856
857 netif_carrier_off(netdev);
858 hw->mac.get_link_status = 1;
859 if (!test_bit(__IGBVF_DOWN, &adapter->state))
860 mod_timer(&adapter->watchdog_timer, jiffies + 1);
861
862 ew32(EIMS, adapter->eims_other);
863
864 return IRQ_HANDLED;
865}
866
867static irqreturn_t igbvf_intr_msix_tx(int irq, void *data)
868{
869 struct net_device *netdev = data;
870 struct igbvf_adapter *adapter = netdev_priv(netdev);
871 struct e1000_hw *hw = &adapter->hw;
872 struct igbvf_ring *tx_ring = adapter->tx_ring;
873
874
875 adapter->total_tx_bytes = 0;
876 adapter->total_tx_packets = 0;
877
878 /* auto mask will automatically reenable the interrupt when we write
879 * EICS */
880 if (!igbvf_clean_tx_irq(tx_ring))
881 /* Ring was not completely cleaned, so fire another interrupt */
882 ew32(EICS, tx_ring->eims_value);
883 else
884 ew32(EIMS, tx_ring->eims_value);
885
886 return IRQ_HANDLED;
887}
888
889static irqreturn_t igbvf_intr_msix_rx(int irq, void *data)
890{
891 struct net_device *netdev = data;
892 struct igbvf_adapter *adapter = netdev_priv(netdev);
893
894 adapter->int_counter0++;
895
896 /* Write the ITR value calculated at the end of the
897 * previous interrupt.
898 */
899 if (adapter->rx_ring->set_itr) {
900 writel(adapter->rx_ring->itr_val,
901 adapter->hw.hw_addr + adapter->rx_ring->itr_register);
902 adapter->rx_ring->set_itr = 0;
903 }
904
905 if (napi_schedule_prep(&adapter->rx_ring->napi)) {
906 adapter->total_rx_bytes = 0;
907 adapter->total_rx_packets = 0;
908 __napi_schedule(&adapter->rx_ring->napi);
909 }
910
911 return IRQ_HANDLED;
912}
913
914#define IGBVF_NO_QUEUE -1
915
916static void igbvf_assign_vector(struct igbvf_adapter *adapter, int rx_queue,
917 int tx_queue, int msix_vector)
918{
919 struct e1000_hw *hw = &adapter->hw;
920 u32 ivar, index;
921
922 /* 82576 uses a table-based method for assigning vectors.
923 Each queue has a single entry in the table to which we write
924 a vector number along with a "valid" bit. Sadly, the layout
925 of the table is somewhat counterintuitive. */
926 if (rx_queue > IGBVF_NO_QUEUE) {
927 index = (rx_queue >> 1);
928 ivar = array_er32(IVAR0, index);
929 if (rx_queue & 0x1) {
930 /* vector goes into third byte of register */
931 ivar = ivar & 0xFF00FFFF;
932 ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
933 } else {
934 /* vector goes into low byte of register */
935 ivar = ivar & 0xFFFFFF00;
936 ivar |= msix_vector | E1000_IVAR_VALID;
937 }
938 adapter->rx_ring[rx_queue].eims_value = 1 << msix_vector;
939 array_ew32(IVAR0, index, ivar);
940 }
941 if (tx_queue > IGBVF_NO_QUEUE) {
942 index = (tx_queue >> 1);
943 ivar = array_er32(IVAR0, index);
944 if (tx_queue & 0x1) {
945 /* vector goes into high byte of register */
946 ivar = ivar & 0x00FFFFFF;
947 ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
948 } else {
949 /* vector goes into second byte of register */
950 ivar = ivar & 0xFFFF00FF;
951 ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
952 }
953 adapter->tx_ring[tx_queue].eims_value = 1 << msix_vector;
954 array_ew32(IVAR0, index, ivar);
955 }
956}
957
958/**
959 * igbvf_configure_msix - Configure MSI-X hardware
960 *
961 * igbvf_configure_msix sets up the hardware to properly
962 * generate MSI-X interrupts.
963 **/
964static void igbvf_configure_msix(struct igbvf_adapter *adapter)
965{
966 u32 tmp;
967 struct e1000_hw *hw = &adapter->hw;
968 struct igbvf_ring *tx_ring = adapter->tx_ring;
969 struct igbvf_ring *rx_ring = adapter->rx_ring;
970 int vector = 0;
971
972 adapter->eims_enable_mask = 0;
973
974 igbvf_assign_vector(adapter, IGBVF_NO_QUEUE, 0, vector++);
975 adapter->eims_enable_mask |= tx_ring->eims_value;
976 if (tx_ring->itr_val)
977 writel(tx_ring->itr_val,
978 hw->hw_addr + tx_ring->itr_register);
979 else
980 writel(1952, hw->hw_addr + tx_ring->itr_register);
981
982 igbvf_assign_vector(adapter, 0, IGBVF_NO_QUEUE, vector++);
983 adapter->eims_enable_mask |= rx_ring->eims_value;
984 if (rx_ring->itr_val)
985 writel(rx_ring->itr_val,
986 hw->hw_addr + rx_ring->itr_register);
987 else
988 writel(1952, hw->hw_addr + rx_ring->itr_register);
989
990 /* set vector for other causes, i.e. link changes */
991
992 tmp = (vector++ | E1000_IVAR_VALID);
993
994 ew32(IVAR_MISC, tmp);
995
996 adapter->eims_enable_mask = (1 << (vector)) - 1;
997 adapter->eims_other = 1 << (vector - 1);
998 e1e_flush();
999}
1000
Alexander Duyck2d165772009-04-09 22:49:20 +00001001static void igbvf_reset_interrupt_capability(struct igbvf_adapter *adapter)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001002{
1003 if (adapter->msix_entries) {
1004 pci_disable_msix(adapter->pdev);
1005 kfree(adapter->msix_entries);
1006 adapter->msix_entries = NULL;
1007 }
1008}
1009
1010/**
1011 * igbvf_set_interrupt_capability - set MSI or MSI-X if supported
1012 *
1013 * Attempt to configure interrupts using the best available
1014 * capabilities of the hardware and kernel.
1015 **/
Alexander Duyck2d165772009-04-09 22:49:20 +00001016static void igbvf_set_interrupt_capability(struct igbvf_adapter *adapter)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001017{
1018 int err = -ENOMEM;
1019 int i;
1020
1021 /* we allocate 3 vectors, 1 for tx, 1 for rx, one for pf messages */
1022 adapter->msix_entries = kcalloc(3, sizeof(struct msix_entry),
1023 GFP_KERNEL);
1024 if (adapter->msix_entries) {
1025 for (i = 0; i < 3; i++)
1026 adapter->msix_entries[i].entry = i;
1027
1028 err = pci_enable_msix(adapter->pdev,
1029 adapter->msix_entries, 3);
1030 }
1031
1032 if (err) {
1033 /* MSI-X failed */
1034 dev_err(&adapter->pdev->dev,
1035 "Failed to initialize MSI-X interrupts.\n");
1036 igbvf_reset_interrupt_capability(adapter);
1037 }
1038}
1039
1040/**
1041 * igbvf_request_msix - Initialize MSI-X interrupts
1042 *
1043 * igbvf_request_msix allocates MSI-X vectors and requests interrupts from the
1044 * kernel.
1045 **/
1046static int igbvf_request_msix(struct igbvf_adapter *adapter)
1047{
1048 struct net_device *netdev = adapter->netdev;
1049 int err = 0, vector = 0;
1050
1051 if (strlen(netdev->name) < (IFNAMSIZ - 5)) {
1052 sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name);
1053 sprintf(adapter->rx_ring->name, "%s-rx-0", netdev->name);
1054 } else {
1055 memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
1056 memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
1057 }
1058
1059 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001060 igbvf_intr_msix_tx, 0, adapter->tx_ring->name,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001061 netdev);
1062 if (err)
1063 goto out;
1064
1065 adapter->tx_ring->itr_register = E1000_EITR(vector);
1066 adapter->tx_ring->itr_val = 1952;
1067 vector++;
1068
1069 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001070 igbvf_intr_msix_rx, 0, adapter->rx_ring->name,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001071 netdev);
1072 if (err)
1073 goto out;
1074
1075 adapter->rx_ring->itr_register = E1000_EITR(vector);
1076 adapter->rx_ring->itr_val = 1952;
1077 vector++;
1078
1079 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001080 igbvf_msix_other, 0, netdev->name, netdev);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001081 if (err)
1082 goto out;
1083
1084 igbvf_configure_msix(adapter);
1085 return 0;
1086out:
1087 return err;
1088}
1089
1090/**
1091 * igbvf_alloc_queues - Allocate memory for all rings
1092 * @adapter: board private structure to initialize
1093 **/
1094static int __devinit igbvf_alloc_queues(struct igbvf_adapter *adapter)
1095{
1096 struct net_device *netdev = adapter->netdev;
1097
1098 adapter->tx_ring = kzalloc(sizeof(struct igbvf_ring), GFP_KERNEL);
1099 if (!adapter->tx_ring)
1100 return -ENOMEM;
1101
1102 adapter->rx_ring = kzalloc(sizeof(struct igbvf_ring), GFP_KERNEL);
1103 if (!adapter->rx_ring) {
1104 kfree(adapter->tx_ring);
1105 return -ENOMEM;
1106 }
1107
1108 netif_napi_add(netdev, &adapter->rx_ring->napi, igbvf_poll, 64);
1109
1110 return 0;
1111}
1112
1113/**
1114 * igbvf_request_irq - initialize interrupts
1115 *
1116 * Attempts to configure interrupts using the best available
1117 * capabilities of the hardware and kernel.
1118 **/
1119static int igbvf_request_irq(struct igbvf_adapter *adapter)
1120{
1121 int err = -1;
1122
1123 /* igbvf supports msi-x only */
1124 if (adapter->msix_entries)
1125 err = igbvf_request_msix(adapter);
1126
1127 if (!err)
1128 return err;
1129
1130 dev_err(&adapter->pdev->dev,
1131 "Unable to allocate interrupt, Error: %d\n", err);
1132
1133 return err;
1134}
1135
1136static void igbvf_free_irq(struct igbvf_adapter *adapter)
1137{
1138 struct net_device *netdev = adapter->netdev;
1139 int vector;
1140
1141 if (adapter->msix_entries) {
1142 for (vector = 0; vector < 3; vector++)
1143 free_irq(adapter->msix_entries[vector].vector, netdev);
1144 }
1145}
1146
1147/**
1148 * igbvf_irq_disable - Mask off interrupt generation on the NIC
1149 **/
1150static void igbvf_irq_disable(struct igbvf_adapter *adapter)
1151{
1152 struct e1000_hw *hw = &adapter->hw;
1153
1154 ew32(EIMC, ~0);
1155
1156 if (adapter->msix_entries)
1157 ew32(EIAC, 0);
1158}
1159
1160/**
1161 * igbvf_irq_enable - Enable default interrupt generation settings
1162 **/
1163static void igbvf_irq_enable(struct igbvf_adapter *adapter)
1164{
1165 struct e1000_hw *hw = &adapter->hw;
1166
1167 ew32(EIAC, adapter->eims_enable_mask);
1168 ew32(EIAM, adapter->eims_enable_mask);
1169 ew32(EIMS, adapter->eims_enable_mask);
1170}
1171
1172/**
1173 * igbvf_poll - NAPI Rx polling callback
1174 * @napi: struct associated with this polling callback
1175 * @budget: amount of packets driver is allowed to process this poll
1176 **/
1177static int igbvf_poll(struct napi_struct *napi, int budget)
1178{
1179 struct igbvf_ring *rx_ring = container_of(napi, struct igbvf_ring, napi);
1180 struct igbvf_adapter *adapter = rx_ring->adapter;
1181 struct e1000_hw *hw = &adapter->hw;
1182 int work_done = 0;
1183
1184 igbvf_clean_rx_irq(adapter, &work_done, budget);
1185
1186 /* If not enough Rx work done, exit the polling mode */
1187 if (work_done < budget) {
1188 napi_complete(napi);
1189
1190 if (adapter->itr_setting & 3)
1191 igbvf_set_itr(adapter);
1192
1193 if (!test_bit(__IGBVF_DOWN, &adapter->state))
1194 ew32(EIMS, adapter->rx_ring->eims_value);
1195 }
1196
1197 return work_done;
1198}
1199
1200/**
1201 * igbvf_set_rlpml - set receive large packet maximum length
1202 * @adapter: board private structure
1203 *
1204 * Configure the maximum size of packets that will be received
1205 */
1206static void igbvf_set_rlpml(struct igbvf_adapter *adapter)
1207{
1208 int max_frame_size = adapter->max_frame_size;
1209 struct e1000_hw *hw = &adapter->hw;
1210
1211 if (adapter->vlgrp)
1212 max_frame_size += VLAN_TAG_SIZE;
1213
1214 e1000_rlpml_set_vf(hw, max_frame_size);
1215}
1216
1217static void igbvf_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1218{
1219 struct igbvf_adapter *adapter = netdev_priv(netdev);
1220 struct e1000_hw *hw = &adapter->hw;
1221
1222 if (hw->mac.ops.set_vfta(hw, vid, true))
1223 dev_err(&adapter->pdev->dev, "Failed to add vlan id %d\n", vid);
1224}
1225
1226static void igbvf_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1227{
1228 struct igbvf_adapter *adapter = netdev_priv(netdev);
1229 struct e1000_hw *hw = &adapter->hw;
1230
1231 igbvf_irq_disable(adapter);
1232 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1233
1234 if (!test_bit(__IGBVF_DOWN, &adapter->state))
1235 igbvf_irq_enable(adapter);
1236
1237 if (hw->mac.ops.set_vfta(hw, vid, false))
1238 dev_err(&adapter->pdev->dev,
1239 "Failed to remove vlan id %d\n", vid);
1240}
1241
1242static void igbvf_vlan_rx_register(struct net_device *netdev,
1243 struct vlan_group *grp)
1244{
1245 struct igbvf_adapter *adapter = netdev_priv(netdev);
1246
1247 adapter->vlgrp = grp;
1248}
1249
1250static void igbvf_restore_vlan(struct igbvf_adapter *adapter)
1251{
1252 u16 vid;
1253
1254 if (!adapter->vlgrp)
1255 return;
1256
Jesse Grossb7381272010-10-20 13:56:02 +00001257 for (vid = 0; vid < VLAN_N_VID; vid++) {
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001258 if (!vlan_group_get_device(adapter->vlgrp, vid))
1259 continue;
1260 igbvf_vlan_rx_add_vid(adapter->netdev, vid);
1261 }
1262
1263 igbvf_set_rlpml(adapter);
1264}
1265
1266/**
1267 * igbvf_configure_tx - Configure Transmit Unit after Reset
1268 * @adapter: board private structure
1269 *
1270 * Configure the Tx unit of the MAC after a reset.
1271 **/
1272static void igbvf_configure_tx(struct igbvf_adapter *adapter)
1273{
1274 struct e1000_hw *hw = &adapter->hw;
1275 struct igbvf_ring *tx_ring = adapter->tx_ring;
1276 u64 tdba;
1277 u32 txdctl, dca_txctrl;
1278
1279 /* disable transmits */
1280 txdctl = er32(TXDCTL(0));
1281 ew32(TXDCTL(0), txdctl & ~E1000_TXDCTL_QUEUE_ENABLE);
1282 msleep(10);
1283
1284 /* Setup the HW Tx Head and Tail descriptor pointers */
1285 ew32(TDLEN(0), tx_ring->count * sizeof(union e1000_adv_tx_desc));
1286 tdba = tx_ring->dma;
Andrew Morton8e20ce92009-06-18 16:49:17 -07001287 ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001288 ew32(TDBAH(0), (tdba >> 32));
1289 ew32(TDH(0), 0);
1290 ew32(TDT(0), 0);
1291 tx_ring->head = E1000_TDH(0);
1292 tx_ring->tail = E1000_TDT(0);
1293
1294 /* Turn off Relaxed Ordering on head write-backs. The writebacks
1295 * MUST be delivered in order or it will completely screw up
1296 * our bookeeping.
1297 */
1298 dca_txctrl = er32(DCA_TXCTRL(0));
1299 dca_txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN;
1300 ew32(DCA_TXCTRL(0), dca_txctrl);
1301
1302 /* enable transmits */
1303 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
1304 ew32(TXDCTL(0), txdctl);
1305
1306 /* Setup Transmit Descriptor Settings for eop descriptor */
1307 adapter->txd_cmd = E1000_ADVTXD_DCMD_EOP | E1000_ADVTXD_DCMD_IFCS;
1308
1309 /* enable Report Status bit */
1310 adapter->txd_cmd |= E1000_ADVTXD_DCMD_RS;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001311}
1312
1313/**
1314 * igbvf_setup_srrctl - configure the receive control registers
1315 * @adapter: Board private structure
1316 **/
1317static void igbvf_setup_srrctl(struct igbvf_adapter *adapter)
1318{
1319 struct e1000_hw *hw = &adapter->hw;
1320 u32 srrctl = 0;
1321
1322 srrctl &= ~(E1000_SRRCTL_DESCTYPE_MASK |
1323 E1000_SRRCTL_BSIZEHDR_MASK |
1324 E1000_SRRCTL_BSIZEPKT_MASK);
1325
1326 /* Enable queue drop to avoid head of line blocking */
1327 srrctl |= E1000_SRRCTL_DROP_EN;
1328
1329 /* Setup buffer sizes */
1330 srrctl |= ALIGN(adapter->rx_buffer_len, 1024) >>
1331 E1000_SRRCTL_BSIZEPKT_SHIFT;
1332
1333 if (adapter->rx_buffer_len < 2048) {
1334 adapter->rx_ps_hdr_size = 0;
1335 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
1336 } else {
1337 adapter->rx_ps_hdr_size = 128;
1338 srrctl |= adapter->rx_ps_hdr_size <<
1339 E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
1340 srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1341 }
1342
1343 ew32(SRRCTL(0), srrctl);
1344}
1345
1346/**
1347 * igbvf_configure_rx - Configure Receive Unit after Reset
1348 * @adapter: board private structure
1349 *
1350 * Configure the Rx unit of the MAC after a reset.
1351 **/
1352static void igbvf_configure_rx(struct igbvf_adapter *adapter)
1353{
1354 struct e1000_hw *hw = &adapter->hw;
1355 struct igbvf_ring *rx_ring = adapter->rx_ring;
1356 u64 rdba;
1357 u32 rdlen, rxdctl;
1358
1359 /* disable receives */
1360 rxdctl = er32(RXDCTL(0));
1361 ew32(RXDCTL(0), rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE);
1362 msleep(10);
1363
1364 rdlen = rx_ring->count * sizeof(union e1000_adv_rx_desc);
1365
1366 /*
1367 * Setup the HW Rx Head and Tail Descriptor Pointers and
1368 * the Base and Length of the Rx Descriptor Ring
1369 */
1370 rdba = rx_ring->dma;
Andrew Morton8e20ce92009-06-18 16:49:17 -07001371 ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001372 ew32(RDBAH(0), (rdba >> 32));
1373 ew32(RDLEN(0), rx_ring->count * sizeof(union e1000_adv_rx_desc));
1374 rx_ring->head = E1000_RDH(0);
1375 rx_ring->tail = E1000_RDT(0);
1376 ew32(RDH(0), 0);
1377 ew32(RDT(0), 0);
1378
1379 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
1380 rxdctl &= 0xFFF00000;
1381 rxdctl |= IGBVF_RX_PTHRESH;
1382 rxdctl |= IGBVF_RX_HTHRESH << 8;
1383 rxdctl |= IGBVF_RX_WTHRESH << 16;
1384
1385 igbvf_set_rlpml(adapter);
1386
1387 /* enable receives */
1388 ew32(RXDCTL(0), rxdctl);
1389}
1390
1391/**
1392 * igbvf_set_multi - Multicast and Promiscuous mode set
1393 * @netdev: network interface device structure
1394 *
1395 * The set_multi entry point is called whenever the multicast address
1396 * list or the network interface flags are updated. This routine is
1397 * responsible for configuring the hardware for proper multicast,
1398 * promiscuous mode, and all-multi behavior.
1399 **/
1400static void igbvf_set_multi(struct net_device *netdev)
1401{
1402 struct igbvf_adapter *adapter = netdev_priv(netdev);
1403 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001404 struct netdev_hw_addr *ha;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001405 u8 *mta_list = NULL;
1406 int i;
1407
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001408 if (!netdev_mc_empty(netdev)) {
1409 mta_list = kmalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001410 if (!mta_list) {
1411 dev_err(&adapter->pdev->dev,
1412 "failed to allocate multicast filter list\n");
1413 return;
1414 }
1415 }
1416
1417 /* prepare a packed array of only addresses. */
Jiri Pirko48e2f182010-02-22 09:22:26 +00001418 i = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001419 netdev_for_each_mc_addr(ha, netdev)
1420 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001421
1422 hw->mac.ops.update_mc_addr_list(hw, mta_list, i, 0, 0);
1423 kfree(mta_list);
1424}
1425
1426/**
1427 * igbvf_configure - configure the hardware for Rx and Tx
1428 * @adapter: private board structure
1429 **/
1430static void igbvf_configure(struct igbvf_adapter *adapter)
1431{
1432 igbvf_set_multi(adapter->netdev);
1433
1434 igbvf_restore_vlan(adapter);
1435
1436 igbvf_configure_tx(adapter);
1437 igbvf_setup_srrctl(adapter);
1438 igbvf_configure_rx(adapter);
1439 igbvf_alloc_rx_buffers(adapter->rx_ring,
1440 igbvf_desc_unused(adapter->rx_ring));
1441}
1442
1443/* igbvf_reset - bring the hardware into a known good state
1444 *
1445 * This function boots the hardware and enables some settings that
1446 * require a configuration cycle of the hardware - those cannot be
1447 * set/changed during runtime. After reset the device needs to be
1448 * properly configured for Rx, Tx etc.
1449 */
Alexander Duyck2d165772009-04-09 22:49:20 +00001450static void igbvf_reset(struct igbvf_adapter *adapter)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001451{
1452 struct e1000_mac_info *mac = &adapter->hw.mac;
1453 struct net_device *netdev = adapter->netdev;
1454 struct e1000_hw *hw = &adapter->hw;
1455
1456 /* Allow time for pending master requests to run */
1457 if (mac->ops.reset_hw(hw))
1458 dev_err(&adapter->pdev->dev, "PF still resetting\n");
1459
1460 mac->ops.init_hw(hw);
1461
1462 if (is_valid_ether_addr(adapter->hw.mac.addr)) {
1463 memcpy(netdev->dev_addr, adapter->hw.mac.addr,
1464 netdev->addr_len);
1465 memcpy(netdev->perm_addr, adapter->hw.mac.addr,
1466 netdev->addr_len);
1467 }
Alexander Duyck72279092009-12-11 22:58:14 -08001468
1469 adapter->last_reset = jiffies;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001470}
1471
1472int igbvf_up(struct igbvf_adapter *adapter)
1473{
1474 struct e1000_hw *hw = &adapter->hw;
1475
1476 /* hardware has been reset, we need to reload some things */
1477 igbvf_configure(adapter);
1478
1479 clear_bit(__IGBVF_DOWN, &adapter->state);
1480
1481 napi_enable(&adapter->rx_ring->napi);
1482 if (adapter->msix_entries)
1483 igbvf_configure_msix(adapter);
1484
1485 /* Clear any pending interrupts. */
1486 er32(EICR);
1487 igbvf_irq_enable(adapter);
1488
1489 /* start the watchdog */
1490 hw->mac.get_link_status = 1;
1491 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1492
1493
1494 return 0;
1495}
1496
1497void igbvf_down(struct igbvf_adapter *adapter)
1498{
1499 struct net_device *netdev = adapter->netdev;
1500 struct e1000_hw *hw = &adapter->hw;
1501 u32 rxdctl, txdctl;
1502
1503 /*
1504 * signal that we're down so the interrupt handler does not
1505 * reschedule our watchdog timer
1506 */
1507 set_bit(__IGBVF_DOWN, &adapter->state);
1508
1509 /* disable receives in the hardware */
1510 rxdctl = er32(RXDCTL(0));
1511 ew32(RXDCTL(0), rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE);
1512
1513 netif_stop_queue(netdev);
1514
1515 /* disable transmits in the hardware */
1516 txdctl = er32(TXDCTL(0));
1517 ew32(TXDCTL(0), txdctl & ~E1000_TXDCTL_QUEUE_ENABLE);
1518
1519 /* flush both disables and wait for them to finish */
1520 e1e_flush();
1521 msleep(10);
1522
1523 napi_disable(&adapter->rx_ring->napi);
1524
1525 igbvf_irq_disable(adapter);
1526
1527 del_timer_sync(&adapter->watchdog_timer);
1528
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001529 netif_carrier_off(netdev);
1530
1531 /* record the stats before reset*/
1532 igbvf_update_stats(adapter);
1533
1534 adapter->link_speed = 0;
1535 adapter->link_duplex = 0;
1536
1537 igbvf_reset(adapter);
1538 igbvf_clean_tx_ring(adapter->tx_ring);
1539 igbvf_clean_rx_ring(adapter->rx_ring);
1540}
1541
1542void igbvf_reinit_locked(struct igbvf_adapter *adapter)
1543{
1544 might_sleep();
1545 while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state))
1546 msleep(1);
1547 igbvf_down(adapter);
1548 igbvf_up(adapter);
1549 clear_bit(__IGBVF_RESETTING, &adapter->state);
1550}
1551
1552/**
1553 * igbvf_sw_init - Initialize general software structures (struct igbvf_adapter)
1554 * @adapter: board private structure to initialize
1555 *
1556 * igbvf_sw_init initializes the Adapter private data structure.
1557 * Fields are initialized based on PCI device information and
1558 * OS network device settings (MTU size).
1559 **/
1560static int __devinit igbvf_sw_init(struct igbvf_adapter *adapter)
1561{
1562 struct net_device *netdev = adapter->netdev;
1563 s32 rc;
1564
1565 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN;
1566 adapter->rx_ps_hdr_size = 0;
1567 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1568 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
1569
1570 adapter->tx_int_delay = 8;
1571 adapter->tx_abs_int_delay = 32;
1572 adapter->rx_int_delay = 0;
1573 adapter->rx_abs_int_delay = 8;
1574 adapter->itr_setting = 3;
1575 adapter->itr = 20000;
1576
1577 /* Set various function pointers */
1578 adapter->ei->init_ops(&adapter->hw);
1579
1580 rc = adapter->hw.mac.ops.init_params(&adapter->hw);
1581 if (rc)
1582 return rc;
1583
1584 rc = adapter->hw.mbx.ops.init_params(&adapter->hw);
1585 if (rc)
1586 return rc;
1587
1588 igbvf_set_interrupt_capability(adapter);
1589
1590 if (igbvf_alloc_queues(adapter))
1591 return -ENOMEM;
1592
1593 spin_lock_init(&adapter->tx_queue_lock);
1594
1595 /* Explicitly disable IRQ since the NIC can be in any state. */
1596 igbvf_irq_disable(adapter);
1597
1598 spin_lock_init(&adapter->stats_lock);
1599
1600 set_bit(__IGBVF_DOWN, &adapter->state);
1601 return 0;
1602}
1603
1604static void igbvf_initialize_last_counter_stats(struct igbvf_adapter *adapter)
1605{
1606 struct e1000_hw *hw = &adapter->hw;
1607
1608 adapter->stats.last_gprc = er32(VFGPRC);
1609 adapter->stats.last_gorc = er32(VFGORC);
1610 adapter->stats.last_gptc = er32(VFGPTC);
1611 adapter->stats.last_gotc = er32(VFGOTC);
1612 adapter->stats.last_mprc = er32(VFMPRC);
1613 adapter->stats.last_gotlbc = er32(VFGOTLBC);
1614 adapter->stats.last_gptlbc = er32(VFGPTLBC);
1615 adapter->stats.last_gorlbc = er32(VFGORLBC);
1616 adapter->stats.last_gprlbc = er32(VFGPRLBC);
1617
1618 adapter->stats.base_gprc = er32(VFGPRC);
1619 adapter->stats.base_gorc = er32(VFGORC);
1620 adapter->stats.base_gptc = er32(VFGPTC);
1621 adapter->stats.base_gotc = er32(VFGOTC);
1622 adapter->stats.base_mprc = er32(VFMPRC);
1623 adapter->stats.base_gotlbc = er32(VFGOTLBC);
1624 adapter->stats.base_gptlbc = er32(VFGPTLBC);
1625 adapter->stats.base_gorlbc = er32(VFGORLBC);
1626 adapter->stats.base_gprlbc = er32(VFGPRLBC);
1627}
1628
1629/**
1630 * igbvf_open - Called when a network interface is made active
1631 * @netdev: network interface device structure
1632 *
1633 * Returns 0 on success, negative value on failure
1634 *
1635 * The open entry point is called when a network interface is made
1636 * active by the system (IFF_UP). At this point all resources needed
1637 * for transmit and receive operations are allocated, the interrupt
1638 * handler is registered with the OS, the watchdog timer is started,
1639 * and the stack is notified that the interface is ready.
1640 **/
1641static int igbvf_open(struct net_device *netdev)
1642{
1643 struct igbvf_adapter *adapter = netdev_priv(netdev);
1644 struct e1000_hw *hw = &adapter->hw;
1645 int err;
1646
1647 /* disallow open during test */
1648 if (test_bit(__IGBVF_TESTING, &adapter->state))
1649 return -EBUSY;
1650
1651 /* allocate transmit descriptors */
1652 err = igbvf_setup_tx_resources(adapter, adapter->tx_ring);
1653 if (err)
1654 goto err_setup_tx;
1655
1656 /* allocate receive descriptors */
1657 err = igbvf_setup_rx_resources(adapter, adapter->rx_ring);
1658 if (err)
1659 goto err_setup_rx;
1660
1661 /*
1662 * before we allocate an interrupt, we must be ready to handle it.
1663 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1664 * as soon as we call pci_request_irq, so we have to setup our
1665 * clean_rx handler before we do so.
1666 */
1667 igbvf_configure(adapter);
1668
1669 err = igbvf_request_irq(adapter);
1670 if (err)
1671 goto err_req_irq;
1672
1673 /* From here on the code is the same as igbvf_up() */
1674 clear_bit(__IGBVF_DOWN, &adapter->state);
1675
1676 napi_enable(&adapter->rx_ring->napi);
1677
1678 /* clear any pending interrupts */
1679 er32(EICR);
1680
1681 igbvf_irq_enable(adapter);
1682
1683 /* start the watchdog */
1684 hw->mac.get_link_status = 1;
1685 mod_timer(&adapter->watchdog_timer, jiffies + 1);
1686
1687 return 0;
1688
1689err_req_irq:
1690 igbvf_free_rx_resources(adapter->rx_ring);
1691err_setup_rx:
1692 igbvf_free_tx_resources(adapter->tx_ring);
1693err_setup_tx:
1694 igbvf_reset(adapter);
1695
1696 return err;
1697}
1698
1699/**
1700 * igbvf_close - Disables a network interface
1701 * @netdev: network interface device structure
1702 *
1703 * Returns 0, this is not allowed to fail
1704 *
1705 * The close entry point is called when an interface is de-activated
1706 * by the OS. The hardware is still under the drivers control, but
1707 * needs to be disabled. A global MAC reset is issued to stop the
1708 * hardware, and all transmit and receive resources are freed.
1709 **/
1710static int igbvf_close(struct net_device *netdev)
1711{
1712 struct igbvf_adapter *adapter = netdev_priv(netdev);
1713
1714 WARN_ON(test_bit(__IGBVF_RESETTING, &adapter->state));
1715 igbvf_down(adapter);
1716
1717 igbvf_free_irq(adapter);
1718
1719 igbvf_free_tx_resources(adapter->tx_ring);
1720 igbvf_free_rx_resources(adapter->rx_ring);
1721
1722 return 0;
1723}
1724/**
1725 * igbvf_set_mac - Change the Ethernet Address of the NIC
1726 * @netdev: network interface device structure
1727 * @p: pointer to an address structure
1728 *
1729 * Returns 0 on success, negative on failure
1730 **/
1731static int igbvf_set_mac(struct net_device *netdev, void *p)
1732{
1733 struct igbvf_adapter *adapter = netdev_priv(netdev);
1734 struct e1000_hw *hw = &adapter->hw;
1735 struct sockaddr *addr = p;
1736
1737 if (!is_valid_ether_addr(addr->sa_data))
1738 return -EADDRNOTAVAIL;
1739
1740 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
1741
1742 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
1743
1744 if (memcmp(addr->sa_data, hw->mac.addr, 6))
1745 return -EADDRNOTAVAIL;
1746
1747 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1748
1749 return 0;
1750}
1751
1752#define UPDATE_VF_COUNTER(reg, name) \
1753 { \
1754 u32 current_counter = er32(reg); \
1755 if (current_counter < adapter->stats.last_##name) \
1756 adapter->stats.name += 0x100000000LL; \
1757 adapter->stats.last_##name = current_counter; \
1758 adapter->stats.name &= 0xFFFFFFFF00000000LL; \
1759 adapter->stats.name |= current_counter; \
1760 }
1761
1762/**
1763 * igbvf_update_stats - Update the board statistics counters
1764 * @adapter: board private structure
1765**/
1766void igbvf_update_stats(struct igbvf_adapter *adapter)
1767{
1768 struct e1000_hw *hw = &adapter->hw;
1769 struct pci_dev *pdev = adapter->pdev;
1770
1771 /*
1772 * Prevent stats update while adapter is being reset, link is down
1773 * or if the pci connection is down.
1774 */
1775 if (adapter->link_speed == 0)
1776 return;
1777
1778 if (test_bit(__IGBVF_RESETTING, &adapter->state))
1779 return;
1780
1781 if (pci_channel_offline(pdev))
1782 return;
1783
1784 UPDATE_VF_COUNTER(VFGPRC, gprc);
1785 UPDATE_VF_COUNTER(VFGORC, gorc);
1786 UPDATE_VF_COUNTER(VFGPTC, gptc);
1787 UPDATE_VF_COUNTER(VFGOTC, gotc);
1788 UPDATE_VF_COUNTER(VFMPRC, mprc);
1789 UPDATE_VF_COUNTER(VFGOTLBC, gotlbc);
1790 UPDATE_VF_COUNTER(VFGPTLBC, gptlbc);
1791 UPDATE_VF_COUNTER(VFGORLBC, gorlbc);
1792 UPDATE_VF_COUNTER(VFGPRLBC, gprlbc);
1793
1794 /* Fill out the OS statistics structure */
1795 adapter->net_stats.multicast = adapter->stats.mprc;
1796}
1797
1798static void igbvf_print_link_info(struct igbvf_adapter *adapter)
1799{
1800 dev_info(&adapter->pdev->dev, "Link is Up %d Mbps %s\n",
1801 adapter->link_speed,
1802 ((adapter->link_duplex == FULL_DUPLEX) ?
1803 "Full Duplex" : "Half Duplex"));
1804}
1805
1806static bool igbvf_has_link(struct igbvf_adapter *adapter)
1807{
1808 struct e1000_hw *hw = &adapter->hw;
1809 s32 ret_val = E1000_SUCCESS;
1810 bool link_active;
1811
Alexander Duyck72279092009-12-11 22:58:14 -08001812 /* If interface is down, stay link down */
1813 if (test_bit(__IGBVF_DOWN, &adapter->state))
1814 return false;
1815
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001816 ret_val = hw->mac.ops.check_for_link(hw);
1817 link_active = !hw->mac.get_link_status;
1818
1819 /* if check for link returns error we will need to reset */
Alexander Duyck72279092009-12-11 22:58:14 -08001820 if (ret_val && time_after(jiffies, adapter->last_reset + (10 * HZ)))
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001821 schedule_work(&adapter->reset_task);
1822
1823 return link_active;
1824}
1825
1826/**
1827 * igbvf_watchdog - Timer Call-back
1828 * @data: pointer to adapter cast into an unsigned long
1829 **/
1830static void igbvf_watchdog(unsigned long data)
1831{
1832 struct igbvf_adapter *adapter = (struct igbvf_adapter *) data;
1833
1834 /* Do the rest outside of interrupt context */
1835 schedule_work(&adapter->watchdog_task);
1836}
1837
1838static void igbvf_watchdog_task(struct work_struct *work)
1839{
1840 struct igbvf_adapter *adapter = container_of(work,
1841 struct igbvf_adapter,
1842 watchdog_task);
1843 struct net_device *netdev = adapter->netdev;
1844 struct e1000_mac_info *mac = &adapter->hw.mac;
1845 struct igbvf_ring *tx_ring = adapter->tx_ring;
1846 struct e1000_hw *hw = &adapter->hw;
1847 u32 link;
1848 int tx_pending = 0;
1849
1850 link = igbvf_has_link(adapter);
1851
1852 if (link) {
1853 if (!netif_carrier_ok(netdev)) {
1854 bool txb2b = 1;
1855
1856 mac->ops.get_link_up_info(&adapter->hw,
1857 &adapter->link_speed,
1858 &adapter->link_duplex);
1859 igbvf_print_link_info(adapter);
1860
Emil Tantilova08af742010-03-25 12:11:48 +00001861 /* adjust timeout factor according to speed/duplex */
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001862 adapter->tx_timeout_factor = 1;
1863 switch (adapter->link_speed) {
1864 case SPEED_10:
1865 txb2b = 0;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001866 adapter->tx_timeout_factor = 16;
1867 break;
1868 case SPEED_100:
1869 txb2b = 0;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001870 /* maybe add some timeout factor ? */
1871 break;
1872 }
1873
1874 netif_carrier_on(netdev);
1875 netif_wake_queue(netdev);
1876 }
1877 } else {
1878 if (netif_carrier_ok(netdev)) {
1879 adapter->link_speed = 0;
1880 adapter->link_duplex = 0;
1881 dev_info(&adapter->pdev->dev, "Link is Down\n");
1882 netif_carrier_off(netdev);
1883 netif_stop_queue(netdev);
1884 }
1885 }
1886
1887 if (netif_carrier_ok(netdev)) {
1888 igbvf_update_stats(adapter);
1889 } else {
1890 tx_pending = (igbvf_desc_unused(tx_ring) + 1 <
1891 tx_ring->count);
1892 if (tx_pending) {
1893 /*
1894 * We've lost link, so the controller stops DMA,
1895 * but we've got queued Tx work that's never going
1896 * to get done, so reset controller to flush Tx.
1897 * (Do the reset outside of interrupt context).
1898 */
1899 adapter->tx_timeout_count++;
1900 schedule_work(&adapter->reset_task);
1901 }
1902 }
1903
1904 /* Cause software interrupt to ensure Rx ring is cleaned */
1905 ew32(EICS, adapter->rx_ring->eims_value);
1906
1907 /* Force detection of hung controller every watchdog period */
1908 adapter->detect_tx_hung = 1;
1909
1910 /* Reset the timer */
1911 if (!test_bit(__IGBVF_DOWN, &adapter->state))
1912 mod_timer(&adapter->watchdog_timer,
1913 round_jiffies(jiffies + (2 * HZ)));
1914}
1915
1916#define IGBVF_TX_FLAGS_CSUM 0x00000001
1917#define IGBVF_TX_FLAGS_VLAN 0x00000002
1918#define IGBVF_TX_FLAGS_TSO 0x00000004
1919#define IGBVF_TX_FLAGS_IPV4 0x00000008
1920#define IGBVF_TX_FLAGS_VLAN_MASK 0xffff0000
1921#define IGBVF_TX_FLAGS_VLAN_SHIFT 16
1922
1923static int igbvf_tso(struct igbvf_adapter *adapter,
1924 struct igbvf_ring *tx_ring,
1925 struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
1926{
1927 struct e1000_adv_tx_context_desc *context_desc;
1928 unsigned int i;
1929 int err;
1930 struct igbvf_buffer *buffer_info;
1931 u32 info = 0, tu_cmd = 0;
1932 u32 mss_l4len_idx, l4len;
1933 *hdr_len = 0;
1934
1935 if (skb_header_cloned(skb)) {
1936 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1937 if (err) {
1938 dev_err(&adapter->pdev->dev,
1939 "igbvf_tso returning an error\n");
1940 return err;
1941 }
1942 }
1943
1944 l4len = tcp_hdrlen(skb);
1945 *hdr_len += l4len;
1946
1947 if (skb->protocol == htons(ETH_P_IP)) {
1948 struct iphdr *iph = ip_hdr(skb);
1949 iph->tot_len = 0;
1950 iph->check = 0;
1951 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
1952 iph->daddr, 0,
1953 IPPROTO_TCP,
1954 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08001955 } else if (skb_is_gso_v6(skb)) {
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001956 ipv6_hdr(skb)->payload_len = 0;
1957 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
1958 &ipv6_hdr(skb)->daddr,
1959 0, IPPROTO_TCP, 0);
1960 }
1961
1962 i = tx_ring->next_to_use;
1963
1964 buffer_info = &tx_ring->buffer_info[i];
1965 context_desc = IGBVF_TX_CTXTDESC_ADV(*tx_ring, i);
1966 /* VLAN MACLEN IPLEN */
1967 if (tx_flags & IGBVF_TX_FLAGS_VLAN)
1968 info |= (tx_flags & IGBVF_TX_FLAGS_VLAN_MASK);
1969 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
1970 *hdr_len += skb_network_offset(skb);
1971 info |= (skb_transport_header(skb) - skb_network_header(skb));
1972 *hdr_len += (skb_transport_header(skb) - skb_network_header(skb));
1973 context_desc->vlan_macip_lens = cpu_to_le32(info);
1974
1975 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
1976 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
1977
1978 if (skb->protocol == htons(ETH_P_IP))
1979 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
1980 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
1981
1982 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
1983
1984 /* MSS L4LEN IDX */
1985 mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
1986 mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
1987
1988 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
1989 context_desc->seqnum_seed = 0;
1990
1991 buffer_info->time_stamp = jiffies;
1992 buffer_info->next_to_watch = i;
1993 buffer_info->dma = 0;
1994 i++;
1995 if (i == tx_ring->count)
1996 i = 0;
1997
1998 tx_ring->next_to_use = i;
1999
2000 return true;
2001}
2002
2003static inline bool igbvf_tx_csum(struct igbvf_adapter *adapter,
2004 struct igbvf_ring *tx_ring,
2005 struct sk_buff *skb, u32 tx_flags)
2006{
2007 struct e1000_adv_tx_context_desc *context_desc;
2008 unsigned int i;
2009 struct igbvf_buffer *buffer_info;
2010 u32 info = 0, tu_cmd = 0;
2011
2012 if ((skb->ip_summed == CHECKSUM_PARTIAL) ||
2013 (tx_flags & IGBVF_TX_FLAGS_VLAN)) {
2014 i = tx_ring->next_to_use;
2015 buffer_info = &tx_ring->buffer_info[i];
2016 context_desc = IGBVF_TX_CTXTDESC_ADV(*tx_ring, i);
2017
2018 if (tx_flags & IGBVF_TX_FLAGS_VLAN)
2019 info |= (tx_flags & IGBVF_TX_FLAGS_VLAN_MASK);
2020
2021 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
2022 if (skb->ip_summed == CHECKSUM_PARTIAL)
2023 info |= (skb_transport_header(skb) -
2024 skb_network_header(skb));
2025
2026
2027 context_desc->vlan_macip_lens = cpu_to_le32(info);
2028
2029 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
2030
2031 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2032 switch (skb->protocol) {
2033 case __constant_htons(ETH_P_IP):
2034 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
2035 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2036 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
2037 break;
2038 case __constant_htons(ETH_P_IPV6):
2039 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2040 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
2041 break;
2042 default:
2043 break;
2044 }
2045 }
2046
2047 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
2048 context_desc->seqnum_seed = 0;
2049 context_desc->mss_l4len_idx = 0;
2050
2051 buffer_info->time_stamp = jiffies;
2052 buffer_info->next_to_watch = i;
2053 buffer_info->dma = 0;
2054 i++;
2055 if (i == tx_ring->count)
2056 i = 0;
2057 tx_ring->next_to_use = i;
2058
2059 return true;
2060 }
2061
2062 return false;
2063}
2064
2065static int igbvf_maybe_stop_tx(struct net_device *netdev, int size)
2066{
2067 struct igbvf_adapter *adapter = netdev_priv(netdev);
2068
2069 /* there is enough descriptors then we don't need to worry */
2070 if (igbvf_desc_unused(adapter->tx_ring) >= size)
2071 return 0;
2072
2073 netif_stop_queue(netdev);
2074
2075 smp_mb();
2076
2077 /* We need to check again just in case room has been made available */
2078 if (igbvf_desc_unused(adapter->tx_ring) < size)
2079 return -EBUSY;
2080
2081 netif_wake_queue(netdev);
2082
2083 ++adapter->restart_queue;
2084 return 0;
2085}
2086
2087#define IGBVF_MAX_TXD_PWR 16
2088#define IGBVF_MAX_DATA_PER_TXD (1 << IGBVF_MAX_TXD_PWR)
2089
2090static inline int igbvf_tx_map_adv(struct igbvf_adapter *adapter,
2091 struct igbvf_ring *tx_ring,
2092 struct sk_buff *skb,
2093 unsigned int first)
2094{
2095 struct igbvf_buffer *buffer_info;
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002096 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002097 unsigned int len = skb_headlen(skb);
2098 unsigned int count = 0, i;
2099 unsigned int f;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002100
2101 i = tx_ring->next_to_use;
2102
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002103 buffer_info = &tx_ring->buffer_info[i];
2104 BUG_ON(len >= IGBVF_MAX_DATA_PER_TXD);
2105 buffer_info->length = len;
2106 /* set time_stamp *before* dma to help avoid a possible race */
2107 buffer_info->time_stamp = jiffies;
2108 buffer_info->next_to_watch = i;
Alexander Duyckac26d7d2010-01-27 15:30:39 +00002109 buffer_info->mapped_as_page = false;
Nick Nunley123e9f12010-04-27 13:09:44 +00002110 buffer_info->dma = dma_map_single(&pdev->dev, skb->data, len,
2111 DMA_TO_DEVICE);
2112 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002113 goto dma_error;
2114
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002115
2116 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
2117 struct skb_frag_struct *frag;
2118
Alexander Duyck85811452010-01-23 01:35:00 -08002119 count++;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002120 i++;
2121 if (i == tx_ring->count)
2122 i = 0;
2123
2124 frag = &skb_shinfo(skb)->frags[f];
2125 len = frag->size;
2126
2127 buffer_info = &tx_ring->buffer_info[i];
2128 BUG_ON(len >= IGBVF_MAX_DATA_PER_TXD);
2129 buffer_info->length = len;
2130 buffer_info->time_stamp = jiffies;
2131 buffer_info->next_to_watch = i;
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002132 buffer_info->mapped_as_page = true;
Nick Nunley123e9f12010-04-27 13:09:44 +00002133 buffer_info->dma = dma_map_page(&pdev->dev,
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002134 frag->page,
2135 frag->page_offset,
2136 len,
Nick Nunley123e9f12010-04-27 13:09:44 +00002137 DMA_TO_DEVICE);
2138 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002139 goto dma_error;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002140 }
2141
2142 tx_ring->buffer_info[i].skb = skb;
2143 tx_ring->buffer_info[first].next_to_watch = i;
2144
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002145 return ++count;
2146
2147dma_error:
2148 dev_err(&pdev->dev, "TX DMA map failed\n");
2149
2150 /* clear timestamp and dma mappings for failed buffer_info mapping */
2151 buffer_info->dma = 0;
2152 buffer_info->time_stamp = 0;
2153 buffer_info->length = 0;
2154 buffer_info->next_to_watch = 0;
2155 buffer_info->mapped_as_page = false;
Roel Kluinc1fa3472010-01-19 14:21:45 +00002156 if (count)
2157 count--;
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002158
2159 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00002160 while (count--) {
2161 if (i==0)
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002162 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00002163 i--;
Alexander Duycka7d5ca42009-12-02 16:47:37 +00002164 buffer_info = &tx_ring->buffer_info[i];
2165 igbvf_put_txbuf(adapter, buffer_info);
2166 }
2167
2168 return 0;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002169}
2170
2171static inline void igbvf_tx_queue_adv(struct igbvf_adapter *adapter,
2172 struct igbvf_ring *tx_ring,
2173 int tx_flags, int count, u32 paylen,
2174 u8 hdr_len)
2175{
2176 union e1000_adv_tx_desc *tx_desc = NULL;
2177 struct igbvf_buffer *buffer_info;
2178 u32 olinfo_status = 0, cmd_type_len;
2179 unsigned int i;
2180
2181 cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
2182 E1000_ADVTXD_DCMD_DEXT);
2183
2184 if (tx_flags & IGBVF_TX_FLAGS_VLAN)
2185 cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
2186
2187 if (tx_flags & IGBVF_TX_FLAGS_TSO) {
2188 cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
2189
2190 /* insert tcp checksum */
2191 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
2192
2193 /* insert ip checksum */
2194 if (tx_flags & IGBVF_TX_FLAGS_IPV4)
2195 olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
2196
2197 } else if (tx_flags & IGBVF_TX_FLAGS_CSUM) {
2198 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
2199 }
2200
2201 olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
2202
2203 i = tx_ring->next_to_use;
2204 while (count--) {
2205 buffer_info = &tx_ring->buffer_info[i];
2206 tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i);
2207 tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
2208 tx_desc->read.cmd_type_len =
2209 cpu_to_le32(cmd_type_len | buffer_info->length);
2210 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
2211 i++;
2212 if (i == tx_ring->count)
2213 i = 0;
2214 }
2215
2216 tx_desc->read.cmd_type_len |= cpu_to_le32(adapter->txd_cmd);
2217 /* Force memory writes to complete before letting h/w
2218 * know there are new descriptors to fetch. (Only
2219 * applicable for weak-ordered memory model archs,
2220 * such as IA-64). */
2221 wmb();
2222
2223 tx_ring->next_to_use = i;
2224 writel(i, adapter->hw.hw_addr + tx_ring->tail);
2225 /* we need this if more than one processor can write to our tail
2226 * at a time, it syncronizes IO on IA64/Altix systems */
2227 mmiowb();
2228}
2229
Stephen Hemminger3b29a562009-08-31 19:50:55 +00002230static netdev_tx_t igbvf_xmit_frame_ring_adv(struct sk_buff *skb,
2231 struct net_device *netdev,
2232 struct igbvf_ring *tx_ring)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002233{
2234 struct igbvf_adapter *adapter = netdev_priv(netdev);
2235 unsigned int first, tx_flags = 0;
2236 u8 hdr_len = 0;
2237 int count = 0;
2238 int tso = 0;
2239
2240 if (test_bit(__IGBVF_DOWN, &adapter->state)) {
2241 dev_kfree_skb_any(skb);
2242 return NETDEV_TX_OK;
2243 }
2244
2245 if (skb->len <= 0) {
2246 dev_kfree_skb_any(skb);
2247 return NETDEV_TX_OK;
2248 }
2249
2250 /*
2251 * need: count + 4 desc gap to keep tail from touching
2252 * + 2 desc gap to keep tail from touching head,
2253 * + 1 desc for skb->data,
2254 * + 1 desc for context descriptor,
2255 * head, otherwise try next time
2256 */
2257 if (igbvf_maybe_stop_tx(netdev, skb_shinfo(skb)->nr_frags + 4)) {
2258 /* this is a hard error */
2259 return NETDEV_TX_BUSY;
2260 }
2261
2262 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
2263 tx_flags |= IGBVF_TX_FLAGS_VLAN;
2264 tx_flags |= (vlan_tx_tag_get(skb) << IGBVF_TX_FLAGS_VLAN_SHIFT);
2265 }
2266
2267 if (skb->protocol == htons(ETH_P_IP))
2268 tx_flags |= IGBVF_TX_FLAGS_IPV4;
2269
2270 first = tx_ring->next_to_use;
2271
2272 tso = skb_is_gso(skb) ?
2273 igbvf_tso(adapter, tx_ring, skb, tx_flags, &hdr_len) : 0;
2274 if (unlikely(tso < 0)) {
2275 dev_kfree_skb_any(skb);
2276 return NETDEV_TX_OK;
2277 }
2278
2279 if (tso)
2280 tx_flags |= IGBVF_TX_FLAGS_TSO;
2281 else if (igbvf_tx_csum(adapter, tx_ring, skb, tx_flags) &&
2282 (skb->ip_summed == CHECKSUM_PARTIAL))
2283 tx_flags |= IGBVF_TX_FLAGS_CSUM;
2284
2285 /*
2286 * count reflects descriptors mapped, if 0 then mapping error
2287 * has occured and we need to rewind the descriptor queue
2288 */
2289 count = igbvf_tx_map_adv(adapter, tx_ring, skb, first);
2290
2291 if (count) {
2292 igbvf_tx_queue_adv(adapter, tx_ring, tx_flags, count,
2293 skb->len, hdr_len);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002294 /* Make sure there is space in the ring for the next send. */
2295 igbvf_maybe_stop_tx(netdev, MAX_SKB_FRAGS + 4);
2296 } else {
2297 dev_kfree_skb_any(skb);
2298 tx_ring->buffer_info[first].time_stamp = 0;
2299 tx_ring->next_to_use = first;
2300 }
2301
2302 return NETDEV_TX_OK;
2303}
2304
Stephen Hemminger3b29a562009-08-31 19:50:55 +00002305static netdev_tx_t igbvf_xmit_frame(struct sk_buff *skb,
2306 struct net_device *netdev)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002307{
2308 struct igbvf_adapter *adapter = netdev_priv(netdev);
2309 struct igbvf_ring *tx_ring;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002310
2311 if (test_bit(__IGBVF_DOWN, &adapter->state)) {
2312 dev_kfree_skb_any(skb);
2313 return NETDEV_TX_OK;
2314 }
2315
2316 tx_ring = &adapter->tx_ring[0];
2317
Stephen Hemminger3b29a562009-08-31 19:50:55 +00002318 return igbvf_xmit_frame_ring_adv(skb, netdev, tx_ring);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002319}
2320
2321/**
2322 * igbvf_tx_timeout - Respond to a Tx Hang
2323 * @netdev: network interface device structure
2324 **/
2325static void igbvf_tx_timeout(struct net_device *netdev)
2326{
2327 struct igbvf_adapter *adapter = netdev_priv(netdev);
2328
2329 /* Do the reset outside of interrupt context */
2330 adapter->tx_timeout_count++;
2331 schedule_work(&adapter->reset_task);
2332}
2333
2334static void igbvf_reset_task(struct work_struct *work)
2335{
2336 struct igbvf_adapter *adapter;
2337 adapter = container_of(work, struct igbvf_adapter, reset_task);
2338
2339 igbvf_reinit_locked(adapter);
2340}
2341
2342/**
2343 * igbvf_get_stats - Get System Network Statistics
2344 * @netdev: network interface device structure
2345 *
2346 * Returns the address of the device statistics structure.
2347 * The statistics are actually updated from the timer callback.
2348 **/
2349static struct net_device_stats *igbvf_get_stats(struct net_device *netdev)
2350{
2351 struct igbvf_adapter *adapter = netdev_priv(netdev);
2352
2353 /* only return the current stats */
2354 return &adapter->net_stats;
2355}
2356
2357/**
2358 * igbvf_change_mtu - Change the Maximum Transfer Unit
2359 * @netdev: network interface device structure
2360 * @new_mtu: new value for maximum frame size
2361 *
2362 * Returns 0 on success, negative on failure
2363 **/
2364static int igbvf_change_mtu(struct net_device *netdev, int new_mtu)
2365{
2366 struct igbvf_adapter *adapter = netdev_priv(netdev);
2367 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2368
2369 if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
2370 dev_err(&adapter->pdev->dev, "Invalid MTU setting\n");
2371 return -EINVAL;
2372 }
2373
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002374#define MAX_STD_JUMBO_FRAME_SIZE 9234
2375 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
2376 dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n");
2377 return -EINVAL;
2378 }
2379
2380 while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state))
2381 msleep(1);
2382 /* igbvf_down has a dependency on max_frame_size */
2383 adapter->max_frame_size = max_frame;
2384 if (netif_running(netdev))
2385 igbvf_down(adapter);
2386
2387 /*
2388 * NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
2389 * means we reserve 2 more, this pushes us to allocate from the next
2390 * larger slab size.
2391 * i.e. RXBUFFER_2048 --> size-4096 slab
2392 * However with the new *_jumbo_rx* routines, jumbo receives will use
2393 * fragmented skbs
2394 */
2395
2396 if (max_frame <= 1024)
2397 adapter->rx_buffer_len = 1024;
2398 else if (max_frame <= 2048)
2399 adapter->rx_buffer_len = 2048;
2400 else
2401#if (PAGE_SIZE / 2) > 16384
2402 adapter->rx_buffer_len = 16384;
2403#else
2404 adapter->rx_buffer_len = PAGE_SIZE / 2;
2405#endif
2406
2407
2408 /* adjust allocation if LPE protects us, and we aren't using SBP */
2409 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
2410 (max_frame == ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN))
2411 adapter->rx_buffer_len = ETH_FRAME_LEN + VLAN_HLEN +
2412 ETH_FCS_LEN;
2413
2414 dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n",
2415 netdev->mtu, new_mtu);
2416 netdev->mtu = new_mtu;
2417
2418 if (netif_running(netdev))
2419 igbvf_up(adapter);
2420 else
2421 igbvf_reset(adapter);
2422
2423 clear_bit(__IGBVF_RESETTING, &adapter->state);
2424
2425 return 0;
2426}
2427
2428static int igbvf_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2429{
2430 switch (cmd) {
2431 default:
2432 return -EOPNOTSUPP;
2433 }
2434}
2435
2436static int igbvf_suspend(struct pci_dev *pdev, pm_message_t state)
2437{
2438 struct net_device *netdev = pci_get_drvdata(pdev);
2439 struct igbvf_adapter *adapter = netdev_priv(netdev);
2440#ifdef CONFIG_PM
2441 int retval = 0;
2442#endif
2443
2444 netif_device_detach(netdev);
2445
2446 if (netif_running(netdev)) {
2447 WARN_ON(test_bit(__IGBVF_RESETTING, &adapter->state));
2448 igbvf_down(adapter);
2449 igbvf_free_irq(adapter);
2450 }
2451
2452#ifdef CONFIG_PM
2453 retval = pci_save_state(pdev);
2454 if (retval)
2455 return retval;
2456#endif
2457
2458 pci_disable_device(pdev);
2459
2460 return 0;
2461}
2462
2463#ifdef CONFIG_PM
2464static int igbvf_resume(struct pci_dev *pdev)
2465{
2466 struct net_device *netdev = pci_get_drvdata(pdev);
2467 struct igbvf_adapter *adapter = netdev_priv(netdev);
2468 u32 err;
2469
2470 pci_restore_state(pdev);
2471 err = pci_enable_device_mem(pdev);
2472 if (err) {
2473 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
2474 return err;
2475 }
2476
2477 pci_set_master(pdev);
2478
2479 if (netif_running(netdev)) {
2480 err = igbvf_request_irq(adapter);
2481 if (err)
2482 return err;
2483 }
2484
2485 igbvf_reset(adapter);
2486
2487 if (netif_running(netdev))
2488 igbvf_up(adapter);
2489
2490 netif_device_attach(netdev);
2491
2492 return 0;
2493}
2494#endif
2495
2496static void igbvf_shutdown(struct pci_dev *pdev)
2497{
2498 igbvf_suspend(pdev, PMSG_SUSPEND);
2499}
2500
2501#ifdef CONFIG_NET_POLL_CONTROLLER
2502/*
2503 * Polling 'interrupt' - used by things like netconsole to send skbs
2504 * without having to re-enable interrupts. It's not called while
2505 * the interrupt routine is executing.
2506 */
2507static void igbvf_netpoll(struct net_device *netdev)
2508{
2509 struct igbvf_adapter *adapter = netdev_priv(netdev);
2510
2511 disable_irq(adapter->pdev->irq);
2512
2513 igbvf_clean_tx_irq(adapter->tx_ring);
2514
2515 enable_irq(adapter->pdev->irq);
2516}
2517#endif
2518
2519/**
2520 * igbvf_io_error_detected - called when PCI error is detected
2521 * @pdev: Pointer to PCI device
2522 * @state: The current pci connection state
2523 *
2524 * This function is called after a PCI bus error affecting
2525 * this device has been detected.
2526 */
2527static pci_ers_result_t igbvf_io_error_detected(struct pci_dev *pdev,
2528 pci_channel_state_t state)
2529{
2530 struct net_device *netdev = pci_get_drvdata(pdev);
2531 struct igbvf_adapter *adapter = netdev_priv(netdev);
2532
2533 netif_device_detach(netdev);
2534
Dean Nelsonc06c4302009-07-31 09:13:33 +00002535 if (state == pci_channel_io_perm_failure)
2536 return PCI_ERS_RESULT_DISCONNECT;
2537
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002538 if (netif_running(netdev))
2539 igbvf_down(adapter);
2540 pci_disable_device(pdev);
2541
2542 /* Request a slot slot reset. */
2543 return PCI_ERS_RESULT_NEED_RESET;
2544}
2545
2546/**
2547 * igbvf_io_slot_reset - called after the pci bus has been reset.
2548 * @pdev: Pointer to PCI device
2549 *
2550 * Restart the card from scratch, as if from a cold-boot. Implementation
2551 * resembles the first-half of the igbvf_resume routine.
2552 */
2553static pci_ers_result_t igbvf_io_slot_reset(struct pci_dev *pdev)
2554{
2555 struct net_device *netdev = pci_get_drvdata(pdev);
2556 struct igbvf_adapter *adapter = netdev_priv(netdev);
2557
2558 if (pci_enable_device_mem(pdev)) {
2559 dev_err(&pdev->dev,
2560 "Cannot re-enable PCI device after reset.\n");
2561 return PCI_ERS_RESULT_DISCONNECT;
2562 }
2563 pci_set_master(pdev);
2564
2565 igbvf_reset(adapter);
2566
2567 return PCI_ERS_RESULT_RECOVERED;
2568}
2569
2570/**
2571 * igbvf_io_resume - called when traffic can start flowing again.
2572 * @pdev: Pointer to PCI device
2573 *
2574 * This callback is called when the error recovery driver tells us that
2575 * its OK to resume normal operation. Implementation resembles the
2576 * second-half of the igbvf_resume routine.
2577 */
2578static void igbvf_io_resume(struct pci_dev *pdev)
2579{
2580 struct net_device *netdev = pci_get_drvdata(pdev);
2581 struct igbvf_adapter *adapter = netdev_priv(netdev);
2582
2583 if (netif_running(netdev)) {
2584 if (igbvf_up(adapter)) {
2585 dev_err(&pdev->dev,
2586 "can't bring device back up after reset\n");
2587 return;
2588 }
2589 }
2590
2591 netif_device_attach(netdev);
2592}
2593
2594static void igbvf_print_device_info(struct igbvf_adapter *adapter)
2595{
2596 struct e1000_hw *hw = &adapter->hw;
2597 struct net_device *netdev = adapter->netdev;
2598 struct pci_dev *pdev = adapter->pdev;
2599
2600 dev_info(&pdev->dev, "Intel(R) 82576 Virtual Function\n");
H Hartley Sweeten753cdc32009-12-29 20:02:29 -08002601 dev_info(&pdev->dev, "Address: %pM\n", netdev->dev_addr);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002602 dev_info(&pdev->dev, "MAC: %d\n", hw->mac.type);
2603}
2604
2605static const struct net_device_ops igbvf_netdev_ops = {
2606 .ndo_open = igbvf_open,
2607 .ndo_stop = igbvf_close,
2608 .ndo_start_xmit = igbvf_xmit_frame,
2609 .ndo_get_stats = igbvf_get_stats,
2610 .ndo_set_multicast_list = igbvf_set_multi,
2611 .ndo_set_mac_address = igbvf_set_mac,
2612 .ndo_change_mtu = igbvf_change_mtu,
2613 .ndo_do_ioctl = igbvf_ioctl,
2614 .ndo_tx_timeout = igbvf_tx_timeout,
2615 .ndo_vlan_rx_register = igbvf_vlan_rx_register,
2616 .ndo_vlan_rx_add_vid = igbvf_vlan_rx_add_vid,
2617 .ndo_vlan_rx_kill_vid = igbvf_vlan_rx_kill_vid,
2618#ifdef CONFIG_NET_POLL_CONTROLLER
2619 .ndo_poll_controller = igbvf_netpoll,
2620#endif
2621};
2622
2623/**
2624 * igbvf_probe - Device Initialization Routine
2625 * @pdev: PCI device information struct
2626 * @ent: entry in igbvf_pci_tbl
2627 *
2628 * Returns 0 on success, negative on failure
2629 *
2630 * igbvf_probe initializes an adapter identified by a pci_dev structure.
2631 * The OS initialization, configuring of the adapter private structure,
2632 * and a hardware reset occur.
2633 **/
2634static int __devinit igbvf_probe(struct pci_dev *pdev,
2635 const struct pci_device_id *ent)
2636{
2637 struct net_device *netdev;
2638 struct igbvf_adapter *adapter;
2639 struct e1000_hw *hw;
2640 const struct igbvf_info *ei = igbvf_info_tbl[ent->driver_data];
2641
2642 static int cards_found;
2643 int err, pci_using_dac;
2644
2645 err = pci_enable_device_mem(pdev);
2646 if (err)
2647 return err;
2648
2649 pci_using_dac = 0;
Nick Nunley123e9f12010-04-27 13:09:44 +00002650 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002651 if (!err) {
Nick Nunley123e9f12010-04-27 13:09:44 +00002652 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002653 if (!err)
2654 pci_using_dac = 1;
2655 } else {
Nick Nunley123e9f12010-04-27 13:09:44 +00002656 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002657 if (err) {
Nick Nunley123e9f12010-04-27 13:09:44 +00002658 err = dma_set_coherent_mask(&pdev->dev,
2659 DMA_BIT_MASK(32));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002660 if (err) {
2661 dev_err(&pdev->dev, "No usable DMA "
2662 "configuration, aborting\n");
2663 goto err_dma;
2664 }
2665 }
2666 }
2667
2668 err = pci_request_regions(pdev, igbvf_driver_name);
2669 if (err)
2670 goto err_pci_reg;
2671
2672 pci_set_master(pdev);
2673
2674 err = -ENOMEM;
2675 netdev = alloc_etherdev(sizeof(struct igbvf_adapter));
2676 if (!netdev)
2677 goto err_alloc_etherdev;
2678
2679 SET_NETDEV_DEV(netdev, &pdev->dev);
2680
2681 pci_set_drvdata(pdev, netdev);
2682 adapter = netdev_priv(netdev);
2683 hw = &adapter->hw;
2684 adapter->netdev = netdev;
2685 adapter->pdev = pdev;
2686 adapter->ei = ei;
2687 adapter->pba = ei->pba;
2688 adapter->flags = ei->flags;
2689 adapter->hw.back = adapter;
2690 adapter->hw.mac.type = ei->mac;
2691 adapter->msg_enable = (1 << NETIF_MSG_DRV | NETIF_MSG_PROBE) - 1;
2692
2693 /* PCI config space info */
2694
2695 hw->vendor_id = pdev->vendor;
2696 hw->device_id = pdev->device;
2697 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2698 hw->subsystem_device_id = pdev->subsystem_device;
2699
2700 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2701
2702 err = -EIO;
2703 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, 0),
2704 pci_resource_len(pdev, 0));
2705
2706 if (!adapter->hw.hw_addr)
2707 goto err_ioremap;
2708
2709 if (ei->get_variants) {
2710 err = ei->get_variants(adapter);
2711 if (err)
2712 goto err_ioremap;
2713 }
2714
2715 /* setup adapter struct */
2716 err = igbvf_sw_init(adapter);
2717 if (err)
2718 goto err_sw_init;
2719
2720 /* construct the net_device struct */
2721 netdev->netdev_ops = &igbvf_netdev_ops;
2722
2723 igbvf_set_ethtool_ops(netdev);
2724 netdev->watchdog_timeo = 5 * HZ;
2725 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
2726
2727 adapter->bd_number = cards_found++;
2728
2729 netdev->features = NETIF_F_SG |
2730 NETIF_F_IP_CSUM |
2731 NETIF_F_HW_VLAN_TX |
2732 NETIF_F_HW_VLAN_RX |
2733 NETIF_F_HW_VLAN_FILTER;
2734
2735 netdev->features |= NETIF_F_IPV6_CSUM;
2736 netdev->features |= NETIF_F_TSO;
2737 netdev->features |= NETIF_F_TSO6;
2738
2739 if (pci_using_dac)
2740 netdev->features |= NETIF_F_HIGHDMA;
2741
2742 netdev->vlan_features |= NETIF_F_TSO;
2743 netdev->vlan_features |= NETIF_F_TSO6;
2744 netdev->vlan_features |= NETIF_F_IP_CSUM;
2745 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
2746 netdev->vlan_features |= NETIF_F_SG;
2747
2748 /*reset the controller to put the device in a known good state */
2749 err = hw->mac.ops.reset_hw(hw);
2750 if (err) {
2751 dev_info(&pdev->dev,
Williams, Mitch A1242b6f2009-12-23 13:22:43 +00002752 "PF still in reset state, assigning new address."
2753 " Is the PF interface up?\n");
Stefan Assmann2c6952d2010-07-26 23:24:50 +00002754 dev_hw_addr_random(adapter->netdev, hw->mac.addr);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002755 } else {
2756 err = hw->mac.ops.read_mac_addr(hw);
2757 if (err) {
2758 dev_err(&pdev->dev, "Error reading MAC address\n");
2759 goto err_hw_init;
2760 }
2761 }
2762
2763 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
2764 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
2765
2766 if (!is_valid_ether_addr(netdev->perm_addr)) {
H Hartley Sweeten753cdc32009-12-29 20:02:29 -08002767 dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
2768 netdev->dev_addr);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002769 err = -EIO;
2770 goto err_hw_init;
2771 }
2772
2773 setup_timer(&adapter->watchdog_timer, &igbvf_watchdog,
2774 (unsigned long) adapter);
2775
2776 INIT_WORK(&adapter->reset_task, igbvf_reset_task);
2777 INIT_WORK(&adapter->watchdog_task, igbvf_watchdog_task);
2778
2779 /* ring size defaults */
2780 adapter->rx_ring->count = 1024;
2781 adapter->tx_ring->count = 1024;
2782
2783 /* reset the hardware with the new settings */
2784 igbvf_reset(adapter);
2785
2786 /* tell the stack to leave us alone until igbvf_open() is called */
2787 netif_carrier_off(netdev);
2788 netif_stop_queue(netdev);
2789
2790 strcpy(netdev->name, "eth%d");
2791 err = register_netdev(netdev);
2792 if (err)
2793 goto err_hw_init;
2794
2795 igbvf_print_device_info(adapter);
2796
2797 igbvf_initialize_last_counter_stats(adapter);
2798
2799 return 0;
2800
2801err_hw_init:
2802 kfree(adapter->tx_ring);
2803 kfree(adapter->rx_ring);
2804err_sw_init:
2805 igbvf_reset_interrupt_capability(adapter);
2806 iounmap(adapter->hw.hw_addr);
2807err_ioremap:
2808 free_netdev(netdev);
2809err_alloc_etherdev:
2810 pci_release_regions(pdev);
2811err_pci_reg:
2812err_dma:
2813 pci_disable_device(pdev);
2814 return err;
2815}
2816
2817/**
2818 * igbvf_remove - Device Removal Routine
2819 * @pdev: PCI device information struct
2820 *
2821 * igbvf_remove is called by the PCI subsystem to alert the driver
2822 * that it should release a PCI device. The could be caused by a
2823 * Hot-Plug event, or because the driver is going to be removed from
2824 * memory.
2825 **/
2826static void __devexit igbvf_remove(struct pci_dev *pdev)
2827{
2828 struct net_device *netdev = pci_get_drvdata(pdev);
2829 struct igbvf_adapter *adapter = netdev_priv(netdev);
2830 struct e1000_hw *hw = &adapter->hw;
2831
2832 /*
2833 * flush_scheduled work may reschedule our watchdog task, so
2834 * explicitly disable watchdog tasks from being rescheduled
2835 */
2836 set_bit(__IGBVF_DOWN, &adapter->state);
2837 del_timer_sync(&adapter->watchdog_timer);
2838
2839 flush_scheduled_work();
2840
2841 unregister_netdev(netdev);
2842
2843 igbvf_reset_interrupt_capability(adapter);
2844
2845 /*
2846 * it is important to delete the napi struct prior to freeing the
2847 * rx ring so that you do not end up with null pointer refs
2848 */
2849 netif_napi_del(&adapter->rx_ring->napi);
2850 kfree(adapter->tx_ring);
2851 kfree(adapter->rx_ring);
2852
2853 iounmap(hw->hw_addr);
2854 if (hw->flash_address)
2855 iounmap(hw->flash_address);
2856 pci_release_regions(pdev);
2857
2858 free_netdev(netdev);
2859
2860 pci_disable_device(pdev);
2861}
2862
2863/* PCI Error Recovery (ERS) */
2864static struct pci_error_handlers igbvf_err_handler = {
2865 .error_detected = igbvf_io_error_detected,
2866 .slot_reset = igbvf_io_slot_reset,
2867 .resume = igbvf_io_resume,
2868};
2869
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00002870static DEFINE_PCI_DEVICE_TABLE(igbvf_pci_tbl) = {
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002871 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_VF), board_vf },
2872 { } /* terminate list */
2873};
2874MODULE_DEVICE_TABLE(pci, igbvf_pci_tbl);
2875
2876/* PCI Device API Driver */
2877static struct pci_driver igbvf_driver = {
2878 .name = igbvf_driver_name,
2879 .id_table = igbvf_pci_tbl,
2880 .probe = igbvf_probe,
2881 .remove = __devexit_p(igbvf_remove),
2882#ifdef CONFIG_PM
2883 /* Power Management Hooks */
2884 .suspend = igbvf_suspend,
2885 .resume = igbvf_resume,
2886#endif
2887 .shutdown = igbvf_shutdown,
2888 .err_handler = &igbvf_err_handler
2889};
2890
2891/**
2892 * igbvf_init_module - Driver Registration Routine
2893 *
2894 * igbvf_init_module is the first routine called when the driver is
2895 * loaded. All it does is register with the PCI subsystem.
2896 **/
2897static int __init igbvf_init_module(void)
2898{
2899 int ret;
2900 printk(KERN_INFO "%s - version %s\n",
2901 igbvf_driver_string, igbvf_driver_version);
2902 printk(KERN_INFO "%s\n", igbvf_copyright);
2903
2904 ret = pci_register_driver(&igbvf_driver);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002905
2906 return ret;
2907}
2908module_init(igbvf_init_module);
2909
2910/**
2911 * igbvf_exit_module - Driver Exit Cleanup Routine
2912 *
2913 * igbvf_exit_module is called just before the driver is removed
2914 * from memory.
2915 **/
2916static void __exit igbvf_exit_module(void)
2917{
2918 pci_unregister_driver(&igbvf_driver);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00002919}
2920module_exit(igbvf_exit_module);
2921
2922
2923MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
2924MODULE_DESCRIPTION("Intel(R) 82576 Virtual Function Network Driver");
2925MODULE_LICENSE("GPL");
2926MODULE_VERSION(DRV_VERSION);
2927
2928/* netdev.c */