1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2012 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 ******************************************************************************/
33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35 #include <linux/types.h>
36 #include <linux/bitops.h>
37 #include <linux/module.h>
38 #include <linux/pci.h>
39 #include <linux/netdevice.h>
40 #include <linux/vmalloc.h>
41 #include <linux/string.h>
44 #include <linux/tcp.h>
45 #include <linux/sctp.h>
46 #include <linux/ipv6.h>
47 #include <linux/slab.h>
48 #include <net/checksum.h>
49 #include <net/ip6_checksum.h>
50 #include <linux/ethtool.h>
52 #include <linux/if_vlan.h>
53 #include <linux/prefetch.h>
57 const char ixgbevf_driver_name
[] = "ixgbevf";
58 static const char ixgbevf_driver_string
[] =
59 "Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver";
61 #define DRV_VERSION "2.6.0-k"
62 const char ixgbevf_driver_version
[] = DRV_VERSION
;
63 static char ixgbevf_copyright
[] =
64 "Copyright (c) 2009 - 2012 Intel Corporation.";
66 static const struct ixgbevf_info
*ixgbevf_info_tbl
[] = {
67 [board_82599_vf
] = &ixgbevf_82599_vf_info
,
68 [board_X540_vf
] = &ixgbevf_X540_vf_info
,
71 /* ixgbevf_pci_tbl - PCI Device ID Table
73 * Wildcard entries (PCI_ANY_ID) should come last
74 * Last entry must be all 0s
76 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
77 * Class, Class Mask, private data (not used) }
79 static struct pci_device_id ixgbevf_pci_tbl
[] = {
80 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_VF
),
82 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X540_VF
),
85 /* required last entry */
88 MODULE_DEVICE_TABLE(pci
, ixgbevf_pci_tbl
);
90 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
91 MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
92 MODULE_LICENSE("GPL");
93 MODULE_VERSION(DRV_VERSION
);
95 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
96 static int debug
= -1;
97 module_param(debug
, int, 0);
98 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
101 static void ixgbevf_set_itr(struct ixgbevf_q_vector
*q_vector
);
102 static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter
*adapter
);
104 static inline void ixgbevf_release_rx_desc(struct ixgbe_hw
*hw
,
105 struct ixgbevf_ring
*rx_ring
,
109 * Force memory writes to complete before letting h/w
110 * know there are new descriptors to fetch. (Only
111 * applicable for weak-ordered memory model archs,
115 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(rx_ring
->reg_idx
), val
);
119 * ixgbevf_set_ivar - set IVAR registers - maps interrupt causes to vectors
120 * @adapter: pointer to adapter struct
121 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
122 * @queue: queue to map the corresponding interrupt to
123 * @msix_vector: the vector to map to the corresponding queue
126 static void ixgbevf_set_ivar(struct ixgbevf_adapter
*adapter
, s8 direction
,
127 u8 queue
, u8 msix_vector
)
130 struct ixgbe_hw
*hw
= &adapter
->hw
;
131 if (direction
== -1) {
133 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
134 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR_MISC
);
137 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR_MISC
, ivar
);
139 /* tx or rx causes */
140 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
141 index
= ((16 * (queue
& 1)) + (8 * direction
));
142 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR(queue
>> 1));
143 ivar
&= ~(0xFF << index
);
144 ivar
|= (msix_vector
<< index
);
145 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR(queue
>> 1), ivar
);
149 static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_ring
*tx_ring
,
150 struct ixgbevf_tx_buffer
153 if (tx_buffer_info
->dma
) {
154 if (tx_buffer_info
->mapped_as_page
)
155 dma_unmap_page(tx_ring
->dev
,
157 tx_buffer_info
->length
,
160 dma_unmap_single(tx_ring
->dev
,
162 tx_buffer_info
->length
,
164 tx_buffer_info
->dma
= 0;
166 if (tx_buffer_info
->skb
) {
167 dev_kfree_skb_any(tx_buffer_info
->skb
);
168 tx_buffer_info
->skb
= NULL
;
170 tx_buffer_info
->time_stamp
= 0;
171 /* tx_buffer_info must be completely set up in the transmit path */
174 #define IXGBE_MAX_TXD_PWR 14
175 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
177 /* Tx Descriptors needed, worst case */
178 #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD)
179 #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
181 static void ixgbevf_tx_timeout(struct net_device
*netdev
);
184 * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
185 * @q_vector: board private structure
186 * @tx_ring: tx ring to clean
188 static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector
*q_vector
,
189 struct ixgbevf_ring
*tx_ring
)
191 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
192 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
193 struct ixgbevf_tx_buffer
*tx_buffer_info
;
194 unsigned int i
, eop
, count
= 0;
195 unsigned int total_bytes
= 0, total_packets
= 0;
197 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
200 i
= tx_ring
->next_to_clean
;
201 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
202 eop_desc
= IXGBEVF_TX_DESC(tx_ring
, eop
);
204 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
205 (count
< tx_ring
->count
)) {
206 bool cleaned
= false;
207 rmb(); /* read buffer_info after eop_desc */
208 /* eop could change between read and DD-check */
209 if (unlikely(eop
!= tx_ring
->tx_buffer_info
[i
].next_to_watch
))
211 for ( ; !cleaned
; count
++) {
213 tx_desc
= IXGBEVF_TX_DESC(tx_ring
, i
);
214 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
215 cleaned
= (i
== eop
);
216 skb
= tx_buffer_info
->skb
;
218 if (cleaned
&& skb
) {
219 unsigned int segs
, bytecount
;
221 /* gso_segs is currently only valid for tcp */
222 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
223 /* multiply data chunks by size of headers */
224 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
226 total_packets
+= segs
;
227 total_bytes
+= bytecount
;
230 ixgbevf_unmap_and_free_tx_resource(tx_ring
,
233 tx_desc
->wb
.status
= 0;
236 if (i
== tx_ring
->count
)
241 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
242 eop_desc
= IXGBEVF_TX_DESC(tx_ring
, eop
);
245 tx_ring
->next_to_clean
= i
;
247 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
248 if (unlikely(count
&& netif_carrier_ok(tx_ring
->netdev
) &&
249 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
250 /* Make sure that anybody stopping the queue after this
251 * sees the new next_to_clean.
254 if (__netif_subqueue_stopped(tx_ring
->netdev
,
255 tx_ring
->queue_index
) &&
256 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
257 netif_wake_subqueue(tx_ring
->netdev
,
258 tx_ring
->queue_index
);
259 ++adapter
->restart_queue
;
263 u64_stats_update_begin(&tx_ring
->syncp
);
264 tx_ring
->total_bytes
+= total_bytes
;
265 tx_ring
->total_packets
+= total_packets
;
266 u64_stats_update_end(&tx_ring
->syncp
);
267 q_vector
->tx
.total_bytes
+= total_bytes
;
268 q_vector
->tx
.total_packets
+= total_packets
;
270 return count
< tx_ring
->count
;
274 * ixgbevf_receive_skb - Send a completed packet up the stack
275 * @q_vector: structure containing interrupt and ring information
276 * @skb: packet to send up
277 * @status: hardware indication of status of receive
278 * @rx_desc: rx descriptor
280 static void ixgbevf_receive_skb(struct ixgbevf_q_vector
*q_vector
,
281 struct sk_buff
*skb
, u8 status
,
282 union ixgbe_adv_rx_desc
*rx_desc
)
284 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
285 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
286 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
288 if (is_vlan
&& test_bit(tag
& VLAN_VID_MASK
, adapter
->active_vlans
))
289 __vlan_hwaccel_put_tag(skb
, tag
);
291 napi_gro_receive(&q_vector
->napi
, skb
);
295 * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
296 * @adapter: address of board private structure
297 * @status_err: hardware indication of status of receive
298 * @skb: skb currently being received and modified
300 static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter
*adapter
,
301 struct ixgbevf_ring
*ring
,
302 u32 status_err
, struct sk_buff
*skb
)
304 skb_checksum_none_assert(skb
);
306 /* Rx csum disabled */
307 if (!(ring
->netdev
->features
& NETIF_F_RXCSUM
))
310 /* if IP and error */
311 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
312 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
313 adapter
->hw_csum_rx_error
++;
317 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
320 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
321 adapter
->hw_csum_rx_error
++;
325 /* It must be a TCP or UDP packet with a valid checksum */
326 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
327 adapter
->hw_csum_rx_good
++;
331 * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
332 * @adapter: address of board private structure
334 static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter
*adapter
,
335 struct ixgbevf_ring
*rx_ring
,
338 struct pci_dev
*pdev
= adapter
->pdev
;
339 union ixgbe_adv_rx_desc
*rx_desc
;
340 struct ixgbevf_rx_buffer
*bi
;
342 unsigned int i
= rx_ring
->next_to_use
;
344 bi
= &rx_ring
->rx_buffer_info
[i
];
346 while (cleaned_count
--) {
347 rx_desc
= IXGBEVF_RX_DESC(rx_ring
, i
);
350 skb
= netdev_alloc_skb_ip_align(rx_ring
->netdev
,
351 rx_ring
->rx_buf_len
);
353 adapter
->alloc_rx_buff_failed
++;
359 bi
->dma
= dma_map_single(&pdev
->dev
, skb
->data
,
362 if (dma_mapping_error(&pdev
->dev
, bi
->dma
)) {
365 dev_err(&pdev
->dev
, "RX DMA map failed\n");
369 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
372 if (i
== rx_ring
->count
)
374 bi
= &rx_ring
->rx_buffer_info
[i
];
378 if (rx_ring
->next_to_use
!= i
) {
379 rx_ring
->next_to_use
= i
;
381 ixgbevf_release_rx_desc(&adapter
->hw
, rx_ring
, i
);
385 static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter
*adapter
,
388 struct ixgbe_hw
*hw
= &adapter
->hw
;
390 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, qmask
);
393 static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector
*q_vector
,
394 struct ixgbevf_ring
*rx_ring
,
397 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
398 struct pci_dev
*pdev
= adapter
->pdev
;
399 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
400 struct ixgbevf_rx_buffer
*rx_buffer_info
, *next_buffer
;
404 int cleaned_count
= 0;
405 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
407 i
= rx_ring
->next_to_clean
;
408 rx_desc
= IXGBEVF_RX_DESC(rx_ring
, i
);
409 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
410 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
412 while (staterr
& IXGBE_RXD_STAT_DD
) {
417 rmb(); /* read descriptor and rx_buffer_info after status DD */
418 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
419 skb
= rx_buffer_info
->skb
;
420 prefetch(skb
->data
- NET_IP_ALIGN
);
421 rx_buffer_info
->skb
= NULL
;
423 if (rx_buffer_info
->dma
) {
424 dma_unmap_single(&pdev
->dev
, rx_buffer_info
->dma
,
427 rx_buffer_info
->dma
= 0;
432 if (i
== rx_ring
->count
)
435 next_rxd
= IXGBEVF_RX_DESC(rx_ring
, i
);
439 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
441 if (!(staterr
& IXGBE_RXD_STAT_EOP
)) {
442 skb
->next
= next_buffer
->skb
;
443 IXGBE_CB(skb
->next
)->prev
= skb
;
444 adapter
->non_eop_descs
++;
448 /* we should not be chaining buffers, if we did drop the skb */
449 if (IXGBE_CB(skb
)->prev
) {
451 struct sk_buff
*this = skb
;
452 skb
= IXGBE_CB(skb
)->prev
;
458 /* ERR_MASK will only have valid bits if EOP set */
459 if (unlikely(staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
)) {
460 dev_kfree_skb_irq(skb
);
464 ixgbevf_rx_checksum(adapter
, rx_ring
, staterr
, skb
);
466 /* probably a little skewed due to removing CRC */
467 total_rx_bytes
+= skb
->len
;
471 * Work around issue of some types of VM to VM loop back
472 * packets not getting split correctly
474 if (staterr
& IXGBE_RXD_STAT_LB
) {
475 u32 header_fixup_len
= skb_headlen(skb
);
476 if (header_fixup_len
< 14)
477 skb_push(skb
, header_fixup_len
);
479 skb
->protocol
= eth_type_trans(skb
, rx_ring
->netdev
);
481 ixgbevf_receive_skb(q_vector
, skb
, staterr
, rx_desc
);
484 rx_desc
->wb
.upper
.status_error
= 0;
486 /* return some buffers to hardware, one at a time is too slow */
487 if (cleaned_count
>= IXGBEVF_RX_BUFFER_WRITE
) {
488 ixgbevf_alloc_rx_buffers(adapter
, rx_ring
,
493 /* use prefetched values */
495 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
497 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
500 rx_ring
->next_to_clean
= i
;
501 cleaned_count
= IXGBE_DESC_UNUSED(rx_ring
);
504 ixgbevf_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
506 u64_stats_update_begin(&rx_ring
->syncp
);
507 rx_ring
->total_packets
+= total_rx_packets
;
508 rx_ring
->total_bytes
+= total_rx_bytes
;
509 u64_stats_update_end(&rx_ring
->syncp
);
510 q_vector
->rx
.total_packets
+= total_rx_packets
;
511 q_vector
->rx
.total_bytes
+= total_rx_bytes
;
517 * ixgbevf_poll - NAPI polling calback
518 * @napi: napi struct with our devices info in it
519 * @budget: amount of work driver is allowed to do this pass, in packets
521 * This function will clean more than one or more rings associated with a
524 static int ixgbevf_poll(struct napi_struct
*napi
, int budget
)
526 struct ixgbevf_q_vector
*q_vector
=
527 container_of(napi
, struct ixgbevf_q_vector
, napi
);
528 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
529 struct ixgbevf_ring
*ring
;
531 bool clean_complete
= true;
533 ixgbevf_for_each_ring(ring
, q_vector
->tx
)
534 clean_complete
&= ixgbevf_clean_tx_irq(q_vector
, ring
);
536 /* attempt to distribute budget to each queue fairly, but don't allow
537 * the budget to go below 1 because we'll exit polling */
538 if (q_vector
->rx
.count
> 1)
539 per_ring_budget
= max(budget
/q_vector
->rx
.count
, 1);
541 per_ring_budget
= budget
;
543 ixgbevf_for_each_ring(ring
, q_vector
->rx
)
544 clean_complete
&= ixgbevf_clean_rx_irq(q_vector
, ring
,
547 /* If all work not completed, return budget and keep polling */
550 /* all work done, exit the polling mode */
552 if (adapter
->rx_itr_setting
& 1)
553 ixgbevf_set_itr(q_vector
);
554 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
555 ixgbevf_irq_enable_queues(adapter
,
556 1 << q_vector
->v_idx
);
562 * ixgbevf_write_eitr - write VTEITR register in hardware specific way
563 * @q_vector: structure containing interrupt and ring information
565 static void ixgbevf_write_eitr(struct ixgbevf_q_vector
*q_vector
)
567 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
568 struct ixgbe_hw
*hw
= &adapter
->hw
;
569 int v_idx
= q_vector
->v_idx
;
570 u32 itr_reg
= q_vector
->itr
& IXGBE_MAX_EITR
;
573 * set the WDIS bit to not clear the timer bits and cause an
574 * immediate assertion of the interrupt
576 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
578 IXGBE_WRITE_REG(hw
, IXGBE_VTEITR(v_idx
), itr_reg
);
582 * ixgbevf_configure_msix - Configure MSI-X hardware
583 * @adapter: board private structure
585 * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X
588 static void ixgbevf_configure_msix(struct ixgbevf_adapter
*adapter
)
590 struct ixgbevf_q_vector
*q_vector
;
591 int q_vectors
, v_idx
;
593 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
594 adapter
->eims_enable_mask
= 0;
597 * Populate the IVAR table and set the ITR values to the
598 * corresponding register.
600 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
601 struct ixgbevf_ring
*ring
;
602 q_vector
= adapter
->q_vector
[v_idx
];
604 ixgbevf_for_each_ring(ring
, q_vector
->rx
)
605 ixgbevf_set_ivar(adapter
, 0, ring
->reg_idx
, v_idx
);
607 ixgbevf_for_each_ring(ring
, q_vector
->tx
)
608 ixgbevf_set_ivar(adapter
, 1, ring
->reg_idx
, v_idx
);
610 if (q_vector
->tx
.ring
&& !q_vector
->rx
.ring
) {
612 if (adapter
->tx_itr_setting
== 1)
613 q_vector
->itr
= IXGBE_10K_ITR
;
615 q_vector
->itr
= adapter
->tx_itr_setting
;
617 /* rx or rx/tx vector */
618 if (adapter
->rx_itr_setting
== 1)
619 q_vector
->itr
= IXGBE_20K_ITR
;
621 q_vector
->itr
= adapter
->rx_itr_setting
;
624 /* add q_vector eims value to global eims_enable_mask */
625 adapter
->eims_enable_mask
|= 1 << v_idx
;
627 ixgbevf_write_eitr(q_vector
);
630 ixgbevf_set_ivar(adapter
, -1, 1, v_idx
);
631 /* setup eims_other and add value to global eims_enable_mask */
632 adapter
->eims_other
= 1 << v_idx
;
633 adapter
->eims_enable_mask
|= adapter
->eims_other
;
640 latency_invalid
= 255
644 * ixgbevf_update_itr - update the dynamic ITR value based on statistics
645 * @q_vector: structure containing interrupt and ring information
646 * @ring_container: structure containing ring performance data
648 * Stores a new ITR value based on packets and byte
649 * counts during the last interrupt. The advantage of per interrupt
650 * computation is faster updates and more accurate ITR for the current
651 * traffic pattern. Constants in this function were computed
652 * based on theoretical maximum wire speed and thresholds were set based
653 * on testing data as well as attempting to minimize response time
654 * while increasing bulk throughput.
656 static void ixgbevf_update_itr(struct ixgbevf_q_vector
*q_vector
,
657 struct ixgbevf_ring_container
*ring_container
)
659 int bytes
= ring_container
->total_bytes
;
660 int packets
= ring_container
->total_packets
;
663 u8 itr_setting
= ring_container
->itr
;
668 /* simple throttlerate management
669 * 0-20MB/s lowest (100000 ints/s)
670 * 20-100MB/s low (20000 ints/s)
671 * 100-1249MB/s bulk (8000 ints/s)
673 /* what was last interrupt timeslice? */
674 timepassed_us
= q_vector
->itr
>> 2;
675 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
677 switch (itr_setting
) {
679 if (bytes_perint
> 10)
680 itr_setting
= low_latency
;
683 if (bytes_perint
> 20)
684 itr_setting
= bulk_latency
;
685 else if (bytes_perint
<= 10)
686 itr_setting
= lowest_latency
;
689 if (bytes_perint
<= 20)
690 itr_setting
= low_latency
;
694 /* clear work counters since we have the values we need */
695 ring_container
->total_bytes
= 0;
696 ring_container
->total_packets
= 0;
698 /* write updated itr to ring container */
699 ring_container
->itr
= itr_setting
;
702 static void ixgbevf_set_itr(struct ixgbevf_q_vector
*q_vector
)
704 u32 new_itr
= q_vector
->itr
;
707 ixgbevf_update_itr(q_vector
, &q_vector
->tx
);
708 ixgbevf_update_itr(q_vector
, &q_vector
->rx
);
710 current_itr
= max(q_vector
->rx
.itr
, q_vector
->tx
.itr
);
712 switch (current_itr
) {
713 /* counts and packets in update_itr are dependent on these numbers */
715 new_itr
= IXGBE_100K_ITR
;
718 new_itr
= IXGBE_20K_ITR
;
722 new_itr
= IXGBE_8K_ITR
;
726 if (new_itr
!= q_vector
->itr
) {
727 /* do an exponential smoothing */
728 new_itr
= (10 * new_itr
* q_vector
->itr
) /
729 ((9 * new_itr
) + q_vector
->itr
);
731 /* save the algorithm value here */
732 q_vector
->itr
= new_itr
;
734 ixgbevf_write_eitr(q_vector
);
738 static irqreturn_t
ixgbevf_msix_other(int irq
, void *data
)
740 struct ixgbevf_adapter
*adapter
= data
;
741 struct ixgbe_hw
*hw
= &adapter
->hw
;
743 hw
->mac
.get_link_status
= 1;
745 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
746 mod_timer(&adapter
->watchdog_timer
, jiffies
);
748 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, adapter
->eims_other
);
755 * ixgbevf_msix_clean_rings - single unshared vector rx clean (all queues)
757 * @data: pointer to our q_vector struct for this interrupt vector
759 static irqreturn_t
ixgbevf_msix_clean_rings(int irq
, void *data
)
761 struct ixgbevf_q_vector
*q_vector
= data
;
763 /* EIAM disabled interrupts (on this vector) for us */
764 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
765 napi_schedule(&q_vector
->napi
);
770 static inline void map_vector_to_rxq(struct ixgbevf_adapter
*a
, int v_idx
,
773 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
775 a
->rx_ring
[r_idx
].next
= q_vector
->rx
.ring
;
776 q_vector
->rx
.ring
= &a
->rx_ring
[r_idx
];
777 q_vector
->rx
.count
++;
780 static inline void map_vector_to_txq(struct ixgbevf_adapter
*a
, int v_idx
,
783 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
785 a
->tx_ring
[t_idx
].next
= q_vector
->tx
.ring
;
786 q_vector
->tx
.ring
= &a
->tx_ring
[t_idx
];
787 q_vector
->tx
.count
++;
791 * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
792 * @adapter: board private structure to initialize
794 * This function maps descriptor rings to the queue-specific vectors
795 * we were allotted through the MSI-X enabling code. Ideally, we'd have
796 * one vector per ring/queue, but on a constrained vector budget, we
797 * group the rings as "efficiently" as possible. You would add new
798 * mapping configurations in here.
800 static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter
*adapter
)
804 int rxr_idx
= 0, txr_idx
= 0;
805 int rxr_remaining
= adapter
->num_rx_queues
;
806 int txr_remaining
= adapter
->num_tx_queues
;
811 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
814 * The ideal configuration...
815 * We have enough vectors to map one per queue.
817 if (q_vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
818 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
819 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
821 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
822 map_vector_to_txq(adapter
, v_start
, txr_idx
);
827 * If we don't have enough vectors for a 1-to-1
828 * mapping, we'll have to group them so there are
829 * multiple queues per vector.
831 /* Re-adjusting *qpv takes care of the remainder. */
832 for (i
= v_start
; i
< q_vectors
; i
++) {
833 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
834 for (j
= 0; j
< rqpv
; j
++) {
835 map_vector_to_rxq(adapter
, i
, rxr_idx
);
840 for (i
= v_start
; i
< q_vectors
; i
++) {
841 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
842 for (j
= 0; j
< tqpv
; j
++) {
843 map_vector_to_txq(adapter
, i
, txr_idx
);
854 * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
855 * @adapter: board private structure
857 * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
858 * interrupts from the kernel.
860 static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter
*adapter
)
862 struct net_device
*netdev
= adapter
->netdev
;
863 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
867 for (vector
= 0; vector
< q_vectors
; vector
++) {
868 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[vector
];
869 struct msix_entry
*entry
= &adapter
->msix_entries
[vector
];
871 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
872 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
873 "%s-%s-%d", netdev
->name
, "TxRx", ri
++);
875 } else if (q_vector
->rx
.ring
) {
876 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
877 "%s-%s-%d", netdev
->name
, "rx", ri
++);
878 } else if (q_vector
->tx
.ring
) {
879 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
880 "%s-%s-%d", netdev
->name
, "tx", ti
++);
882 /* skip this unused q_vector */
885 err
= request_irq(entry
->vector
, &ixgbevf_msix_clean_rings
, 0,
886 q_vector
->name
, q_vector
);
889 "request_irq failed for MSIX interrupt "
891 goto free_queue_irqs
;
895 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
896 &ixgbevf_msix_other
, 0, netdev
->name
, adapter
);
899 "request_irq for msix_other failed: %d\n", err
);
900 goto free_queue_irqs
;
908 free_irq(adapter
->msix_entries
[vector
].vector
,
909 adapter
->q_vector
[vector
]);
911 pci_disable_msix(adapter
->pdev
);
912 kfree(adapter
->msix_entries
);
913 adapter
->msix_entries
= NULL
;
917 static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter
*adapter
)
919 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
921 for (i
= 0; i
< q_vectors
; i
++) {
922 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[i
];
923 q_vector
->rx
.ring
= NULL
;
924 q_vector
->tx
.ring
= NULL
;
925 q_vector
->rx
.count
= 0;
926 q_vector
->tx
.count
= 0;
931 * ixgbevf_request_irq - initialize interrupts
932 * @adapter: board private structure
934 * Attempts to configure interrupts using the best available
935 * capabilities of the hardware and kernel.
937 static int ixgbevf_request_irq(struct ixgbevf_adapter
*adapter
)
941 err
= ixgbevf_request_msix_irqs(adapter
);
945 "request_irq failed, Error %d\n", err
);
950 static void ixgbevf_free_irq(struct ixgbevf_adapter
*adapter
)
954 q_vectors
= adapter
->num_msix_vectors
;
957 free_irq(adapter
->msix_entries
[i
].vector
, adapter
);
960 for (; i
>= 0; i
--) {
961 /* free only the irqs that were actually requested */
962 if (!adapter
->q_vector
[i
]->rx
.ring
&&
963 !adapter
->q_vector
[i
]->tx
.ring
)
966 free_irq(adapter
->msix_entries
[i
].vector
,
967 adapter
->q_vector
[i
]);
970 ixgbevf_reset_q_vectors(adapter
);
974 * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
975 * @adapter: board private structure
977 static inline void ixgbevf_irq_disable(struct ixgbevf_adapter
*adapter
)
979 struct ixgbe_hw
*hw
= &adapter
->hw
;
982 IXGBE_WRITE_REG(hw
, IXGBE_VTEIAM
, 0);
983 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, ~0);
984 IXGBE_WRITE_REG(hw
, IXGBE_VTEIAC
, 0);
986 IXGBE_WRITE_FLUSH(hw
);
988 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
989 synchronize_irq(adapter
->msix_entries
[i
].vector
);
993 * ixgbevf_irq_enable - Enable default interrupt generation settings
994 * @adapter: board private structure
996 static inline void ixgbevf_irq_enable(struct ixgbevf_adapter
*adapter
)
998 struct ixgbe_hw
*hw
= &adapter
->hw
;
1000 IXGBE_WRITE_REG(hw
, IXGBE_VTEIAM
, adapter
->eims_enable_mask
);
1001 IXGBE_WRITE_REG(hw
, IXGBE_VTEIAC
, adapter
->eims_enable_mask
);
1002 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, adapter
->eims_enable_mask
);
1006 * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
1007 * @adapter: board private structure
1009 * Configure the Tx unit of the MAC after a reset.
1011 static void ixgbevf_configure_tx(struct ixgbevf_adapter
*adapter
)
1014 struct ixgbe_hw
*hw
= &adapter
->hw
;
1015 u32 i
, j
, tdlen
, txctrl
;
1017 /* Setup the HW Tx Head and Tail descriptor pointers */
1018 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1019 struct ixgbevf_ring
*ring
= &adapter
->tx_ring
[i
];
1022 tdlen
= ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
1023 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAL(j
),
1024 (tdba
& DMA_BIT_MASK(32)));
1025 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAH(j
), (tdba
>> 32));
1026 IXGBE_WRITE_REG(hw
, IXGBE_VFTDLEN(j
), tdlen
);
1027 IXGBE_WRITE_REG(hw
, IXGBE_VFTDH(j
), 0);
1028 IXGBE_WRITE_REG(hw
, IXGBE_VFTDT(j
), 0);
1029 adapter
->tx_ring
[i
].head
= IXGBE_VFTDH(j
);
1030 adapter
->tx_ring
[i
].tail
= IXGBE_VFTDT(j
);
1031 /* Disable Tx Head Writeback RO bit, since this hoses
1032 * bookkeeping if things aren't delivered in order.
1034 txctrl
= IXGBE_READ_REG(hw
, IXGBE_VFDCA_TXCTRL(j
));
1035 txctrl
&= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN
;
1036 IXGBE_WRITE_REG(hw
, IXGBE_VFDCA_TXCTRL(j
), txctrl
);
1040 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1042 static void ixgbevf_configure_srrctl(struct ixgbevf_adapter
*adapter
, int index
)
1044 struct ixgbevf_ring
*rx_ring
;
1045 struct ixgbe_hw
*hw
= &adapter
->hw
;
1048 rx_ring
= &adapter
->rx_ring
[index
];
1050 srrctl
= IXGBE_SRRCTL_DROP_EN
;
1052 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1054 srrctl
|= ALIGN(rx_ring
->rx_buf_len
, 1024) >>
1055 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1057 IXGBE_WRITE_REG(hw
, IXGBE_VFSRRCTL(index
), srrctl
);
1060 static void ixgbevf_set_rx_buffer_len(struct ixgbevf_adapter
*adapter
)
1062 struct ixgbe_hw
*hw
= &adapter
->hw
;
1063 struct net_device
*netdev
= adapter
->netdev
;
1064 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1068 /* notify the PF of our intent to use this size of frame */
1069 ixgbevf_rlpml_set_vf(hw
, max_frame
);
1071 /* PF will allow an extra 4 bytes past for vlan tagged frames */
1072 max_frame
+= VLAN_HLEN
;
1075 * Make best use of allocation by using all but 1K of a
1076 * power of 2 allocation that will be used for skb->head.
1078 if ((hw
->mac
.type
== ixgbe_mac_X540_vf
) &&
1079 (max_frame
<= MAXIMUM_ETHERNET_VLAN_SIZE
))
1080 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1081 else if (max_frame
<= IXGBEVF_RXBUFFER_3K
)
1082 rx_buf_len
= IXGBEVF_RXBUFFER_3K
;
1083 else if (max_frame
<= IXGBEVF_RXBUFFER_7K
)
1084 rx_buf_len
= IXGBEVF_RXBUFFER_7K
;
1085 else if (max_frame
<= IXGBEVF_RXBUFFER_15K
)
1086 rx_buf_len
= IXGBEVF_RXBUFFER_15K
;
1088 rx_buf_len
= IXGBEVF_MAX_RXBUFFER
;
1090 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1091 adapter
->rx_ring
[i
].rx_buf_len
= rx_buf_len
;
1095 * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
1096 * @adapter: board private structure
1098 * Configure the Rx unit of the MAC after a reset.
1100 static void ixgbevf_configure_rx(struct ixgbevf_adapter
*adapter
)
1103 struct ixgbe_hw
*hw
= &adapter
->hw
;
1107 /* PSRTYPE must be initialized in 82599 */
1108 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, 0);
1110 /* set_rx_buffer_len must be called before ring initialization */
1111 ixgbevf_set_rx_buffer_len(adapter
);
1113 rdlen
= adapter
->rx_ring
[0].count
* sizeof(union ixgbe_adv_rx_desc
);
1114 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1115 * the Base and Length of the Rx Descriptor Ring */
1116 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1117 rdba
= adapter
->rx_ring
[i
].dma
;
1118 j
= adapter
->rx_ring
[i
].reg_idx
;
1119 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAL(j
),
1120 (rdba
& DMA_BIT_MASK(32)));
1121 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAH(j
), (rdba
>> 32));
1122 IXGBE_WRITE_REG(hw
, IXGBE_VFRDLEN(j
), rdlen
);
1123 IXGBE_WRITE_REG(hw
, IXGBE_VFRDH(j
), 0);
1124 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(j
), 0);
1125 adapter
->rx_ring
[i
].head
= IXGBE_VFRDH(j
);
1126 adapter
->rx_ring
[i
].tail
= IXGBE_VFRDT(j
);
1128 ixgbevf_configure_srrctl(adapter
, j
);
1132 static int ixgbevf_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
1134 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1135 struct ixgbe_hw
*hw
= &adapter
->hw
;
1138 if (!hw
->mac
.ops
.set_vfta
)
1141 spin_lock_bh(&adapter
->mbx_lock
);
1143 /* add VID to filter table */
1144 err
= hw
->mac
.ops
.set_vfta(hw
, vid
, 0, true);
1146 spin_unlock_bh(&adapter
->mbx_lock
);
1148 /* translate error return types so error makes sense */
1149 if (err
== IXGBE_ERR_MBX
)
1152 if (err
== IXGBE_ERR_INVALID_ARGUMENT
)
1155 set_bit(vid
, adapter
->active_vlans
);
1160 static int ixgbevf_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
1162 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1163 struct ixgbe_hw
*hw
= &adapter
->hw
;
1164 int err
= -EOPNOTSUPP
;
1166 spin_lock_bh(&adapter
->mbx_lock
);
1168 /* remove VID from filter table */
1169 if (hw
->mac
.ops
.set_vfta
)
1170 err
= hw
->mac
.ops
.set_vfta(hw
, vid
, 0, false);
1172 spin_unlock_bh(&adapter
->mbx_lock
);
1174 clear_bit(vid
, adapter
->active_vlans
);
1179 static void ixgbevf_restore_vlan(struct ixgbevf_adapter
*adapter
)
1183 for_each_set_bit(vid
, adapter
->active_vlans
, VLAN_N_VID
)
1184 ixgbevf_vlan_rx_add_vid(adapter
->netdev
, vid
);
1187 static int ixgbevf_write_uc_addr_list(struct net_device
*netdev
)
1189 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1190 struct ixgbe_hw
*hw
= &adapter
->hw
;
1193 if ((netdev_uc_count(netdev
)) > 10) {
1194 pr_err("Too many unicast filters - No Space\n");
1198 if (!netdev_uc_empty(netdev
)) {
1199 struct netdev_hw_addr
*ha
;
1200 netdev_for_each_uc_addr(ha
, netdev
) {
1201 hw
->mac
.ops
.set_uc_addr(hw
, ++count
, ha
->addr
);
1206 * If the list is empty then send message to PF driver to
1207 * clear all macvlans on this VF.
1209 hw
->mac
.ops
.set_uc_addr(hw
, 0, NULL
);
1216 * ixgbevf_set_rx_mode - Multicast set
1217 * @netdev: network interface device structure
1219 * The set_rx_method entry point is called whenever the multicast address
1220 * list or the network interface flags are updated. This routine is
1221 * responsible for configuring the hardware for proper multicast mode.
1223 static void ixgbevf_set_rx_mode(struct net_device
*netdev
)
1225 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1226 struct ixgbe_hw
*hw
= &adapter
->hw
;
1228 spin_lock_bh(&adapter
->mbx_lock
);
1230 /* reprogram multicast list */
1231 if (hw
->mac
.ops
.update_mc_addr_list
)
1232 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
1234 ixgbevf_write_uc_addr_list(netdev
);
1236 spin_unlock_bh(&adapter
->mbx_lock
);
1239 static void ixgbevf_napi_enable_all(struct ixgbevf_adapter
*adapter
)
1242 struct ixgbevf_q_vector
*q_vector
;
1243 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1245 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1246 q_vector
= adapter
->q_vector
[q_idx
];
1247 napi_enable(&q_vector
->napi
);
1251 static void ixgbevf_napi_disable_all(struct ixgbevf_adapter
*adapter
)
1254 struct ixgbevf_q_vector
*q_vector
;
1255 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1257 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1258 q_vector
= adapter
->q_vector
[q_idx
];
1259 napi_disable(&q_vector
->napi
);
1263 static void ixgbevf_configure(struct ixgbevf_adapter
*adapter
)
1265 struct net_device
*netdev
= adapter
->netdev
;
1268 ixgbevf_set_rx_mode(netdev
);
1270 ixgbevf_restore_vlan(adapter
);
1272 ixgbevf_configure_tx(adapter
);
1273 ixgbevf_configure_rx(adapter
);
1274 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1275 struct ixgbevf_ring
*ring
= &adapter
->rx_ring
[i
];
1276 ixgbevf_alloc_rx_buffers(adapter
, ring
,
1277 IXGBE_DESC_UNUSED(ring
));
1281 #define IXGBE_MAX_RX_DESC_POLL 10
1282 static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter
*adapter
,
1285 struct ixgbe_hw
*hw
= &adapter
->hw
;
1286 int j
= adapter
->rx_ring
[rxr
].reg_idx
;
1289 for (k
= 0; k
< IXGBE_MAX_RX_DESC_POLL
; k
++) {
1290 if (IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
)) & IXGBE_RXDCTL_ENABLE
)
1295 if (k
>= IXGBE_MAX_RX_DESC_POLL
) {
1296 hw_dbg(hw
, "RXDCTL.ENABLE on Rx queue %d "
1297 "not set within the polling period\n", rxr
);
1300 ixgbevf_release_rx_desc(&adapter
->hw
, &adapter
->rx_ring
[rxr
],
1301 (adapter
->rx_ring
[rxr
].count
- 1));
1304 static void ixgbevf_save_reset_stats(struct ixgbevf_adapter
*adapter
)
1306 /* Only save pre-reset stats if there are some */
1307 if (adapter
->stats
.vfgprc
|| adapter
->stats
.vfgptc
) {
1308 adapter
->stats
.saved_reset_vfgprc
+= adapter
->stats
.vfgprc
-
1309 adapter
->stats
.base_vfgprc
;
1310 adapter
->stats
.saved_reset_vfgptc
+= adapter
->stats
.vfgptc
-
1311 adapter
->stats
.base_vfgptc
;
1312 adapter
->stats
.saved_reset_vfgorc
+= adapter
->stats
.vfgorc
-
1313 adapter
->stats
.base_vfgorc
;
1314 adapter
->stats
.saved_reset_vfgotc
+= adapter
->stats
.vfgotc
-
1315 adapter
->stats
.base_vfgotc
;
1316 adapter
->stats
.saved_reset_vfmprc
+= adapter
->stats
.vfmprc
-
1317 adapter
->stats
.base_vfmprc
;
1321 static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter
*adapter
)
1323 struct ixgbe_hw
*hw
= &adapter
->hw
;
1325 adapter
->stats
.last_vfgprc
= IXGBE_READ_REG(hw
, IXGBE_VFGPRC
);
1326 adapter
->stats
.last_vfgorc
= IXGBE_READ_REG(hw
, IXGBE_VFGORC_LSB
);
1327 adapter
->stats
.last_vfgorc
|=
1328 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGORC_MSB
))) << 32);
1329 adapter
->stats
.last_vfgptc
= IXGBE_READ_REG(hw
, IXGBE_VFGPTC
);
1330 adapter
->stats
.last_vfgotc
= IXGBE_READ_REG(hw
, IXGBE_VFGOTC_LSB
);
1331 adapter
->stats
.last_vfgotc
|=
1332 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGOTC_MSB
))) << 32);
1333 adapter
->stats
.last_vfmprc
= IXGBE_READ_REG(hw
, IXGBE_VFMPRC
);
1335 adapter
->stats
.base_vfgprc
= adapter
->stats
.last_vfgprc
;
1336 adapter
->stats
.base_vfgorc
= adapter
->stats
.last_vfgorc
;
1337 adapter
->stats
.base_vfgptc
= adapter
->stats
.last_vfgptc
;
1338 adapter
->stats
.base_vfgotc
= adapter
->stats
.last_vfgotc
;
1339 adapter
->stats
.base_vfmprc
= adapter
->stats
.last_vfmprc
;
1342 static void ixgbevf_negotiate_api(struct ixgbevf_adapter
*adapter
)
1344 struct ixgbe_hw
*hw
= &adapter
->hw
;
1345 int api
[] = { ixgbe_mbox_api_11
,
1347 ixgbe_mbox_api_unknown
};
1348 int err
= 0, idx
= 0;
1350 spin_lock_bh(&adapter
->mbx_lock
);
1352 while (api
[idx
] != ixgbe_mbox_api_unknown
) {
1353 err
= ixgbevf_negotiate_api_version(hw
, api
[idx
]);
1359 spin_unlock_bh(&adapter
->mbx_lock
);
1362 static void ixgbevf_up_complete(struct ixgbevf_adapter
*adapter
)
1364 struct net_device
*netdev
= adapter
->netdev
;
1365 struct ixgbe_hw
*hw
= &adapter
->hw
;
1367 int num_rx_rings
= adapter
->num_rx_queues
;
1370 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1371 j
= adapter
->tx_ring
[i
].reg_idx
;
1372 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1373 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
1374 txdctl
|= (8 << 16);
1375 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1378 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1379 j
= adapter
->tx_ring
[i
].reg_idx
;
1380 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1381 txdctl
|= IXGBE_TXDCTL_ENABLE
;
1382 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1385 for (i
= 0; i
< num_rx_rings
; i
++) {
1386 j
= adapter
->rx_ring
[i
].reg_idx
;
1387 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1388 rxdctl
|= IXGBE_RXDCTL_ENABLE
| IXGBE_RXDCTL_VME
;
1389 if (hw
->mac
.type
== ixgbe_mac_X540_vf
) {
1390 rxdctl
&= ~IXGBE_RXDCTL_RLPMLMASK
;
1391 rxdctl
|= ((netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
) |
1392 IXGBE_RXDCTL_RLPML_EN
);
1394 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), rxdctl
);
1395 ixgbevf_rx_desc_queue_enable(adapter
, i
);
1398 ixgbevf_configure_msix(adapter
);
1400 spin_lock_bh(&adapter
->mbx_lock
);
1402 if (hw
->mac
.ops
.set_rar
) {
1403 if (is_valid_ether_addr(hw
->mac
.addr
))
1404 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
1406 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.perm_addr
, 0);
1409 spin_unlock_bh(&adapter
->mbx_lock
);
1411 clear_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1412 ixgbevf_napi_enable_all(adapter
);
1414 /* enable transmits */
1415 netif_tx_start_all_queues(netdev
);
1417 ixgbevf_save_reset_stats(adapter
);
1418 ixgbevf_init_last_counter_stats(adapter
);
1420 hw
->mac
.get_link_status
= 1;
1421 mod_timer(&adapter
->watchdog_timer
, jiffies
);
1424 static int ixgbevf_reset_queues(struct ixgbevf_adapter
*adapter
)
1426 struct ixgbe_hw
*hw
= &adapter
->hw
;
1427 struct ixgbevf_ring
*rx_ring
;
1428 unsigned int def_q
= 0;
1429 unsigned int num_tcs
= 0;
1430 unsigned int num_rx_queues
= 1;
1433 spin_lock_bh(&adapter
->mbx_lock
);
1435 /* fetch queue configuration from the PF */
1436 err
= ixgbevf_get_queues(hw
, &num_tcs
, &def_q
);
1438 spin_unlock_bh(&adapter
->mbx_lock
);
1444 /* update default Tx ring register index */
1445 adapter
->tx_ring
[0].reg_idx
= def_q
;
1447 /* we need as many queues as traffic classes */
1448 num_rx_queues
= num_tcs
;
1451 /* nothing to do if we have the correct number of queues */
1452 if (adapter
->num_rx_queues
== num_rx_queues
)
1455 /* allocate new rings */
1456 rx_ring
= kcalloc(num_rx_queues
,
1457 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
1461 /* setup ring fields */
1462 for (i
= 0; i
< num_rx_queues
; i
++) {
1463 rx_ring
[i
].count
= adapter
->rx_ring_count
;
1464 rx_ring
[i
].queue_index
= i
;
1465 rx_ring
[i
].reg_idx
= i
;
1466 rx_ring
[i
].dev
= &adapter
->pdev
->dev
;
1467 rx_ring
[i
].netdev
= adapter
->netdev
;
1469 /* allocate resources on the ring */
1470 err
= ixgbevf_setup_rx_resources(adapter
, &rx_ring
[i
]);
1474 ixgbevf_free_rx_resources(adapter
, &rx_ring
[i
]);
1481 /* free the existing rings and queues */
1482 ixgbevf_free_all_rx_resources(adapter
);
1483 adapter
->num_rx_queues
= 0;
1484 kfree(adapter
->rx_ring
);
1486 /* move new rings into position on the adapter struct */
1487 adapter
->rx_ring
= rx_ring
;
1488 adapter
->num_rx_queues
= num_rx_queues
;
1490 /* reset ring to vector mapping */
1491 ixgbevf_reset_q_vectors(adapter
);
1492 ixgbevf_map_rings_to_vectors(adapter
);
1497 void ixgbevf_up(struct ixgbevf_adapter
*adapter
)
1499 struct ixgbe_hw
*hw
= &adapter
->hw
;
1501 ixgbevf_negotiate_api(adapter
);
1503 ixgbevf_reset_queues(adapter
);
1505 ixgbevf_configure(adapter
);
1507 ixgbevf_up_complete(adapter
);
1509 /* clear any pending interrupts, may auto mask */
1510 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
1512 ixgbevf_irq_enable(adapter
);
1516 * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
1517 * @adapter: board private structure
1518 * @rx_ring: ring to free buffers from
1520 static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter
*adapter
,
1521 struct ixgbevf_ring
*rx_ring
)
1523 struct pci_dev
*pdev
= adapter
->pdev
;
1527 if (!rx_ring
->rx_buffer_info
)
1530 /* Free all the Rx ring sk_buffs */
1531 for (i
= 0; i
< rx_ring
->count
; i
++) {
1532 struct ixgbevf_rx_buffer
*rx_buffer_info
;
1534 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1535 if (rx_buffer_info
->dma
) {
1536 dma_unmap_single(&pdev
->dev
, rx_buffer_info
->dma
,
1537 rx_ring
->rx_buf_len
,
1539 rx_buffer_info
->dma
= 0;
1541 if (rx_buffer_info
->skb
) {
1542 struct sk_buff
*skb
= rx_buffer_info
->skb
;
1543 rx_buffer_info
->skb
= NULL
;
1545 struct sk_buff
*this = skb
;
1546 skb
= IXGBE_CB(skb
)->prev
;
1547 dev_kfree_skb(this);
1552 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
1553 memset(rx_ring
->rx_buffer_info
, 0, size
);
1555 /* Zero out the descriptor ring */
1556 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1558 rx_ring
->next_to_clean
= 0;
1559 rx_ring
->next_to_use
= 0;
1562 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1564 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1568 * ixgbevf_clean_tx_ring - Free Tx Buffers
1569 * @adapter: board private structure
1570 * @tx_ring: ring to be cleaned
1572 static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter
*adapter
,
1573 struct ixgbevf_ring
*tx_ring
)
1575 struct ixgbevf_tx_buffer
*tx_buffer_info
;
1579 if (!tx_ring
->tx_buffer_info
)
1582 /* Free all the Tx ring sk_buffs */
1584 for (i
= 0; i
< tx_ring
->count
; i
++) {
1585 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
1586 ixgbevf_unmap_and_free_tx_resource(tx_ring
, tx_buffer_info
);
1589 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
1590 memset(tx_ring
->tx_buffer_info
, 0, size
);
1592 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1594 tx_ring
->next_to_use
= 0;
1595 tx_ring
->next_to_clean
= 0;
1598 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1600 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1604 * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
1605 * @adapter: board private structure
1607 static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter
*adapter
)
1611 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1612 ixgbevf_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
1616 * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
1617 * @adapter: board private structure
1619 static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter
*adapter
)
1623 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1624 ixgbevf_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1627 void ixgbevf_down(struct ixgbevf_adapter
*adapter
)
1629 struct net_device
*netdev
= adapter
->netdev
;
1630 struct ixgbe_hw
*hw
= &adapter
->hw
;
1634 /* signal that we are down to the interrupt handler */
1635 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1636 /* disable receives */
1638 netif_tx_disable(netdev
);
1642 netif_tx_stop_all_queues(netdev
);
1644 ixgbevf_irq_disable(adapter
);
1646 ixgbevf_napi_disable_all(adapter
);
1648 del_timer_sync(&adapter
->watchdog_timer
);
1649 /* can't call flush scheduled work here because it can deadlock
1650 * if linkwatch_event tries to acquire the rtnl_lock which we are
1652 while (adapter
->flags
& IXGBE_FLAG_IN_WATCHDOG_TASK
)
1655 /* disable transmits in the hardware now that interrupts are off */
1656 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1657 j
= adapter
->tx_ring
[i
].reg_idx
;
1658 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1659 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
),
1660 (txdctl
& ~IXGBE_TXDCTL_ENABLE
));
1663 netif_carrier_off(netdev
);
1665 if (!pci_channel_offline(adapter
->pdev
))
1666 ixgbevf_reset(adapter
);
1668 ixgbevf_clean_all_tx_rings(adapter
);
1669 ixgbevf_clean_all_rx_rings(adapter
);
1672 void ixgbevf_reinit_locked(struct ixgbevf_adapter
*adapter
)
1674 WARN_ON(in_interrupt());
1676 while (test_and_set_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
1680 * Check if PF is up before re-init. If not then skip until
1681 * later when the PF is up and ready to service requests from
1682 * the VF via mailbox. If the VF is up and running then the
1683 * watchdog task will continue to schedule reset tasks until
1684 * the PF is up and running.
1686 ixgbevf_down(adapter
);
1687 ixgbevf_up(adapter
);
1689 clear_bit(__IXGBEVF_RESETTING
, &adapter
->state
);
1692 void ixgbevf_reset(struct ixgbevf_adapter
*adapter
)
1694 struct ixgbe_hw
*hw
= &adapter
->hw
;
1695 struct net_device
*netdev
= adapter
->netdev
;
1697 spin_lock_bh(&adapter
->mbx_lock
);
1699 if (hw
->mac
.ops
.reset_hw(hw
))
1700 hw_dbg(hw
, "PF still resetting\n");
1702 hw
->mac
.ops
.init_hw(hw
);
1704 spin_unlock_bh(&adapter
->mbx_lock
);
1706 if (is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
1707 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
,
1709 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
,
1714 static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter
*adapter
,
1717 int err
, vector_threshold
;
1719 /* We'll want at least 2 (vector_threshold):
1720 * 1) TxQ[0] + RxQ[0] handler
1721 * 2) Other (Link Status Change, etc.)
1723 vector_threshold
= MIN_MSIX_COUNT
;
1725 /* The more we get, the more we will assign to Tx/Rx Cleanup
1726 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1727 * Right now, we simply care about how many we'll get; we'll
1728 * set them up later while requesting irq's.
1730 while (vectors
>= vector_threshold
) {
1731 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1733 if (!err
) /* Success in acquiring all requested vectors. */
1736 vectors
= 0; /* Nasty failure, quit now */
1737 else /* err == number of vectors we should try again with */
1741 if (vectors
< vector_threshold
) {
1742 /* Can't allocate enough MSI-X interrupts? Oh well.
1743 * This just means we'll go with either a single MSI
1744 * vector or fall back to legacy interrupts.
1746 hw_dbg(&adapter
->hw
,
1747 "Unable to allocate MSI-X interrupts\n");
1748 kfree(adapter
->msix_entries
);
1749 adapter
->msix_entries
= NULL
;
1752 * Adjust for only the vectors we'll use, which is minimum
1753 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
1754 * vectors we were allocated.
1756 adapter
->num_msix_vectors
= vectors
;
1761 * ixgbevf_set_num_queues - Allocate queues for device, feature dependent
1762 * @adapter: board private structure to initialize
1764 * This is the top level queue allocation routine. The order here is very
1765 * important, starting with the "most" number of features turned on at once,
1766 * and ending with the smallest set of features. This way large combinations
1767 * can be allocated if they're turned on, and smaller combinations are the
1768 * fallthrough conditions.
1771 static void ixgbevf_set_num_queues(struct ixgbevf_adapter
*adapter
)
1773 /* Start with base case */
1774 adapter
->num_rx_queues
= 1;
1775 adapter
->num_tx_queues
= 1;
1779 * ixgbevf_alloc_queues - Allocate memory for all rings
1780 * @adapter: board private structure to initialize
1782 * We allocate one ring per queue at run-time since we don't know the
1783 * number of queues at compile-time. The polling_netdev array is
1784 * intended for Multiqueue, but should work fine with a single queue.
1786 static int ixgbevf_alloc_queues(struct ixgbevf_adapter
*adapter
)
1790 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1791 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
1792 if (!adapter
->tx_ring
)
1793 goto err_tx_ring_allocation
;
1795 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1796 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
1797 if (!adapter
->rx_ring
)
1798 goto err_rx_ring_allocation
;
1800 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1801 adapter
->tx_ring
[i
].count
= adapter
->tx_ring_count
;
1802 adapter
->tx_ring
[i
].queue_index
= i
;
1803 /* reg_idx may be remapped later by DCB config */
1804 adapter
->tx_ring
[i
].reg_idx
= i
;
1805 adapter
->tx_ring
[i
].dev
= &adapter
->pdev
->dev
;
1806 adapter
->tx_ring
[i
].netdev
= adapter
->netdev
;
1809 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1810 adapter
->rx_ring
[i
].count
= adapter
->rx_ring_count
;
1811 adapter
->rx_ring
[i
].queue_index
= i
;
1812 adapter
->rx_ring
[i
].reg_idx
= i
;
1813 adapter
->rx_ring
[i
].dev
= &adapter
->pdev
->dev
;
1814 adapter
->rx_ring
[i
].netdev
= adapter
->netdev
;
1819 err_rx_ring_allocation
:
1820 kfree(adapter
->tx_ring
);
1821 err_tx_ring_allocation
:
1826 * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
1827 * @adapter: board private structure to initialize
1829 * Attempt to configure the interrupts using the best available
1830 * capabilities of the hardware and the kernel.
1832 static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter
*adapter
)
1834 struct net_device
*netdev
= adapter
->netdev
;
1836 int vector
, v_budget
;
1839 * It's easy to be greedy for MSI-X vectors, but it really
1840 * doesn't do us much good if we have a lot more vectors
1841 * than CPU's. So let's be conservative and only ask for
1842 * (roughly) the same number of vectors as there are CPU's.
1843 * The default is to use pairs of vectors.
1845 v_budget
= max(adapter
->num_rx_queues
, adapter
->num_tx_queues
);
1846 v_budget
= min_t(int, v_budget
, num_online_cpus());
1847 v_budget
+= NON_Q_VECTORS
;
1849 /* A failure in MSI-X entry allocation isn't fatal, but it does
1850 * mean we disable MSI-X capabilities of the adapter. */
1851 adapter
->msix_entries
= kcalloc(v_budget
,
1852 sizeof(struct msix_entry
), GFP_KERNEL
);
1853 if (!adapter
->msix_entries
) {
1858 for (vector
= 0; vector
< v_budget
; vector
++)
1859 adapter
->msix_entries
[vector
].entry
= vector
;
1861 ixgbevf_acquire_msix_vectors(adapter
, v_budget
);
1863 err
= netif_set_real_num_tx_queues(netdev
, adapter
->num_tx_queues
);
1867 err
= netif_set_real_num_rx_queues(netdev
, adapter
->num_rx_queues
);
1874 * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
1875 * @adapter: board private structure to initialize
1877 * We allocate one q_vector per queue interrupt. If allocation fails we
1880 static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter
*adapter
)
1882 int q_idx
, num_q_vectors
;
1883 struct ixgbevf_q_vector
*q_vector
;
1885 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1887 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1888 q_vector
= kzalloc(sizeof(struct ixgbevf_q_vector
), GFP_KERNEL
);
1891 q_vector
->adapter
= adapter
;
1892 q_vector
->v_idx
= q_idx
;
1893 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1895 adapter
->q_vector
[q_idx
] = q_vector
;
1903 q_vector
= adapter
->q_vector
[q_idx
];
1904 netif_napi_del(&q_vector
->napi
);
1906 adapter
->q_vector
[q_idx
] = NULL
;
1912 * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
1913 * @adapter: board private structure to initialize
1915 * This function frees the memory allocated to the q_vectors. In addition if
1916 * NAPI is enabled it will delete any references to the NAPI struct prior
1917 * to freeing the q_vector.
1919 static void ixgbevf_free_q_vectors(struct ixgbevf_adapter
*adapter
)
1921 int q_idx
, num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1923 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1924 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
1926 adapter
->q_vector
[q_idx
] = NULL
;
1927 netif_napi_del(&q_vector
->napi
);
1933 * ixgbevf_reset_interrupt_capability - Reset MSIX setup
1934 * @adapter: board private structure
1937 static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter
*adapter
)
1939 pci_disable_msix(adapter
->pdev
);
1940 kfree(adapter
->msix_entries
);
1941 adapter
->msix_entries
= NULL
;
1945 * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
1946 * @adapter: board private structure to initialize
1949 static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter
*adapter
)
1953 /* Number of supported queues */
1954 ixgbevf_set_num_queues(adapter
);
1956 err
= ixgbevf_set_interrupt_capability(adapter
);
1958 hw_dbg(&adapter
->hw
,
1959 "Unable to setup interrupt capabilities\n");
1960 goto err_set_interrupt
;
1963 err
= ixgbevf_alloc_q_vectors(adapter
);
1965 hw_dbg(&adapter
->hw
, "Unable to allocate memory for queue "
1967 goto err_alloc_q_vectors
;
1970 err
= ixgbevf_alloc_queues(adapter
);
1972 pr_err("Unable to allocate memory for queues\n");
1973 goto err_alloc_queues
;
1976 hw_dbg(&adapter
->hw
, "Multiqueue %s: Rx Queue count = %u, "
1977 "Tx Queue count = %u\n",
1978 (adapter
->num_rx_queues
> 1) ? "Enabled" :
1979 "Disabled", adapter
->num_rx_queues
, adapter
->num_tx_queues
);
1981 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1985 ixgbevf_free_q_vectors(adapter
);
1986 err_alloc_q_vectors
:
1987 ixgbevf_reset_interrupt_capability(adapter
);
1993 * ixgbevf_clear_interrupt_scheme - Clear the current interrupt scheme settings
1994 * @adapter: board private structure to clear interrupt scheme on
1996 * We go through and clear interrupt specific resources and reset the structure
1997 * to pre-load conditions
1999 static void ixgbevf_clear_interrupt_scheme(struct ixgbevf_adapter
*adapter
)
2001 adapter
->num_tx_queues
= 0;
2002 adapter
->num_rx_queues
= 0;
2004 ixgbevf_free_q_vectors(adapter
);
2005 ixgbevf_reset_interrupt_capability(adapter
);
2009 * ixgbevf_sw_init - Initialize general software structures
2010 * (struct ixgbevf_adapter)
2011 * @adapter: board private structure to initialize
2013 * ixgbevf_sw_init initializes the Adapter private data structure.
2014 * Fields are initialized based on PCI device information and
2015 * OS network device settings (MTU size).
2017 static int __devinit
ixgbevf_sw_init(struct ixgbevf_adapter
*adapter
)
2019 struct ixgbe_hw
*hw
= &adapter
->hw
;
2020 struct pci_dev
*pdev
= adapter
->pdev
;
2023 /* PCI config space info */
2025 hw
->vendor_id
= pdev
->vendor
;
2026 hw
->device_id
= pdev
->device
;
2027 hw
->revision_id
= pdev
->revision
;
2028 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2029 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2031 hw
->mbx
.ops
.init_params(hw
);
2033 /* assume legacy case in which PF would only give VF 2 queues */
2034 hw
->mac
.max_tx_queues
= 2;
2035 hw
->mac
.max_rx_queues
= 2;
2037 err
= hw
->mac
.ops
.reset_hw(hw
);
2039 dev_info(&pdev
->dev
,
2040 "PF still in reset state, assigning new address\n");
2041 eth_hw_addr_random(adapter
->netdev
);
2042 memcpy(adapter
->hw
.mac
.addr
, adapter
->netdev
->dev_addr
,
2043 adapter
->netdev
->addr_len
);
2045 err
= hw
->mac
.ops
.init_hw(hw
);
2047 pr_err("init_shared_code failed: %d\n", err
);
2050 memcpy(adapter
->netdev
->dev_addr
, adapter
->hw
.mac
.addr
,
2051 adapter
->netdev
->addr_len
);
2054 /* lock to protect mailbox accesses */
2055 spin_lock_init(&adapter
->mbx_lock
);
2057 /* Enable dynamic interrupt throttling rates */
2058 adapter
->rx_itr_setting
= 1;
2059 adapter
->tx_itr_setting
= 1;
2061 /* set default ring sizes */
2062 adapter
->tx_ring_count
= IXGBEVF_DEFAULT_TXD
;
2063 adapter
->rx_ring_count
= IXGBEVF_DEFAULT_RXD
;
2065 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2072 #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
2074 u32 current_counter = IXGBE_READ_REG(hw, reg); \
2075 if (current_counter < last_counter) \
2076 counter += 0x100000000LL; \
2077 last_counter = current_counter; \
2078 counter &= 0xFFFFFFFF00000000LL; \
2079 counter |= current_counter; \
2082 #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
2084 u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
2085 u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
2086 u64 current_counter = (current_counter_msb << 32) | \
2087 current_counter_lsb; \
2088 if (current_counter < last_counter) \
2089 counter += 0x1000000000LL; \
2090 last_counter = current_counter; \
2091 counter &= 0xFFFFFFF000000000LL; \
2092 counter |= current_counter; \
2095 * ixgbevf_update_stats - Update the board statistics counters.
2096 * @adapter: board private structure
2098 void ixgbevf_update_stats(struct ixgbevf_adapter
*adapter
)
2100 struct ixgbe_hw
*hw
= &adapter
->hw
;
2102 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC
, adapter
->stats
.last_vfgprc
,
2103 adapter
->stats
.vfgprc
);
2104 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC
, adapter
->stats
.last_vfgptc
,
2105 adapter
->stats
.vfgptc
);
2106 UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB
, IXGBE_VFGORC_MSB
,
2107 adapter
->stats
.last_vfgorc
,
2108 adapter
->stats
.vfgorc
);
2109 UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB
, IXGBE_VFGOTC_MSB
,
2110 adapter
->stats
.last_vfgotc
,
2111 adapter
->stats
.vfgotc
);
2112 UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC
, adapter
->stats
.last_vfmprc
,
2113 adapter
->stats
.vfmprc
);
2117 * ixgbevf_watchdog - Timer Call-back
2118 * @data: pointer to adapter cast into an unsigned long
2120 static void ixgbevf_watchdog(unsigned long data
)
2122 struct ixgbevf_adapter
*adapter
= (struct ixgbevf_adapter
*)data
;
2123 struct ixgbe_hw
*hw
= &adapter
->hw
;
2128 * Do the watchdog outside of interrupt context due to the lovely
2129 * delays that some of the newer hardware requires
2132 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2133 goto watchdog_short_circuit
;
2135 /* get one bit for every active tx/rx interrupt vector */
2136 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
2137 struct ixgbevf_q_vector
*qv
= adapter
->q_vector
[i
];
2138 if (qv
->rx
.ring
|| qv
->tx
.ring
)
2142 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, eics
);
2144 watchdog_short_circuit
:
2145 schedule_work(&adapter
->watchdog_task
);
2149 * ixgbevf_tx_timeout - Respond to a Tx Hang
2150 * @netdev: network interface device structure
2152 static void ixgbevf_tx_timeout(struct net_device
*netdev
)
2154 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2156 /* Do the reset outside of interrupt context */
2157 schedule_work(&adapter
->reset_task
);
2160 static void ixgbevf_reset_task(struct work_struct
*work
)
2162 struct ixgbevf_adapter
*adapter
;
2163 adapter
= container_of(work
, struct ixgbevf_adapter
, reset_task
);
2165 /* If we're already down or resetting, just bail */
2166 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
) ||
2167 test_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
2170 adapter
->tx_timeout_count
++;
2172 ixgbevf_reinit_locked(adapter
);
2176 * ixgbevf_watchdog_task - worker thread to bring link up
2177 * @work: pointer to work_struct containing our data
2179 static void ixgbevf_watchdog_task(struct work_struct
*work
)
2181 struct ixgbevf_adapter
*adapter
= container_of(work
,
2182 struct ixgbevf_adapter
,
2184 struct net_device
*netdev
= adapter
->netdev
;
2185 struct ixgbe_hw
*hw
= &adapter
->hw
;
2186 u32 link_speed
= adapter
->link_speed
;
2187 bool link_up
= adapter
->link_up
;
2189 adapter
->flags
|= IXGBE_FLAG_IN_WATCHDOG_TASK
;
2192 * Always check the link on the watchdog because we have
2195 if (hw
->mac
.ops
.check_link
) {
2198 spin_lock_bh(&adapter
->mbx_lock
);
2200 need_reset
= hw
->mac
.ops
.check_link(hw
, &link_speed
,
2203 spin_unlock_bh(&adapter
->mbx_lock
);
2206 adapter
->link_up
= link_up
;
2207 adapter
->link_speed
= link_speed
;
2208 netif_carrier_off(netdev
);
2209 netif_tx_stop_all_queues(netdev
);
2210 schedule_work(&adapter
->reset_task
);
2214 /* always assume link is up, if no check link
2216 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
2219 adapter
->link_up
= link_up
;
2220 adapter
->link_speed
= link_speed
;
2223 if (!netif_carrier_ok(netdev
)) {
2224 hw_dbg(&adapter
->hw
, "NIC Link is Up, %u Gbps\n",
2225 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
) ?
2227 netif_carrier_on(netdev
);
2228 netif_tx_wake_all_queues(netdev
);
2231 adapter
->link_up
= false;
2232 adapter
->link_speed
= 0;
2233 if (netif_carrier_ok(netdev
)) {
2234 hw_dbg(&adapter
->hw
, "NIC Link is Down\n");
2235 netif_carrier_off(netdev
);
2236 netif_tx_stop_all_queues(netdev
);
2240 ixgbevf_update_stats(adapter
);
2243 /* Reset the timer */
2244 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2245 mod_timer(&adapter
->watchdog_timer
,
2246 round_jiffies(jiffies
+ (2 * HZ
)));
2248 adapter
->flags
&= ~IXGBE_FLAG_IN_WATCHDOG_TASK
;
2252 * ixgbevf_free_tx_resources - Free Tx Resources per Queue
2253 * @adapter: board private structure
2254 * @tx_ring: Tx descriptor ring for a specific queue
2256 * Free all transmit software resources
2258 void ixgbevf_free_tx_resources(struct ixgbevf_adapter
*adapter
,
2259 struct ixgbevf_ring
*tx_ring
)
2261 struct pci_dev
*pdev
= adapter
->pdev
;
2263 ixgbevf_clean_tx_ring(adapter
, tx_ring
);
2265 vfree(tx_ring
->tx_buffer_info
);
2266 tx_ring
->tx_buffer_info
= NULL
;
2268 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
2271 tx_ring
->desc
= NULL
;
2275 * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
2276 * @adapter: board private structure
2278 * Free all transmit software resources
2280 static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2284 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2285 if (adapter
->tx_ring
[i
].desc
)
2286 ixgbevf_free_tx_resources(adapter
,
2287 &adapter
->tx_ring
[i
]);
2292 * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
2293 * @adapter: board private structure
2294 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2296 * Return 0 on success, negative on failure
2298 int ixgbevf_setup_tx_resources(struct ixgbevf_adapter
*adapter
,
2299 struct ixgbevf_ring
*tx_ring
)
2301 struct pci_dev
*pdev
= adapter
->pdev
;
2304 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
2305 tx_ring
->tx_buffer_info
= vzalloc(size
);
2306 if (!tx_ring
->tx_buffer_info
)
2309 /* round up to nearest 4K */
2310 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
2311 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
2313 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
2314 &tx_ring
->dma
, GFP_KERNEL
);
2318 tx_ring
->next_to_use
= 0;
2319 tx_ring
->next_to_clean
= 0;
2323 vfree(tx_ring
->tx_buffer_info
);
2324 tx_ring
->tx_buffer_info
= NULL
;
2325 hw_dbg(&adapter
->hw
, "Unable to allocate memory for the transmit "
2326 "descriptor ring\n");
2331 * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
2332 * @adapter: board private structure
2334 * If this function returns with an error, then it's possible one or
2335 * more of the rings is populated (while the rest are not). It is the
2336 * callers duty to clean those orphaned rings.
2338 * Return 0 on success, negative on failure
2340 static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2344 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2345 err
= ixgbevf_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
2348 hw_dbg(&adapter
->hw
,
2349 "Allocation for Tx Queue %u failed\n", i
);
2357 * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
2358 * @adapter: board private structure
2359 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2361 * Returns 0 on success, negative on failure
2363 int ixgbevf_setup_rx_resources(struct ixgbevf_adapter
*adapter
,
2364 struct ixgbevf_ring
*rx_ring
)
2366 struct pci_dev
*pdev
= adapter
->pdev
;
2369 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
2370 rx_ring
->rx_buffer_info
= vzalloc(size
);
2371 if (!rx_ring
->rx_buffer_info
)
2374 /* Round up to nearest 4K */
2375 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
2376 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
2378 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
2379 &rx_ring
->dma
, GFP_KERNEL
);
2381 if (!rx_ring
->desc
) {
2382 hw_dbg(&adapter
->hw
,
2383 "Unable to allocate memory for "
2384 "the receive descriptor ring\n");
2385 vfree(rx_ring
->rx_buffer_info
);
2386 rx_ring
->rx_buffer_info
= NULL
;
2390 rx_ring
->next_to_clean
= 0;
2391 rx_ring
->next_to_use
= 0;
2399 * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
2400 * @adapter: board private structure
2402 * If this function returns with an error, then it's possible one or
2403 * more of the rings is populated (while the rest are not). It is the
2404 * callers duty to clean those orphaned rings.
2406 * Return 0 on success, negative on failure
2408 static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2412 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2413 err
= ixgbevf_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2416 hw_dbg(&adapter
->hw
,
2417 "Allocation for Rx Queue %u failed\n", i
);
2424 * ixgbevf_free_rx_resources - Free Rx Resources
2425 * @adapter: board private structure
2426 * @rx_ring: ring to clean the resources from
2428 * Free all receive software resources
2430 void ixgbevf_free_rx_resources(struct ixgbevf_adapter
*adapter
,
2431 struct ixgbevf_ring
*rx_ring
)
2433 struct pci_dev
*pdev
= adapter
->pdev
;
2435 ixgbevf_clean_rx_ring(adapter
, rx_ring
);
2437 vfree(rx_ring
->rx_buffer_info
);
2438 rx_ring
->rx_buffer_info
= NULL
;
2440 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
2443 rx_ring
->desc
= NULL
;
2447 * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
2448 * @adapter: board private structure
2450 * Free all receive software resources
2452 static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2456 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2457 if (adapter
->rx_ring
[i
].desc
)
2458 ixgbevf_free_rx_resources(adapter
,
2459 &adapter
->rx_ring
[i
]);
2462 static int ixgbevf_setup_queues(struct ixgbevf_adapter
*adapter
)
2464 struct ixgbe_hw
*hw
= &adapter
->hw
;
2465 struct ixgbevf_ring
*rx_ring
;
2466 unsigned int def_q
= 0;
2467 unsigned int num_tcs
= 0;
2468 unsigned int num_rx_queues
= 1;
2471 spin_lock_bh(&adapter
->mbx_lock
);
2473 /* fetch queue configuration from the PF */
2474 err
= ixgbevf_get_queues(hw
, &num_tcs
, &def_q
);
2476 spin_unlock_bh(&adapter
->mbx_lock
);
2482 /* update default Tx ring register index */
2483 adapter
->tx_ring
[0].reg_idx
= def_q
;
2485 /* we need as many queues as traffic classes */
2486 num_rx_queues
= num_tcs
;
2489 /* nothing to do if we have the correct number of queues */
2490 if (adapter
->num_rx_queues
== num_rx_queues
)
2493 /* allocate new rings */
2494 rx_ring
= kcalloc(num_rx_queues
,
2495 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
2499 /* setup ring fields */
2500 for (i
= 0; i
< num_rx_queues
; i
++) {
2501 rx_ring
[i
].count
= adapter
->rx_ring_count
;
2502 rx_ring
[i
].queue_index
= i
;
2503 rx_ring
[i
].reg_idx
= i
;
2504 rx_ring
[i
].dev
= &adapter
->pdev
->dev
;
2505 rx_ring
[i
].netdev
= adapter
->netdev
;
2508 /* free the existing ring and queues */
2509 adapter
->num_rx_queues
= 0;
2510 kfree(adapter
->rx_ring
);
2512 /* move new rings into position on the adapter struct */
2513 adapter
->rx_ring
= rx_ring
;
2514 adapter
->num_rx_queues
= num_rx_queues
;
2520 * ixgbevf_open - Called when a network interface is made active
2521 * @netdev: network interface device structure
2523 * Returns 0 on success, negative value on failure
2525 * The open entry point is called when a network interface is made
2526 * active by the system (IFF_UP). At this point all resources needed
2527 * for transmit and receive operations are allocated, the interrupt
2528 * handler is registered with the OS, the watchdog timer is started,
2529 * and the stack is notified that the interface is ready.
2531 static int ixgbevf_open(struct net_device
*netdev
)
2533 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2534 struct ixgbe_hw
*hw
= &adapter
->hw
;
2537 /* disallow open during test */
2538 if (test_bit(__IXGBEVF_TESTING
, &adapter
->state
))
2541 if (hw
->adapter_stopped
) {
2542 ixgbevf_reset(adapter
);
2543 /* if adapter is still stopped then PF isn't up and
2544 * the vf can't start. */
2545 if (hw
->adapter_stopped
) {
2546 err
= IXGBE_ERR_MBX
;
2547 pr_err("Unable to start - perhaps the PF Driver isn't "
2549 goto err_setup_reset
;
2553 ixgbevf_negotiate_api(adapter
);
2555 /* setup queue reg_idx and Rx queue count */
2556 err
= ixgbevf_setup_queues(adapter
);
2558 goto err_setup_queues
;
2560 /* allocate transmit descriptors */
2561 err
= ixgbevf_setup_all_tx_resources(adapter
);
2565 /* allocate receive descriptors */
2566 err
= ixgbevf_setup_all_rx_resources(adapter
);
2570 ixgbevf_configure(adapter
);
2573 * Map the Tx/Rx rings to the vectors we were allotted.
2574 * if request_irq will be called in this function map_rings
2575 * must be called *before* up_complete
2577 ixgbevf_map_rings_to_vectors(adapter
);
2579 ixgbevf_up_complete(adapter
);
2581 /* clear any pending interrupts, may auto mask */
2582 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
2583 err
= ixgbevf_request_irq(adapter
);
2587 ixgbevf_irq_enable(adapter
);
2592 ixgbevf_down(adapter
);
2593 ixgbevf_free_irq(adapter
);
2595 ixgbevf_free_all_rx_resources(adapter
);
2597 ixgbevf_free_all_tx_resources(adapter
);
2599 ixgbevf_reset(adapter
);
2607 * ixgbevf_close - Disables a network interface
2608 * @netdev: network interface device structure
2610 * Returns 0, this is not allowed to fail
2612 * The close entry point is called when an interface is de-activated
2613 * by the OS. The hardware is still under the drivers control, but
2614 * needs to be disabled. A global MAC reset is issued to stop the
2615 * hardware, and all transmit and receive resources are freed.
2617 static int ixgbevf_close(struct net_device
*netdev
)
2619 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2621 ixgbevf_down(adapter
);
2622 ixgbevf_free_irq(adapter
);
2624 ixgbevf_free_all_tx_resources(adapter
);
2625 ixgbevf_free_all_rx_resources(adapter
);
2630 static void ixgbevf_tx_ctxtdesc(struct ixgbevf_ring
*tx_ring
,
2631 u32 vlan_macip_lens
, u32 type_tucmd
,
2634 struct ixgbe_adv_tx_context_desc
*context_desc
;
2635 u16 i
= tx_ring
->next_to_use
;
2637 context_desc
= IXGBEVF_TX_CTXTDESC(tx_ring
, i
);
2640 tx_ring
->next_to_use
= (i
< tx_ring
->count
) ? i
: 0;
2642 /* set bits to identify this as an advanced context descriptor */
2643 type_tucmd
|= IXGBE_TXD_CMD_DEXT
| IXGBE_ADVTXD_DTYP_CTXT
;
2645 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2646 context_desc
->seqnum_seed
= 0;
2647 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd
);
2648 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
2651 static int ixgbevf_tso(struct ixgbevf_ring
*tx_ring
,
2652 struct sk_buff
*skb
, u32 tx_flags
, u8
*hdr_len
)
2654 u32 vlan_macip_lens
, type_tucmd
;
2655 u32 mss_l4len_idx
, l4len
;
2657 if (!skb_is_gso(skb
))
2660 if (skb_header_cloned(skb
)) {
2661 int err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2666 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2667 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2669 if (skb
->protocol
== htons(ETH_P_IP
)) {
2670 struct iphdr
*iph
= ip_hdr(skb
);
2673 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2677 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2678 } else if (skb_is_gso_v6(skb
)) {
2679 ipv6_hdr(skb
)->payload_len
= 0;
2680 tcp_hdr(skb
)->check
=
2681 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2682 &ipv6_hdr(skb
)->daddr
,
2686 /* compute header lengths */
2687 l4len
= tcp_hdrlen(skb
);
2689 *hdr_len
= skb_transport_offset(skb
) + l4len
;
2691 /* mss_l4len_id: use 1 as index for TSO */
2692 mss_l4len_idx
= l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
;
2693 mss_l4len_idx
|= skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
;
2694 mss_l4len_idx
|= 1 << IXGBE_ADVTXD_IDX_SHIFT
;
2696 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
2697 vlan_macip_lens
= skb_network_header_len(skb
);
2698 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
2699 vlan_macip_lens
|= tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
2701 ixgbevf_tx_ctxtdesc(tx_ring
, vlan_macip_lens
,
2702 type_tucmd
, mss_l4len_idx
);
2707 static bool ixgbevf_tx_csum(struct ixgbevf_ring
*tx_ring
,
2708 struct sk_buff
*skb
, u32 tx_flags
)
2713 u32 vlan_macip_lens
= 0;
2714 u32 mss_l4len_idx
= 0;
2717 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2719 switch (skb
->protocol
) {
2720 case __constant_htons(ETH_P_IP
):
2721 vlan_macip_lens
|= skb_network_header_len(skb
);
2722 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2723 l4_hdr
= ip_hdr(skb
)->protocol
;
2725 case __constant_htons(ETH_P_IPV6
):
2726 vlan_macip_lens
|= skb_network_header_len(skb
);
2727 l4_hdr
= ipv6_hdr(skb
)->nexthdr
;
2730 if (unlikely(net_ratelimit())) {
2731 dev_warn(tx_ring
->dev
,
2732 "partial checksum but proto=%x!\n",
2740 type_tucmd
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2741 mss_l4len_idx
= tcp_hdrlen(skb
) <<
2742 IXGBE_ADVTXD_L4LEN_SHIFT
;
2745 type_tucmd
|= IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
2746 mss_l4len_idx
= sizeof(struct sctphdr
) <<
2747 IXGBE_ADVTXD_L4LEN_SHIFT
;
2750 mss_l4len_idx
= sizeof(struct udphdr
) <<
2751 IXGBE_ADVTXD_L4LEN_SHIFT
;
2754 if (unlikely(net_ratelimit())) {
2755 dev_warn(tx_ring
->dev
,
2756 "partial checksum but l4 proto=%x!\n",
2763 /* vlan_macip_lens: MACLEN, VLAN tag */
2764 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
2765 vlan_macip_lens
|= tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
2767 ixgbevf_tx_ctxtdesc(tx_ring
, vlan_macip_lens
,
2768 type_tucmd
, mss_l4len_idx
);
2770 return (skb
->ip_summed
== CHECKSUM_PARTIAL
);
2773 static int ixgbevf_tx_map(struct ixgbevf_ring
*tx_ring
,
2774 struct sk_buff
*skb
, u32 tx_flags
,
2777 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2779 unsigned int total
= skb
->len
;
2780 unsigned int offset
= 0, size
;
2782 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2786 i
= tx_ring
->next_to_use
;
2788 len
= min(skb_headlen(skb
), total
);
2790 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2791 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2793 tx_buffer_info
->length
= size
;
2794 tx_buffer_info
->mapped_as_page
= false;
2795 tx_buffer_info
->dma
= dma_map_single(tx_ring
->dev
,
2797 size
, DMA_TO_DEVICE
);
2798 if (dma_mapping_error(tx_ring
->dev
, tx_buffer_info
->dma
))
2800 tx_buffer_info
->next_to_watch
= i
;
2807 if (i
== tx_ring
->count
)
2811 for (f
= 0; f
< nr_frags
; f
++) {
2812 const struct skb_frag_struct
*frag
;
2814 frag
= &skb_shinfo(skb
)->frags
[f
];
2815 len
= min((unsigned int)skb_frag_size(frag
), total
);
2819 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2820 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2822 tx_buffer_info
->length
= size
;
2823 tx_buffer_info
->dma
=
2824 skb_frag_dma_map(tx_ring
->dev
, frag
,
2825 offset
, size
, DMA_TO_DEVICE
);
2826 if (dma_mapping_error(tx_ring
->dev
,
2827 tx_buffer_info
->dma
))
2829 tx_buffer_info
->mapped_as_page
= true;
2830 tx_buffer_info
->next_to_watch
= i
;
2837 if (i
== tx_ring
->count
)
2845 i
= tx_ring
->count
- 1;
2848 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
2849 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
2850 tx_ring
->tx_buffer_info
[first
].time_stamp
= jiffies
;
2855 dev_err(tx_ring
->dev
, "TX DMA map failed\n");
2857 /* clear timestamp and dma mappings for failed tx_buffer_info map */
2858 tx_buffer_info
->dma
= 0;
2859 tx_buffer_info
->next_to_watch
= 0;
2862 /* clear timestamp and dma mappings for remaining portion of packet */
2863 while (count
>= 0) {
2867 i
+= tx_ring
->count
;
2868 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2869 ixgbevf_unmap_and_free_tx_resource(tx_ring
, tx_buffer_info
);
2875 static void ixgbevf_tx_queue(struct ixgbevf_ring
*tx_ring
, int tx_flags
,
2876 int count
, u32 paylen
, u8 hdr_len
)
2878 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
2879 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2880 u32 olinfo_status
= 0, cmd_type_len
= 0;
2883 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
2885 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
2887 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
2889 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2890 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
2892 if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
2893 olinfo_status
|= IXGBE_ADVTXD_POPTS_TXSM
;
2895 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
2896 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
2898 /* use index 1 context for tso */
2899 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
2900 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
2901 olinfo_status
|= IXGBE_ADVTXD_POPTS_IXSM
;
2906 * Check Context must be set if Tx switch is enabled, which it
2907 * always is for case where virtual functions are running
2909 olinfo_status
|= IXGBE_ADVTXD_CC
;
2911 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
2913 i
= tx_ring
->next_to_use
;
2915 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2916 tx_desc
= IXGBEVF_TX_DESC(tx_ring
, i
);
2917 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
2918 tx_desc
->read
.cmd_type_len
=
2919 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
2920 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
2922 if (i
== tx_ring
->count
)
2926 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
2928 tx_ring
->next_to_use
= i
;
2931 static int __ixgbevf_maybe_stop_tx(struct ixgbevf_ring
*tx_ring
, int size
)
2933 struct ixgbevf_adapter
*adapter
= netdev_priv(tx_ring
->netdev
);
2935 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
2936 /* Herbert's original patch had:
2937 * smp_mb__after_netif_stop_queue();
2938 * but since that doesn't exist yet, just open code it. */
2941 /* We need to check again in a case another CPU has just
2942 * made room available. */
2943 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
2946 /* A reprieve! - use start_queue because it doesn't call schedule */
2947 netif_start_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
2948 ++adapter
->restart_queue
;
2952 static int ixgbevf_maybe_stop_tx(struct ixgbevf_ring
*tx_ring
, int size
)
2954 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
2956 return __ixgbevf_maybe_stop_tx(tx_ring
, size
);
2959 static int ixgbevf_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
2961 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2962 struct ixgbevf_ring
*tx_ring
;
2964 unsigned int tx_flags
= 0;
2967 u16 count
= TXD_USE_COUNT(skb_headlen(skb
));
2968 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
2972 tx_ring
= &adapter
->tx_ring
[r_idx
];
2975 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
2976 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
2977 * + 2 desc gap to keep tail from touching head,
2978 * + 1 desc for context descriptor,
2979 * otherwise try next time
2981 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
2982 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
2983 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
2985 count
+= skb_shinfo(skb
)->nr_frags
;
2987 if (ixgbevf_maybe_stop_tx(tx_ring
, count
+ 3)) {
2989 return NETDEV_TX_BUSY
;
2992 if (vlan_tx_tag_present(skb
)) {
2993 tx_flags
|= vlan_tx_tag_get(skb
);
2994 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
2995 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
2998 first
= tx_ring
->next_to_use
;
3000 if (skb
->protocol
== htons(ETH_P_IP
))
3001 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
3002 tso
= ixgbevf_tso(tx_ring
, skb
, tx_flags
, &hdr_len
);
3004 dev_kfree_skb_any(skb
);
3005 return NETDEV_TX_OK
;
3009 tx_flags
|= IXGBE_TX_FLAGS_TSO
| IXGBE_TX_FLAGS_CSUM
;
3010 else if (ixgbevf_tx_csum(tx_ring
, skb
, tx_flags
))
3011 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
3013 ixgbevf_tx_queue(tx_ring
, tx_flags
,
3014 ixgbevf_tx_map(tx_ring
, skb
, tx_flags
, first
),
3017 * Force memory writes to complete before letting h/w
3018 * know there are new descriptors to fetch. (Only
3019 * applicable for weak-ordered memory model archs,
3024 writel(tx_ring
->next_to_use
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3026 ixgbevf_maybe_stop_tx(tx_ring
, DESC_NEEDED
);
3028 return NETDEV_TX_OK
;
3032 * ixgbevf_set_mac - Change the Ethernet Address of the NIC
3033 * @netdev: network interface device structure
3034 * @p: pointer to an address structure
3036 * Returns 0 on success, negative on failure
3038 static int ixgbevf_set_mac(struct net_device
*netdev
, void *p
)
3040 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3041 struct ixgbe_hw
*hw
= &adapter
->hw
;
3042 struct sockaddr
*addr
= p
;
3044 if (!is_valid_ether_addr(addr
->sa_data
))
3045 return -EADDRNOTAVAIL
;
3047 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3048 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3050 spin_lock_bh(&adapter
->mbx_lock
);
3052 if (hw
->mac
.ops
.set_rar
)
3053 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
3055 spin_unlock_bh(&adapter
->mbx_lock
);
3061 * ixgbevf_change_mtu - Change the Maximum Transfer Unit
3062 * @netdev: network interface device structure
3063 * @new_mtu: new value for maximum frame size
3065 * Returns 0 on success, negative on failure
3067 static int ixgbevf_change_mtu(struct net_device
*netdev
, int new_mtu
)
3069 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3070 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3071 int max_possible_frame
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3073 switch (adapter
->hw
.api_version
) {
3074 case ixgbe_mbox_api_11
:
3075 max_possible_frame
= IXGBE_MAX_JUMBO_FRAME_SIZE
;
3078 if (adapter
->hw
.mac
.type
== ixgbe_mac_X540_vf
)
3079 max_possible_frame
= IXGBE_MAX_JUMBO_FRAME_SIZE
;
3083 /* MTU < 68 is an error and causes problems on some kernels */
3084 if ((new_mtu
< 68) || (max_frame
> max_possible_frame
))
3087 hw_dbg(&adapter
->hw
, "changing MTU from %d to %d\n",
3088 netdev
->mtu
, new_mtu
);
3089 /* must set new MTU before calling down or up */
3090 netdev
->mtu
= new_mtu
;
3092 if (netif_running(netdev
))
3093 ixgbevf_reinit_locked(adapter
);
3098 static int ixgbevf_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3100 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3101 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3106 netif_device_detach(netdev
);
3108 if (netif_running(netdev
)) {
3110 ixgbevf_down(adapter
);
3111 ixgbevf_free_irq(adapter
);
3112 ixgbevf_free_all_tx_resources(adapter
);
3113 ixgbevf_free_all_rx_resources(adapter
);
3117 ixgbevf_clear_interrupt_scheme(adapter
);
3120 retval
= pci_save_state(pdev
);
3125 pci_disable_device(pdev
);
3131 static int ixgbevf_resume(struct pci_dev
*pdev
)
3133 struct ixgbevf_adapter
*adapter
= pci_get_drvdata(pdev
);
3134 struct net_device
*netdev
= adapter
->netdev
;
3137 pci_set_power_state(pdev
, PCI_D0
);
3138 pci_restore_state(pdev
);
3140 * pci_restore_state clears dev->state_saved so call
3141 * pci_save_state to restore it.
3143 pci_save_state(pdev
);
3145 err
= pci_enable_device_mem(pdev
);
3147 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend\n");
3150 pci_set_master(pdev
);
3153 err
= ixgbevf_init_interrupt_scheme(adapter
);
3156 dev_err(&pdev
->dev
, "Cannot initialize interrupts\n");
3160 ixgbevf_reset(adapter
);
3162 if (netif_running(netdev
)) {
3163 err
= ixgbevf_open(netdev
);
3168 netif_device_attach(netdev
);
3173 #endif /* CONFIG_PM */
3174 static void ixgbevf_shutdown(struct pci_dev
*pdev
)
3176 ixgbevf_suspend(pdev
, PMSG_SUSPEND
);
3179 static struct rtnl_link_stats64
*ixgbevf_get_stats(struct net_device
*netdev
,
3180 struct rtnl_link_stats64
*stats
)
3182 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3185 const struct ixgbevf_ring
*ring
;
3188 ixgbevf_update_stats(adapter
);
3190 stats
->multicast
= adapter
->stats
.vfmprc
- adapter
->stats
.base_vfmprc
;
3192 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3193 ring
= &adapter
->rx_ring
[i
];
3195 start
= u64_stats_fetch_begin_bh(&ring
->syncp
);
3196 bytes
= ring
->total_bytes
;
3197 packets
= ring
->total_packets
;
3198 } while (u64_stats_fetch_retry_bh(&ring
->syncp
, start
));
3199 stats
->rx_bytes
+= bytes
;
3200 stats
->rx_packets
+= packets
;
3203 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3204 ring
= &adapter
->tx_ring
[i
];
3206 start
= u64_stats_fetch_begin_bh(&ring
->syncp
);
3207 bytes
= ring
->total_bytes
;
3208 packets
= ring
->total_packets
;
3209 } while (u64_stats_fetch_retry_bh(&ring
->syncp
, start
));
3210 stats
->tx_bytes
+= bytes
;
3211 stats
->tx_packets
+= packets
;
3217 static const struct net_device_ops ixgbevf_netdev_ops
= {
3218 .ndo_open
= ixgbevf_open
,
3219 .ndo_stop
= ixgbevf_close
,
3220 .ndo_start_xmit
= ixgbevf_xmit_frame
,
3221 .ndo_set_rx_mode
= ixgbevf_set_rx_mode
,
3222 .ndo_get_stats64
= ixgbevf_get_stats
,
3223 .ndo_validate_addr
= eth_validate_addr
,
3224 .ndo_set_mac_address
= ixgbevf_set_mac
,
3225 .ndo_change_mtu
= ixgbevf_change_mtu
,
3226 .ndo_tx_timeout
= ixgbevf_tx_timeout
,
3227 .ndo_vlan_rx_add_vid
= ixgbevf_vlan_rx_add_vid
,
3228 .ndo_vlan_rx_kill_vid
= ixgbevf_vlan_rx_kill_vid
,
3231 static void ixgbevf_assign_netdev_ops(struct net_device
*dev
)
3233 dev
->netdev_ops
= &ixgbevf_netdev_ops
;
3234 ixgbevf_set_ethtool_ops(dev
);
3235 dev
->watchdog_timeo
= 5 * HZ
;
3239 * ixgbevf_probe - Device Initialization Routine
3240 * @pdev: PCI device information struct
3241 * @ent: entry in ixgbevf_pci_tbl
3243 * Returns 0 on success, negative on failure
3245 * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
3246 * The OS initialization, configuring of the adapter private structure,
3247 * and a hardware reset occur.
3249 static int __devinit
ixgbevf_probe(struct pci_dev
*pdev
,
3250 const struct pci_device_id
*ent
)
3252 struct net_device
*netdev
;
3253 struct ixgbevf_adapter
*adapter
= NULL
;
3254 struct ixgbe_hw
*hw
= NULL
;
3255 const struct ixgbevf_info
*ii
= ixgbevf_info_tbl
[ent
->driver_data
];
3256 static int cards_found
;
3257 int err
, pci_using_dac
;
3259 err
= pci_enable_device(pdev
);
3263 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64)) &&
3264 !dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
3267 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
3269 err
= dma_set_coherent_mask(&pdev
->dev
,
3272 dev_err(&pdev
->dev
, "No usable DMA "
3273 "configuration, aborting\n");
3280 err
= pci_request_regions(pdev
, ixgbevf_driver_name
);
3282 dev_err(&pdev
->dev
, "pci_request_regions failed 0x%x\n", err
);
3286 pci_set_master(pdev
);
3288 netdev
= alloc_etherdev_mq(sizeof(struct ixgbevf_adapter
),
3292 goto err_alloc_etherdev
;
3295 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3297 pci_set_drvdata(pdev
, netdev
);
3298 adapter
= netdev_priv(netdev
);
3300 adapter
->netdev
= netdev
;
3301 adapter
->pdev
= pdev
;
3304 adapter
->msg_enable
= netif_msg_init(debug
, DEFAULT_MSG_ENABLE
);
3307 * call save state here in standalone driver because it relies on
3308 * adapter struct to exist, and needs to call netdev_priv
3310 pci_save_state(pdev
);
3312 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
3313 pci_resource_len(pdev
, 0));
3319 ixgbevf_assign_netdev_ops(netdev
);
3321 adapter
->bd_number
= cards_found
;
3324 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
3325 hw
->mac
.type
= ii
->mac
;
3327 memcpy(&hw
->mbx
.ops
, &ixgbevf_mbx_ops
,
3328 sizeof(struct ixgbe_mbx_operations
));
3330 /* setup the private structure */
3331 err
= ixgbevf_sw_init(adapter
);
3335 /* The HW MAC address was set and/or determined in sw_init */
3336 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3338 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
3339 pr_err("invalid MAC address\n");
3344 netdev
->hw_features
= NETIF_F_SG
|
3351 netdev
->features
= netdev
->hw_features
|
3352 NETIF_F_HW_VLAN_TX
|
3353 NETIF_F_HW_VLAN_RX
|
3354 NETIF_F_HW_VLAN_FILTER
;
3356 netdev
->vlan_features
|= NETIF_F_TSO
;
3357 netdev
->vlan_features
|= NETIF_F_TSO6
;
3358 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
3359 netdev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
3360 netdev
->vlan_features
|= NETIF_F_SG
;
3363 netdev
->features
|= NETIF_F_HIGHDMA
;
3365 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
3367 init_timer(&adapter
->watchdog_timer
);
3368 adapter
->watchdog_timer
.function
= ixgbevf_watchdog
;
3369 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
3371 INIT_WORK(&adapter
->reset_task
, ixgbevf_reset_task
);
3372 INIT_WORK(&adapter
->watchdog_task
, ixgbevf_watchdog_task
);
3374 err
= ixgbevf_init_interrupt_scheme(adapter
);
3378 /* pick up the PCI bus settings for reporting later */
3379 if (hw
->mac
.ops
.get_bus_info
)
3380 hw
->mac
.ops
.get_bus_info(hw
);
3382 strcpy(netdev
->name
, "eth%d");
3384 err
= register_netdev(netdev
);
3388 netif_carrier_off(netdev
);
3390 ixgbevf_init_last_counter_stats(adapter
);
3392 /* print the MAC address */
3393 hw_dbg(hw
, "%pM\n", netdev
->dev_addr
);
3395 hw_dbg(hw
, "MAC: %d\n", hw
->mac
.type
);
3397 hw_dbg(hw
, "Intel(R) 82599 Virtual Function\n");
3402 ixgbevf_clear_interrupt_scheme(adapter
);
3404 ixgbevf_reset_interrupt_capability(adapter
);
3405 iounmap(hw
->hw_addr
);
3407 free_netdev(netdev
);
3409 pci_release_regions(pdev
);
3412 pci_disable_device(pdev
);
3417 * ixgbevf_remove - Device Removal Routine
3418 * @pdev: PCI device information struct
3420 * ixgbevf_remove is called by the PCI subsystem to alert the driver
3421 * that it should release a PCI device. The could be caused by a
3422 * Hot-Plug event, or because the driver is going to be removed from
3425 static void __devexit
ixgbevf_remove(struct pci_dev
*pdev
)
3427 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3428 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3430 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
3432 del_timer_sync(&adapter
->watchdog_timer
);
3434 cancel_work_sync(&adapter
->reset_task
);
3435 cancel_work_sync(&adapter
->watchdog_task
);
3437 if (netdev
->reg_state
== NETREG_REGISTERED
)
3438 unregister_netdev(netdev
);
3440 ixgbevf_clear_interrupt_scheme(adapter
);
3441 ixgbevf_reset_interrupt_capability(adapter
);
3443 iounmap(adapter
->hw
.hw_addr
);
3444 pci_release_regions(pdev
);
3446 hw_dbg(&adapter
->hw
, "Remove complete\n");
3448 kfree(adapter
->tx_ring
);
3449 kfree(adapter
->rx_ring
);
3451 free_netdev(netdev
);
3453 pci_disable_device(pdev
);
3457 * ixgbevf_io_error_detected - called when PCI error is detected
3458 * @pdev: Pointer to PCI device
3459 * @state: The current pci connection state
3461 * This function is called after a PCI bus error affecting
3462 * this device has been detected.
3464 static pci_ers_result_t
ixgbevf_io_error_detected(struct pci_dev
*pdev
,
3465 pci_channel_state_t state
)
3467 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3468 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3470 netif_device_detach(netdev
);
3472 if (state
== pci_channel_io_perm_failure
)
3473 return PCI_ERS_RESULT_DISCONNECT
;
3475 if (netif_running(netdev
))
3476 ixgbevf_down(adapter
);
3478 pci_disable_device(pdev
);
3480 /* Request a slot slot reset. */
3481 return PCI_ERS_RESULT_NEED_RESET
;
3485 * ixgbevf_io_slot_reset - called after the pci bus has been reset.
3486 * @pdev: Pointer to PCI device
3488 * Restart the card from scratch, as if from a cold-boot. Implementation
3489 * resembles the first-half of the ixgbevf_resume routine.
3491 static pci_ers_result_t
ixgbevf_io_slot_reset(struct pci_dev
*pdev
)
3493 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3494 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3496 if (pci_enable_device_mem(pdev
)) {
3498 "Cannot re-enable PCI device after reset.\n");
3499 return PCI_ERS_RESULT_DISCONNECT
;
3502 pci_set_master(pdev
);
3504 ixgbevf_reset(adapter
);
3506 return PCI_ERS_RESULT_RECOVERED
;
3510 * ixgbevf_io_resume - called when traffic can start flowing again.
3511 * @pdev: Pointer to PCI device
3513 * This callback is called when the error recovery driver tells us that
3514 * its OK to resume normal operation. Implementation resembles the
3515 * second-half of the ixgbevf_resume routine.
3517 static void ixgbevf_io_resume(struct pci_dev
*pdev
)
3519 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3520 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3522 if (netif_running(netdev
))
3523 ixgbevf_up(adapter
);
3525 netif_device_attach(netdev
);
3528 /* PCI Error Recovery (ERS) */
3529 static const struct pci_error_handlers ixgbevf_err_handler
= {
3530 .error_detected
= ixgbevf_io_error_detected
,
3531 .slot_reset
= ixgbevf_io_slot_reset
,
3532 .resume
= ixgbevf_io_resume
,
3535 static struct pci_driver ixgbevf_driver
= {
3536 .name
= ixgbevf_driver_name
,
3537 .id_table
= ixgbevf_pci_tbl
,
3538 .probe
= ixgbevf_probe
,
3539 .remove
= __devexit_p(ixgbevf_remove
),
3541 /* Power Management Hooks */
3542 .suspend
= ixgbevf_suspend
,
3543 .resume
= ixgbevf_resume
,
3545 .shutdown
= ixgbevf_shutdown
,
3546 .err_handler
= &ixgbevf_err_handler
3550 * ixgbevf_init_module - Driver Registration Routine
3552 * ixgbevf_init_module is the first routine called when the driver is
3553 * loaded. All it does is register with the PCI subsystem.
3555 static int __init
ixgbevf_init_module(void)
3558 pr_info("%s - version %s\n", ixgbevf_driver_string
,
3559 ixgbevf_driver_version
);
3561 pr_info("%s\n", ixgbevf_copyright
);
3563 ret
= pci_register_driver(&ixgbevf_driver
);
3567 module_init(ixgbevf_init_module
);
3570 * ixgbevf_exit_module - Driver Exit Cleanup Routine
3572 * ixgbevf_exit_module is called just before the driver is removed
3575 static void __exit
ixgbevf_exit_module(void)
3577 pci_unregister_driver(&ixgbevf_driver
);
3582 * ixgbevf_get_hw_dev_name - return device name string
3583 * used by hardware layer to print debugging information
3585 char *ixgbevf_get_hw_dev_name(struct ixgbe_hw
*hw
)
3587 struct ixgbevf_adapter
*adapter
= hw
->back
;
3588 return adapter
->netdev
->name
;
3592 module_exit(ixgbevf_exit_module
);
3594 /* ixgbevf_main.c */