1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2010 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) 10 Gigabit PCI Express Virtual Function Network Driver";
54 #define DRV_VERSION "2.0.0-k2"
55 const char ixgbevf_driver_version
[] = DRV_VERSION
;
56 static char ixgbevf_copyright
[] =
57 "Copyright (c) 2009 - 2010 Intel Corporation.";
59 static const struct ixgbevf_info
*ixgbevf_info_tbl
[] = {
60 [board_82599_vf
] = &ixgbevf_82599_vf_info
,
61 [board_X540_vf
] = &ixgbevf_X540_vf_info
,
64 /* ixgbevf_pci_tbl - PCI Device ID Table
66 * Wildcard entries (PCI_ANY_ID) should come last
67 * Last entry must be all 0s
69 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
70 * Class, Class Mask, private data (not used) }
72 static struct pci_device_id ixgbevf_pci_tbl
[] = {
73 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_VF
),
75 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X540_VF
),
78 /* required last entry */
81 MODULE_DEVICE_TABLE(pci
, ixgbevf_pci_tbl
);
83 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
84 MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
85 MODULE_LICENSE("GPL");
86 MODULE_VERSION(DRV_VERSION
);
88 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
91 static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector
*q_vector
);
92 static void ixgbevf_write_eitr(struct ixgbevf_adapter
*adapter
, int v_idx
,
95 static inline void ixgbevf_release_rx_desc(struct ixgbe_hw
*hw
,
96 struct ixgbevf_ring
*rx_ring
,
100 * Force memory writes to complete before letting h/w
101 * know there are new descriptors to fetch. (Only
102 * applicable for weak-ordered memory model archs,
106 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(rx_ring
->reg_idx
), val
);
110 * ixgbevf_set_ivar - set IVAR registers - maps interrupt causes to vectors
111 * @adapter: pointer to adapter struct
112 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
113 * @queue: queue to map the corresponding interrupt to
114 * @msix_vector: the vector to map to the corresponding queue
117 static void ixgbevf_set_ivar(struct ixgbevf_adapter
*adapter
, s8 direction
,
118 u8 queue
, u8 msix_vector
)
121 struct ixgbe_hw
*hw
= &adapter
->hw
;
122 if (direction
== -1) {
124 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
125 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR_MISC
);
128 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR_MISC
, ivar
);
130 /* tx or rx causes */
131 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
132 index
= ((16 * (queue
& 1)) + (8 * direction
));
133 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR(queue
>> 1));
134 ivar
&= ~(0xFF << index
);
135 ivar
|= (msix_vector
<< index
);
136 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR(queue
>> 1), ivar
);
140 static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_adapter
*adapter
,
141 struct ixgbevf_tx_buffer
144 if (tx_buffer_info
->dma
) {
145 if (tx_buffer_info
->mapped_as_page
)
146 dma_unmap_page(&adapter
->pdev
->dev
,
148 tx_buffer_info
->length
,
151 dma_unmap_single(&adapter
->pdev
->dev
,
153 tx_buffer_info
->length
,
155 tx_buffer_info
->dma
= 0;
157 if (tx_buffer_info
->skb
) {
158 dev_kfree_skb_any(tx_buffer_info
->skb
);
159 tx_buffer_info
->skb
= NULL
;
161 tx_buffer_info
->time_stamp
= 0;
162 /* tx_buffer_info must be completely set up in the transmit path */
165 #define IXGBE_MAX_TXD_PWR 14
166 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
168 /* Tx Descriptors needed, worst case */
169 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
170 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
172 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
173 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
175 #define DESC_NEEDED TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD)
178 static void ixgbevf_tx_timeout(struct net_device
*netdev
);
181 * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
182 * @adapter: board private structure
183 * @tx_ring: tx ring to clean
185 static bool ixgbevf_clean_tx_irq(struct ixgbevf_adapter
*adapter
,
186 struct ixgbevf_ring
*tx_ring
)
188 struct net_device
*netdev
= adapter
->netdev
;
189 struct ixgbe_hw
*hw
= &adapter
->hw
;
190 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
191 struct ixgbevf_tx_buffer
*tx_buffer_info
;
192 unsigned int i
, eop
, count
= 0;
193 unsigned int total_bytes
= 0, total_packets
= 0;
195 i
= tx_ring
->next_to_clean
;
196 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
197 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
199 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
200 (count
< tx_ring
->work_limit
)) {
201 bool cleaned
= false;
202 rmb(); /* read buffer_info after eop_desc */
203 for ( ; !cleaned
; count
++) {
205 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
206 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
207 cleaned
= (i
== eop
);
208 skb
= tx_buffer_info
->skb
;
210 if (cleaned
&& skb
) {
211 unsigned int segs
, bytecount
;
213 /* gso_segs is currently only valid for tcp */
214 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
215 /* multiply data chunks by size of headers */
216 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
218 total_packets
+= segs
;
219 total_bytes
+= bytecount
;
222 ixgbevf_unmap_and_free_tx_resource(adapter
,
225 tx_desc
->wb
.status
= 0;
228 if (i
== tx_ring
->count
)
232 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
233 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
236 tx_ring
->next_to_clean
= i
;
238 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
239 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
240 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
241 /* Make sure that anybody stopping the queue after this
242 * sees the new next_to_clean.
246 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
247 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
248 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
249 ++adapter
->restart_queue
;
252 if (netif_queue_stopped(netdev
) &&
253 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
254 netif_wake_queue(netdev
);
255 ++adapter
->restart_queue
;
260 /* re-arm the interrupt */
261 if ((count
>= tx_ring
->work_limit
) &&
262 (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))) {
263 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, tx_ring
->v_idx
);
266 tx_ring
->total_bytes
+= total_bytes
;
267 tx_ring
->total_packets
+= total_packets
;
269 netdev
->stats
.tx_bytes
+= total_bytes
;
270 netdev
->stats
.tx_packets
+= total_packets
;
272 return count
< tx_ring
->work_limit
;
276 * ixgbevf_receive_skb - Send a completed packet up the stack
277 * @q_vector: structure containing interrupt and ring information
278 * @skb: packet to send up
279 * @status: hardware indication of status of receive
280 * @rx_ring: rx descriptor ring (for a specific queue) to setup
281 * @rx_desc: rx descriptor
283 static void ixgbevf_receive_skb(struct ixgbevf_q_vector
*q_vector
,
284 struct sk_buff
*skb
, u8 status
,
285 struct ixgbevf_ring
*ring
,
286 union ixgbe_adv_rx_desc
*rx_desc
)
288 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
289 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
290 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
292 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
)) {
293 if (adapter
->vlgrp
&& is_vlan
)
294 vlan_gro_receive(&q_vector
->napi
,
298 napi_gro_receive(&q_vector
->napi
, skb
);
300 if (adapter
->vlgrp
&& is_vlan
)
301 vlan_hwaccel_rx(skb
, adapter
->vlgrp
, tag
);
308 * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
309 * @adapter: address of board private structure
310 * @status_err: hardware indication of status of receive
311 * @skb: skb currently being received and modified
313 static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter
*adapter
,
314 u32 status_err
, struct sk_buff
*skb
)
316 skb_checksum_none_assert(skb
);
318 /* Rx csum disabled */
319 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
322 /* if IP and error */
323 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
324 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
325 adapter
->hw_csum_rx_error
++;
329 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
332 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
333 adapter
->hw_csum_rx_error
++;
337 /* It must be a TCP or UDP packet with a valid checksum */
338 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
339 adapter
->hw_csum_rx_good
++;
343 * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
344 * @adapter: address of board private structure
346 static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter
*adapter
,
347 struct ixgbevf_ring
*rx_ring
,
350 struct pci_dev
*pdev
= adapter
->pdev
;
351 union ixgbe_adv_rx_desc
*rx_desc
;
352 struct ixgbevf_rx_buffer
*bi
;
355 unsigned int bufsz
= rx_ring
->rx_buf_len
+ NET_IP_ALIGN
;
357 i
= rx_ring
->next_to_use
;
358 bi
= &rx_ring
->rx_buffer_info
[i
];
360 while (cleaned_count
--) {
361 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
364 (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)) {
366 bi
->page
= netdev_alloc_page(adapter
->netdev
);
368 adapter
->alloc_rx_page_failed
++;
373 /* use a half page if we're re-using */
374 bi
->page_offset
^= (PAGE_SIZE
/ 2);
377 bi
->page_dma
= dma_map_page(&pdev
->dev
, bi
->page
,
385 skb
= netdev_alloc_skb(adapter
->netdev
,
389 adapter
->alloc_rx_buff_failed
++;
394 * Make buffer alignment 2 beyond a 16 byte boundary
395 * this will result in a 16 byte aligned IP header after
396 * the 14 byte MAC header is removed
398 skb_reserve(skb
, NET_IP_ALIGN
);
403 bi
->dma
= dma_map_single(&pdev
->dev
, skb
->data
,
407 /* Refresh the desc even if buffer_addrs didn't change because
408 * each write-back erases this info. */
409 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
410 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
411 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
413 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
417 if (i
== rx_ring
->count
)
419 bi
= &rx_ring
->rx_buffer_info
[i
];
423 if (rx_ring
->next_to_use
!= i
) {
424 rx_ring
->next_to_use
= i
;
426 i
= (rx_ring
->count
- 1);
428 ixgbevf_release_rx_desc(&adapter
->hw
, rx_ring
, i
);
432 static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter
*adapter
,
436 struct ixgbe_hw
*hw
= &adapter
->hw
;
438 mask
= (qmask
& 0xFFFFFFFF);
439 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, mask
);
442 static inline u16
ixgbevf_get_hdr_info(union ixgbe_adv_rx_desc
*rx_desc
)
444 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
447 static inline u16
ixgbevf_get_pkt_info(union ixgbe_adv_rx_desc
*rx_desc
)
449 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
452 static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector
*q_vector
,
453 struct ixgbevf_ring
*rx_ring
,
454 int *work_done
, int work_to_do
)
456 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
457 struct pci_dev
*pdev
= adapter
->pdev
;
458 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
459 struct ixgbevf_rx_buffer
*rx_buffer_info
, *next_buffer
;
464 bool cleaned
= false;
465 int cleaned_count
= 0;
466 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
468 i
= rx_ring
->next_to_clean
;
469 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
470 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
471 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
473 while (staterr
& IXGBE_RXD_STAT_DD
) {
475 if (*work_done
>= work_to_do
)
479 rmb(); /* read descriptor and rx_buffer_info after status DD */
480 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
481 hdr_info
= le16_to_cpu(ixgbevf_get_hdr_info(rx_desc
));
482 len
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
483 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
484 if (hdr_info
& IXGBE_RXDADV_SPH
)
485 adapter
->rx_hdr_split
++;
486 if (len
> IXGBEVF_RX_HDR_SIZE
)
487 len
= IXGBEVF_RX_HDR_SIZE
;
488 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
490 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
493 skb
= rx_buffer_info
->skb
;
494 prefetch(skb
->data
- NET_IP_ALIGN
);
495 rx_buffer_info
->skb
= NULL
;
497 if (rx_buffer_info
->dma
) {
498 dma_unmap_single(&pdev
->dev
, rx_buffer_info
->dma
,
501 rx_buffer_info
->dma
= 0;
506 dma_unmap_page(&pdev
->dev
, rx_buffer_info
->page_dma
,
507 PAGE_SIZE
/ 2, DMA_FROM_DEVICE
);
508 rx_buffer_info
->page_dma
= 0;
509 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
510 rx_buffer_info
->page
,
511 rx_buffer_info
->page_offset
,
514 if ((rx_ring
->rx_buf_len
> (PAGE_SIZE
/ 2)) ||
515 (page_count(rx_buffer_info
->page
) != 1))
516 rx_buffer_info
->page
= NULL
;
518 get_page(rx_buffer_info
->page
);
520 skb
->len
+= upper_len
;
521 skb
->data_len
+= upper_len
;
522 skb
->truesize
+= upper_len
;
526 if (i
== rx_ring
->count
)
529 next_rxd
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
533 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
535 if (!(staterr
& IXGBE_RXD_STAT_EOP
)) {
536 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
537 rx_buffer_info
->skb
= next_buffer
->skb
;
538 rx_buffer_info
->dma
= next_buffer
->dma
;
539 next_buffer
->skb
= skb
;
540 next_buffer
->dma
= 0;
542 skb
->next
= next_buffer
->skb
;
543 skb
->next
->prev
= skb
;
545 adapter
->non_eop_descs
++;
549 /* ERR_MASK will only have valid bits if EOP set */
550 if (unlikely(staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
)) {
551 dev_kfree_skb_irq(skb
);
555 ixgbevf_rx_checksum(adapter
, staterr
, skb
);
557 /* probably a little skewed due to removing CRC */
558 total_rx_bytes
+= skb
->len
;
562 * Work around issue of some types of VM to VM loop back
563 * packets not getting split correctly
565 if (staterr
& IXGBE_RXD_STAT_LB
) {
566 u32 header_fixup_len
= skb_headlen(skb
);
567 if (header_fixup_len
< 14)
568 skb_push(skb
, header_fixup_len
);
570 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
572 ixgbevf_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
575 rx_desc
->wb
.upper
.status_error
= 0;
577 /* return some buffers to hardware, one at a time is too slow */
578 if (cleaned_count
>= IXGBEVF_RX_BUFFER_WRITE
) {
579 ixgbevf_alloc_rx_buffers(adapter
, rx_ring
,
584 /* use prefetched values */
586 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
588 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
591 rx_ring
->next_to_clean
= i
;
592 cleaned_count
= IXGBE_DESC_UNUSED(rx_ring
);
595 ixgbevf_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
597 rx_ring
->total_packets
+= total_rx_packets
;
598 rx_ring
->total_bytes
+= total_rx_bytes
;
599 adapter
->netdev
->stats
.rx_bytes
+= total_rx_bytes
;
600 adapter
->netdev
->stats
.rx_packets
+= total_rx_packets
;
606 * ixgbevf_clean_rxonly - msix (aka one shot) rx clean routine
607 * @napi: napi struct with our devices info in it
608 * @budget: amount of work driver is allowed to do this pass, in packets
610 * This function is optimized for cleaning one queue only on a single
613 static int ixgbevf_clean_rxonly(struct napi_struct
*napi
, int budget
)
615 struct ixgbevf_q_vector
*q_vector
=
616 container_of(napi
, struct ixgbevf_q_vector
, napi
);
617 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
618 struct ixgbevf_ring
*rx_ring
= NULL
;
622 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
623 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
625 ixgbevf_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
627 /* If all Rx work done, exit the polling mode */
628 if (work_done
< budget
) {
630 if (adapter
->itr_setting
& 1)
631 ixgbevf_set_itr_msix(q_vector
);
632 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
633 ixgbevf_irq_enable_queues(adapter
, rx_ring
->v_idx
);
640 * ixgbevf_clean_rxonly_many - msix (aka one shot) rx clean routine
641 * @napi: napi struct with our devices info in it
642 * @budget: amount of work driver is allowed to do this pass, in packets
644 * This function will clean more than one rx queue associated with a
647 static int ixgbevf_clean_rxonly_many(struct napi_struct
*napi
, int budget
)
649 struct ixgbevf_q_vector
*q_vector
=
650 container_of(napi
, struct ixgbevf_q_vector
, napi
);
651 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
652 struct ixgbevf_ring
*rx_ring
= NULL
;
653 int work_done
= 0, i
;
657 /* attempt to distribute budget to each queue fairly, but don't allow
658 * the budget to go below 1 because we'll exit polling */
659 budget
/= (q_vector
->rxr_count
?: 1);
660 budget
= max(budget
, 1);
661 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
662 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
663 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
664 ixgbevf_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
665 enable_mask
|= rx_ring
->v_idx
;
666 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
670 #ifndef HAVE_NETDEV_NAPI_LIST
671 if (!netif_running(adapter
->netdev
))
675 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
676 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
678 /* If all Rx work done, exit the polling mode */
679 if (work_done
< budget
) {
681 if (adapter
->itr_setting
& 1)
682 ixgbevf_set_itr_msix(q_vector
);
683 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
684 ixgbevf_irq_enable_queues(adapter
, enable_mask
);
692 * ixgbevf_configure_msix - Configure MSI-X hardware
693 * @adapter: board private structure
695 * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X
698 static void ixgbevf_configure_msix(struct ixgbevf_adapter
*adapter
)
700 struct ixgbevf_q_vector
*q_vector
;
701 struct ixgbe_hw
*hw
= &adapter
->hw
;
702 int i
, j
, q_vectors
, v_idx
, r_idx
;
705 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
708 * Populate the IVAR table and set the ITR values to the
709 * corresponding register.
711 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
712 q_vector
= adapter
->q_vector
[v_idx
];
713 /* XXX for_each_set_bit(...) */
714 r_idx
= find_first_bit(q_vector
->rxr_idx
,
715 adapter
->num_rx_queues
);
717 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
718 j
= adapter
->rx_ring
[r_idx
].reg_idx
;
719 ixgbevf_set_ivar(adapter
, 0, j
, v_idx
);
720 r_idx
= find_next_bit(q_vector
->rxr_idx
,
721 adapter
->num_rx_queues
,
724 r_idx
= find_first_bit(q_vector
->txr_idx
,
725 adapter
->num_tx_queues
);
727 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
728 j
= adapter
->tx_ring
[r_idx
].reg_idx
;
729 ixgbevf_set_ivar(adapter
, 1, j
, v_idx
);
730 r_idx
= find_next_bit(q_vector
->txr_idx
,
731 adapter
->num_tx_queues
,
735 /* if this is a tx only vector halve the interrupt rate */
736 if (q_vector
->txr_count
&& !q_vector
->rxr_count
)
737 q_vector
->eitr
= (adapter
->eitr_param
>> 1);
738 else if (q_vector
->rxr_count
)
740 q_vector
->eitr
= adapter
->eitr_param
;
742 ixgbevf_write_eitr(adapter
, v_idx
, q_vector
->eitr
);
745 ixgbevf_set_ivar(adapter
, -1, 1, v_idx
);
747 /* set up to autoclear timer, and the vectors */
748 mask
= IXGBE_EIMS_ENABLE_MASK
;
749 mask
&= ~IXGBE_EIMS_OTHER
;
750 IXGBE_WRITE_REG(hw
, IXGBE_VTEIAC
, mask
);
757 latency_invalid
= 255
761 * ixgbevf_update_itr - update the dynamic ITR value based on statistics
762 * @adapter: pointer to adapter
763 * @eitr: eitr setting (ints per sec) to give last timeslice
764 * @itr_setting: current throttle rate in ints/second
765 * @packets: the number of packets during this measurement interval
766 * @bytes: the number of bytes during this measurement interval
768 * Stores a new ITR value based on packets and byte
769 * counts during the last interrupt. The advantage of per interrupt
770 * computation is faster updates and more accurate ITR for the current
771 * traffic pattern. Constants in this function were computed
772 * based on theoretical maximum wire speed and thresholds were set based
773 * on testing data as well as attempting to minimize response time
774 * while increasing bulk throughput.
776 static u8
ixgbevf_update_itr(struct ixgbevf_adapter
*adapter
,
777 u32 eitr
, u8 itr_setting
,
778 int packets
, int bytes
)
780 unsigned int retval
= itr_setting
;
785 goto update_itr_done
;
788 /* simple throttlerate management
789 * 0-20MB/s lowest (100000 ints/s)
790 * 20-100MB/s low (20000 ints/s)
791 * 100-1249MB/s bulk (8000 ints/s)
793 /* what was last interrupt timeslice? */
794 timepassed_us
= 1000000/eitr
;
795 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
797 switch (itr_setting
) {
799 if (bytes_perint
> adapter
->eitr_low
)
800 retval
= low_latency
;
803 if (bytes_perint
> adapter
->eitr_high
)
804 retval
= bulk_latency
;
805 else if (bytes_perint
<= adapter
->eitr_low
)
806 retval
= lowest_latency
;
809 if (bytes_perint
<= adapter
->eitr_high
)
810 retval
= low_latency
;
819 * ixgbevf_write_eitr - write VTEITR register in hardware specific way
820 * @adapter: pointer to adapter struct
821 * @v_idx: vector index into q_vector array
822 * @itr_reg: new value to be written in *register* format, not ints/s
824 * This function is made to be called by ethtool and by the driver
825 * when it needs to update VTEITR registers at runtime. Hardware
826 * specific quirks/differences are taken care of here.
828 static void ixgbevf_write_eitr(struct ixgbevf_adapter
*adapter
, int v_idx
,
831 struct ixgbe_hw
*hw
= &adapter
->hw
;
833 itr_reg
= EITR_INTS_PER_SEC_TO_REG(itr_reg
);
836 * set the WDIS bit to not clear the timer bits and cause an
837 * immediate assertion of the interrupt
839 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
841 IXGBE_WRITE_REG(hw
, IXGBE_VTEITR(v_idx
), itr_reg
);
844 static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector
*q_vector
)
846 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
848 u8 current_itr
, ret_itr
;
849 int i
, r_idx
, v_idx
= q_vector
->v_idx
;
850 struct ixgbevf_ring
*rx_ring
, *tx_ring
;
852 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
853 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
854 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
855 ret_itr
= ixgbevf_update_itr(adapter
, q_vector
->eitr
,
857 tx_ring
->total_packets
,
858 tx_ring
->total_bytes
);
859 /* if the result for this queue would decrease interrupt
860 * rate for this vector then use that result */
861 q_vector
->tx_itr
= ((q_vector
->tx_itr
> ret_itr
) ?
862 q_vector
->tx_itr
- 1 : ret_itr
);
863 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
867 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
868 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
869 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
870 ret_itr
= ixgbevf_update_itr(adapter
, q_vector
->eitr
,
872 rx_ring
->total_packets
,
873 rx_ring
->total_bytes
);
874 /* if the result for this queue would decrease interrupt
875 * rate for this vector then use that result */
876 q_vector
->rx_itr
= ((q_vector
->rx_itr
> ret_itr
) ?
877 q_vector
->rx_itr
- 1 : ret_itr
);
878 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
882 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
884 switch (current_itr
) {
885 /* counts and packets in update_itr are dependent on these numbers */
890 new_itr
= 20000; /* aka hwitr = ~200 */
898 if (new_itr
!= q_vector
->eitr
) {
901 /* save the algorithm value here, not the smoothed one */
902 q_vector
->eitr
= new_itr
;
903 /* do an exponential smoothing */
904 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
905 itr_reg
= EITR_INTS_PER_SEC_TO_REG(new_itr
);
906 ixgbevf_write_eitr(adapter
, v_idx
, itr_reg
);
910 static irqreturn_t
ixgbevf_msix_mbx(int irq
, void *data
)
912 struct net_device
*netdev
= data
;
913 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
914 struct ixgbe_hw
*hw
= &adapter
->hw
;
918 eicr
= IXGBE_READ_REG(hw
, IXGBE_VTEICS
);
919 IXGBE_WRITE_REG(hw
, IXGBE_VTEICR
, eicr
);
921 if (!hw
->mbx
.ops
.check_for_ack(hw
)) {
923 * checking for the ack clears the PFACK bit. Place
924 * it back in the v2p_mailbox cache so that anyone
925 * polling for an ack will not miss it. Also
926 * avoid the read below because the code to read
927 * the mailbox will also clear the ack bit. This was
928 * causing lost acks. Just cache the bit and exit
931 hw
->mbx
.v2p_mailbox
|= IXGBE_VFMAILBOX_PFACK
;
935 /* Not an ack interrupt, go ahead and read the message */
936 hw
->mbx
.ops
.read(hw
, &msg
, 1);
938 if ((msg
& IXGBE_MBVFICR_VFREQ_MASK
) == IXGBE_PF_CONTROL_MSG
)
939 mod_timer(&adapter
->watchdog_timer
,
940 round_jiffies(jiffies
+ 1));
946 static irqreturn_t
ixgbevf_msix_clean_tx(int irq
, void *data
)
948 struct ixgbevf_q_vector
*q_vector
= data
;
949 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
950 struct ixgbevf_ring
*tx_ring
;
953 if (!q_vector
->txr_count
)
956 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
957 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
958 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
959 tx_ring
->total_bytes
= 0;
960 tx_ring
->total_packets
= 0;
961 ixgbevf_clean_tx_irq(adapter
, tx_ring
);
962 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
966 if (adapter
->itr_setting
& 1)
967 ixgbevf_set_itr_msix(q_vector
);
973 * ixgbevf_msix_clean_rx - single unshared vector rx clean (all queues)
975 * @data: pointer to our q_vector struct for this interrupt vector
977 static irqreturn_t
ixgbevf_msix_clean_rx(int irq
, void *data
)
979 struct ixgbevf_q_vector
*q_vector
= data
;
980 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
981 struct ixgbe_hw
*hw
= &adapter
->hw
;
982 struct ixgbevf_ring
*rx_ring
;
986 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
987 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
988 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
989 rx_ring
->total_bytes
= 0;
990 rx_ring
->total_packets
= 0;
991 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
995 if (!q_vector
->rxr_count
)
998 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
999 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1000 /* disable interrupts on this vector only */
1001 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, rx_ring
->v_idx
);
1002 napi_schedule(&q_vector
->napi
);
1008 static irqreturn_t
ixgbevf_msix_clean_many(int irq
, void *data
)
1010 ixgbevf_msix_clean_rx(irq
, data
);
1011 ixgbevf_msix_clean_tx(irq
, data
);
1016 static inline void map_vector_to_rxq(struct ixgbevf_adapter
*a
, int v_idx
,
1019 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1021 set_bit(r_idx
, q_vector
->rxr_idx
);
1022 q_vector
->rxr_count
++;
1023 a
->rx_ring
[r_idx
].v_idx
= 1 << v_idx
;
1026 static inline void map_vector_to_txq(struct ixgbevf_adapter
*a
, int v_idx
,
1029 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1031 set_bit(t_idx
, q_vector
->txr_idx
);
1032 q_vector
->txr_count
++;
1033 a
->tx_ring
[t_idx
].v_idx
= 1 << v_idx
;
1037 * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
1038 * @adapter: board private structure to initialize
1040 * This function maps descriptor rings to the queue-specific vectors
1041 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1042 * one vector per ring/queue, but on a constrained vector budget, we
1043 * group the rings as "efficiently" as possible. You would add new
1044 * mapping configurations in here.
1046 static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter
*adapter
)
1050 int rxr_idx
= 0, txr_idx
= 0;
1051 int rxr_remaining
= adapter
->num_rx_queues
;
1052 int txr_remaining
= adapter
->num_tx_queues
;
1057 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1060 * The ideal configuration...
1061 * We have enough vectors to map one per queue.
1063 if (q_vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
1064 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
1065 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
1067 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
1068 map_vector_to_txq(adapter
, v_start
, txr_idx
);
1073 * If we don't have enough vectors for a 1-to-1
1074 * mapping, we'll have to group them so there are
1075 * multiple queues per vector.
1077 /* Re-adjusting *qpv takes care of the remainder. */
1078 for (i
= v_start
; i
< q_vectors
; i
++) {
1079 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
1080 for (j
= 0; j
< rqpv
; j
++) {
1081 map_vector_to_rxq(adapter
, i
, rxr_idx
);
1086 for (i
= v_start
; i
< q_vectors
; i
++) {
1087 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
1088 for (j
= 0; j
< tqpv
; j
++) {
1089 map_vector_to_txq(adapter
, i
, txr_idx
);
1100 * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
1101 * @adapter: board private structure
1103 * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
1104 * interrupts from the kernel.
1106 static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter
*adapter
)
1108 struct net_device
*netdev
= adapter
->netdev
;
1109 irqreturn_t (*handler
)(int, void *);
1110 int i
, vector
, q_vectors
, err
;
1113 /* Decrement for Other and TCP Timer vectors */
1114 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1116 #define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
1117 ? &ixgbevf_msix_clean_many : \
1118 (_v)->rxr_count ? &ixgbevf_msix_clean_rx : \
1119 (_v)->txr_count ? &ixgbevf_msix_clean_tx : \
1121 for (vector
= 0; vector
< q_vectors
; vector
++) {
1122 handler
= SET_HANDLER(adapter
->q_vector
[vector
]);
1124 if (handler
== &ixgbevf_msix_clean_rx
) {
1125 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1126 netdev
->name
, "rx", ri
++);
1127 } else if (handler
== &ixgbevf_msix_clean_tx
) {
1128 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1129 netdev
->name
, "tx", ti
++);
1130 } else if (handler
== &ixgbevf_msix_clean_many
) {
1131 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1132 netdev
->name
, "TxRx", vector
);
1134 /* skip this unused q_vector */
1137 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1138 handler
, 0, adapter
->name
[vector
],
1139 adapter
->q_vector
[vector
]);
1141 hw_dbg(&adapter
->hw
,
1142 "request_irq failed for MSIX interrupt "
1143 "Error: %d\n", err
);
1144 goto free_queue_irqs
;
1148 sprintf(adapter
->name
[vector
], "%s:mbx", netdev
->name
);
1149 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1150 &ixgbevf_msix_mbx
, 0, adapter
->name
[vector
], netdev
);
1152 hw_dbg(&adapter
->hw
,
1153 "request_irq for msix_mbx failed: %d\n", err
);
1154 goto free_queue_irqs
;
1160 for (i
= vector
- 1; i
>= 0; i
--)
1161 free_irq(adapter
->msix_entries
[--vector
].vector
,
1162 &(adapter
->q_vector
[i
]));
1163 pci_disable_msix(adapter
->pdev
);
1164 kfree(adapter
->msix_entries
);
1165 adapter
->msix_entries
= NULL
;
1169 static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter
*adapter
)
1171 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1173 for (i
= 0; i
< q_vectors
; i
++) {
1174 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[i
];
1175 bitmap_zero(q_vector
->rxr_idx
, MAX_RX_QUEUES
);
1176 bitmap_zero(q_vector
->txr_idx
, MAX_TX_QUEUES
);
1177 q_vector
->rxr_count
= 0;
1178 q_vector
->txr_count
= 0;
1179 q_vector
->eitr
= adapter
->eitr_param
;
1184 * ixgbevf_request_irq - initialize interrupts
1185 * @adapter: board private structure
1187 * Attempts to configure interrupts using the best available
1188 * capabilities of the hardware and kernel.
1190 static int ixgbevf_request_irq(struct ixgbevf_adapter
*adapter
)
1194 err
= ixgbevf_request_msix_irqs(adapter
);
1197 hw_dbg(&adapter
->hw
,
1198 "request_irq failed, Error %d\n", err
);
1203 static void ixgbevf_free_irq(struct ixgbevf_adapter
*adapter
)
1205 struct net_device
*netdev
= adapter
->netdev
;
1208 q_vectors
= adapter
->num_msix_vectors
;
1212 free_irq(adapter
->msix_entries
[i
].vector
, netdev
);
1215 for (; i
>= 0; i
--) {
1216 free_irq(adapter
->msix_entries
[i
].vector
,
1217 adapter
->q_vector
[i
]);
1220 ixgbevf_reset_q_vectors(adapter
);
1224 * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
1225 * @adapter: board private structure
1227 static inline void ixgbevf_irq_disable(struct ixgbevf_adapter
*adapter
)
1230 struct ixgbe_hw
*hw
= &adapter
->hw
;
1232 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, ~0);
1234 IXGBE_WRITE_FLUSH(hw
);
1236 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
1237 synchronize_irq(adapter
->msix_entries
[i
].vector
);
1241 * ixgbevf_irq_enable - Enable default interrupt generation settings
1242 * @adapter: board private structure
1244 static inline void ixgbevf_irq_enable(struct ixgbevf_adapter
*adapter
,
1245 bool queues
, bool flush
)
1247 struct ixgbe_hw
*hw
= &adapter
->hw
;
1251 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
1254 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, mask
);
1257 ixgbevf_irq_enable_queues(adapter
, qmask
);
1260 IXGBE_WRITE_FLUSH(hw
);
1264 * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
1265 * @adapter: board private structure
1267 * Configure the Tx unit of the MAC after a reset.
1269 static void ixgbevf_configure_tx(struct ixgbevf_adapter
*adapter
)
1272 struct ixgbe_hw
*hw
= &adapter
->hw
;
1273 u32 i
, j
, tdlen
, txctrl
;
1275 /* Setup the HW Tx Head and Tail descriptor pointers */
1276 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1277 struct ixgbevf_ring
*ring
= &adapter
->tx_ring
[i
];
1280 tdlen
= ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
1281 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAL(j
),
1282 (tdba
& DMA_BIT_MASK(32)));
1283 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAH(j
), (tdba
>> 32));
1284 IXGBE_WRITE_REG(hw
, IXGBE_VFTDLEN(j
), tdlen
);
1285 IXGBE_WRITE_REG(hw
, IXGBE_VFTDH(j
), 0);
1286 IXGBE_WRITE_REG(hw
, IXGBE_VFTDT(j
), 0);
1287 adapter
->tx_ring
[i
].head
= IXGBE_VFTDH(j
);
1288 adapter
->tx_ring
[i
].tail
= IXGBE_VFTDT(j
);
1289 /* Disable Tx Head Writeback RO bit, since this hoses
1290 * bookkeeping if things aren't delivered in order.
1292 txctrl
= IXGBE_READ_REG(hw
, IXGBE_VFDCA_TXCTRL(j
));
1293 txctrl
&= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN
;
1294 IXGBE_WRITE_REG(hw
, IXGBE_VFDCA_TXCTRL(j
), txctrl
);
1298 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1300 static void ixgbevf_configure_srrctl(struct ixgbevf_adapter
*adapter
, int index
)
1302 struct ixgbevf_ring
*rx_ring
;
1303 struct ixgbe_hw
*hw
= &adapter
->hw
;
1306 rx_ring
= &adapter
->rx_ring
[index
];
1308 srrctl
= IXGBE_SRRCTL_DROP_EN
;
1310 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1311 u16 bufsz
= IXGBEVF_RXBUFFER_2048
;
1312 /* grow the amount we can receive on large page machines */
1313 if (bufsz
< (PAGE_SIZE
/ 2))
1314 bufsz
= (PAGE_SIZE
/ 2);
1315 /* cap the bufsz at our largest descriptor size */
1316 bufsz
= min((u16
)IXGBEVF_MAX_RXBUFFER
, bufsz
);
1318 srrctl
|= bufsz
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1319 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
1320 srrctl
|= ((IXGBEVF_RX_HDR_SIZE
<<
1321 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
1322 IXGBE_SRRCTL_BSIZEHDR_MASK
);
1324 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1326 if (rx_ring
->rx_buf_len
== MAXIMUM_ETHERNET_VLAN_SIZE
)
1327 srrctl
|= IXGBEVF_RXBUFFER_2048
>>
1328 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1330 srrctl
|= rx_ring
->rx_buf_len
>>
1331 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1333 IXGBE_WRITE_REG(hw
, IXGBE_VFSRRCTL(index
), srrctl
);
1337 * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
1338 * @adapter: board private structure
1340 * Configure the Rx unit of the MAC after a reset.
1342 static void ixgbevf_configure_rx(struct ixgbevf_adapter
*adapter
)
1345 struct ixgbe_hw
*hw
= &adapter
->hw
;
1346 struct net_device
*netdev
= adapter
->netdev
;
1347 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1352 /* Decide whether to use packet split mode or not */
1353 if (netdev
->mtu
> ETH_DATA_LEN
) {
1354 if (adapter
->flags
& IXGBE_FLAG_RX_PS_CAPABLE
)
1355 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
1357 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
1359 if (adapter
->flags
& IXGBE_FLAG_RX_1BUF_CAPABLE
)
1360 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
1362 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
1365 /* Set the RX buffer length according to the mode */
1366 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1367 /* PSRTYPE must be initialized in 82599 */
1368 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
1369 IXGBE_PSRTYPE_UDPHDR
|
1370 IXGBE_PSRTYPE_IPV4HDR
|
1371 IXGBE_PSRTYPE_IPV6HDR
|
1372 IXGBE_PSRTYPE_L2HDR
;
1373 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, psrtype
);
1374 rx_buf_len
= IXGBEVF_RX_HDR_SIZE
;
1376 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, 0);
1377 if (netdev
->mtu
<= ETH_DATA_LEN
)
1378 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1380 rx_buf_len
= ALIGN(max_frame
, 1024);
1383 rdlen
= adapter
->rx_ring
[0].count
* sizeof(union ixgbe_adv_rx_desc
);
1384 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1385 * the Base and Length of the Rx Descriptor Ring */
1386 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1387 rdba
= adapter
->rx_ring
[i
].dma
;
1388 j
= adapter
->rx_ring
[i
].reg_idx
;
1389 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAL(j
),
1390 (rdba
& DMA_BIT_MASK(32)));
1391 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAH(j
), (rdba
>> 32));
1392 IXGBE_WRITE_REG(hw
, IXGBE_VFRDLEN(j
), rdlen
);
1393 IXGBE_WRITE_REG(hw
, IXGBE_VFRDH(j
), 0);
1394 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(j
), 0);
1395 adapter
->rx_ring
[i
].head
= IXGBE_VFRDH(j
);
1396 adapter
->rx_ring
[i
].tail
= IXGBE_VFRDT(j
);
1397 adapter
->rx_ring
[i
].rx_buf_len
= rx_buf_len
;
1399 ixgbevf_configure_srrctl(adapter
, j
);
1403 static void ixgbevf_vlan_rx_register(struct net_device
*netdev
,
1404 struct vlan_group
*grp
)
1406 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1407 struct ixgbe_hw
*hw
= &adapter
->hw
;
1411 adapter
->vlgrp
= grp
;
1413 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1414 j
= adapter
->rx_ring
[i
].reg_idx
;
1415 ctrl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1416 ctrl
|= IXGBE_RXDCTL_VME
;
1417 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), ctrl
);
1421 static void ixgbevf_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
1423 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1424 struct ixgbe_hw
*hw
= &adapter
->hw
;
1426 /* add VID to filter table */
1427 if (hw
->mac
.ops
.set_vfta
)
1428 hw
->mac
.ops
.set_vfta(hw
, vid
, 0, true);
1431 static void ixgbevf_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
1433 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1434 struct ixgbe_hw
*hw
= &adapter
->hw
;
1436 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
1437 ixgbevf_irq_disable(adapter
);
1439 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
1441 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
1442 ixgbevf_irq_enable(adapter
, true, true);
1444 /* remove VID from filter table */
1445 if (hw
->mac
.ops
.set_vfta
)
1446 hw
->mac
.ops
.set_vfta(hw
, vid
, 0, false);
1449 static void ixgbevf_restore_vlan(struct ixgbevf_adapter
*adapter
)
1451 ixgbevf_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
1453 if (adapter
->vlgrp
) {
1455 for (vid
= 0; vid
< VLAN_N_VID
; vid
++) {
1456 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
1458 ixgbevf_vlan_rx_add_vid(adapter
->netdev
, vid
);
1464 * ixgbevf_set_rx_mode - Multicast set
1465 * @netdev: network interface device structure
1467 * The set_rx_method entry point is called whenever the multicast address
1468 * list or the network interface flags are updated. This routine is
1469 * responsible for configuring the hardware for proper multicast mode.
1471 static void ixgbevf_set_rx_mode(struct net_device
*netdev
)
1473 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1474 struct ixgbe_hw
*hw
= &adapter
->hw
;
1476 /* reprogram multicast list */
1477 if (hw
->mac
.ops
.update_mc_addr_list
)
1478 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
1481 static void ixgbevf_napi_enable_all(struct ixgbevf_adapter
*adapter
)
1484 struct ixgbevf_q_vector
*q_vector
;
1485 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1487 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1488 struct napi_struct
*napi
;
1489 q_vector
= adapter
->q_vector
[q_idx
];
1490 if (!q_vector
->rxr_count
)
1492 napi
= &q_vector
->napi
;
1493 if (q_vector
->rxr_count
> 1)
1494 napi
->poll
= &ixgbevf_clean_rxonly_many
;
1500 static void ixgbevf_napi_disable_all(struct ixgbevf_adapter
*adapter
)
1503 struct ixgbevf_q_vector
*q_vector
;
1504 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1506 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1507 q_vector
= adapter
->q_vector
[q_idx
];
1508 if (!q_vector
->rxr_count
)
1510 napi_disable(&q_vector
->napi
);
1514 static void ixgbevf_configure(struct ixgbevf_adapter
*adapter
)
1516 struct net_device
*netdev
= adapter
->netdev
;
1519 ixgbevf_set_rx_mode(netdev
);
1521 ixgbevf_restore_vlan(adapter
);
1523 ixgbevf_configure_tx(adapter
);
1524 ixgbevf_configure_rx(adapter
);
1525 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1526 struct ixgbevf_ring
*ring
= &adapter
->rx_ring
[i
];
1527 ixgbevf_alloc_rx_buffers(adapter
, ring
, ring
->count
);
1528 ring
->next_to_use
= ring
->count
- 1;
1529 writel(ring
->next_to_use
, adapter
->hw
.hw_addr
+ ring
->tail
);
1533 #define IXGBE_MAX_RX_DESC_POLL 10
1534 static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter
*adapter
,
1537 struct ixgbe_hw
*hw
= &adapter
->hw
;
1538 int j
= adapter
->rx_ring
[rxr
].reg_idx
;
1541 for (k
= 0; k
< IXGBE_MAX_RX_DESC_POLL
; k
++) {
1542 if (IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
)) & IXGBE_RXDCTL_ENABLE
)
1547 if (k
>= IXGBE_MAX_RX_DESC_POLL
) {
1548 hw_dbg(hw
, "RXDCTL.ENABLE on Rx queue %d "
1549 "not set within the polling period\n", rxr
);
1552 ixgbevf_release_rx_desc(&adapter
->hw
, &adapter
->rx_ring
[rxr
],
1553 (adapter
->rx_ring
[rxr
].count
- 1));
1556 static void ixgbevf_save_reset_stats(struct ixgbevf_adapter
*adapter
)
1558 /* Only save pre-reset stats if there are some */
1559 if (adapter
->stats
.vfgprc
|| adapter
->stats
.vfgptc
) {
1560 adapter
->stats
.saved_reset_vfgprc
+= adapter
->stats
.vfgprc
-
1561 adapter
->stats
.base_vfgprc
;
1562 adapter
->stats
.saved_reset_vfgptc
+= adapter
->stats
.vfgptc
-
1563 adapter
->stats
.base_vfgptc
;
1564 adapter
->stats
.saved_reset_vfgorc
+= adapter
->stats
.vfgorc
-
1565 adapter
->stats
.base_vfgorc
;
1566 adapter
->stats
.saved_reset_vfgotc
+= adapter
->stats
.vfgotc
-
1567 adapter
->stats
.base_vfgotc
;
1568 adapter
->stats
.saved_reset_vfmprc
+= adapter
->stats
.vfmprc
-
1569 adapter
->stats
.base_vfmprc
;
1573 static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter
*adapter
)
1575 struct ixgbe_hw
*hw
= &adapter
->hw
;
1577 adapter
->stats
.last_vfgprc
= IXGBE_READ_REG(hw
, IXGBE_VFGPRC
);
1578 adapter
->stats
.last_vfgorc
= IXGBE_READ_REG(hw
, IXGBE_VFGORC_LSB
);
1579 adapter
->stats
.last_vfgorc
|=
1580 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGORC_MSB
))) << 32);
1581 adapter
->stats
.last_vfgptc
= IXGBE_READ_REG(hw
, IXGBE_VFGPTC
);
1582 adapter
->stats
.last_vfgotc
= IXGBE_READ_REG(hw
, IXGBE_VFGOTC_LSB
);
1583 adapter
->stats
.last_vfgotc
|=
1584 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGOTC_MSB
))) << 32);
1585 adapter
->stats
.last_vfmprc
= IXGBE_READ_REG(hw
, IXGBE_VFMPRC
);
1587 adapter
->stats
.base_vfgprc
= adapter
->stats
.last_vfgprc
;
1588 adapter
->stats
.base_vfgorc
= adapter
->stats
.last_vfgorc
;
1589 adapter
->stats
.base_vfgptc
= adapter
->stats
.last_vfgptc
;
1590 adapter
->stats
.base_vfgotc
= adapter
->stats
.last_vfgotc
;
1591 adapter
->stats
.base_vfmprc
= adapter
->stats
.last_vfmprc
;
1594 static int ixgbevf_up_complete(struct ixgbevf_adapter
*adapter
)
1596 struct net_device
*netdev
= adapter
->netdev
;
1597 struct ixgbe_hw
*hw
= &adapter
->hw
;
1599 int num_rx_rings
= adapter
->num_rx_queues
;
1602 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1603 j
= adapter
->tx_ring
[i
].reg_idx
;
1604 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1605 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
1606 txdctl
|= (8 << 16);
1607 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1610 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1611 j
= adapter
->tx_ring
[i
].reg_idx
;
1612 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1613 txdctl
|= IXGBE_TXDCTL_ENABLE
;
1614 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1617 for (i
= 0; i
< num_rx_rings
; i
++) {
1618 j
= adapter
->rx_ring
[i
].reg_idx
;
1619 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1620 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
1621 if (hw
->mac
.type
== ixgbe_mac_X540_vf
) {
1622 rxdctl
&= ~IXGBE_RXDCTL_RLPMLMASK
;
1623 rxdctl
|= ((netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
) |
1624 IXGBE_RXDCTL_RLPML_EN
);
1626 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), rxdctl
);
1627 ixgbevf_rx_desc_queue_enable(adapter
, i
);
1630 ixgbevf_configure_msix(adapter
);
1632 if (hw
->mac
.ops
.set_rar
) {
1633 if (is_valid_ether_addr(hw
->mac
.addr
))
1634 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
1636 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.perm_addr
, 0);
1639 clear_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1640 ixgbevf_napi_enable_all(adapter
);
1642 /* enable transmits */
1643 netif_tx_start_all_queues(netdev
);
1645 ixgbevf_save_reset_stats(adapter
);
1646 ixgbevf_init_last_counter_stats(adapter
);
1648 /* bring the link up in the watchdog, this could race with our first
1649 * link up interrupt but shouldn't be a problem */
1650 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1651 adapter
->link_check_timeout
= jiffies
;
1652 mod_timer(&adapter
->watchdog_timer
, jiffies
);
1656 int ixgbevf_up(struct ixgbevf_adapter
*adapter
)
1659 struct ixgbe_hw
*hw
= &adapter
->hw
;
1661 ixgbevf_configure(adapter
);
1663 err
= ixgbevf_up_complete(adapter
);
1665 /* clear any pending interrupts, may auto mask */
1666 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
1668 ixgbevf_irq_enable(adapter
, true, true);
1674 * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
1675 * @adapter: board private structure
1676 * @rx_ring: ring to free buffers from
1678 static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter
*adapter
,
1679 struct ixgbevf_ring
*rx_ring
)
1681 struct pci_dev
*pdev
= adapter
->pdev
;
1685 if (!rx_ring
->rx_buffer_info
)
1688 /* Free all the Rx ring sk_buffs */
1689 for (i
= 0; i
< rx_ring
->count
; i
++) {
1690 struct ixgbevf_rx_buffer
*rx_buffer_info
;
1692 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1693 if (rx_buffer_info
->dma
) {
1694 dma_unmap_single(&pdev
->dev
, rx_buffer_info
->dma
,
1695 rx_ring
->rx_buf_len
,
1697 rx_buffer_info
->dma
= 0;
1699 if (rx_buffer_info
->skb
) {
1700 struct sk_buff
*skb
= rx_buffer_info
->skb
;
1701 rx_buffer_info
->skb
= NULL
;
1703 struct sk_buff
*this = skb
;
1705 dev_kfree_skb(this);
1708 if (!rx_buffer_info
->page
)
1710 dma_unmap_page(&pdev
->dev
, rx_buffer_info
->page_dma
,
1711 PAGE_SIZE
/ 2, DMA_FROM_DEVICE
);
1712 rx_buffer_info
->page_dma
= 0;
1713 put_page(rx_buffer_info
->page
);
1714 rx_buffer_info
->page
= NULL
;
1715 rx_buffer_info
->page_offset
= 0;
1718 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
1719 memset(rx_ring
->rx_buffer_info
, 0, size
);
1721 /* Zero out the descriptor ring */
1722 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1724 rx_ring
->next_to_clean
= 0;
1725 rx_ring
->next_to_use
= 0;
1728 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1730 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1734 * ixgbevf_clean_tx_ring - Free Tx Buffers
1735 * @adapter: board private structure
1736 * @tx_ring: ring to be cleaned
1738 static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter
*adapter
,
1739 struct ixgbevf_ring
*tx_ring
)
1741 struct ixgbevf_tx_buffer
*tx_buffer_info
;
1745 if (!tx_ring
->tx_buffer_info
)
1748 /* Free all the Tx ring sk_buffs */
1750 for (i
= 0; i
< tx_ring
->count
; i
++) {
1751 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
1752 ixgbevf_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
1755 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
1756 memset(tx_ring
->tx_buffer_info
, 0, size
);
1758 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1760 tx_ring
->next_to_use
= 0;
1761 tx_ring
->next_to_clean
= 0;
1764 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1766 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1770 * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
1771 * @adapter: board private structure
1773 static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter
*adapter
)
1777 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1778 ixgbevf_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
1782 * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
1783 * @adapter: board private structure
1785 static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter
*adapter
)
1789 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1790 ixgbevf_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1793 void ixgbevf_down(struct ixgbevf_adapter
*adapter
)
1795 struct net_device
*netdev
= adapter
->netdev
;
1796 struct ixgbe_hw
*hw
= &adapter
->hw
;
1800 /* signal that we are down to the interrupt handler */
1801 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1802 /* disable receives */
1804 netif_tx_disable(netdev
);
1808 netif_tx_stop_all_queues(netdev
);
1810 ixgbevf_irq_disable(adapter
);
1812 ixgbevf_napi_disable_all(adapter
);
1814 del_timer_sync(&adapter
->watchdog_timer
);
1815 /* can't call flush scheduled work here because it can deadlock
1816 * if linkwatch_event tries to acquire the rtnl_lock which we are
1818 while (adapter
->flags
& IXGBE_FLAG_IN_WATCHDOG_TASK
)
1821 /* disable transmits in the hardware now that interrupts are off */
1822 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1823 j
= adapter
->tx_ring
[i
].reg_idx
;
1824 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1825 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
),
1826 (txdctl
& ~IXGBE_TXDCTL_ENABLE
));
1829 netif_carrier_off(netdev
);
1831 if (!pci_channel_offline(adapter
->pdev
))
1832 ixgbevf_reset(adapter
);
1834 ixgbevf_clean_all_tx_rings(adapter
);
1835 ixgbevf_clean_all_rx_rings(adapter
);
1838 void ixgbevf_reinit_locked(struct ixgbevf_adapter
*adapter
)
1840 struct ixgbe_hw
*hw
= &adapter
->hw
;
1842 WARN_ON(in_interrupt());
1844 while (test_and_set_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
1848 * Check if PF is up before re-init. If not then skip until
1849 * later when the PF is up and ready to service requests from
1850 * the VF via mailbox. If the VF is up and running then the
1851 * watchdog task will continue to schedule reset tasks until
1852 * the PF is up and running.
1854 if (!hw
->mac
.ops
.reset_hw(hw
)) {
1855 ixgbevf_down(adapter
);
1856 ixgbevf_up(adapter
);
1859 clear_bit(__IXGBEVF_RESETTING
, &adapter
->state
);
1862 void ixgbevf_reset(struct ixgbevf_adapter
*adapter
)
1864 struct ixgbe_hw
*hw
= &adapter
->hw
;
1865 struct net_device
*netdev
= adapter
->netdev
;
1867 if (hw
->mac
.ops
.reset_hw(hw
))
1868 hw_dbg(hw
, "PF still resetting\n");
1870 hw
->mac
.ops
.init_hw(hw
);
1872 if (is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
1873 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
,
1875 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
,
1880 static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter
*adapter
,
1883 int err
, vector_threshold
;
1885 /* We'll want at least 3 (vector_threshold):
1888 * 3) Other (Link Status Change, etc.)
1890 vector_threshold
= MIN_MSIX_COUNT
;
1892 /* The more we get, the more we will assign to Tx/Rx Cleanup
1893 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1894 * Right now, we simply care about how many we'll get; we'll
1895 * set them up later while requesting irq's.
1897 while (vectors
>= vector_threshold
) {
1898 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1900 if (!err
) /* Success in acquiring all requested vectors. */
1903 vectors
= 0; /* Nasty failure, quit now */
1904 else /* err == number of vectors we should try again with */
1908 if (vectors
< vector_threshold
) {
1909 /* Can't allocate enough MSI-X interrupts? Oh well.
1910 * This just means we'll go with either a single MSI
1911 * vector or fall back to legacy interrupts.
1913 hw_dbg(&adapter
->hw
,
1914 "Unable to allocate MSI-X interrupts\n");
1915 kfree(adapter
->msix_entries
);
1916 adapter
->msix_entries
= NULL
;
1919 * Adjust for only the vectors we'll use, which is minimum
1920 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
1921 * vectors we were allocated.
1923 adapter
->num_msix_vectors
= vectors
;
1928 * ixgbevf_set_num_queues: Allocate queues for device, feature dependent
1929 * @adapter: board private structure to initialize
1931 * This is the top level queue allocation routine. The order here is very
1932 * important, starting with the "most" number of features turned on at once,
1933 * and ending with the smallest set of features. This way large combinations
1934 * can be allocated if they're turned on, and smaller combinations are the
1935 * fallthrough conditions.
1938 static void ixgbevf_set_num_queues(struct ixgbevf_adapter
*adapter
)
1940 /* Start with base case */
1941 adapter
->num_rx_queues
= 1;
1942 adapter
->num_tx_queues
= 1;
1943 adapter
->num_rx_pools
= adapter
->num_rx_queues
;
1944 adapter
->num_rx_queues_per_pool
= 1;
1948 * ixgbevf_alloc_queues - Allocate memory for all rings
1949 * @adapter: board private structure to initialize
1951 * We allocate one ring per queue at run-time since we don't know the
1952 * number of queues at compile-time. The polling_netdev array is
1953 * intended for Multiqueue, but should work fine with a single queue.
1955 static int ixgbevf_alloc_queues(struct ixgbevf_adapter
*adapter
)
1959 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1960 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
1961 if (!adapter
->tx_ring
)
1962 goto err_tx_ring_allocation
;
1964 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1965 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
1966 if (!adapter
->rx_ring
)
1967 goto err_rx_ring_allocation
;
1969 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1970 adapter
->tx_ring
[i
].count
= adapter
->tx_ring_count
;
1971 adapter
->tx_ring
[i
].queue_index
= i
;
1972 adapter
->tx_ring
[i
].reg_idx
= i
;
1975 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1976 adapter
->rx_ring
[i
].count
= adapter
->rx_ring_count
;
1977 adapter
->rx_ring
[i
].queue_index
= i
;
1978 adapter
->rx_ring
[i
].reg_idx
= i
;
1983 err_rx_ring_allocation
:
1984 kfree(adapter
->tx_ring
);
1985 err_tx_ring_allocation
:
1990 * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
1991 * @adapter: board private structure to initialize
1993 * Attempt to configure the interrupts using the best available
1994 * capabilities of the hardware and the kernel.
1996 static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter
*adapter
)
1999 int vector
, v_budget
;
2002 * It's easy to be greedy for MSI-X vectors, but it really
2003 * doesn't do us much good if we have a lot more vectors
2004 * than CPU's. So let's be conservative and only ask for
2005 * (roughly) twice the number of vectors as there are CPU's.
2007 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
2008 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS
;
2010 /* A failure in MSI-X entry allocation isn't fatal, but it does
2011 * mean we disable MSI-X capabilities of the adapter. */
2012 adapter
->msix_entries
= kcalloc(v_budget
,
2013 sizeof(struct msix_entry
), GFP_KERNEL
);
2014 if (!adapter
->msix_entries
) {
2019 for (vector
= 0; vector
< v_budget
; vector
++)
2020 adapter
->msix_entries
[vector
].entry
= vector
;
2022 ixgbevf_acquire_msix_vectors(adapter
, v_budget
);
2029 * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
2030 * @adapter: board private structure to initialize
2032 * We allocate one q_vector per queue interrupt. If allocation fails we
2035 static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter
*adapter
)
2037 int q_idx
, num_q_vectors
;
2038 struct ixgbevf_q_vector
*q_vector
;
2040 int (*poll
)(struct napi_struct
*, int);
2042 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2043 napi_vectors
= adapter
->num_rx_queues
;
2044 poll
= &ixgbevf_clean_rxonly
;
2046 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
2047 q_vector
= kzalloc(sizeof(struct ixgbevf_q_vector
), GFP_KERNEL
);
2050 q_vector
->adapter
= adapter
;
2051 q_vector
->v_idx
= q_idx
;
2052 q_vector
->eitr
= adapter
->eitr_param
;
2053 if (q_idx
< napi_vectors
)
2054 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
2056 adapter
->q_vector
[q_idx
] = q_vector
;
2064 q_vector
= adapter
->q_vector
[q_idx
];
2065 netif_napi_del(&q_vector
->napi
);
2067 adapter
->q_vector
[q_idx
] = NULL
;
2073 * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
2074 * @adapter: board private structure to initialize
2076 * This function frees the memory allocated to the q_vectors. In addition if
2077 * NAPI is enabled it will delete any references to the NAPI struct prior
2078 * to freeing the q_vector.
2080 static void ixgbevf_free_q_vectors(struct ixgbevf_adapter
*adapter
)
2082 int q_idx
, num_q_vectors
;
2085 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2086 napi_vectors
= adapter
->num_rx_queues
;
2088 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
2089 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
2091 adapter
->q_vector
[q_idx
] = NULL
;
2092 if (q_idx
< napi_vectors
)
2093 netif_napi_del(&q_vector
->napi
);
2099 * ixgbevf_reset_interrupt_capability - Reset MSIX setup
2100 * @adapter: board private structure
2103 static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter
*adapter
)
2105 pci_disable_msix(adapter
->pdev
);
2106 kfree(adapter
->msix_entries
);
2107 adapter
->msix_entries
= NULL
;
2111 * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
2112 * @adapter: board private structure to initialize
2115 static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter
*adapter
)
2119 /* Number of supported queues */
2120 ixgbevf_set_num_queues(adapter
);
2122 err
= ixgbevf_set_interrupt_capability(adapter
);
2124 hw_dbg(&adapter
->hw
,
2125 "Unable to setup interrupt capabilities\n");
2126 goto err_set_interrupt
;
2129 err
= ixgbevf_alloc_q_vectors(adapter
);
2131 hw_dbg(&adapter
->hw
, "Unable to allocate memory for queue "
2133 goto err_alloc_q_vectors
;
2136 err
= ixgbevf_alloc_queues(adapter
);
2138 printk(KERN_ERR
"Unable to allocate memory for queues\n");
2139 goto err_alloc_queues
;
2142 hw_dbg(&adapter
->hw
, "Multiqueue %s: Rx Queue count = %u, "
2143 "Tx Queue count = %u\n",
2144 (adapter
->num_rx_queues
> 1) ? "Enabled" :
2145 "Disabled", adapter
->num_rx_queues
, adapter
->num_tx_queues
);
2147 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2151 ixgbevf_free_q_vectors(adapter
);
2152 err_alloc_q_vectors
:
2153 ixgbevf_reset_interrupt_capability(adapter
);
2159 * ixgbevf_sw_init - Initialize general software structures
2160 * (struct ixgbevf_adapter)
2161 * @adapter: board private structure to initialize
2163 * ixgbevf_sw_init initializes the Adapter private data structure.
2164 * Fields are initialized based on PCI device information and
2165 * OS network device settings (MTU size).
2167 static int __devinit
ixgbevf_sw_init(struct ixgbevf_adapter
*adapter
)
2169 struct ixgbe_hw
*hw
= &adapter
->hw
;
2170 struct pci_dev
*pdev
= adapter
->pdev
;
2173 /* PCI config space info */
2175 hw
->vendor_id
= pdev
->vendor
;
2176 hw
->device_id
= pdev
->device
;
2177 hw
->revision_id
= pdev
->revision
;
2178 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2179 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2181 hw
->mbx
.ops
.init_params(hw
);
2182 hw
->mac
.max_tx_queues
= MAX_TX_QUEUES
;
2183 hw
->mac
.max_rx_queues
= MAX_RX_QUEUES
;
2184 err
= hw
->mac
.ops
.reset_hw(hw
);
2186 dev_info(&pdev
->dev
,
2187 "PF still in reset state, assigning new address\n");
2188 dev_hw_addr_random(adapter
->netdev
, hw
->mac
.addr
);
2190 err
= hw
->mac
.ops
.init_hw(hw
);
2192 printk(KERN_ERR
"init_shared_code failed: %d\n", err
);
2197 /* Enable dynamic interrupt throttling rates */
2198 adapter
->eitr_param
= 20000;
2199 adapter
->itr_setting
= 1;
2201 /* set defaults for eitr in MegaBytes */
2202 adapter
->eitr_low
= 10;
2203 adapter
->eitr_high
= 20;
2205 /* set default ring sizes */
2206 adapter
->tx_ring_count
= IXGBEVF_DEFAULT_TXD
;
2207 adapter
->rx_ring_count
= IXGBEVF_DEFAULT_RXD
;
2209 /* enable rx csum by default */
2210 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
2212 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2218 #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
2220 u32 current_counter = IXGBE_READ_REG(hw, reg); \
2221 if (current_counter < last_counter) \
2222 counter += 0x100000000LL; \
2223 last_counter = current_counter; \
2224 counter &= 0xFFFFFFFF00000000LL; \
2225 counter |= current_counter; \
2228 #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
2230 u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
2231 u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
2232 u64 current_counter = (current_counter_msb << 32) | \
2233 current_counter_lsb; \
2234 if (current_counter < last_counter) \
2235 counter += 0x1000000000LL; \
2236 last_counter = current_counter; \
2237 counter &= 0xFFFFFFF000000000LL; \
2238 counter |= current_counter; \
2241 * ixgbevf_update_stats - Update the board statistics counters.
2242 * @adapter: board private structure
2244 void ixgbevf_update_stats(struct ixgbevf_adapter
*adapter
)
2246 struct ixgbe_hw
*hw
= &adapter
->hw
;
2248 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC
, adapter
->stats
.last_vfgprc
,
2249 adapter
->stats
.vfgprc
);
2250 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC
, adapter
->stats
.last_vfgptc
,
2251 adapter
->stats
.vfgptc
);
2252 UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB
, IXGBE_VFGORC_MSB
,
2253 adapter
->stats
.last_vfgorc
,
2254 adapter
->stats
.vfgorc
);
2255 UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB
, IXGBE_VFGOTC_MSB
,
2256 adapter
->stats
.last_vfgotc
,
2257 adapter
->stats
.vfgotc
);
2258 UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC
, adapter
->stats
.last_vfmprc
,
2259 adapter
->stats
.vfmprc
);
2261 /* Fill out the OS statistics structure */
2262 adapter
->netdev
->stats
.multicast
= adapter
->stats
.vfmprc
-
2263 adapter
->stats
.base_vfmprc
;
2267 * ixgbevf_watchdog - Timer Call-back
2268 * @data: pointer to adapter cast into an unsigned long
2270 static void ixgbevf_watchdog(unsigned long data
)
2272 struct ixgbevf_adapter
*adapter
= (struct ixgbevf_adapter
*)data
;
2273 struct ixgbe_hw
*hw
= &adapter
->hw
;
2278 * Do the watchdog outside of interrupt context due to the lovely
2279 * delays that some of the newer hardware requires
2282 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2283 goto watchdog_short_circuit
;
2285 /* get one bit for every active tx/rx interrupt vector */
2286 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
2287 struct ixgbevf_q_vector
*qv
= adapter
->q_vector
[i
];
2288 if (qv
->rxr_count
|| qv
->txr_count
)
2292 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, (u32
)eics
);
2294 watchdog_short_circuit
:
2295 schedule_work(&adapter
->watchdog_task
);
2299 * ixgbevf_tx_timeout - Respond to a Tx Hang
2300 * @netdev: network interface device structure
2302 static void ixgbevf_tx_timeout(struct net_device
*netdev
)
2304 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2306 /* Do the reset outside of interrupt context */
2307 schedule_work(&adapter
->reset_task
);
2310 static void ixgbevf_reset_task(struct work_struct
*work
)
2312 struct ixgbevf_adapter
*adapter
;
2313 adapter
= container_of(work
, struct ixgbevf_adapter
, reset_task
);
2315 /* If we're already down or resetting, just bail */
2316 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
) ||
2317 test_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
2320 adapter
->tx_timeout_count
++;
2322 ixgbevf_reinit_locked(adapter
);
2326 * ixgbevf_watchdog_task - worker thread to bring link up
2327 * @work: pointer to work_struct containing our data
2329 static void ixgbevf_watchdog_task(struct work_struct
*work
)
2331 struct ixgbevf_adapter
*adapter
= container_of(work
,
2332 struct ixgbevf_adapter
,
2334 struct net_device
*netdev
= adapter
->netdev
;
2335 struct ixgbe_hw
*hw
= &adapter
->hw
;
2336 u32 link_speed
= adapter
->link_speed
;
2337 bool link_up
= adapter
->link_up
;
2339 adapter
->flags
|= IXGBE_FLAG_IN_WATCHDOG_TASK
;
2342 * Always check the link on the watchdog because we have
2345 if (hw
->mac
.ops
.check_link
) {
2346 if ((hw
->mac
.ops
.check_link(hw
, &link_speed
,
2347 &link_up
, false)) != 0) {
2348 adapter
->link_up
= link_up
;
2349 adapter
->link_speed
= link_speed
;
2350 netif_carrier_off(netdev
);
2351 netif_tx_stop_all_queues(netdev
);
2352 schedule_work(&adapter
->reset_task
);
2356 /* always assume link is up, if no check link
2358 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
2361 adapter
->link_up
= link_up
;
2362 adapter
->link_speed
= link_speed
;
2365 if (!netif_carrier_ok(netdev
)) {
2366 hw_dbg(&adapter
->hw
, "NIC Link is Up, %u Gbps\n",
2367 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
) ?
2369 netif_carrier_on(netdev
);
2370 netif_tx_wake_all_queues(netdev
);
2373 adapter
->link_up
= false;
2374 adapter
->link_speed
= 0;
2375 if (netif_carrier_ok(netdev
)) {
2376 hw_dbg(&adapter
->hw
, "NIC Link is Down\n");
2377 netif_carrier_off(netdev
);
2378 netif_tx_stop_all_queues(netdev
);
2382 ixgbevf_update_stats(adapter
);
2385 /* Reset the timer */
2386 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2387 mod_timer(&adapter
->watchdog_timer
,
2388 round_jiffies(jiffies
+ (2 * HZ
)));
2390 adapter
->flags
&= ~IXGBE_FLAG_IN_WATCHDOG_TASK
;
2394 * ixgbevf_free_tx_resources - Free Tx Resources per Queue
2395 * @adapter: board private structure
2396 * @tx_ring: Tx descriptor ring for a specific queue
2398 * Free all transmit software resources
2400 void ixgbevf_free_tx_resources(struct ixgbevf_adapter
*adapter
,
2401 struct ixgbevf_ring
*tx_ring
)
2403 struct pci_dev
*pdev
= adapter
->pdev
;
2405 ixgbevf_clean_tx_ring(adapter
, tx_ring
);
2407 vfree(tx_ring
->tx_buffer_info
);
2408 tx_ring
->tx_buffer_info
= NULL
;
2410 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
2413 tx_ring
->desc
= NULL
;
2417 * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
2418 * @adapter: board private structure
2420 * Free all transmit software resources
2422 static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2426 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2427 if (adapter
->tx_ring
[i
].desc
)
2428 ixgbevf_free_tx_resources(adapter
,
2429 &adapter
->tx_ring
[i
]);
2434 * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
2435 * @adapter: board private structure
2436 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2438 * Return 0 on success, negative on failure
2440 int ixgbevf_setup_tx_resources(struct ixgbevf_adapter
*adapter
,
2441 struct ixgbevf_ring
*tx_ring
)
2443 struct pci_dev
*pdev
= adapter
->pdev
;
2446 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
2447 tx_ring
->tx_buffer_info
= vzalloc(size
);
2448 if (!tx_ring
->tx_buffer_info
)
2451 /* round up to nearest 4K */
2452 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
2453 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
2455 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
2456 &tx_ring
->dma
, GFP_KERNEL
);
2460 tx_ring
->next_to_use
= 0;
2461 tx_ring
->next_to_clean
= 0;
2462 tx_ring
->work_limit
= tx_ring
->count
;
2466 vfree(tx_ring
->tx_buffer_info
);
2467 tx_ring
->tx_buffer_info
= NULL
;
2468 hw_dbg(&adapter
->hw
, "Unable to allocate memory for the transmit "
2469 "descriptor ring\n");
2474 * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
2475 * @adapter: board private structure
2477 * If this function returns with an error, then it's possible one or
2478 * more of the rings is populated (while the rest are not). It is the
2479 * callers duty to clean those orphaned rings.
2481 * Return 0 on success, negative on failure
2483 static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2487 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2488 err
= ixgbevf_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
2491 hw_dbg(&adapter
->hw
,
2492 "Allocation for Tx Queue %u failed\n", i
);
2500 * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
2501 * @adapter: board private structure
2502 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2504 * Returns 0 on success, negative on failure
2506 int ixgbevf_setup_rx_resources(struct ixgbevf_adapter
*adapter
,
2507 struct ixgbevf_ring
*rx_ring
)
2509 struct pci_dev
*pdev
= adapter
->pdev
;
2512 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
2513 rx_ring
->rx_buffer_info
= vzalloc(size
);
2514 if (!rx_ring
->rx_buffer_info
) {
2515 hw_dbg(&adapter
->hw
,
2516 "Unable to vmalloc buffer memory for "
2517 "the receive descriptor ring\n");
2521 /* Round up to nearest 4K */
2522 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
2523 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
2525 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
2526 &rx_ring
->dma
, GFP_KERNEL
);
2528 if (!rx_ring
->desc
) {
2529 hw_dbg(&adapter
->hw
,
2530 "Unable to allocate memory for "
2531 "the receive descriptor ring\n");
2532 vfree(rx_ring
->rx_buffer_info
);
2533 rx_ring
->rx_buffer_info
= NULL
;
2537 rx_ring
->next_to_clean
= 0;
2538 rx_ring
->next_to_use
= 0;
2546 * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
2547 * @adapter: board private structure
2549 * If this function returns with an error, then it's possible one or
2550 * more of the rings is populated (while the rest are not). It is the
2551 * callers duty to clean those orphaned rings.
2553 * Return 0 on success, negative on failure
2555 static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2559 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2560 err
= ixgbevf_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2563 hw_dbg(&adapter
->hw
,
2564 "Allocation for Rx Queue %u failed\n", i
);
2571 * ixgbevf_free_rx_resources - Free Rx Resources
2572 * @adapter: board private structure
2573 * @rx_ring: ring to clean the resources from
2575 * Free all receive software resources
2577 void ixgbevf_free_rx_resources(struct ixgbevf_adapter
*adapter
,
2578 struct ixgbevf_ring
*rx_ring
)
2580 struct pci_dev
*pdev
= adapter
->pdev
;
2582 ixgbevf_clean_rx_ring(adapter
, rx_ring
);
2584 vfree(rx_ring
->rx_buffer_info
);
2585 rx_ring
->rx_buffer_info
= NULL
;
2587 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
2590 rx_ring
->desc
= NULL
;
2594 * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
2595 * @adapter: board private structure
2597 * Free all receive software resources
2599 static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2603 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2604 if (adapter
->rx_ring
[i
].desc
)
2605 ixgbevf_free_rx_resources(adapter
,
2606 &adapter
->rx_ring
[i
]);
2610 * ixgbevf_open - Called when a network interface is made active
2611 * @netdev: network interface device structure
2613 * Returns 0 on success, negative value on failure
2615 * The open entry point is called when a network interface is made
2616 * active by the system (IFF_UP). At this point all resources needed
2617 * for transmit and receive operations are allocated, the interrupt
2618 * handler is registered with the OS, the watchdog timer is started,
2619 * and the stack is notified that the interface is ready.
2621 static int ixgbevf_open(struct net_device
*netdev
)
2623 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2624 struct ixgbe_hw
*hw
= &adapter
->hw
;
2627 /* disallow open during test */
2628 if (test_bit(__IXGBEVF_TESTING
, &adapter
->state
))
2631 if (hw
->adapter_stopped
) {
2632 ixgbevf_reset(adapter
);
2633 /* if adapter is still stopped then PF isn't up and
2634 * the vf can't start. */
2635 if (hw
->adapter_stopped
) {
2636 err
= IXGBE_ERR_MBX
;
2637 printk(KERN_ERR
"Unable to start - perhaps the PF"
2638 " Driver isn't up yet\n");
2639 goto err_setup_reset
;
2643 /* allocate transmit descriptors */
2644 err
= ixgbevf_setup_all_tx_resources(adapter
);
2648 /* allocate receive descriptors */
2649 err
= ixgbevf_setup_all_rx_resources(adapter
);
2653 ixgbevf_configure(adapter
);
2656 * Map the Tx/Rx rings to the vectors we were allotted.
2657 * if request_irq will be called in this function map_rings
2658 * must be called *before* up_complete
2660 ixgbevf_map_rings_to_vectors(adapter
);
2662 err
= ixgbevf_up_complete(adapter
);
2666 /* clear any pending interrupts, may auto mask */
2667 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
2668 err
= ixgbevf_request_irq(adapter
);
2672 ixgbevf_irq_enable(adapter
, true, true);
2677 ixgbevf_down(adapter
);
2679 ixgbevf_free_irq(adapter
);
2681 ixgbevf_free_all_rx_resources(adapter
);
2683 ixgbevf_free_all_tx_resources(adapter
);
2684 ixgbevf_reset(adapter
);
2692 * ixgbevf_close - Disables a network interface
2693 * @netdev: network interface device structure
2695 * Returns 0, this is not allowed to fail
2697 * The close entry point is called when an interface is de-activated
2698 * by the OS. The hardware is still under the drivers control, but
2699 * needs to be disabled. A global MAC reset is issued to stop the
2700 * hardware, and all transmit and receive resources are freed.
2702 static int ixgbevf_close(struct net_device
*netdev
)
2704 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2706 ixgbevf_down(adapter
);
2707 ixgbevf_free_irq(adapter
);
2709 ixgbevf_free_all_tx_resources(adapter
);
2710 ixgbevf_free_all_rx_resources(adapter
);
2715 static int ixgbevf_tso(struct ixgbevf_adapter
*adapter
,
2716 struct ixgbevf_ring
*tx_ring
,
2717 struct sk_buff
*skb
, u32 tx_flags
, u8
*hdr_len
)
2719 struct ixgbe_adv_tx_context_desc
*context_desc
;
2722 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2723 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
;
2724 u32 mss_l4len_idx
, l4len
;
2726 if (skb_is_gso(skb
)) {
2727 if (skb_header_cloned(skb
)) {
2728 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2732 l4len
= tcp_hdrlen(skb
);
2735 if (skb
->protocol
== htons(ETH_P_IP
)) {
2736 struct iphdr
*iph
= ip_hdr(skb
);
2739 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2743 adapter
->hw_tso_ctxt
++;
2744 } else if (skb_is_gso_v6(skb
)) {
2745 ipv6_hdr(skb
)->payload_len
= 0;
2746 tcp_hdr(skb
)->check
=
2747 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2748 &ipv6_hdr(skb
)->daddr
,
2750 adapter
->hw_tso6_ctxt
++;
2753 i
= tx_ring
->next_to_use
;
2755 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2756 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2758 /* VLAN MACLEN IPLEN */
2759 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2761 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
2762 vlan_macip_lens
|= ((skb_network_offset(skb
)) <<
2763 IXGBE_ADVTXD_MACLEN_SHIFT
);
2764 *hdr_len
+= skb_network_offset(skb
);
2766 (skb_transport_header(skb
) - skb_network_header(skb
));
2768 (skb_transport_header(skb
) - skb_network_header(skb
));
2769 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2770 context_desc
->seqnum_seed
= 0;
2772 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2773 type_tucmd_mlhl
= (IXGBE_TXD_CMD_DEXT
|
2774 IXGBE_ADVTXD_DTYP_CTXT
);
2776 if (skb
->protocol
== htons(ETH_P_IP
))
2777 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2778 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2779 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2783 (skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
);
2784 mss_l4len_idx
|= (l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
);
2785 /* use index 1 for TSO */
2786 mss_l4len_idx
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
2787 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
2789 tx_buffer_info
->time_stamp
= jiffies
;
2790 tx_buffer_info
->next_to_watch
= i
;
2793 if (i
== tx_ring
->count
)
2795 tx_ring
->next_to_use
= i
;
2803 static bool ixgbevf_tx_csum(struct ixgbevf_adapter
*adapter
,
2804 struct ixgbevf_ring
*tx_ring
,
2805 struct sk_buff
*skb
, u32 tx_flags
)
2807 struct ixgbe_adv_tx_context_desc
*context_desc
;
2809 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2810 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
2812 if (skb
->ip_summed
== CHECKSUM_PARTIAL
||
2813 (tx_flags
& IXGBE_TX_FLAGS_VLAN
)) {
2814 i
= tx_ring
->next_to_use
;
2815 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2816 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2818 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2819 vlan_macip_lens
|= (tx_flags
&
2820 IXGBE_TX_FLAGS_VLAN_MASK
);
2821 vlan_macip_lens
|= (skb_network_offset(skb
) <<
2822 IXGBE_ADVTXD_MACLEN_SHIFT
);
2823 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2824 vlan_macip_lens
|= (skb_transport_header(skb
) -
2825 skb_network_header(skb
));
2827 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2828 context_desc
->seqnum_seed
= 0;
2830 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
2831 IXGBE_ADVTXD_DTYP_CTXT
);
2833 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2834 switch (skb
->protocol
) {
2835 case __constant_htons(ETH_P_IP
):
2836 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2837 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
2839 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2841 case __constant_htons(ETH_P_IPV6
):
2842 /* XXX what about other V6 headers?? */
2843 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
2845 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2848 if (unlikely(net_ratelimit())) {
2850 "partial checksum but "
2858 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2859 /* use index zero for tx checksum offload */
2860 context_desc
->mss_l4len_idx
= 0;
2862 tx_buffer_info
->time_stamp
= jiffies
;
2863 tx_buffer_info
->next_to_watch
= i
;
2865 adapter
->hw_csum_tx_good
++;
2867 if (i
== tx_ring
->count
)
2869 tx_ring
->next_to_use
= i
;
2877 static int ixgbevf_tx_map(struct ixgbevf_adapter
*adapter
,
2878 struct ixgbevf_ring
*tx_ring
,
2879 struct sk_buff
*skb
, u32 tx_flags
,
2882 struct pci_dev
*pdev
= adapter
->pdev
;
2883 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2885 unsigned int total
= skb
->len
;
2886 unsigned int offset
= 0, size
;
2888 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2892 i
= tx_ring
->next_to_use
;
2894 len
= min(skb_headlen(skb
), total
);
2896 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2897 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2899 tx_buffer_info
->length
= size
;
2900 tx_buffer_info
->mapped_as_page
= false;
2901 tx_buffer_info
->dma
= dma_map_single(&adapter
->pdev
->dev
,
2903 size
, DMA_TO_DEVICE
);
2904 if (dma_mapping_error(&pdev
->dev
, tx_buffer_info
->dma
))
2906 tx_buffer_info
->time_stamp
= jiffies
;
2907 tx_buffer_info
->next_to_watch
= i
;
2914 if (i
== tx_ring
->count
)
2918 for (f
= 0; f
< nr_frags
; f
++) {
2919 struct skb_frag_struct
*frag
;
2921 frag
= &skb_shinfo(skb
)->frags
[f
];
2922 len
= min((unsigned int)frag
->size
, total
);
2923 offset
= frag
->page_offset
;
2926 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2927 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2929 tx_buffer_info
->length
= size
;
2930 tx_buffer_info
->dma
= dma_map_page(&adapter
->pdev
->dev
,
2935 tx_buffer_info
->mapped_as_page
= true;
2936 if (dma_mapping_error(&pdev
->dev
, tx_buffer_info
->dma
))
2938 tx_buffer_info
->time_stamp
= jiffies
;
2939 tx_buffer_info
->next_to_watch
= i
;
2946 if (i
== tx_ring
->count
)
2954 i
= tx_ring
->count
- 1;
2957 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
2958 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
2963 dev_err(&pdev
->dev
, "TX DMA map failed\n");
2965 /* clear timestamp and dma mappings for failed tx_buffer_info map */
2966 tx_buffer_info
->dma
= 0;
2967 tx_buffer_info
->time_stamp
= 0;
2968 tx_buffer_info
->next_to_watch
= 0;
2971 /* clear timestamp and dma mappings for remaining portion of packet */
2972 while (count
>= 0) {
2976 i
+= tx_ring
->count
;
2977 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2978 ixgbevf_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
2984 static void ixgbevf_tx_queue(struct ixgbevf_adapter
*adapter
,
2985 struct ixgbevf_ring
*tx_ring
, int tx_flags
,
2986 int count
, u32 paylen
, u8 hdr_len
)
2988 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
2989 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2990 u32 olinfo_status
= 0, cmd_type_len
= 0;
2993 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
2995 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
2997 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
2999 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
3000 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
3002 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
3003 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
3005 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
3006 IXGBE_ADVTXD_POPTS_SHIFT
;
3008 /* use index 1 context for tso */
3009 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
3010 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
3011 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
3012 IXGBE_ADVTXD_POPTS_SHIFT
;
3014 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
3015 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
3016 IXGBE_ADVTXD_POPTS_SHIFT
;
3018 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
3020 i
= tx_ring
->next_to_use
;
3022 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3023 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
3024 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
3025 tx_desc
->read
.cmd_type_len
=
3026 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
3027 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
3029 if (i
== tx_ring
->count
)
3033 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
3036 * Force memory writes to complete before letting h/w
3037 * know there are new descriptors to fetch. (Only
3038 * applicable for weak-ordered memory model archs,
3043 tx_ring
->next_to_use
= i
;
3044 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3047 static int __ixgbevf_maybe_stop_tx(struct net_device
*netdev
,
3048 struct ixgbevf_ring
*tx_ring
, int size
)
3050 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3052 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
3053 /* Herbert's original patch had:
3054 * smp_mb__after_netif_stop_queue();
3055 * but since that doesn't exist yet, just open code it. */
3058 /* We need to check again in a case another CPU has just
3059 * made room available. */
3060 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
3063 /* A reprieve! - use start_queue because it doesn't call schedule */
3064 netif_start_subqueue(netdev
, tx_ring
->queue_index
);
3065 ++adapter
->restart_queue
;
3069 static int ixgbevf_maybe_stop_tx(struct net_device
*netdev
,
3070 struct ixgbevf_ring
*tx_ring
, int size
)
3072 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
3074 return __ixgbevf_maybe_stop_tx(netdev
, tx_ring
, size
);
3077 static int ixgbevf_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
3079 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3080 struct ixgbevf_ring
*tx_ring
;
3082 unsigned int tx_flags
= 0;
3089 tx_ring
= &adapter
->tx_ring
[r_idx
];
3091 if (vlan_tx_tag_present(skb
)) {
3092 tx_flags
|= vlan_tx_tag_get(skb
);
3093 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
3094 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
3097 /* four things can cause us to need a context descriptor */
3098 if (skb_is_gso(skb
) ||
3099 (skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
3100 (tx_flags
& IXGBE_TX_FLAGS_VLAN
))
3103 count
+= TXD_USE_COUNT(skb_headlen(skb
));
3104 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
3105 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
3107 if (ixgbevf_maybe_stop_tx(netdev
, tx_ring
, count
)) {
3109 return NETDEV_TX_BUSY
;
3112 first
= tx_ring
->next_to_use
;
3114 if (skb
->protocol
== htons(ETH_P_IP
))
3115 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
3116 tso
= ixgbevf_tso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
3118 dev_kfree_skb_any(skb
);
3119 return NETDEV_TX_OK
;
3123 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
3124 else if (ixgbevf_tx_csum(adapter
, tx_ring
, skb
, tx_flags
) &&
3125 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3126 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
3128 ixgbevf_tx_queue(adapter
, tx_ring
, tx_flags
,
3129 ixgbevf_tx_map(adapter
, tx_ring
, skb
, tx_flags
, first
),
3132 ixgbevf_maybe_stop_tx(netdev
, tx_ring
, DESC_NEEDED
);
3134 return NETDEV_TX_OK
;
3138 * ixgbevf_set_mac - Change the Ethernet Address of the NIC
3139 * @netdev: network interface device structure
3140 * @p: pointer to an address structure
3142 * Returns 0 on success, negative on failure
3144 static int ixgbevf_set_mac(struct net_device
*netdev
, void *p
)
3146 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3147 struct ixgbe_hw
*hw
= &adapter
->hw
;
3148 struct sockaddr
*addr
= p
;
3150 if (!is_valid_ether_addr(addr
->sa_data
))
3151 return -EADDRNOTAVAIL
;
3153 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3154 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3156 if (hw
->mac
.ops
.set_rar
)
3157 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
3163 * ixgbevf_change_mtu - Change the Maximum Transfer Unit
3164 * @netdev: network interface device structure
3165 * @new_mtu: new value for maximum frame size
3167 * Returns 0 on success, negative on failure
3169 static int ixgbevf_change_mtu(struct net_device
*netdev
, int new_mtu
)
3171 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3172 struct ixgbe_hw
*hw
= &adapter
->hw
;
3173 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3174 int max_possible_frame
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3177 if (adapter
->hw
.mac
.type
== ixgbe_mac_X540_vf
)
3178 max_possible_frame
= IXGBE_MAX_JUMBO_FRAME_SIZE
;
3180 /* MTU < 68 is an error and causes problems on some kernels */
3181 if ((new_mtu
< 68) || (max_frame
> max_possible_frame
))
3184 hw_dbg(&adapter
->hw
, "changing MTU from %d to %d\n",
3185 netdev
->mtu
, new_mtu
);
3186 /* must set new MTU before calling down or up */
3187 netdev
->mtu
= new_mtu
;
3189 msg
[0] = IXGBE_VF_SET_LPE
;
3191 hw
->mbx
.ops
.write_posted(hw
, msg
, 2);
3193 if (netif_running(netdev
))
3194 ixgbevf_reinit_locked(adapter
);
3199 static void ixgbevf_shutdown(struct pci_dev
*pdev
)
3201 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3202 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3204 netif_device_detach(netdev
);
3206 if (netif_running(netdev
)) {
3207 ixgbevf_down(adapter
);
3208 ixgbevf_free_irq(adapter
);
3209 ixgbevf_free_all_tx_resources(adapter
);
3210 ixgbevf_free_all_rx_resources(adapter
);
3214 pci_save_state(pdev
);
3217 pci_disable_device(pdev
);
3220 static const struct net_device_ops ixgbe_netdev_ops
= {
3221 .ndo_open
= &ixgbevf_open
,
3222 .ndo_stop
= &ixgbevf_close
,
3223 .ndo_start_xmit
= &ixgbevf_xmit_frame
,
3224 .ndo_set_rx_mode
= &ixgbevf_set_rx_mode
,
3225 .ndo_set_multicast_list
= &ixgbevf_set_rx_mode
,
3226 .ndo_validate_addr
= eth_validate_addr
,
3227 .ndo_set_mac_address
= &ixgbevf_set_mac
,
3228 .ndo_change_mtu
= &ixgbevf_change_mtu
,
3229 .ndo_tx_timeout
= &ixgbevf_tx_timeout
,
3230 .ndo_vlan_rx_register
= &ixgbevf_vlan_rx_register
,
3231 .ndo_vlan_rx_add_vid
= &ixgbevf_vlan_rx_add_vid
,
3232 .ndo_vlan_rx_kill_vid
= &ixgbevf_vlan_rx_kill_vid
,
3235 static void ixgbevf_assign_netdev_ops(struct net_device
*dev
)
3237 dev
->netdev_ops
= &ixgbe_netdev_ops
;
3238 ixgbevf_set_ethtool_ops(dev
);
3239 dev
->watchdog_timeo
= 5 * HZ
;
3243 * ixgbevf_probe - Device Initialization Routine
3244 * @pdev: PCI device information struct
3245 * @ent: entry in ixgbevf_pci_tbl
3247 * Returns 0 on success, negative on failure
3249 * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
3250 * The OS initialization, configuring of the adapter private structure,
3251 * and a hardware reset occur.
3253 static int __devinit
ixgbevf_probe(struct pci_dev
*pdev
,
3254 const struct pci_device_id
*ent
)
3256 struct net_device
*netdev
;
3257 struct ixgbevf_adapter
*adapter
= NULL
;
3258 struct ixgbe_hw
*hw
= NULL
;
3259 const struct ixgbevf_info
*ii
= ixgbevf_info_tbl
[ent
->driver_data
];
3260 static int cards_found
;
3261 int err
, pci_using_dac
;
3263 err
= pci_enable_device(pdev
);
3267 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64)) &&
3268 !dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
3271 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
3273 err
= dma_set_coherent_mask(&pdev
->dev
,
3276 dev_err(&pdev
->dev
, "No usable DMA "
3277 "configuration, aborting\n");
3284 err
= pci_request_regions(pdev
, ixgbevf_driver_name
);
3286 dev_err(&pdev
->dev
, "pci_request_regions failed 0x%x\n", err
);
3290 pci_set_master(pdev
);
3293 netdev
= alloc_etherdev_mq(sizeof(struct ixgbevf_adapter
),
3296 netdev
= alloc_etherdev(sizeof(struct ixgbevf_adapter
));
3300 goto err_alloc_etherdev
;
3303 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3305 pci_set_drvdata(pdev
, netdev
);
3306 adapter
= netdev_priv(netdev
);
3308 adapter
->netdev
= netdev
;
3309 adapter
->pdev
= pdev
;
3312 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
3315 * call save state here in standalone driver because it relies on
3316 * adapter struct to exist, and needs to call netdev_priv
3318 pci_save_state(pdev
);
3320 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
3321 pci_resource_len(pdev
, 0));
3327 ixgbevf_assign_netdev_ops(netdev
);
3329 adapter
->bd_number
= cards_found
;
3332 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
3333 hw
->mac
.type
= ii
->mac
;
3335 memcpy(&hw
->mbx
.ops
, &ixgbevf_mbx_ops
,
3336 sizeof(struct ixgbe_mac_operations
));
3338 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_CAPABLE
;
3339 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
3340 adapter
->flags
|= IXGBE_FLAG_RX_1BUF_CAPABLE
;
3342 /* setup the private structure */
3343 err
= ixgbevf_sw_init(adapter
);
3345 netdev
->features
= NETIF_F_SG
|
3347 NETIF_F_HW_VLAN_TX
|
3348 NETIF_F_HW_VLAN_RX
|
3349 NETIF_F_HW_VLAN_FILTER
;
3351 netdev
->features
|= NETIF_F_IPV6_CSUM
;
3352 netdev
->features
|= NETIF_F_TSO
;
3353 netdev
->features
|= NETIF_F_TSO6
;
3354 netdev
->features
|= NETIF_F_GRO
;
3355 netdev
->vlan_features
|= NETIF_F_TSO
;
3356 netdev
->vlan_features
|= NETIF_F_TSO6
;
3357 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
3358 netdev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
3359 netdev
->vlan_features
|= NETIF_F_SG
;
3362 netdev
->features
|= NETIF_F_HIGHDMA
;
3364 /* The HW MAC address was set and/or determined in sw_init */
3365 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3366 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3368 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
3369 printk(KERN_ERR
"invalid MAC address\n");
3374 init_timer(&adapter
->watchdog_timer
);
3375 adapter
->watchdog_timer
.function
= ixgbevf_watchdog
;
3376 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
3378 INIT_WORK(&adapter
->reset_task
, ixgbevf_reset_task
);
3379 INIT_WORK(&adapter
->watchdog_task
, ixgbevf_watchdog_task
);
3381 err
= ixgbevf_init_interrupt_scheme(adapter
);
3385 /* pick up the PCI bus settings for reporting later */
3386 if (hw
->mac
.ops
.get_bus_info
)
3387 hw
->mac
.ops
.get_bus_info(hw
);
3389 strcpy(netdev
->name
, "eth%d");
3391 err
= register_netdev(netdev
);
3395 adapter
->netdev_registered
= true;
3397 netif_carrier_off(netdev
);
3399 ixgbevf_init_last_counter_stats(adapter
);
3401 /* print the MAC address */
3402 hw_dbg(hw
, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
3403 netdev
->dev_addr
[0],
3404 netdev
->dev_addr
[1],
3405 netdev
->dev_addr
[2],
3406 netdev
->dev_addr
[3],
3407 netdev
->dev_addr
[4],
3408 netdev
->dev_addr
[5]);
3410 hw_dbg(hw
, "MAC: %d\n", hw
->mac
.type
);
3412 hw_dbg(hw
, "LRO is disabled\n");
3414 hw_dbg(hw
, "Intel(R) 82599 Virtual Function\n");
3420 ixgbevf_reset_interrupt_capability(adapter
);
3421 iounmap(hw
->hw_addr
);
3423 free_netdev(netdev
);
3425 pci_release_regions(pdev
);
3428 pci_disable_device(pdev
);
3433 * ixgbevf_remove - Device Removal Routine
3434 * @pdev: PCI device information struct
3436 * ixgbevf_remove is called by the PCI subsystem to alert the driver
3437 * that it should release a PCI device. The could be caused by a
3438 * Hot-Plug event, or because the driver is going to be removed from
3441 static void __devexit
ixgbevf_remove(struct pci_dev
*pdev
)
3443 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3444 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3446 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
3448 del_timer_sync(&adapter
->watchdog_timer
);
3450 cancel_work_sync(&adapter
->reset_task
);
3451 cancel_work_sync(&adapter
->watchdog_task
);
3453 if (adapter
->netdev_registered
) {
3454 unregister_netdev(netdev
);
3455 adapter
->netdev_registered
= false;
3458 ixgbevf_reset_interrupt_capability(adapter
);
3460 iounmap(adapter
->hw
.hw_addr
);
3461 pci_release_regions(pdev
);
3463 hw_dbg(&adapter
->hw
, "Remove complete\n");
3465 kfree(adapter
->tx_ring
);
3466 kfree(adapter
->rx_ring
);
3468 free_netdev(netdev
);
3470 pci_disable_device(pdev
);
3473 static struct pci_driver ixgbevf_driver
= {
3474 .name
= ixgbevf_driver_name
,
3475 .id_table
= ixgbevf_pci_tbl
,
3476 .probe
= ixgbevf_probe
,
3477 .remove
= __devexit_p(ixgbevf_remove
),
3478 .shutdown
= ixgbevf_shutdown
,
3482 * ixgbevf_init_module - Driver Registration Routine
3484 * ixgbevf_init_module is the first routine called when the driver is
3485 * loaded. All it does is register with the PCI subsystem.
3487 static int __init
ixgbevf_init_module(void)
3490 printk(KERN_INFO
"ixgbevf: %s - version %s\n", ixgbevf_driver_string
,
3491 ixgbevf_driver_version
);
3493 printk(KERN_INFO
"%s\n", ixgbevf_copyright
);
3495 ret
= pci_register_driver(&ixgbevf_driver
);
3499 module_init(ixgbevf_init_module
);
3502 * ixgbevf_exit_module - Driver Exit Cleanup Routine
3504 * ixgbevf_exit_module is called just before the driver is removed
3507 static void __exit
ixgbevf_exit_module(void)
3509 pci_unregister_driver(&ixgbevf_driver
);
3514 * ixgbevf_get_hw_dev_name - return device name string
3515 * used by hardware layer to print debugging information
3517 char *ixgbevf_get_hw_dev_name(struct ixgbe_hw
*hw
)
3519 struct ixgbevf_adapter
*adapter
= hw
->back
;
3520 return adapter
->netdev
->name
;
3524 module_exit(ixgbevf_exit_module
);
3526 /* ixgbevf_main.c */