1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2009 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
29 /******************************************************************************
30 Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
31 ******************************************************************************/
32 #include <linux/types.h>
33 #include <linux/module.h>
34 #include <linux/pci.h>
35 #include <linux/netdevice.h>
36 #include <linux/vmalloc.h>
37 #include <linux/string.h>
40 #include <linux/tcp.h>
41 #include <linux/ipv6.h>
42 #include <linux/slab.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <linux/ethtool.h>
46 #include <linux/if_vlan.h>
50 char ixgbevf_driver_name
[] = "ixgbevf";
51 static const char ixgbevf_driver_string
[] =
52 "Intel(R) 82599 Virtual Function";
54 #define DRV_VERSION "1.0.0-k0"
55 const char ixgbevf_driver_version
[] = DRV_VERSION
;
56 static char ixgbevf_copyright
[] = "Copyright (c) 2009 Intel Corporation.";
58 static const struct ixgbevf_info
*ixgbevf_info_tbl
[] = {
59 [board_82599_vf
] = &ixgbevf_vf_info
,
62 /* ixgbevf_pci_tbl - PCI Device ID Table
64 * Wildcard entries (PCI_ANY_ID) should come last
65 * Last entry must be all 0s
67 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
68 * Class, Class Mask, private data (not used) }
70 static struct pci_device_id ixgbevf_pci_tbl
[] = {
71 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_VF
),
74 /* required last entry */
77 MODULE_DEVICE_TABLE(pci
, ixgbevf_pci_tbl
);
79 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
80 MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
81 MODULE_LICENSE("GPL");
82 MODULE_VERSION(DRV_VERSION
);
84 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
87 static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector
*q_vector
);
88 static void ixgbevf_write_eitr(struct ixgbevf_adapter
*adapter
, int v_idx
,
91 static inline void ixgbevf_release_rx_desc(struct ixgbe_hw
*hw
,
92 struct ixgbevf_ring
*rx_ring
,
96 * Force memory writes to complete before letting h/w
97 * know there are new descriptors to fetch. (Only
98 * applicable for weak-ordered memory model archs,
102 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(rx_ring
->reg_idx
), val
);
106 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
107 * @adapter: pointer to adapter struct
108 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
109 * @queue: queue to map the corresponding interrupt to
110 * @msix_vector: the vector to map to the corresponding queue
113 static void ixgbevf_set_ivar(struct ixgbevf_adapter
*adapter
, s8 direction
,
114 u8 queue
, u8 msix_vector
)
117 struct ixgbe_hw
*hw
= &adapter
->hw
;
118 if (direction
== -1) {
120 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
121 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR_MISC
);
124 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR_MISC
, ivar
);
126 /* tx or rx causes */
127 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
128 index
= ((16 * (queue
& 1)) + (8 * direction
));
129 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR(queue
>> 1));
130 ivar
&= ~(0xFF << index
);
131 ivar
|= (msix_vector
<< index
);
132 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR(queue
>> 1), ivar
);
136 static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_adapter
*adapter
,
137 struct ixgbevf_tx_buffer
140 if (tx_buffer_info
->dma
) {
141 if (tx_buffer_info
->mapped_as_page
)
142 dma_unmap_page(&adapter
->pdev
->dev
,
144 tx_buffer_info
->length
,
147 dma_unmap_single(&adapter
->pdev
->dev
,
149 tx_buffer_info
->length
,
151 tx_buffer_info
->dma
= 0;
153 if (tx_buffer_info
->skb
) {
154 dev_kfree_skb_any(tx_buffer_info
->skb
);
155 tx_buffer_info
->skb
= NULL
;
157 tx_buffer_info
->time_stamp
= 0;
158 /* tx_buffer_info must be completely set up in the transmit path */
161 static inline bool ixgbevf_check_tx_hang(struct ixgbevf_adapter
*adapter
,
162 struct ixgbevf_ring
*tx_ring
,
165 struct ixgbe_hw
*hw
= &adapter
->hw
;
168 /* Detect a transmit hang in hardware, this serializes the
169 * check with the clearing of time_stamp and movement of eop */
170 head
= readl(hw
->hw_addr
+ tx_ring
->head
);
171 tail
= readl(hw
->hw_addr
+ tx_ring
->tail
);
172 adapter
->detect_tx_hung
= false;
173 if ((head
!= tail
) &&
174 tx_ring
->tx_buffer_info
[eop
].time_stamp
&&
175 time_after(jiffies
, tx_ring
->tx_buffer_info
[eop
].time_stamp
+ HZ
)) {
176 /* detected Tx unit hang */
177 union ixgbe_adv_tx_desc
*tx_desc
;
178 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
179 printk(KERN_ERR
"Detected Tx Unit Hang\n"
181 " TDH, TDT <%x>, <%x>\n"
182 " next_to_use <%x>\n"
183 " next_to_clean <%x>\n"
184 "tx_buffer_info[next_to_clean]\n"
185 " time_stamp <%lx>\n"
187 tx_ring
->queue_index
,
189 tx_ring
->next_to_use
, eop
,
190 tx_ring
->tx_buffer_info
[eop
].time_stamp
, jiffies
);
197 #define IXGBE_MAX_TXD_PWR 14
198 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
200 /* Tx Descriptors needed, worst case */
201 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
202 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
204 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
205 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
207 #define DESC_NEEDED TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD)
210 static void ixgbevf_tx_timeout(struct net_device
*netdev
);
213 * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
214 * @adapter: board private structure
215 * @tx_ring: tx ring to clean
217 static bool ixgbevf_clean_tx_irq(struct ixgbevf_adapter
*adapter
,
218 struct ixgbevf_ring
*tx_ring
)
220 struct net_device
*netdev
= adapter
->netdev
;
221 struct ixgbe_hw
*hw
= &adapter
->hw
;
222 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
223 struct ixgbevf_tx_buffer
*tx_buffer_info
;
224 unsigned int i
, eop
, count
= 0;
225 unsigned int total_bytes
= 0, total_packets
= 0;
227 i
= tx_ring
->next_to_clean
;
228 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
229 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
231 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
232 (count
< tx_ring
->work_limit
)) {
233 bool cleaned
= false;
234 rmb(); /* read buffer_info after eop_desc */
235 for ( ; !cleaned
; count
++) {
237 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
238 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
239 cleaned
= (i
== eop
);
240 skb
= tx_buffer_info
->skb
;
242 if (cleaned
&& skb
) {
243 unsigned int segs
, bytecount
;
245 /* gso_segs is currently only valid for tcp */
246 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
247 /* multiply data chunks by size of headers */
248 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
250 total_packets
+= segs
;
251 total_bytes
+= bytecount
;
254 ixgbevf_unmap_and_free_tx_resource(adapter
,
257 tx_desc
->wb
.status
= 0;
260 if (i
== tx_ring
->count
)
264 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
265 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
268 tx_ring
->next_to_clean
= i
;
270 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
271 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
272 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
273 /* Make sure that anybody stopping the queue after this
274 * sees the new next_to_clean.
278 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
279 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
280 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
281 ++adapter
->restart_queue
;
284 if (netif_queue_stopped(netdev
) &&
285 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
286 netif_wake_queue(netdev
);
287 ++adapter
->restart_queue
;
292 if (adapter
->detect_tx_hung
) {
293 if (ixgbevf_check_tx_hang(adapter
, tx_ring
, i
)) {
294 /* schedule immediate reset if we believe we hung */
296 "tx hang %d detected, resetting adapter\n",
297 adapter
->tx_timeout_count
+ 1);
298 ixgbevf_tx_timeout(adapter
->netdev
);
302 /* re-arm the interrupt */
303 if ((count
>= tx_ring
->work_limit
) &&
304 (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))) {
305 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, tx_ring
->v_idx
);
308 tx_ring
->total_bytes
+= total_bytes
;
309 tx_ring
->total_packets
+= total_packets
;
311 netdev
->stats
.tx_bytes
+= total_bytes
;
312 netdev
->stats
.tx_packets
+= total_packets
;
314 return count
< tx_ring
->work_limit
;
318 * ixgbevf_receive_skb - Send a completed packet up the stack
319 * @q_vector: structure containing interrupt and ring information
320 * @skb: packet to send up
321 * @status: hardware indication of status of receive
322 * @rx_ring: rx descriptor ring (for a specific queue) to setup
323 * @rx_desc: rx descriptor
325 static void ixgbevf_receive_skb(struct ixgbevf_q_vector
*q_vector
,
326 struct sk_buff
*skb
, u8 status
,
327 struct ixgbevf_ring
*ring
,
328 union ixgbe_adv_rx_desc
*rx_desc
)
330 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
331 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
332 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
335 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
)) {
336 if (adapter
->vlgrp
&& is_vlan
)
337 vlan_gro_receive(&q_vector
->napi
,
341 napi_gro_receive(&q_vector
->napi
, skb
);
343 if (adapter
->vlgrp
&& is_vlan
)
344 ret
= vlan_hwaccel_rx(skb
, adapter
->vlgrp
, tag
);
351 * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
352 * @adapter: address of board private structure
353 * @status_err: hardware indication of status of receive
354 * @skb: skb currently being received and modified
356 static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter
*adapter
,
357 u32 status_err
, struct sk_buff
*skb
)
359 skb_checksum_none_assert(skb
);
361 /* Rx csum disabled */
362 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
365 /* if IP and error */
366 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
367 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
368 adapter
->hw_csum_rx_error
++;
372 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
375 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
376 adapter
->hw_csum_rx_error
++;
380 /* It must be a TCP or UDP packet with a valid checksum */
381 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
382 adapter
->hw_csum_rx_good
++;
386 * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
387 * @adapter: address of board private structure
389 static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter
*adapter
,
390 struct ixgbevf_ring
*rx_ring
,
393 struct pci_dev
*pdev
= adapter
->pdev
;
394 union ixgbe_adv_rx_desc
*rx_desc
;
395 struct ixgbevf_rx_buffer
*bi
;
398 unsigned int bufsz
= rx_ring
->rx_buf_len
+ NET_IP_ALIGN
;
400 i
= rx_ring
->next_to_use
;
401 bi
= &rx_ring
->rx_buffer_info
[i
];
403 while (cleaned_count
--) {
404 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
407 (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)) {
409 bi
->page
= netdev_alloc_page(adapter
->netdev
);
411 adapter
->alloc_rx_page_failed
++;
416 /* use a half page if we're re-using */
417 bi
->page_offset
^= (PAGE_SIZE
/ 2);
420 bi
->page_dma
= dma_map_page(&pdev
->dev
, bi
->page
,
428 skb
= netdev_alloc_skb(adapter
->netdev
,
432 adapter
->alloc_rx_buff_failed
++;
437 * Make buffer alignment 2 beyond a 16 byte boundary
438 * this will result in a 16 byte aligned IP header after
439 * the 14 byte MAC header is removed
441 skb_reserve(skb
, NET_IP_ALIGN
);
446 bi
->dma
= dma_map_single(&pdev
->dev
, skb
->data
,
450 /* Refresh the desc even if buffer_addrs didn't change because
451 * each write-back erases this info. */
452 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
453 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
454 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
456 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
460 if (i
== rx_ring
->count
)
462 bi
= &rx_ring
->rx_buffer_info
[i
];
466 if (rx_ring
->next_to_use
!= i
) {
467 rx_ring
->next_to_use
= i
;
469 i
= (rx_ring
->count
- 1);
471 ixgbevf_release_rx_desc(&adapter
->hw
, rx_ring
, i
);
475 static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter
*adapter
,
479 struct ixgbe_hw
*hw
= &adapter
->hw
;
481 mask
= (qmask
& 0xFFFFFFFF);
482 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, mask
);
485 static inline u16
ixgbevf_get_hdr_info(union ixgbe_adv_rx_desc
*rx_desc
)
487 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
490 static inline u16
ixgbevf_get_pkt_info(union ixgbe_adv_rx_desc
*rx_desc
)
492 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
495 static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector
*q_vector
,
496 struct ixgbevf_ring
*rx_ring
,
497 int *work_done
, int work_to_do
)
499 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
500 struct pci_dev
*pdev
= adapter
->pdev
;
501 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
502 struct ixgbevf_rx_buffer
*rx_buffer_info
, *next_buffer
;
507 bool cleaned
= false;
508 int cleaned_count
= 0;
509 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
511 i
= rx_ring
->next_to_clean
;
512 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
513 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
514 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
516 while (staterr
& IXGBE_RXD_STAT_DD
) {
518 if (*work_done
>= work_to_do
)
522 rmb(); /* read descriptor and rx_buffer_info after status DD */
523 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
524 hdr_info
= le16_to_cpu(ixgbevf_get_hdr_info(rx_desc
));
525 len
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
526 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
527 if (hdr_info
& IXGBE_RXDADV_SPH
)
528 adapter
->rx_hdr_split
++;
529 if (len
> IXGBEVF_RX_HDR_SIZE
)
530 len
= IXGBEVF_RX_HDR_SIZE
;
531 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
533 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
536 skb
= rx_buffer_info
->skb
;
537 prefetch(skb
->data
- NET_IP_ALIGN
);
538 rx_buffer_info
->skb
= NULL
;
540 if (rx_buffer_info
->dma
) {
541 dma_unmap_single(&pdev
->dev
, rx_buffer_info
->dma
,
544 rx_buffer_info
->dma
= 0;
549 dma_unmap_page(&pdev
->dev
, rx_buffer_info
->page_dma
,
550 PAGE_SIZE
/ 2, DMA_FROM_DEVICE
);
551 rx_buffer_info
->page_dma
= 0;
552 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
553 rx_buffer_info
->page
,
554 rx_buffer_info
->page_offset
,
557 if ((rx_ring
->rx_buf_len
> (PAGE_SIZE
/ 2)) ||
558 (page_count(rx_buffer_info
->page
) != 1))
559 rx_buffer_info
->page
= NULL
;
561 get_page(rx_buffer_info
->page
);
563 skb
->len
+= upper_len
;
564 skb
->data_len
+= upper_len
;
565 skb
->truesize
+= upper_len
;
569 if (i
== rx_ring
->count
)
572 next_rxd
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
576 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
578 if (!(staterr
& IXGBE_RXD_STAT_EOP
)) {
579 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
580 rx_buffer_info
->skb
= next_buffer
->skb
;
581 rx_buffer_info
->dma
= next_buffer
->dma
;
582 next_buffer
->skb
= skb
;
583 next_buffer
->dma
= 0;
585 skb
->next
= next_buffer
->skb
;
586 skb
->next
->prev
= skb
;
588 adapter
->non_eop_descs
++;
592 /* ERR_MASK will only have valid bits if EOP set */
593 if (unlikely(staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
)) {
594 dev_kfree_skb_irq(skb
);
598 ixgbevf_rx_checksum(adapter
, staterr
, skb
);
600 /* probably a little skewed due to removing CRC */
601 total_rx_bytes
+= skb
->len
;
605 * Work around issue of some types of VM to VM loop back
606 * packets not getting split correctly
608 if (staterr
& IXGBE_RXD_STAT_LB
) {
609 u32 header_fixup_len
= skb_headlen(skb
);
610 if (header_fixup_len
< 14)
611 skb_push(skb
, header_fixup_len
);
613 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
615 ixgbevf_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
618 rx_desc
->wb
.upper
.status_error
= 0;
620 /* return some buffers to hardware, one at a time is too slow */
621 if (cleaned_count
>= IXGBEVF_RX_BUFFER_WRITE
) {
622 ixgbevf_alloc_rx_buffers(adapter
, rx_ring
,
627 /* use prefetched values */
629 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
631 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
634 rx_ring
->next_to_clean
= i
;
635 cleaned_count
= IXGBE_DESC_UNUSED(rx_ring
);
638 ixgbevf_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
640 rx_ring
->total_packets
+= total_rx_packets
;
641 rx_ring
->total_bytes
+= total_rx_bytes
;
642 adapter
->netdev
->stats
.rx_bytes
+= total_rx_bytes
;
643 adapter
->netdev
->stats
.rx_packets
+= total_rx_packets
;
649 * ixgbevf_clean_rxonly - msix (aka one shot) rx clean routine
650 * @napi: napi struct with our devices info in it
651 * @budget: amount of work driver is allowed to do this pass, in packets
653 * This function is optimized for cleaning one queue only on a single
656 static int ixgbevf_clean_rxonly(struct napi_struct
*napi
, int budget
)
658 struct ixgbevf_q_vector
*q_vector
=
659 container_of(napi
, struct ixgbevf_q_vector
, napi
);
660 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
661 struct ixgbevf_ring
*rx_ring
= NULL
;
665 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
666 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
668 ixgbevf_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
670 /* If all Rx work done, exit the polling mode */
671 if (work_done
< budget
) {
673 if (adapter
->itr_setting
& 1)
674 ixgbevf_set_itr_msix(q_vector
);
675 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
676 ixgbevf_irq_enable_queues(adapter
, rx_ring
->v_idx
);
683 * ixgbevf_clean_rxonly_many - msix (aka one shot) rx clean routine
684 * @napi: napi struct with our devices info in it
685 * @budget: amount of work driver is allowed to do this pass, in packets
687 * This function will clean more than one rx queue associated with a
690 static int ixgbevf_clean_rxonly_many(struct napi_struct
*napi
, int budget
)
692 struct ixgbevf_q_vector
*q_vector
=
693 container_of(napi
, struct ixgbevf_q_vector
, napi
);
694 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
695 struct ixgbevf_ring
*rx_ring
= NULL
;
696 int work_done
= 0, i
;
700 /* attempt to distribute budget to each queue fairly, but don't allow
701 * the budget to go below 1 because we'll exit polling */
702 budget
/= (q_vector
->rxr_count
?: 1);
703 budget
= max(budget
, 1);
704 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
705 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
706 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
707 ixgbevf_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
708 enable_mask
|= rx_ring
->v_idx
;
709 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
713 #ifndef HAVE_NETDEV_NAPI_LIST
714 if (!netif_running(adapter
->netdev
))
718 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
719 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
721 /* If all Rx work done, exit the polling mode */
722 if (work_done
< budget
) {
724 if (adapter
->itr_setting
& 1)
725 ixgbevf_set_itr_msix(q_vector
);
726 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
727 ixgbevf_irq_enable_queues(adapter
, enable_mask
);
735 * ixgbevf_configure_msix - Configure MSI-X hardware
736 * @adapter: board private structure
738 * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X
741 static void ixgbevf_configure_msix(struct ixgbevf_adapter
*adapter
)
743 struct ixgbevf_q_vector
*q_vector
;
744 struct ixgbe_hw
*hw
= &adapter
->hw
;
745 int i
, j
, q_vectors
, v_idx
, r_idx
;
748 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
751 * Populate the IVAR table and set the ITR values to the
752 * corresponding register.
754 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
755 q_vector
= adapter
->q_vector
[v_idx
];
756 /* XXX for_each_set_bit(...) */
757 r_idx
= find_first_bit(q_vector
->rxr_idx
,
758 adapter
->num_rx_queues
);
760 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
761 j
= adapter
->rx_ring
[r_idx
].reg_idx
;
762 ixgbevf_set_ivar(adapter
, 0, j
, v_idx
);
763 r_idx
= find_next_bit(q_vector
->rxr_idx
,
764 adapter
->num_rx_queues
,
767 r_idx
= find_first_bit(q_vector
->txr_idx
,
768 adapter
->num_tx_queues
);
770 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
771 j
= adapter
->tx_ring
[r_idx
].reg_idx
;
772 ixgbevf_set_ivar(adapter
, 1, j
, v_idx
);
773 r_idx
= find_next_bit(q_vector
->txr_idx
,
774 adapter
->num_tx_queues
,
778 /* if this is a tx only vector halve the interrupt rate */
779 if (q_vector
->txr_count
&& !q_vector
->rxr_count
)
780 q_vector
->eitr
= (adapter
->eitr_param
>> 1);
781 else if (q_vector
->rxr_count
)
783 q_vector
->eitr
= adapter
->eitr_param
;
785 ixgbevf_write_eitr(adapter
, v_idx
, q_vector
->eitr
);
788 ixgbevf_set_ivar(adapter
, -1, 1, v_idx
);
790 /* set up to autoclear timer, and the vectors */
791 mask
= IXGBE_EIMS_ENABLE_MASK
;
792 mask
&= ~IXGBE_EIMS_OTHER
;
793 IXGBE_WRITE_REG(hw
, IXGBE_VTEIAC
, mask
);
800 latency_invalid
= 255
804 * ixgbevf_update_itr - update the dynamic ITR value based on statistics
805 * @adapter: pointer to adapter
806 * @eitr: eitr setting (ints per sec) to give last timeslice
807 * @itr_setting: current throttle rate in ints/second
808 * @packets: the number of packets during this measurement interval
809 * @bytes: the number of bytes during this measurement interval
811 * Stores a new ITR value based on packets and byte
812 * counts during the last interrupt. The advantage of per interrupt
813 * computation is faster updates and more accurate ITR for the current
814 * traffic pattern. Constants in this function were computed
815 * based on theoretical maximum wire speed and thresholds were set based
816 * on testing data as well as attempting to minimize response time
817 * while increasing bulk throughput.
819 static u8
ixgbevf_update_itr(struct ixgbevf_adapter
*adapter
,
820 u32 eitr
, u8 itr_setting
,
821 int packets
, int bytes
)
823 unsigned int retval
= itr_setting
;
828 goto update_itr_done
;
831 /* simple throttlerate management
832 * 0-20MB/s lowest (100000 ints/s)
833 * 20-100MB/s low (20000 ints/s)
834 * 100-1249MB/s bulk (8000 ints/s)
836 /* what was last interrupt timeslice? */
837 timepassed_us
= 1000000/eitr
;
838 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
840 switch (itr_setting
) {
842 if (bytes_perint
> adapter
->eitr_low
)
843 retval
= low_latency
;
846 if (bytes_perint
> adapter
->eitr_high
)
847 retval
= bulk_latency
;
848 else if (bytes_perint
<= adapter
->eitr_low
)
849 retval
= lowest_latency
;
852 if (bytes_perint
<= adapter
->eitr_high
)
853 retval
= low_latency
;
862 * ixgbevf_write_eitr - write VTEITR register in hardware specific way
863 * @adapter: pointer to adapter struct
864 * @v_idx: vector index into q_vector array
865 * @itr_reg: new value to be written in *register* format, not ints/s
867 * This function is made to be called by ethtool and by the driver
868 * when it needs to update VTEITR registers at runtime. Hardware
869 * specific quirks/differences are taken care of here.
871 static void ixgbevf_write_eitr(struct ixgbevf_adapter
*adapter
, int v_idx
,
874 struct ixgbe_hw
*hw
= &adapter
->hw
;
876 itr_reg
= EITR_INTS_PER_SEC_TO_REG(itr_reg
);
879 * set the WDIS bit to not clear the timer bits and cause an
880 * immediate assertion of the interrupt
882 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
884 IXGBE_WRITE_REG(hw
, IXGBE_VTEITR(v_idx
), itr_reg
);
887 static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector
*q_vector
)
889 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
891 u8 current_itr
, ret_itr
;
892 int i
, r_idx
, v_idx
= q_vector
->v_idx
;
893 struct ixgbevf_ring
*rx_ring
, *tx_ring
;
895 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
896 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
897 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
898 ret_itr
= ixgbevf_update_itr(adapter
, q_vector
->eitr
,
900 tx_ring
->total_packets
,
901 tx_ring
->total_bytes
);
902 /* if the result for this queue would decrease interrupt
903 * rate for this vector then use that result */
904 q_vector
->tx_itr
= ((q_vector
->tx_itr
> ret_itr
) ?
905 q_vector
->tx_itr
- 1 : ret_itr
);
906 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
910 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
911 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
912 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
913 ret_itr
= ixgbevf_update_itr(adapter
, q_vector
->eitr
,
915 rx_ring
->total_packets
,
916 rx_ring
->total_bytes
);
917 /* if the result for this queue would decrease interrupt
918 * rate for this vector then use that result */
919 q_vector
->rx_itr
= ((q_vector
->rx_itr
> ret_itr
) ?
920 q_vector
->rx_itr
- 1 : ret_itr
);
921 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
925 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
927 switch (current_itr
) {
928 /* counts and packets in update_itr are dependent on these numbers */
933 new_itr
= 20000; /* aka hwitr = ~200 */
941 if (new_itr
!= q_vector
->eitr
) {
944 /* save the algorithm value here, not the smoothed one */
945 q_vector
->eitr
= new_itr
;
946 /* do an exponential smoothing */
947 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
948 itr_reg
= EITR_INTS_PER_SEC_TO_REG(new_itr
);
949 ixgbevf_write_eitr(adapter
, v_idx
, itr_reg
);
953 static irqreturn_t
ixgbevf_msix_mbx(int irq
, void *data
)
955 struct net_device
*netdev
= data
;
956 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
957 struct ixgbe_hw
*hw
= &adapter
->hw
;
961 eicr
= IXGBE_READ_REG(hw
, IXGBE_VTEICS
);
962 IXGBE_WRITE_REG(hw
, IXGBE_VTEICR
, eicr
);
964 if (!hw
->mbx
.ops
.check_for_ack(hw
)) {
966 * checking for the ack clears the PFACK bit. Place
967 * it back in the v2p_mailbox cache so that anyone
968 * polling for an ack will not miss it. Also
969 * avoid the read below because the code to read
970 * the mailbox will also clear the ack bit. This was
971 * causing lost acks. Just cache the bit and exit
974 hw
->mbx
.v2p_mailbox
|= IXGBE_VFMAILBOX_PFACK
;
978 /* Not an ack interrupt, go ahead and read the message */
979 hw
->mbx
.ops
.read(hw
, &msg
, 1);
981 if ((msg
& IXGBE_MBVFICR_VFREQ_MASK
) == IXGBE_PF_CONTROL_MSG
)
982 mod_timer(&adapter
->watchdog_timer
,
983 round_jiffies(jiffies
+ 1));
989 static irqreturn_t
ixgbevf_msix_clean_tx(int irq
, void *data
)
991 struct ixgbevf_q_vector
*q_vector
= data
;
992 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
993 struct ixgbevf_ring
*tx_ring
;
996 if (!q_vector
->txr_count
)
999 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
1000 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
1001 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
1002 tx_ring
->total_bytes
= 0;
1003 tx_ring
->total_packets
= 0;
1004 ixgbevf_clean_tx_irq(adapter
, tx_ring
);
1005 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1009 if (adapter
->itr_setting
& 1)
1010 ixgbevf_set_itr_msix(q_vector
);
1016 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1018 * @data: pointer to our q_vector struct for this interrupt vector
1020 static irqreturn_t
ixgbevf_msix_clean_rx(int irq
, void *data
)
1022 struct ixgbevf_q_vector
*q_vector
= data
;
1023 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
1024 struct ixgbe_hw
*hw
= &adapter
->hw
;
1025 struct ixgbevf_ring
*rx_ring
;
1029 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1030 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1031 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1032 rx_ring
->total_bytes
= 0;
1033 rx_ring
->total_packets
= 0;
1034 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1038 if (!q_vector
->rxr_count
)
1041 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1042 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1043 /* disable interrupts on this vector only */
1044 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, rx_ring
->v_idx
);
1045 napi_schedule(&q_vector
->napi
);
1051 static irqreturn_t
ixgbevf_msix_clean_many(int irq
, void *data
)
1053 ixgbevf_msix_clean_rx(irq
, data
);
1054 ixgbevf_msix_clean_tx(irq
, data
);
1059 static inline void map_vector_to_rxq(struct ixgbevf_adapter
*a
, int v_idx
,
1062 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1064 set_bit(r_idx
, q_vector
->rxr_idx
);
1065 q_vector
->rxr_count
++;
1066 a
->rx_ring
[r_idx
].v_idx
= 1 << v_idx
;
1069 static inline void map_vector_to_txq(struct ixgbevf_adapter
*a
, int v_idx
,
1072 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1074 set_bit(t_idx
, q_vector
->txr_idx
);
1075 q_vector
->txr_count
++;
1076 a
->tx_ring
[t_idx
].v_idx
= 1 << v_idx
;
1080 * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
1081 * @adapter: board private structure to initialize
1083 * This function maps descriptor rings to the queue-specific vectors
1084 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1085 * one vector per ring/queue, but on a constrained vector budget, we
1086 * group the rings as "efficiently" as possible. You would add new
1087 * mapping configurations in here.
1089 static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter
*adapter
)
1093 int rxr_idx
= 0, txr_idx
= 0;
1094 int rxr_remaining
= adapter
->num_rx_queues
;
1095 int txr_remaining
= adapter
->num_tx_queues
;
1100 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1103 * The ideal configuration...
1104 * We have enough vectors to map one per queue.
1106 if (q_vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
1107 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
1108 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
1110 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
1111 map_vector_to_txq(adapter
, v_start
, txr_idx
);
1116 * If we don't have enough vectors for a 1-to-1
1117 * mapping, we'll have to group them so there are
1118 * multiple queues per vector.
1120 /* Re-adjusting *qpv takes care of the remainder. */
1121 for (i
= v_start
; i
< q_vectors
; i
++) {
1122 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
1123 for (j
= 0; j
< rqpv
; j
++) {
1124 map_vector_to_rxq(adapter
, i
, rxr_idx
);
1129 for (i
= v_start
; i
< q_vectors
; i
++) {
1130 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
1131 for (j
= 0; j
< tqpv
; j
++) {
1132 map_vector_to_txq(adapter
, i
, txr_idx
);
1143 * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
1144 * @adapter: board private structure
1146 * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
1147 * interrupts from the kernel.
1149 static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter
*adapter
)
1151 struct net_device
*netdev
= adapter
->netdev
;
1152 irqreturn_t (*handler
)(int, void *);
1153 int i
, vector
, q_vectors
, err
;
1156 /* Decrement for Other and TCP Timer vectors */
1157 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1159 #define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
1160 ? &ixgbevf_msix_clean_many : \
1161 (_v)->rxr_count ? &ixgbevf_msix_clean_rx : \
1162 (_v)->txr_count ? &ixgbevf_msix_clean_tx : \
1164 for (vector
= 0; vector
< q_vectors
; vector
++) {
1165 handler
= SET_HANDLER(adapter
->q_vector
[vector
]);
1167 if (handler
== &ixgbevf_msix_clean_rx
) {
1168 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1169 netdev
->name
, "rx", ri
++);
1170 } else if (handler
== &ixgbevf_msix_clean_tx
) {
1171 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1172 netdev
->name
, "tx", ti
++);
1173 } else if (handler
== &ixgbevf_msix_clean_many
) {
1174 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1175 netdev
->name
, "TxRx", vector
);
1177 /* skip this unused q_vector */
1180 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1181 handler
, 0, adapter
->name
[vector
],
1182 adapter
->q_vector
[vector
]);
1184 hw_dbg(&adapter
->hw
,
1185 "request_irq failed for MSIX interrupt "
1186 "Error: %d\n", err
);
1187 goto free_queue_irqs
;
1191 sprintf(adapter
->name
[vector
], "%s:mbx", netdev
->name
);
1192 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1193 &ixgbevf_msix_mbx
, 0, adapter
->name
[vector
], netdev
);
1195 hw_dbg(&adapter
->hw
,
1196 "request_irq for msix_mbx failed: %d\n", err
);
1197 goto free_queue_irqs
;
1203 for (i
= vector
- 1; i
>= 0; i
--)
1204 free_irq(adapter
->msix_entries
[--vector
].vector
,
1205 &(adapter
->q_vector
[i
]));
1206 pci_disable_msix(adapter
->pdev
);
1207 kfree(adapter
->msix_entries
);
1208 adapter
->msix_entries
= NULL
;
1212 static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter
*adapter
)
1214 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1216 for (i
= 0; i
< q_vectors
; i
++) {
1217 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[i
];
1218 bitmap_zero(q_vector
->rxr_idx
, MAX_RX_QUEUES
);
1219 bitmap_zero(q_vector
->txr_idx
, MAX_TX_QUEUES
);
1220 q_vector
->rxr_count
= 0;
1221 q_vector
->txr_count
= 0;
1222 q_vector
->eitr
= adapter
->eitr_param
;
1227 * ixgbevf_request_irq - initialize interrupts
1228 * @adapter: board private structure
1230 * Attempts to configure interrupts using the best available
1231 * capabilities of the hardware and kernel.
1233 static int ixgbevf_request_irq(struct ixgbevf_adapter
*adapter
)
1237 err
= ixgbevf_request_msix_irqs(adapter
);
1240 hw_dbg(&adapter
->hw
,
1241 "request_irq failed, Error %d\n", err
);
1246 static void ixgbevf_free_irq(struct ixgbevf_adapter
*adapter
)
1248 struct net_device
*netdev
= adapter
->netdev
;
1251 q_vectors
= adapter
->num_msix_vectors
;
1255 free_irq(adapter
->msix_entries
[i
].vector
, netdev
);
1258 for (; i
>= 0; i
--) {
1259 free_irq(adapter
->msix_entries
[i
].vector
,
1260 adapter
->q_vector
[i
]);
1263 ixgbevf_reset_q_vectors(adapter
);
1267 * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
1268 * @adapter: board private structure
1270 static inline void ixgbevf_irq_disable(struct ixgbevf_adapter
*adapter
)
1273 struct ixgbe_hw
*hw
= &adapter
->hw
;
1275 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, ~0);
1277 IXGBE_WRITE_FLUSH(hw
);
1279 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
1280 synchronize_irq(adapter
->msix_entries
[i
].vector
);
1284 * ixgbevf_irq_enable - Enable default interrupt generation settings
1285 * @adapter: board private structure
1287 static inline void ixgbevf_irq_enable(struct ixgbevf_adapter
*adapter
,
1288 bool queues
, bool flush
)
1290 struct ixgbe_hw
*hw
= &adapter
->hw
;
1294 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
1297 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, mask
);
1300 ixgbevf_irq_enable_queues(adapter
, qmask
);
1303 IXGBE_WRITE_FLUSH(hw
);
1307 * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
1308 * @adapter: board private structure
1310 * Configure the Tx unit of the MAC after a reset.
1312 static void ixgbevf_configure_tx(struct ixgbevf_adapter
*adapter
)
1315 struct ixgbe_hw
*hw
= &adapter
->hw
;
1316 u32 i
, j
, tdlen
, txctrl
;
1318 /* Setup the HW Tx Head and Tail descriptor pointers */
1319 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1320 struct ixgbevf_ring
*ring
= &adapter
->tx_ring
[i
];
1323 tdlen
= ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
1324 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAL(j
),
1325 (tdba
& DMA_BIT_MASK(32)));
1326 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAH(j
), (tdba
>> 32));
1327 IXGBE_WRITE_REG(hw
, IXGBE_VFTDLEN(j
), tdlen
);
1328 IXGBE_WRITE_REG(hw
, IXGBE_VFTDH(j
), 0);
1329 IXGBE_WRITE_REG(hw
, IXGBE_VFTDT(j
), 0);
1330 adapter
->tx_ring
[i
].head
= IXGBE_VFTDH(j
);
1331 adapter
->tx_ring
[i
].tail
= IXGBE_VFTDT(j
);
1332 /* Disable Tx Head Writeback RO bit, since this hoses
1333 * bookkeeping if things aren't delivered in order.
1335 txctrl
= IXGBE_READ_REG(hw
, IXGBE_VFDCA_TXCTRL(j
));
1336 txctrl
&= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN
;
1337 IXGBE_WRITE_REG(hw
, IXGBE_VFDCA_TXCTRL(j
), txctrl
);
1341 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1343 static void ixgbevf_configure_srrctl(struct ixgbevf_adapter
*adapter
, int index
)
1345 struct ixgbevf_ring
*rx_ring
;
1346 struct ixgbe_hw
*hw
= &adapter
->hw
;
1349 rx_ring
= &adapter
->rx_ring
[index
];
1351 srrctl
= IXGBE_SRRCTL_DROP_EN
;
1353 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1354 u16 bufsz
= IXGBEVF_RXBUFFER_2048
;
1355 /* grow the amount we can receive on large page machines */
1356 if (bufsz
< (PAGE_SIZE
/ 2))
1357 bufsz
= (PAGE_SIZE
/ 2);
1358 /* cap the bufsz at our largest descriptor size */
1359 bufsz
= min((u16
)IXGBEVF_MAX_RXBUFFER
, bufsz
);
1361 srrctl
|= bufsz
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1362 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
1363 srrctl
|= ((IXGBEVF_RX_HDR_SIZE
<<
1364 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
1365 IXGBE_SRRCTL_BSIZEHDR_MASK
);
1367 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1369 if (rx_ring
->rx_buf_len
== MAXIMUM_ETHERNET_VLAN_SIZE
)
1370 srrctl
|= IXGBEVF_RXBUFFER_2048
>>
1371 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1373 srrctl
|= rx_ring
->rx_buf_len
>>
1374 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1376 IXGBE_WRITE_REG(hw
, IXGBE_VFSRRCTL(index
), srrctl
);
1380 * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
1381 * @adapter: board private structure
1383 * Configure the Rx unit of the MAC after a reset.
1385 static void ixgbevf_configure_rx(struct ixgbevf_adapter
*adapter
)
1388 struct ixgbe_hw
*hw
= &adapter
->hw
;
1389 struct net_device
*netdev
= adapter
->netdev
;
1390 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1395 /* Decide whether to use packet split mode or not */
1396 if (netdev
->mtu
> ETH_DATA_LEN
) {
1397 if (adapter
->flags
& IXGBE_FLAG_RX_PS_CAPABLE
)
1398 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
1400 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
1402 if (adapter
->flags
& IXGBE_FLAG_RX_1BUF_CAPABLE
)
1403 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
1405 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
1408 /* Set the RX buffer length according to the mode */
1409 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1410 /* PSRTYPE must be initialized in 82599 */
1411 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
1412 IXGBE_PSRTYPE_UDPHDR
|
1413 IXGBE_PSRTYPE_IPV4HDR
|
1414 IXGBE_PSRTYPE_IPV6HDR
|
1415 IXGBE_PSRTYPE_L2HDR
;
1416 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, psrtype
);
1417 rx_buf_len
= IXGBEVF_RX_HDR_SIZE
;
1419 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, 0);
1420 if (netdev
->mtu
<= ETH_DATA_LEN
)
1421 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1423 rx_buf_len
= ALIGN(max_frame
, 1024);
1426 rdlen
= adapter
->rx_ring
[0].count
* sizeof(union ixgbe_adv_rx_desc
);
1427 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1428 * the Base and Length of the Rx Descriptor Ring */
1429 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1430 rdba
= adapter
->rx_ring
[i
].dma
;
1431 j
= adapter
->rx_ring
[i
].reg_idx
;
1432 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAL(j
),
1433 (rdba
& DMA_BIT_MASK(32)));
1434 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAH(j
), (rdba
>> 32));
1435 IXGBE_WRITE_REG(hw
, IXGBE_VFRDLEN(j
), rdlen
);
1436 IXGBE_WRITE_REG(hw
, IXGBE_VFRDH(j
), 0);
1437 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(j
), 0);
1438 adapter
->rx_ring
[i
].head
= IXGBE_VFRDH(j
);
1439 adapter
->rx_ring
[i
].tail
= IXGBE_VFRDT(j
);
1440 adapter
->rx_ring
[i
].rx_buf_len
= rx_buf_len
;
1442 ixgbevf_configure_srrctl(adapter
, j
);
1446 static void ixgbevf_vlan_rx_register(struct net_device
*netdev
,
1447 struct vlan_group
*grp
)
1449 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1450 struct ixgbe_hw
*hw
= &adapter
->hw
;
1454 adapter
->vlgrp
= grp
;
1456 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1457 j
= adapter
->rx_ring
[i
].reg_idx
;
1458 ctrl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1459 ctrl
|= IXGBE_RXDCTL_VME
;
1460 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), ctrl
);
1464 static void ixgbevf_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
1466 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1467 struct ixgbe_hw
*hw
= &adapter
->hw
;
1469 /* add VID to filter table */
1470 if (hw
->mac
.ops
.set_vfta
)
1471 hw
->mac
.ops
.set_vfta(hw
, vid
, 0, true);
1474 static void ixgbevf_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
1476 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1477 struct ixgbe_hw
*hw
= &adapter
->hw
;
1479 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
1480 ixgbevf_irq_disable(adapter
);
1482 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
1484 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
1485 ixgbevf_irq_enable(adapter
, true, true);
1487 /* remove VID from filter table */
1488 if (hw
->mac
.ops
.set_vfta
)
1489 hw
->mac
.ops
.set_vfta(hw
, vid
, 0, false);
1492 static void ixgbevf_restore_vlan(struct ixgbevf_adapter
*adapter
)
1494 ixgbevf_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
1496 if (adapter
->vlgrp
) {
1498 for (vid
= 0; vid
< VLAN_N_VID
; vid
++) {
1499 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
1501 ixgbevf_vlan_rx_add_vid(adapter
->netdev
, vid
);
1507 * ixgbevf_set_rx_mode - Multicast set
1508 * @netdev: network interface device structure
1510 * The set_rx_method entry point is called whenever the multicast address
1511 * list or the network interface flags are updated. This routine is
1512 * responsible for configuring the hardware for proper multicast mode.
1514 static void ixgbevf_set_rx_mode(struct net_device
*netdev
)
1516 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1517 struct ixgbe_hw
*hw
= &adapter
->hw
;
1519 /* reprogram multicast list */
1520 if (hw
->mac
.ops
.update_mc_addr_list
)
1521 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
1524 static void ixgbevf_napi_enable_all(struct ixgbevf_adapter
*adapter
)
1527 struct ixgbevf_q_vector
*q_vector
;
1528 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1530 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1531 struct napi_struct
*napi
;
1532 q_vector
= adapter
->q_vector
[q_idx
];
1533 if (!q_vector
->rxr_count
)
1535 napi
= &q_vector
->napi
;
1536 if (q_vector
->rxr_count
> 1)
1537 napi
->poll
= &ixgbevf_clean_rxonly_many
;
1543 static void ixgbevf_napi_disable_all(struct ixgbevf_adapter
*adapter
)
1546 struct ixgbevf_q_vector
*q_vector
;
1547 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1549 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1550 q_vector
= adapter
->q_vector
[q_idx
];
1551 if (!q_vector
->rxr_count
)
1553 napi_disable(&q_vector
->napi
);
1557 static void ixgbevf_configure(struct ixgbevf_adapter
*adapter
)
1559 struct net_device
*netdev
= adapter
->netdev
;
1562 ixgbevf_set_rx_mode(netdev
);
1564 ixgbevf_restore_vlan(adapter
);
1566 ixgbevf_configure_tx(adapter
);
1567 ixgbevf_configure_rx(adapter
);
1568 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1569 struct ixgbevf_ring
*ring
= &adapter
->rx_ring
[i
];
1570 ixgbevf_alloc_rx_buffers(adapter
, ring
, ring
->count
);
1571 ring
->next_to_use
= ring
->count
- 1;
1572 writel(ring
->next_to_use
, adapter
->hw
.hw_addr
+ ring
->tail
);
1576 #define IXGBE_MAX_RX_DESC_POLL 10
1577 static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter
*adapter
,
1580 struct ixgbe_hw
*hw
= &adapter
->hw
;
1581 int j
= adapter
->rx_ring
[rxr
].reg_idx
;
1584 for (k
= 0; k
< IXGBE_MAX_RX_DESC_POLL
; k
++) {
1585 if (IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
)) & IXGBE_RXDCTL_ENABLE
)
1590 if (k
>= IXGBE_MAX_RX_DESC_POLL
) {
1591 hw_dbg(hw
, "RXDCTL.ENABLE on Rx queue %d "
1592 "not set within the polling period\n", rxr
);
1595 ixgbevf_release_rx_desc(&adapter
->hw
, &adapter
->rx_ring
[rxr
],
1596 (adapter
->rx_ring
[rxr
].count
- 1));
1599 static void ixgbevf_save_reset_stats(struct ixgbevf_adapter
*adapter
)
1601 /* Only save pre-reset stats if there are some */
1602 if (adapter
->stats
.vfgprc
|| adapter
->stats
.vfgptc
) {
1603 adapter
->stats
.saved_reset_vfgprc
+= adapter
->stats
.vfgprc
-
1604 adapter
->stats
.base_vfgprc
;
1605 adapter
->stats
.saved_reset_vfgptc
+= adapter
->stats
.vfgptc
-
1606 adapter
->stats
.base_vfgptc
;
1607 adapter
->stats
.saved_reset_vfgorc
+= adapter
->stats
.vfgorc
-
1608 adapter
->stats
.base_vfgorc
;
1609 adapter
->stats
.saved_reset_vfgotc
+= adapter
->stats
.vfgotc
-
1610 adapter
->stats
.base_vfgotc
;
1611 adapter
->stats
.saved_reset_vfmprc
+= adapter
->stats
.vfmprc
-
1612 adapter
->stats
.base_vfmprc
;
1616 static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter
*adapter
)
1618 struct ixgbe_hw
*hw
= &adapter
->hw
;
1620 adapter
->stats
.last_vfgprc
= IXGBE_READ_REG(hw
, IXGBE_VFGPRC
);
1621 adapter
->stats
.last_vfgorc
= IXGBE_READ_REG(hw
, IXGBE_VFGORC_LSB
);
1622 adapter
->stats
.last_vfgorc
|=
1623 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGORC_MSB
))) << 32);
1624 adapter
->stats
.last_vfgptc
= IXGBE_READ_REG(hw
, IXGBE_VFGPTC
);
1625 adapter
->stats
.last_vfgotc
= IXGBE_READ_REG(hw
, IXGBE_VFGOTC_LSB
);
1626 adapter
->stats
.last_vfgotc
|=
1627 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGOTC_MSB
))) << 32);
1628 adapter
->stats
.last_vfmprc
= IXGBE_READ_REG(hw
, IXGBE_VFMPRC
);
1630 adapter
->stats
.base_vfgprc
= adapter
->stats
.last_vfgprc
;
1631 adapter
->stats
.base_vfgorc
= adapter
->stats
.last_vfgorc
;
1632 adapter
->stats
.base_vfgptc
= adapter
->stats
.last_vfgptc
;
1633 adapter
->stats
.base_vfgotc
= adapter
->stats
.last_vfgotc
;
1634 adapter
->stats
.base_vfmprc
= adapter
->stats
.last_vfmprc
;
1637 static int ixgbevf_up_complete(struct ixgbevf_adapter
*adapter
)
1639 struct net_device
*netdev
= adapter
->netdev
;
1640 struct ixgbe_hw
*hw
= &adapter
->hw
;
1642 int num_rx_rings
= adapter
->num_rx_queues
;
1645 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1646 j
= adapter
->tx_ring
[i
].reg_idx
;
1647 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1648 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
1649 txdctl
|= (8 << 16);
1650 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1653 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1654 j
= adapter
->tx_ring
[i
].reg_idx
;
1655 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1656 txdctl
|= IXGBE_TXDCTL_ENABLE
;
1657 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1660 for (i
= 0; i
< num_rx_rings
; i
++) {
1661 j
= adapter
->rx_ring
[i
].reg_idx
;
1662 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1663 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
1664 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), rxdctl
);
1665 ixgbevf_rx_desc_queue_enable(adapter
, i
);
1668 ixgbevf_configure_msix(adapter
);
1670 if (hw
->mac
.ops
.set_rar
) {
1671 if (is_valid_ether_addr(hw
->mac
.addr
))
1672 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
1674 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.perm_addr
, 0);
1677 clear_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1678 ixgbevf_napi_enable_all(adapter
);
1680 /* enable transmits */
1681 netif_tx_start_all_queues(netdev
);
1683 ixgbevf_save_reset_stats(adapter
);
1684 ixgbevf_init_last_counter_stats(adapter
);
1686 /* bring the link up in the watchdog, this could race with our first
1687 * link up interrupt but shouldn't be a problem */
1688 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1689 adapter
->link_check_timeout
= jiffies
;
1690 mod_timer(&adapter
->watchdog_timer
, jiffies
);
1694 int ixgbevf_up(struct ixgbevf_adapter
*adapter
)
1697 struct ixgbe_hw
*hw
= &adapter
->hw
;
1699 ixgbevf_configure(adapter
);
1701 err
= ixgbevf_up_complete(adapter
);
1703 /* clear any pending interrupts, may auto mask */
1704 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
1706 ixgbevf_irq_enable(adapter
, true, true);
1712 * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
1713 * @adapter: board private structure
1714 * @rx_ring: ring to free buffers from
1716 static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter
*adapter
,
1717 struct ixgbevf_ring
*rx_ring
)
1719 struct pci_dev
*pdev
= adapter
->pdev
;
1723 if (!rx_ring
->rx_buffer_info
)
1726 /* Free all the Rx ring sk_buffs */
1727 for (i
= 0; i
< rx_ring
->count
; i
++) {
1728 struct ixgbevf_rx_buffer
*rx_buffer_info
;
1730 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1731 if (rx_buffer_info
->dma
) {
1732 dma_unmap_single(&pdev
->dev
, rx_buffer_info
->dma
,
1733 rx_ring
->rx_buf_len
,
1735 rx_buffer_info
->dma
= 0;
1737 if (rx_buffer_info
->skb
) {
1738 struct sk_buff
*skb
= rx_buffer_info
->skb
;
1739 rx_buffer_info
->skb
= NULL
;
1741 struct sk_buff
*this = skb
;
1743 dev_kfree_skb(this);
1746 if (!rx_buffer_info
->page
)
1748 dma_unmap_page(&pdev
->dev
, rx_buffer_info
->page_dma
,
1749 PAGE_SIZE
/ 2, DMA_FROM_DEVICE
);
1750 rx_buffer_info
->page_dma
= 0;
1751 put_page(rx_buffer_info
->page
);
1752 rx_buffer_info
->page
= NULL
;
1753 rx_buffer_info
->page_offset
= 0;
1756 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
1757 memset(rx_ring
->rx_buffer_info
, 0, size
);
1759 /* Zero out the descriptor ring */
1760 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1762 rx_ring
->next_to_clean
= 0;
1763 rx_ring
->next_to_use
= 0;
1766 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1768 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1772 * ixgbevf_clean_tx_ring - Free Tx Buffers
1773 * @adapter: board private structure
1774 * @tx_ring: ring to be cleaned
1776 static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter
*adapter
,
1777 struct ixgbevf_ring
*tx_ring
)
1779 struct ixgbevf_tx_buffer
*tx_buffer_info
;
1783 if (!tx_ring
->tx_buffer_info
)
1786 /* Free all the Tx ring sk_buffs */
1788 for (i
= 0; i
< tx_ring
->count
; i
++) {
1789 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
1790 ixgbevf_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
1793 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
1794 memset(tx_ring
->tx_buffer_info
, 0, size
);
1796 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1798 tx_ring
->next_to_use
= 0;
1799 tx_ring
->next_to_clean
= 0;
1802 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1804 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1808 * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
1809 * @adapter: board private structure
1811 static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter
*adapter
)
1815 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1816 ixgbevf_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
1820 * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
1821 * @adapter: board private structure
1823 static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter
*adapter
)
1827 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1828 ixgbevf_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1831 void ixgbevf_down(struct ixgbevf_adapter
*adapter
)
1833 struct net_device
*netdev
= adapter
->netdev
;
1834 struct ixgbe_hw
*hw
= &adapter
->hw
;
1838 /* signal that we are down to the interrupt handler */
1839 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1840 /* disable receives */
1842 netif_tx_disable(netdev
);
1846 netif_tx_stop_all_queues(netdev
);
1848 ixgbevf_irq_disable(adapter
);
1850 ixgbevf_napi_disable_all(adapter
);
1852 del_timer_sync(&adapter
->watchdog_timer
);
1853 /* can't call flush scheduled work here because it can deadlock
1854 * if linkwatch_event tries to acquire the rtnl_lock which we are
1856 while (adapter
->flags
& IXGBE_FLAG_IN_WATCHDOG_TASK
)
1859 /* disable transmits in the hardware now that interrupts are off */
1860 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1861 j
= adapter
->tx_ring
[i
].reg_idx
;
1862 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1863 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
),
1864 (txdctl
& ~IXGBE_TXDCTL_ENABLE
));
1867 netif_carrier_off(netdev
);
1869 if (!pci_channel_offline(adapter
->pdev
))
1870 ixgbevf_reset(adapter
);
1872 ixgbevf_clean_all_tx_rings(adapter
);
1873 ixgbevf_clean_all_rx_rings(adapter
);
1876 void ixgbevf_reinit_locked(struct ixgbevf_adapter
*adapter
)
1878 struct ixgbe_hw
*hw
= &adapter
->hw
;
1880 WARN_ON(in_interrupt());
1882 while (test_and_set_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
1886 * Check if PF is up before re-init. If not then skip until
1887 * later when the PF is up and ready to service requests from
1888 * the VF via mailbox. If the VF is up and running then the
1889 * watchdog task will continue to schedule reset tasks until
1890 * the PF is up and running.
1892 if (!hw
->mac
.ops
.reset_hw(hw
)) {
1893 ixgbevf_down(adapter
);
1894 ixgbevf_up(adapter
);
1897 clear_bit(__IXGBEVF_RESETTING
, &adapter
->state
);
1900 void ixgbevf_reset(struct ixgbevf_adapter
*adapter
)
1902 struct ixgbe_hw
*hw
= &adapter
->hw
;
1903 struct net_device
*netdev
= adapter
->netdev
;
1905 if (hw
->mac
.ops
.reset_hw(hw
))
1906 hw_dbg(hw
, "PF still resetting\n");
1908 hw
->mac
.ops
.init_hw(hw
);
1910 if (is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
1911 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
,
1913 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
,
1918 static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter
*adapter
,
1921 int err
, vector_threshold
;
1923 /* We'll want at least 3 (vector_threshold):
1926 * 3) Other (Link Status Change, etc.)
1928 vector_threshold
= MIN_MSIX_COUNT
;
1930 /* The more we get, the more we will assign to Tx/Rx Cleanup
1931 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1932 * Right now, we simply care about how many we'll get; we'll
1933 * set them up later while requesting irq's.
1935 while (vectors
>= vector_threshold
) {
1936 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1938 if (!err
) /* Success in acquiring all requested vectors. */
1941 vectors
= 0; /* Nasty failure, quit now */
1942 else /* err == number of vectors we should try again with */
1946 if (vectors
< vector_threshold
) {
1947 /* Can't allocate enough MSI-X interrupts? Oh well.
1948 * This just means we'll go with either a single MSI
1949 * vector or fall back to legacy interrupts.
1951 hw_dbg(&adapter
->hw
,
1952 "Unable to allocate MSI-X interrupts\n");
1953 kfree(adapter
->msix_entries
);
1954 adapter
->msix_entries
= NULL
;
1957 * Adjust for only the vectors we'll use, which is minimum
1958 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
1959 * vectors we were allocated.
1961 adapter
->num_msix_vectors
= vectors
;
1966 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
1967 * @adapter: board private structure to initialize
1969 * This is the top level queue allocation routine. The order here is very
1970 * important, starting with the "most" number of features turned on at once,
1971 * and ending with the smallest set of features. This way large combinations
1972 * can be allocated if they're turned on, and smaller combinations are the
1973 * fallthrough conditions.
1976 static void ixgbevf_set_num_queues(struct ixgbevf_adapter
*adapter
)
1978 /* Start with base case */
1979 adapter
->num_rx_queues
= 1;
1980 adapter
->num_tx_queues
= 1;
1981 adapter
->num_rx_pools
= adapter
->num_rx_queues
;
1982 adapter
->num_rx_queues_per_pool
= 1;
1986 * ixgbevf_alloc_queues - Allocate memory for all rings
1987 * @adapter: board private structure to initialize
1989 * We allocate one ring per queue at run-time since we don't know the
1990 * number of queues at compile-time. The polling_netdev array is
1991 * intended for Multiqueue, but should work fine with a single queue.
1993 static int ixgbevf_alloc_queues(struct ixgbevf_adapter
*adapter
)
1997 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1998 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
1999 if (!adapter
->tx_ring
)
2000 goto err_tx_ring_allocation
;
2002 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
2003 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
2004 if (!adapter
->rx_ring
)
2005 goto err_rx_ring_allocation
;
2007 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2008 adapter
->tx_ring
[i
].count
= adapter
->tx_ring_count
;
2009 adapter
->tx_ring
[i
].queue_index
= i
;
2010 adapter
->tx_ring
[i
].reg_idx
= i
;
2013 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2014 adapter
->rx_ring
[i
].count
= adapter
->rx_ring_count
;
2015 adapter
->rx_ring
[i
].queue_index
= i
;
2016 adapter
->rx_ring
[i
].reg_idx
= i
;
2021 err_rx_ring_allocation
:
2022 kfree(adapter
->tx_ring
);
2023 err_tx_ring_allocation
:
2028 * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
2029 * @adapter: board private structure to initialize
2031 * Attempt to configure the interrupts using the best available
2032 * capabilities of the hardware and the kernel.
2034 static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter
*adapter
)
2037 int vector
, v_budget
;
2040 * It's easy to be greedy for MSI-X vectors, but it really
2041 * doesn't do us much good if we have a lot more vectors
2042 * than CPU's. So let's be conservative and only ask for
2043 * (roughly) twice the number of vectors as there are CPU's.
2045 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
2046 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS
;
2048 /* A failure in MSI-X entry allocation isn't fatal, but it does
2049 * mean we disable MSI-X capabilities of the adapter. */
2050 adapter
->msix_entries
= kcalloc(v_budget
,
2051 sizeof(struct msix_entry
), GFP_KERNEL
);
2052 if (!adapter
->msix_entries
) {
2057 for (vector
= 0; vector
< v_budget
; vector
++)
2058 adapter
->msix_entries
[vector
].entry
= vector
;
2060 ixgbevf_acquire_msix_vectors(adapter
, v_budget
);
2067 * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
2068 * @adapter: board private structure to initialize
2070 * We allocate one q_vector per queue interrupt. If allocation fails we
2073 static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter
*adapter
)
2075 int q_idx
, num_q_vectors
;
2076 struct ixgbevf_q_vector
*q_vector
;
2078 int (*poll
)(struct napi_struct
*, int);
2080 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2081 napi_vectors
= adapter
->num_rx_queues
;
2082 poll
= &ixgbevf_clean_rxonly
;
2084 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
2085 q_vector
= kzalloc(sizeof(struct ixgbevf_q_vector
), GFP_KERNEL
);
2088 q_vector
->adapter
= adapter
;
2089 q_vector
->v_idx
= q_idx
;
2090 q_vector
->eitr
= adapter
->eitr_param
;
2091 if (q_idx
< napi_vectors
)
2092 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
2094 adapter
->q_vector
[q_idx
] = q_vector
;
2102 q_vector
= adapter
->q_vector
[q_idx
];
2103 netif_napi_del(&q_vector
->napi
);
2105 adapter
->q_vector
[q_idx
] = NULL
;
2111 * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
2112 * @adapter: board private structure to initialize
2114 * This function frees the memory allocated to the q_vectors. In addition if
2115 * NAPI is enabled it will delete any references to the NAPI struct prior
2116 * to freeing the q_vector.
2118 static void ixgbevf_free_q_vectors(struct ixgbevf_adapter
*adapter
)
2120 int q_idx
, num_q_vectors
;
2123 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2124 napi_vectors
= adapter
->num_rx_queues
;
2126 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
2127 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
2129 adapter
->q_vector
[q_idx
] = NULL
;
2130 if (q_idx
< napi_vectors
)
2131 netif_napi_del(&q_vector
->napi
);
2137 * ixgbevf_reset_interrupt_capability - Reset MSIX setup
2138 * @adapter: board private structure
2141 static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter
*adapter
)
2143 pci_disable_msix(adapter
->pdev
);
2144 kfree(adapter
->msix_entries
);
2145 adapter
->msix_entries
= NULL
;
2149 * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
2150 * @adapter: board private structure to initialize
2153 static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter
*adapter
)
2157 /* Number of supported queues */
2158 ixgbevf_set_num_queues(adapter
);
2160 err
= ixgbevf_set_interrupt_capability(adapter
);
2162 hw_dbg(&adapter
->hw
,
2163 "Unable to setup interrupt capabilities\n");
2164 goto err_set_interrupt
;
2167 err
= ixgbevf_alloc_q_vectors(adapter
);
2169 hw_dbg(&adapter
->hw
, "Unable to allocate memory for queue "
2171 goto err_alloc_q_vectors
;
2174 err
= ixgbevf_alloc_queues(adapter
);
2176 printk(KERN_ERR
"Unable to allocate memory for queues\n");
2177 goto err_alloc_queues
;
2180 hw_dbg(&adapter
->hw
, "Multiqueue %s: Rx Queue count = %u, "
2181 "Tx Queue count = %u\n",
2182 (adapter
->num_rx_queues
> 1) ? "Enabled" :
2183 "Disabled", adapter
->num_rx_queues
, adapter
->num_tx_queues
);
2185 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2189 ixgbevf_free_q_vectors(adapter
);
2190 err_alloc_q_vectors
:
2191 ixgbevf_reset_interrupt_capability(adapter
);
2197 * ixgbevf_sw_init - Initialize general software structures
2198 * (struct ixgbevf_adapter)
2199 * @adapter: board private structure to initialize
2201 * ixgbevf_sw_init initializes the Adapter private data structure.
2202 * Fields are initialized based on PCI device information and
2203 * OS network device settings (MTU size).
2205 static int __devinit
ixgbevf_sw_init(struct ixgbevf_adapter
*adapter
)
2207 struct ixgbe_hw
*hw
= &adapter
->hw
;
2208 struct pci_dev
*pdev
= adapter
->pdev
;
2211 /* PCI config space info */
2213 hw
->vendor_id
= pdev
->vendor
;
2214 hw
->device_id
= pdev
->device
;
2215 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2216 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2217 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2219 hw
->mbx
.ops
.init_params(hw
);
2220 hw
->mac
.max_tx_queues
= MAX_TX_QUEUES
;
2221 hw
->mac
.max_rx_queues
= MAX_RX_QUEUES
;
2222 err
= hw
->mac
.ops
.reset_hw(hw
);
2224 dev_info(&pdev
->dev
,
2225 "PF still in reset state, assigning new address\n");
2226 dev_hw_addr_random(adapter
->netdev
, hw
->mac
.addr
);
2228 err
= hw
->mac
.ops
.init_hw(hw
);
2230 printk(KERN_ERR
"init_shared_code failed: %d\n", err
);
2235 /* Enable dynamic interrupt throttling rates */
2236 adapter
->eitr_param
= 20000;
2237 adapter
->itr_setting
= 1;
2239 /* set defaults for eitr in MegaBytes */
2240 adapter
->eitr_low
= 10;
2241 adapter
->eitr_high
= 20;
2243 /* set default ring sizes */
2244 adapter
->tx_ring_count
= IXGBEVF_DEFAULT_TXD
;
2245 adapter
->rx_ring_count
= IXGBEVF_DEFAULT_RXD
;
2247 /* enable rx csum by default */
2248 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
2250 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2256 #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
2258 u32 current_counter = IXGBE_READ_REG(hw, reg); \
2259 if (current_counter < last_counter) \
2260 counter += 0x100000000LL; \
2261 last_counter = current_counter; \
2262 counter &= 0xFFFFFFFF00000000LL; \
2263 counter |= current_counter; \
2266 #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
2268 u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
2269 u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
2270 u64 current_counter = (current_counter_msb << 32) | \
2271 current_counter_lsb; \
2272 if (current_counter < last_counter) \
2273 counter += 0x1000000000LL; \
2274 last_counter = current_counter; \
2275 counter &= 0xFFFFFFF000000000LL; \
2276 counter |= current_counter; \
2279 * ixgbevf_update_stats - Update the board statistics counters.
2280 * @adapter: board private structure
2282 void ixgbevf_update_stats(struct ixgbevf_adapter
*adapter
)
2284 struct ixgbe_hw
*hw
= &adapter
->hw
;
2286 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC
, adapter
->stats
.last_vfgprc
,
2287 adapter
->stats
.vfgprc
);
2288 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC
, adapter
->stats
.last_vfgptc
,
2289 adapter
->stats
.vfgptc
);
2290 UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB
, IXGBE_VFGORC_MSB
,
2291 adapter
->stats
.last_vfgorc
,
2292 adapter
->stats
.vfgorc
);
2293 UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB
, IXGBE_VFGOTC_MSB
,
2294 adapter
->stats
.last_vfgotc
,
2295 adapter
->stats
.vfgotc
);
2296 UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC
, adapter
->stats
.last_vfmprc
,
2297 adapter
->stats
.vfmprc
);
2299 /* Fill out the OS statistics structure */
2300 adapter
->netdev
->stats
.multicast
= adapter
->stats
.vfmprc
-
2301 adapter
->stats
.base_vfmprc
;
2305 * ixgbevf_watchdog - Timer Call-back
2306 * @data: pointer to adapter cast into an unsigned long
2308 static void ixgbevf_watchdog(unsigned long data
)
2310 struct ixgbevf_adapter
*adapter
= (struct ixgbevf_adapter
*)data
;
2311 struct ixgbe_hw
*hw
= &adapter
->hw
;
2316 * Do the watchdog outside of interrupt context due to the lovely
2317 * delays that some of the newer hardware requires
2320 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2321 goto watchdog_short_circuit
;
2323 /* get one bit for every active tx/rx interrupt vector */
2324 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
2325 struct ixgbevf_q_vector
*qv
= adapter
->q_vector
[i
];
2326 if (qv
->rxr_count
|| qv
->txr_count
)
2330 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, (u32
)eics
);
2332 watchdog_short_circuit
:
2333 schedule_work(&adapter
->watchdog_task
);
2337 * ixgbevf_tx_timeout - Respond to a Tx Hang
2338 * @netdev: network interface device structure
2340 static void ixgbevf_tx_timeout(struct net_device
*netdev
)
2342 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2344 /* Do the reset outside of interrupt context */
2345 schedule_work(&adapter
->reset_task
);
2348 static void ixgbevf_reset_task(struct work_struct
*work
)
2350 struct ixgbevf_adapter
*adapter
;
2351 adapter
= container_of(work
, struct ixgbevf_adapter
, reset_task
);
2353 /* If we're already down or resetting, just bail */
2354 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
) ||
2355 test_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
2358 adapter
->tx_timeout_count
++;
2360 ixgbevf_reinit_locked(adapter
);
2364 * ixgbevf_watchdog_task - worker thread to bring link up
2365 * @work: pointer to work_struct containing our data
2367 static void ixgbevf_watchdog_task(struct work_struct
*work
)
2369 struct ixgbevf_adapter
*adapter
= container_of(work
,
2370 struct ixgbevf_adapter
,
2372 struct net_device
*netdev
= adapter
->netdev
;
2373 struct ixgbe_hw
*hw
= &adapter
->hw
;
2374 u32 link_speed
= adapter
->link_speed
;
2375 bool link_up
= adapter
->link_up
;
2377 adapter
->flags
|= IXGBE_FLAG_IN_WATCHDOG_TASK
;
2380 * Always check the link on the watchdog because we have
2383 if (hw
->mac
.ops
.check_link
) {
2384 if ((hw
->mac
.ops
.check_link(hw
, &link_speed
,
2385 &link_up
, false)) != 0) {
2386 adapter
->link_up
= link_up
;
2387 adapter
->link_speed
= link_speed
;
2388 netif_carrier_off(netdev
);
2389 netif_tx_stop_all_queues(netdev
);
2390 schedule_work(&adapter
->reset_task
);
2394 /* always assume link is up, if no check link
2396 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
2399 adapter
->link_up
= link_up
;
2400 adapter
->link_speed
= link_speed
;
2403 if (!netif_carrier_ok(netdev
)) {
2404 hw_dbg(&adapter
->hw
, "NIC Link is Up, %u Gbps\n",
2405 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
) ?
2407 netif_carrier_on(netdev
);
2408 netif_tx_wake_all_queues(netdev
);
2410 /* Force detection of hung controller */
2411 adapter
->detect_tx_hung
= true;
2414 adapter
->link_up
= false;
2415 adapter
->link_speed
= 0;
2416 if (netif_carrier_ok(netdev
)) {
2417 hw_dbg(&adapter
->hw
, "NIC Link is Down\n");
2418 netif_carrier_off(netdev
);
2419 netif_tx_stop_all_queues(netdev
);
2423 ixgbevf_update_stats(adapter
);
2426 /* Force detection of hung controller every watchdog period */
2427 adapter
->detect_tx_hung
= true;
2429 /* Reset the timer */
2430 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2431 mod_timer(&adapter
->watchdog_timer
,
2432 round_jiffies(jiffies
+ (2 * HZ
)));
2434 adapter
->flags
&= ~IXGBE_FLAG_IN_WATCHDOG_TASK
;
2438 * ixgbevf_free_tx_resources - Free Tx Resources per Queue
2439 * @adapter: board private structure
2440 * @tx_ring: Tx descriptor ring for a specific queue
2442 * Free all transmit software resources
2444 void ixgbevf_free_tx_resources(struct ixgbevf_adapter
*adapter
,
2445 struct ixgbevf_ring
*tx_ring
)
2447 struct pci_dev
*pdev
= adapter
->pdev
;
2449 ixgbevf_clean_tx_ring(adapter
, tx_ring
);
2451 vfree(tx_ring
->tx_buffer_info
);
2452 tx_ring
->tx_buffer_info
= NULL
;
2454 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
2457 tx_ring
->desc
= NULL
;
2461 * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
2462 * @adapter: board private structure
2464 * Free all transmit software resources
2466 static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2470 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2471 if (adapter
->tx_ring
[i
].desc
)
2472 ixgbevf_free_tx_resources(adapter
,
2473 &adapter
->tx_ring
[i
]);
2478 * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
2479 * @adapter: board private structure
2480 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2482 * Return 0 on success, negative on failure
2484 int ixgbevf_setup_tx_resources(struct ixgbevf_adapter
*adapter
,
2485 struct ixgbevf_ring
*tx_ring
)
2487 struct pci_dev
*pdev
= adapter
->pdev
;
2490 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
2491 tx_ring
->tx_buffer_info
= vmalloc(size
);
2492 if (!tx_ring
->tx_buffer_info
)
2494 memset(tx_ring
->tx_buffer_info
, 0, size
);
2496 /* round up to nearest 4K */
2497 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
2498 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
2500 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
2501 &tx_ring
->dma
, GFP_KERNEL
);
2505 tx_ring
->next_to_use
= 0;
2506 tx_ring
->next_to_clean
= 0;
2507 tx_ring
->work_limit
= tx_ring
->count
;
2511 vfree(tx_ring
->tx_buffer_info
);
2512 tx_ring
->tx_buffer_info
= NULL
;
2513 hw_dbg(&adapter
->hw
, "Unable to allocate memory for the transmit "
2514 "descriptor ring\n");
2519 * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
2520 * @adapter: board private structure
2522 * If this function returns with an error, then it's possible one or
2523 * more of the rings is populated (while the rest are not). It is the
2524 * callers duty to clean those orphaned rings.
2526 * Return 0 on success, negative on failure
2528 static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2532 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2533 err
= ixgbevf_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
2536 hw_dbg(&adapter
->hw
,
2537 "Allocation for Tx Queue %u failed\n", i
);
2545 * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
2546 * @adapter: board private structure
2547 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2549 * Returns 0 on success, negative on failure
2551 int ixgbevf_setup_rx_resources(struct ixgbevf_adapter
*adapter
,
2552 struct ixgbevf_ring
*rx_ring
)
2554 struct pci_dev
*pdev
= adapter
->pdev
;
2557 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
2558 rx_ring
->rx_buffer_info
= vmalloc(size
);
2559 if (!rx_ring
->rx_buffer_info
) {
2560 hw_dbg(&adapter
->hw
,
2561 "Unable to vmalloc buffer memory for "
2562 "the receive descriptor ring\n");
2565 memset(rx_ring
->rx_buffer_info
, 0, size
);
2567 /* Round up to nearest 4K */
2568 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
2569 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
2571 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
2572 &rx_ring
->dma
, GFP_KERNEL
);
2574 if (!rx_ring
->desc
) {
2575 hw_dbg(&adapter
->hw
,
2576 "Unable to allocate memory for "
2577 "the receive descriptor ring\n");
2578 vfree(rx_ring
->rx_buffer_info
);
2579 rx_ring
->rx_buffer_info
= NULL
;
2583 rx_ring
->next_to_clean
= 0;
2584 rx_ring
->next_to_use
= 0;
2592 * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
2593 * @adapter: board private structure
2595 * If this function returns with an error, then it's possible one or
2596 * more of the rings is populated (while the rest are not). It is the
2597 * callers duty to clean those orphaned rings.
2599 * Return 0 on success, negative on failure
2601 static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2605 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2606 err
= ixgbevf_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2609 hw_dbg(&adapter
->hw
,
2610 "Allocation for Rx Queue %u failed\n", i
);
2617 * ixgbevf_free_rx_resources - Free Rx Resources
2618 * @adapter: board private structure
2619 * @rx_ring: ring to clean the resources from
2621 * Free all receive software resources
2623 void ixgbevf_free_rx_resources(struct ixgbevf_adapter
*adapter
,
2624 struct ixgbevf_ring
*rx_ring
)
2626 struct pci_dev
*pdev
= adapter
->pdev
;
2628 ixgbevf_clean_rx_ring(adapter
, rx_ring
);
2630 vfree(rx_ring
->rx_buffer_info
);
2631 rx_ring
->rx_buffer_info
= NULL
;
2633 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
2636 rx_ring
->desc
= NULL
;
2640 * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
2641 * @adapter: board private structure
2643 * Free all receive software resources
2645 static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2649 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2650 if (adapter
->rx_ring
[i
].desc
)
2651 ixgbevf_free_rx_resources(adapter
,
2652 &adapter
->rx_ring
[i
]);
2656 * ixgbevf_open - Called when a network interface is made active
2657 * @netdev: network interface device structure
2659 * Returns 0 on success, negative value on failure
2661 * The open entry point is called when a network interface is made
2662 * active by the system (IFF_UP). At this point all resources needed
2663 * for transmit and receive operations are allocated, the interrupt
2664 * handler is registered with the OS, the watchdog timer is started,
2665 * and the stack is notified that the interface is ready.
2667 static int ixgbevf_open(struct net_device
*netdev
)
2669 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2670 struct ixgbe_hw
*hw
= &adapter
->hw
;
2673 /* disallow open during test */
2674 if (test_bit(__IXGBEVF_TESTING
, &adapter
->state
))
2677 if (hw
->adapter_stopped
) {
2678 ixgbevf_reset(adapter
);
2679 /* if adapter is still stopped then PF isn't up and
2680 * the vf can't start. */
2681 if (hw
->adapter_stopped
) {
2682 err
= IXGBE_ERR_MBX
;
2683 printk(KERN_ERR
"Unable to start - perhaps the PF"
2684 " Driver isn't up yet\n");
2685 goto err_setup_reset
;
2689 /* allocate transmit descriptors */
2690 err
= ixgbevf_setup_all_tx_resources(adapter
);
2694 /* allocate receive descriptors */
2695 err
= ixgbevf_setup_all_rx_resources(adapter
);
2699 ixgbevf_configure(adapter
);
2702 * Map the Tx/Rx rings to the vectors we were allotted.
2703 * if request_irq will be called in this function map_rings
2704 * must be called *before* up_complete
2706 ixgbevf_map_rings_to_vectors(adapter
);
2708 err
= ixgbevf_up_complete(adapter
);
2712 /* clear any pending interrupts, may auto mask */
2713 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
2714 err
= ixgbevf_request_irq(adapter
);
2718 ixgbevf_irq_enable(adapter
, true, true);
2723 ixgbevf_down(adapter
);
2725 ixgbevf_free_irq(adapter
);
2727 ixgbevf_free_all_rx_resources(adapter
);
2729 ixgbevf_free_all_tx_resources(adapter
);
2730 ixgbevf_reset(adapter
);
2738 * ixgbevf_close - Disables a network interface
2739 * @netdev: network interface device structure
2741 * Returns 0, this is not allowed to fail
2743 * The close entry point is called when an interface is de-activated
2744 * by the OS. The hardware is still under the drivers control, but
2745 * needs to be disabled. A global MAC reset is issued to stop the
2746 * hardware, and all transmit and receive resources are freed.
2748 static int ixgbevf_close(struct net_device
*netdev
)
2750 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2752 ixgbevf_down(adapter
);
2753 ixgbevf_free_irq(adapter
);
2755 ixgbevf_free_all_tx_resources(adapter
);
2756 ixgbevf_free_all_rx_resources(adapter
);
2761 static int ixgbevf_tso(struct ixgbevf_adapter
*adapter
,
2762 struct ixgbevf_ring
*tx_ring
,
2763 struct sk_buff
*skb
, u32 tx_flags
, u8
*hdr_len
)
2765 struct ixgbe_adv_tx_context_desc
*context_desc
;
2768 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2769 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
;
2770 u32 mss_l4len_idx
, l4len
;
2772 if (skb_is_gso(skb
)) {
2773 if (skb_header_cloned(skb
)) {
2774 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2778 l4len
= tcp_hdrlen(skb
);
2781 if (skb
->protocol
== htons(ETH_P_IP
)) {
2782 struct iphdr
*iph
= ip_hdr(skb
);
2785 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2789 adapter
->hw_tso_ctxt
++;
2790 } else if (skb_is_gso_v6(skb
)) {
2791 ipv6_hdr(skb
)->payload_len
= 0;
2792 tcp_hdr(skb
)->check
=
2793 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2794 &ipv6_hdr(skb
)->daddr
,
2796 adapter
->hw_tso6_ctxt
++;
2799 i
= tx_ring
->next_to_use
;
2801 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2802 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2804 /* VLAN MACLEN IPLEN */
2805 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2807 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
2808 vlan_macip_lens
|= ((skb_network_offset(skb
)) <<
2809 IXGBE_ADVTXD_MACLEN_SHIFT
);
2810 *hdr_len
+= skb_network_offset(skb
);
2812 (skb_transport_header(skb
) - skb_network_header(skb
));
2814 (skb_transport_header(skb
) - skb_network_header(skb
));
2815 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2816 context_desc
->seqnum_seed
= 0;
2818 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2819 type_tucmd_mlhl
= (IXGBE_TXD_CMD_DEXT
|
2820 IXGBE_ADVTXD_DTYP_CTXT
);
2822 if (skb
->protocol
== htons(ETH_P_IP
))
2823 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2824 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2825 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2829 (skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
);
2830 mss_l4len_idx
|= (l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
);
2831 /* use index 1 for TSO */
2832 mss_l4len_idx
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
2833 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
2835 tx_buffer_info
->time_stamp
= jiffies
;
2836 tx_buffer_info
->next_to_watch
= i
;
2839 if (i
== tx_ring
->count
)
2841 tx_ring
->next_to_use
= i
;
2849 static bool ixgbevf_tx_csum(struct ixgbevf_adapter
*adapter
,
2850 struct ixgbevf_ring
*tx_ring
,
2851 struct sk_buff
*skb
, u32 tx_flags
)
2853 struct ixgbe_adv_tx_context_desc
*context_desc
;
2855 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2856 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
2858 if (skb
->ip_summed
== CHECKSUM_PARTIAL
||
2859 (tx_flags
& IXGBE_TX_FLAGS_VLAN
)) {
2860 i
= tx_ring
->next_to_use
;
2861 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2862 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2864 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2865 vlan_macip_lens
|= (tx_flags
&
2866 IXGBE_TX_FLAGS_VLAN_MASK
);
2867 vlan_macip_lens
|= (skb_network_offset(skb
) <<
2868 IXGBE_ADVTXD_MACLEN_SHIFT
);
2869 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2870 vlan_macip_lens
|= (skb_transport_header(skb
) -
2871 skb_network_header(skb
));
2873 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2874 context_desc
->seqnum_seed
= 0;
2876 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
2877 IXGBE_ADVTXD_DTYP_CTXT
);
2879 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2880 switch (skb
->protocol
) {
2881 case __constant_htons(ETH_P_IP
):
2882 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2883 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
2885 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2887 case __constant_htons(ETH_P_IPV6
):
2888 /* XXX what about other V6 headers?? */
2889 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
2891 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2894 if (unlikely(net_ratelimit())) {
2896 "partial checksum but "
2904 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2905 /* use index zero for tx checksum offload */
2906 context_desc
->mss_l4len_idx
= 0;
2908 tx_buffer_info
->time_stamp
= jiffies
;
2909 tx_buffer_info
->next_to_watch
= i
;
2911 adapter
->hw_csum_tx_good
++;
2913 if (i
== tx_ring
->count
)
2915 tx_ring
->next_to_use
= i
;
2923 static int ixgbevf_tx_map(struct ixgbevf_adapter
*adapter
,
2924 struct ixgbevf_ring
*tx_ring
,
2925 struct sk_buff
*skb
, u32 tx_flags
,
2928 struct pci_dev
*pdev
= adapter
->pdev
;
2929 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2931 unsigned int total
= skb
->len
;
2932 unsigned int offset
= 0, size
;
2934 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2938 i
= tx_ring
->next_to_use
;
2940 len
= min(skb_headlen(skb
), total
);
2942 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2943 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2945 tx_buffer_info
->length
= size
;
2946 tx_buffer_info
->mapped_as_page
= false;
2947 tx_buffer_info
->dma
= dma_map_single(&adapter
->pdev
->dev
,
2949 size
, DMA_TO_DEVICE
);
2950 if (dma_mapping_error(&pdev
->dev
, tx_buffer_info
->dma
))
2952 tx_buffer_info
->time_stamp
= jiffies
;
2953 tx_buffer_info
->next_to_watch
= i
;
2960 if (i
== tx_ring
->count
)
2964 for (f
= 0; f
< nr_frags
; f
++) {
2965 struct skb_frag_struct
*frag
;
2967 frag
= &skb_shinfo(skb
)->frags
[f
];
2968 len
= min((unsigned int)frag
->size
, total
);
2969 offset
= frag
->page_offset
;
2972 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2973 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2975 tx_buffer_info
->length
= size
;
2976 tx_buffer_info
->dma
= dma_map_page(&adapter
->pdev
->dev
,
2981 tx_buffer_info
->mapped_as_page
= true;
2982 if (dma_mapping_error(&pdev
->dev
, tx_buffer_info
->dma
))
2984 tx_buffer_info
->time_stamp
= jiffies
;
2985 tx_buffer_info
->next_to_watch
= i
;
2992 if (i
== tx_ring
->count
)
3000 i
= tx_ring
->count
- 1;
3003 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
3004 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
3009 dev_err(&pdev
->dev
, "TX DMA map failed\n");
3011 /* clear timestamp and dma mappings for failed tx_buffer_info map */
3012 tx_buffer_info
->dma
= 0;
3013 tx_buffer_info
->time_stamp
= 0;
3014 tx_buffer_info
->next_to_watch
= 0;
3017 /* clear timestamp and dma mappings for remaining portion of packet */
3018 while (count
>= 0) {
3022 i
+= tx_ring
->count
;
3023 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3024 ixgbevf_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
3030 static void ixgbevf_tx_queue(struct ixgbevf_adapter
*adapter
,
3031 struct ixgbevf_ring
*tx_ring
, int tx_flags
,
3032 int count
, u32 paylen
, u8 hdr_len
)
3034 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
3035 struct ixgbevf_tx_buffer
*tx_buffer_info
;
3036 u32 olinfo_status
= 0, cmd_type_len
= 0;
3039 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
3041 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
3043 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
3045 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
3046 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
3048 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
3049 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
3051 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
3052 IXGBE_ADVTXD_POPTS_SHIFT
;
3054 /* use index 1 context for tso */
3055 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
3056 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
3057 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
3058 IXGBE_ADVTXD_POPTS_SHIFT
;
3060 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
3061 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
3062 IXGBE_ADVTXD_POPTS_SHIFT
;
3064 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
3066 i
= tx_ring
->next_to_use
;
3068 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3069 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
3070 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
3071 tx_desc
->read
.cmd_type_len
=
3072 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
3073 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
3075 if (i
== tx_ring
->count
)
3079 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
3082 * Force memory writes to complete before letting h/w
3083 * know there are new descriptors to fetch. (Only
3084 * applicable for weak-ordered memory model archs,
3089 tx_ring
->next_to_use
= i
;
3090 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3093 static int __ixgbevf_maybe_stop_tx(struct net_device
*netdev
,
3094 struct ixgbevf_ring
*tx_ring
, int size
)
3096 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3098 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
3099 /* Herbert's original patch had:
3100 * smp_mb__after_netif_stop_queue();
3101 * but since that doesn't exist yet, just open code it. */
3104 /* We need to check again in a case another CPU has just
3105 * made room available. */
3106 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
3109 /* A reprieve! - use start_queue because it doesn't call schedule */
3110 netif_start_subqueue(netdev
, tx_ring
->queue_index
);
3111 ++adapter
->restart_queue
;
3115 static int ixgbevf_maybe_stop_tx(struct net_device
*netdev
,
3116 struct ixgbevf_ring
*tx_ring
, int size
)
3118 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
3120 return __ixgbevf_maybe_stop_tx(netdev
, tx_ring
, size
);
3123 static int ixgbevf_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
3125 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3126 struct ixgbevf_ring
*tx_ring
;
3128 unsigned int tx_flags
= 0;
3135 tx_ring
= &adapter
->tx_ring
[r_idx
];
3137 if (vlan_tx_tag_present(skb
)) {
3138 tx_flags
|= vlan_tx_tag_get(skb
);
3139 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
3140 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
3143 /* four things can cause us to need a context descriptor */
3144 if (skb_is_gso(skb
) ||
3145 (skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
3146 (tx_flags
& IXGBE_TX_FLAGS_VLAN
))
3149 count
+= TXD_USE_COUNT(skb_headlen(skb
));
3150 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
3151 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
3153 if (ixgbevf_maybe_stop_tx(netdev
, tx_ring
, count
)) {
3155 return NETDEV_TX_BUSY
;
3158 first
= tx_ring
->next_to_use
;
3160 if (skb
->protocol
== htons(ETH_P_IP
))
3161 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
3162 tso
= ixgbevf_tso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
3164 dev_kfree_skb_any(skb
);
3165 return NETDEV_TX_OK
;
3169 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
3170 else if (ixgbevf_tx_csum(adapter
, tx_ring
, skb
, tx_flags
) &&
3171 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3172 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
3174 ixgbevf_tx_queue(adapter
, tx_ring
, tx_flags
,
3175 ixgbevf_tx_map(adapter
, tx_ring
, skb
, tx_flags
, first
),
3178 ixgbevf_maybe_stop_tx(netdev
, tx_ring
, DESC_NEEDED
);
3180 return NETDEV_TX_OK
;
3184 * ixgbevf_set_mac - Change the Ethernet Address of the NIC
3185 * @netdev: network interface device structure
3186 * @p: pointer to an address structure
3188 * Returns 0 on success, negative on failure
3190 static int ixgbevf_set_mac(struct net_device
*netdev
, void *p
)
3192 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3193 struct ixgbe_hw
*hw
= &adapter
->hw
;
3194 struct sockaddr
*addr
= p
;
3196 if (!is_valid_ether_addr(addr
->sa_data
))
3197 return -EADDRNOTAVAIL
;
3199 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3200 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3202 if (hw
->mac
.ops
.set_rar
)
3203 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
3209 * ixgbevf_change_mtu - Change the Maximum Transfer Unit
3210 * @netdev: network interface device structure
3211 * @new_mtu: new value for maximum frame size
3213 * Returns 0 on success, negative on failure
3215 static int ixgbevf_change_mtu(struct net_device
*netdev
, int new_mtu
)
3217 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3218 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3220 /* MTU < 68 is an error and causes problems on some kernels */
3221 if ((new_mtu
< 68) || (max_frame
> MAXIMUM_ETHERNET_VLAN_SIZE
))
3224 hw_dbg(&adapter
->hw
, "changing MTU from %d to %d\n",
3225 netdev
->mtu
, new_mtu
);
3226 /* must set new MTU before calling down or up */
3227 netdev
->mtu
= new_mtu
;
3229 if (netif_running(netdev
))
3230 ixgbevf_reinit_locked(adapter
);
3235 static void ixgbevf_shutdown(struct pci_dev
*pdev
)
3237 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3238 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3240 netif_device_detach(netdev
);
3242 if (netif_running(netdev
)) {
3243 ixgbevf_down(adapter
);
3244 ixgbevf_free_irq(adapter
);
3245 ixgbevf_free_all_tx_resources(adapter
);
3246 ixgbevf_free_all_rx_resources(adapter
);
3250 pci_save_state(pdev
);
3253 pci_disable_device(pdev
);
3256 static const struct net_device_ops ixgbe_netdev_ops
= {
3257 .ndo_open
= &ixgbevf_open
,
3258 .ndo_stop
= &ixgbevf_close
,
3259 .ndo_start_xmit
= &ixgbevf_xmit_frame
,
3260 .ndo_set_rx_mode
= &ixgbevf_set_rx_mode
,
3261 .ndo_set_multicast_list
= &ixgbevf_set_rx_mode
,
3262 .ndo_validate_addr
= eth_validate_addr
,
3263 .ndo_set_mac_address
= &ixgbevf_set_mac
,
3264 .ndo_change_mtu
= &ixgbevf_change_mtu
,
3265 .ndo_tx_timeout
= &ixgbevf_tx_timeout
,
3266 .ndo_vlan_rx_register
= &ixgbevf_vlan_rx_register
,
3267 .ndo_vlan_rx_add_vid
= &ixgbevf_vlan_rx_add_vid
,
3268 .ndo_vlan_rx_kill_vid
= &ixgbevf_vlan_rx_kill_vid
,
3271 static void ixgbevf_assign_netdev_ops(struct net_device
*dev
)
3273 struct ixgbevf_adapter
*adapter
;
3274 adapter
= netdev_priv(dev
);
3275 dev
->netdev_ops
= &ixgbe_netdev_ops
;
3276 ixgbevf_set_ethtool_ops(dev
);
3277 dev
->watchdog_timeo
= 5 * HZ
;
3281 * ixgbevf_probe - Device Initialization Routine
3282 * @pdev: PCI device information struct
3283 * @ent: entry in ixgbevf_pci_tbl
3285 * Returns 0 on success, negative on failure
3287 * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
3288 * The OS initialization, configuring of the adapter private structure,
3289 * and a hardware reset occur.
3291 static int __devinit
ixgbevf_probe(struct pci_dev
*pdev
,
3292 const struct pci_device_id
*ent
)
3294 struct net_device
*netdev
;
3295 struct ixgbevf_adapter
*adapter
= NULL
;
3296 struct ixgbe_hw
*hw
= NULL
;
3297 const struct ixgbevf_info
*ii
= ixgbevf_info_tbl
[ent
->driver_data
];
3298 static int cards_found
;
3299 int err
, pci_using_dac
;
3301 err
= pci_enable_device(pdev
);
3305 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64)) &&
3306 !dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
3309 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
3311 err
= dma_set_coherent_mask(&pdev
->dev
,
3314 dev_err(&pdev
->dev
, "No usable DMA "
3315 "configuration, aborting\n");
3322 err
= pci_request_regions(pdev
, ixgbevf_driver_name
);
3324 dev_err(&pdev
->dev
, "pci_request_regions failed 0x%x\n", err
);
3328 pci_set_master(pdev
);
3331 netdev
= alloc_etherdev_mq(sizeof(struct ixgbevf_adapter
),
3334 netdev
= alloc_etherdev(sizeof(struct ixgbevf_adapter
));
3338 goto err_alloc_etherdev
;
3341 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3343 pci_set_drvdata(pdev
, netdev
);
3344 adapter
= netdev_priv(netdev
);
3346 adapter
->netdev
= netdev
;
3347 adapter
->pdev
= pdev
;
3350 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
3353 * call save state here in standalone driver because it relies on
3354 * adapter struct to exist, and needs to call netdev_priv
3356 pci_save_state(pdev
);
3358 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
3359 pci_resource_len(pdev
, 0));
3365 ixgbevf_assign_netdev_ops(netdev
);
3367 adapter
->bd_number
= cards_found
;
3370 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
3371 hw
->mac
.type
= ii
->mac
;
3373 memcpy(&hw
->mbx
.ops
, &ixgbevf_mbx_ops
,
3374 sizeof(struct ixgbe_mac_operations
));
3376 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_CAPABLE
;
3377 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
3378 adapter
->flags
|= IXGBE_FLAG_RX_1BUF_CAPABLE
;
3380 /* setup the private structure */
3381 err
= ixgbevf_sw_init(adapter
);
3383 netdev
->features
= NETIF_F_SG
|
3385 NETIF_F_HW_VLAN_TX
|
3386 NETIF_F_HW_VLAN_RX
|
3387 NETIF_F_HW_VLAN_FILTER
;
3389 netdev
->features
|= NETIF_F_IPV6_CSUM
;
3390 netdev
->features
|= NETIF_F_TSO
;
3391 netdev
->features
|= NETIF_F_TSO6
;
3392 netdev
->features
|= NETIF_F_GRO
;
3393 netdev
->vlan_features
|= NETIF_F_TSO
;
3394 netdev
->vlan_features
|= NETIF_F_TSO6
;
3395 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
3396 netdev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
3397 netdev
->vlan_features
|= NETIF_F_SG
;
3400 netdev
->features
|= NETIF_F_HIGHDMA
;
3402 /* The HW MAC address was set and/or determined in sw_init */
3403 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3404 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3406 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
3407 printk(KERN_ERR
"invalid MAC address\n");
3412 init_timer(&adapter
->watchdog_timer
);
3413 adapter
->watchdog_timer
.function
= ixgbevf_watchdog
;
3414 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
3416 INIT_WORK(&adapter
->reset_task
, ixgbevf_reset_task
);
3417 INIT_WORK(&adapter
->watchdog_task
, ixgbevf_watchdog_task
);
3419 err
= ixgbevf_init_interrupt_scheme(adapter
);
3423 /* pick up the PCI bus settings for reporting later */
3424 if (hw
->mac
.ops
.get_bus_info
)
3425 hw
->mac
.ops
.get_bus_info(hw
);
3428 netif_carrier_off(netdev
);
3429 netif_tx_stop_all_queues(netdev
);
3431 strcpy(netdev
->name
, "eth%d");
3433 err
= register_netdev(netdev
);
3437 adapter
->netdev_registered
= true;
3439 ixgbevf_init_last_counter_stats(adapter
);
3441 /* print the MAC address */
3442 hw_dbg(hw
, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
3443 netdev
->dev_addr
[0],
3444 netdev
->dev_addr
[1],
3445 netdev
->dev_addr
[2],
3446 netdev
->dev_addr
[3],
3447 netdev
->dev_addr
[4],
3448 netdev
->dev_addr
[5]);
3450 hw_dbg(hw
, "MAC: %d\n", hw
->mac
.type
);
3452 hw_dbg(hw
, "LRO is disabled\n");
3454 hw_dbg(hw
, "Intel(R) 82599 Virtual Function\n");
3460 ixgbevf_reset_interrupt_capability(adapter
);
3461 iounmap(hw
->hw_addr
);
3463 free_netdev(netdev
);
3465 pci_release_regions(pdev
);
3468 pci_disable_device(pdev
);
3473 * ixgbevf_remove - Device Removal Routine
3474 * @pdev: PCI device information struct
3476 * ixgbevf_remove is called by the PCI subsystem to alert the driver
3477 * that it should release a PCI device. The could be caused by a
3478 * Hot-Plug event, or because the driver is going to be removed from
3481 static void __devexit
ixgbevf_remove(struct pci_dev
*pdev
)
3483 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3484 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3486 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
3488 del_timer_sync(&adapter
->watchdog_timer
);
3490 cancel_work_sync(&adapter
->watchdog_task
);
3492 flush_scheduled_work();
3494 if (adapter
->netdev_registered
) {
3495 unregister_netdev(netdev
);
3496 adapter
->netdev_registered
= false;
3499 ixgbevf_reset_interrupt_capability(adapter
);
3501 iounmap(adapter
->hw
.hw_addr
);
3502 pci_release_regions(pdev
);
3504 hw_dbg(&adapter
->hw
, "Remove complete\n");
3506 kfree(adapter
->tx_ring
);
3507 kfree(adapter
->rx_ring
);
3509 free_netdev(netdev
);
3511 pci_disable_device(pdev
);
3514 static struct pci_driver ixgbevf_driver
= {
3515 .name
= ixgbevf_driver_name
,
3516 .id_table
= ixgbevf_pci_tbl
,
3517 .probe
= ixgbevf_probe
,
3518 .remove
= __devexit_p(ixgbevf_remove
),
3519 .shutdown
= ixgbevf_shutdown
,
3523 * ixgbe_init_module - Driver Registration Routine
3525 * ixgbe_init_module is the first routine called when the driver is
3526 * loaded. All it does is register with the PCI subsystem.
3528 static int __init
ixgbevf_init_module(void)
3531 printk(KERN_INFO
"ixgbevf: %s - version %s\n", ixgbevf_driver_string
,
3532 ixgbevf_driver_version
);
3534 printk(KERN_INFO
"%s\n", ixgbevf_copyright
);
3536 ret
= pci_register_driver(&ixgbevf_driver
);
3540 module_init(ixgbevf_init_module
);
3543 * ixgbe_exit_module - Driver Exit Cleanup Routine
3545 * ixgbe_exit_module is called just before the driver is removed
3548 static void __exit
ixgbevf_exit_module(void)
3550 pci_unregister_driver(&ixgbevf_driver
);
3555 * ixgbe_get_hw_dev_name - return device name string
3556 * used by hardware layer to print debugging information
3558 char *ixgbevf_get_hw_dev_name(struct ixgbe_hw
*hw
)
3560 struct ixgbevf_adapter
*adapter
= hw
->back
;
3561 return adapter
->netdev
->name
;
3565 module_exit(ixgbevf_exit_module
);
3567 /* ixgbevf_main.c */