1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2009 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
29 /******************************************************************************
30 Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
31 ******************************************************************************/
32 #include <linux/types.h>
33 #include <linux/module.h>
34 #include <linux/pci.h>
35 #include <linux/netdevice.h>
36 #include <linux/vmalloc.h>
37 #include <linux/string.h>
40 #include <linux/tcp.h>
41 #include <linux/ipv6.h>
42 #include <net/checksum.h>
43 #include <net/ip6_checksum.h>
44 #include <linux/ethtool.h>
45 #include <linux/if_vlan.h>
49 char ixgbevf_driver_name
[] = "ixgbevf";
50 static const char ixgbevf_driver_string
[] =
51 "Intel(R) 82599 Virtual Function";
53 #define DRV_VERSION "1.0.0-k0"
54 const char ixgbevf_driver_version
[] = DRV_VERSION
;
55 static char ixgbevf_copyright
[] = "Copyright (c) 2009 Intel Corporation.";
57 static const struct ixgbevf_info
*ixgbevf_info_tbl
[] = {
58 [board_82599_vf
] = &ixgbevf_vf_info
,
61 /* ixgbevf_pci_tbl - PCI Device ID Table
63 * Wildcard entries (PCI_ANY_ID) should come last
64 * Last entry must be all 0s
66 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
67 * Class, Class Mask, private data (not used) }
69 static struct pci_device_id ixgbevf_pci_tbl
[] = {
70 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_VF
),
73 /* required last entry */
76 MODULE_DEVICE_TABLE(pci
, ixgbevf_pci_tbl
);
78 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
79 MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
80 MODULE_LICENSE("GPL");
81 MODULE_VERSION(DRV_VERSION
);
83 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
86 static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector
*q_vector
);
87 static void ixgbevf_write_eitr(struct ixgbevf_adapter
*adapter
, int v_idx
,
90 static inline void ixgbevf_release_rx_desc(struct ixgbe_hw
*hw
,
91 struct ixgbevf_ring
*rx_ring
,
95 * Force memory writes to complete before letting h/w
96 * know there are new descriptors to fetch. (Only
97 * applicable for weak-ordered memory model archs,
101 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(rx_ring
->reg_idx
), val
);
105 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
106 * @adapter: pointer to adapter struct
107 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
108 * @queue: queue to map the corresponding interrupt to
109 * @msix_vector: the vector to map to the corresponding queue
112 static void ixgbevf_set_ivar(struct ixgbevf_adapter
*adapter
, s8 direction
,
113 u8 queue
, u8 msix_vector
)
116 struct ixgbe_hw
*hw
= &adapter
->hw
;
117 if (direction
== -1) {
119 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
120 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR_MISC
);
123 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR_MISC
, ivar
);
125 /* tx or rx causes */
126 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
127 index
= ((16 * (queue
& 1)) + (8 * direction
));
128 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR(queue
>> 1));
129 ivar
&= ~(0xFF << index
);
130 ivar
|= (msix_vector
<< index
);
131 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR(queue
>> 1), ivar
);
135 static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_adapter
*adapter
,
136 struct ixgbevf_tx_buffer
139 if (tx_buffer_info
->dma
) {
140 if (tx_buffer_info
->mapped_as_page
)
141 pci_unmap_page(adapter
->pdev
,
143 tx_buffer_info
->length
,
146 pci_unmap_single(adapter
->pdev
,
148 tx_buffer_info
->length
,
150 tx_buffer_info
->dma
= 0;
152 if (tx_buffer_info
->skb
) {
153 dev_kfree_skb_any(tx_buffer_info
->skb
);
154 tx_buffer_info
->skb
= NULL
;
156 tx_buffer_info
->time_stamp
= 0;
157 /* tx_buffer_info must be completely set up in the transmit path */
160 static inline bool ixgbevf_check_tx_hang(struct ixgbevf_adapter
*adapter
,
161 struct ixgbevf_ring
*tx_ring
,
164 struct ixgbe_hw
*hw
= &adapter
->hw
;
167 /* Detect a transmit hang in hardware, this serializes the
168 * check with the clearing of time_stamp and movement of eop */
169 head
= readl(hw
->hw_addr
+ tx_ring
->head
);
170 tail
= readl(hw
->hw_addr
+ tx_ring
->tail
);
171 adapter
->detect_tx_hung
= false;
172 if ((head
!= tail
) &&
173 tx_ring
->tx_buffer_info
[eop
].time_stamp
&&
174 time_after(jiffies
, tx_ring
->tx_buffer_info
[eop
].time_stamp
+ HZ
)) {
175 /* detected Tx unit hang */
176 union ixgbe_adv_tx_desc
*tx_desc
;
177 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
178 printk(KERN_ERR
"Detected Tx Unit Hang\n"
180 " TDH, TDT <%x>, <%x>\n"
181 " next_to_use <%x>\n"
182 " next_to_clean <%x>\n"
183 "tx_buffer_info[next_to_clean]\n"
184 " time_stamp <%lx>\n"
186 tx_ring
->queue_index
,
188 tx_ring
->next_to_use
, eop
,
189 tx_ring
->tx_buffer_info
[eop
].time_stamp
, jiffies
);
196 #define IXGBE_MAX_TXD_PWR 14
197 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
199 /* Tx Descriptors needed, worst case */
200 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
201 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
203 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
204 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
206 #define DESC_NEEDED TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD)
209 static void ixgbevf_tx_timeout(struct net_device
*netdev
);
212 * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
213 * @adapter: board private structure
214 * @tx_ring: tx ring to clean
216 static bool ixgbevf_clean_tx_irq(struct ixgbevf_adapter
*adapter
,
217 struct ixgbevf_ring
*tx_ring
)
219 struct net_device
*netdev
= adapter
->netdev
;
220 struct ixgbe_hw
*hw
= &adapter
->hw
;
221 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
222 struct ixgbevf_tx_buffer
*tx_buffer_info
;
223 unsigned int i
, eop
, count
= 0;
224 unsigned int total_bytes
= 0, total_packets
= 0;
226 i
= tx_ring
->next_to_clean
;
227 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
228 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
230 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
231 (count
< tx_ring
->work_limit
)) {
232 bool cleaned
= false;
233 for ( ; !cleaned
; count
++) {
235 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
236 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
237 cleaned
= (i
== eop
);
238 skb
= tx_buffer_info
->skb
;
240 if (cleaned
&& skb
) {
241 unsigned int segs
, bytecount
;
243 /* gso_segs is currently only valid for tcp */
244 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
245 /* multiply data chunks by size of headers */
246 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
248 total_packets
+= segs
;
249 total_bytes
+= bytecount
;
252 ixgbevf_unmap_and_free_tx_resource(adapter
,
255 tx_desc
->wb
.status
= 0;
258 if (i
== tx_ring
->count
)
262 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
263 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
266 tx_ring
->next_to_clean
= i
;
268 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
269 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
270 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
271 /* Make sure that anybody stopping the queue after this
272 * sees the new next_to_clean.
276 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
277 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
278 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
279 ++adapter
->restart_queue
;
282 if (netif_queue_stopped(netdev
) &&
283 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
284 netif_wake_queue(netdev
);
285 ++adapter
->restart_queue
;
290 if (adapter
->detect_tx_hung
) {
291 if (ixgbevf_check_tx_hang(adapter
, tx_ring
, i
)) {
292 /* schedule immediate reset if we believe we hung */
294 "tx hang %d detected, resetting adapter\n",
295 adapter
->tx_timeout_count
+ 1);
296 ixgbevf_tx_timeout(adapter
->netdev
);
300 /* re-arm the interrupt */
301 if ((count
>= tx_ring
->work_limit
) &&
302 (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))) {
303 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, tx_ring
->v_idx
);
306 tx_ring
->total_bytes
+= total_bytes
;
307 tx_ring
->total_packets
+= total_packets
;
309 adapter
->net_stats
.tx_bytes
+= total_bytes
;
310 adapter
->net_stats
.tx_packets
+= total_packets
;
312 return (count
< tx_ring
->work_limit
);
316 * ixgbevf_receive_skb - Send a completed packet up the stack
317 * @q_vector: structure containing interrupt and ring information
318 * @skb: packet to send up
319 * @status: hardware indication of status of receive
320 * @rx_ring: rx descriptor ring (for a specific queue) to setup
321 * @rx_desc: rx descriptor
323 static void ixgbevf_receive_skb(struct ixgbevf_q_vector
*q_vector
,
324 struct sk_buff
*skb
, u8 status
,
325 struct ixgbevf_ring
*ring
,
326 union ixgbe_adv_rx_desc
*rx_desc
)
328 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
329 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
330 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
333 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
)) {
334 if (adapter
->vlgrp
&& is_vlan
)
335 vlan_gro_receive(&q_vector
->napi
,
339 napi_gro_receive(&q_vector
->napi
, skb
);
341 if (adapter
->vlgrp
&& is_vlan
)
342 ret
= vlan_hwaccel_rx(skb
, adapter
->vlgrp
, tag
);
349 * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
350 * @adapter: address of board private structure
351 * @status_err: hardware indication of status of receive
352 * @skb: skb currently being received and modified
354 static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter
*adapter
,
355 u32 status_err
, struct sk_buff
*skb
)
357 skb
->ip_summed
= CHECKSUM_NONE
;
359 /* Rx csum disabled */
360 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
363 /* if IP and error */
364 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
365 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
366 adapter
->hw_csum_rx_error
++;
370 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
373 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
374 adapter
->hw_csum_rx_error
++;
378 /* It must be a TCP or UDP packet with a valid checksum */
379 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
380 adapter
->hw_csum_rx_good
++;
384 * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
385 * @adapter: address of board private structure
387 static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter
*adapter
,
388 struct ixgbevf_ring
*rx_ring
,
391 struct pci_dev
*pdev
= adapter
->pdev
;
392 union ixgbe_adv_rx_desc
*rx_desc
;
393 struct ixgbevf_rx_buffer
*bi
;
396 unsigned int bufsz
= rx_ring
->rx_buf_len
+ NET_IP_ALIGN
;
398 i
= rx_ring
->next_to_use
;
399 bi
= &rx_ring
->rx_buffer_info
[i
];
401 while (cleaned_count
--) {
402 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
405 (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)) {
407 bi
->page
= netdev_alloc_page(adapter
->netdev
);
409 adapter
->alloc_rx_page_failed
++;
414 /* use a half page if we're re-using */
415 bi
->page_offset
^= (PAGE_SIZE
/ 2);
418 bi
->page_dma
= pci_map_page(pdev
, bi
->page
,
426 skb
= netdev_alloc_skb(adapter
->netdev
,
430 adapter
->alloc_rx_buff_failed
++;
435 * Make buffer alignment 2 beyond a 16 byte boundary
436 * this will result in a 16 byte aligned IP header after
437 * the 14 byte MAC header is removed
439 skb_reserve(skb
, NET_IP_ALIGN
);
444 bi
->dma
= pci_map_single(pdev
, skb
->data
,
448 /* Refresh the desc even if buffer_addrs didn't change because
449 * each write-back erases this info. */
450 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
451 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
452 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
454 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
458 if (i
== rx_ring
->count
)
460 bi
= &rx_ring
->rx_buffer_info
[i
];
464 if (rx_ring
->next_to_use
!= i
) {
465 rx_ring
->next_to_use
= i
;
467 i
= (rx_ring
->count
- 1);
469 ixgbevf_release_rx_desc(&adapter
->hw
, rx_ring
, i
);
473 static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter
*adapter
,
477 struct ixgbe_hw
*hw
= &adapter
->hw
;
479 mask
= (qmask
& 0xFFFFFFFF);
480 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, mask
);
483 static inline u16
ixgbevf_get_hdr_info(union ixgbe_adv_rx_desc
*rx_desc
)
485 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
488 static inline u16
ixgbevf_get_pkt_info(union ixgbe_adv_rx_desc
*rx_desc
)
490 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
493 static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector
*q_vector
,
494 struct ixgbevf_ring
*rx_ring
,
495 int *work_done
, int work_to_do
)
497 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
498 struct pci_dev
*pdev
= adapter
->pdev
;
499 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
500 struct ixgbevf_rx_buffer
*rx_buffer_info
, *next_buffer
;
505 bool cleaned
= false;
506 int cleaned_count
= 0;
507 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
509 i
= rx_ring
->next_to_clean
;
510 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
511 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
512 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
514 while (staterr
& IXGBE_RXD_STAT_DD
) {
516 if (*work_done
>= work_to_do
)
520 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
521 hdr_info
= le16_to_cpu(ixgbevf_get_hdr_info(rx_desc
));
522 len
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
523 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
524 if (hdr_info
& IXGBE_RXDADV_SPH
)
525 adapter
->rx_hdr_split
++;
526 if (len
> IXGBEVF_RX_HDR_SIZE
)
527 len
= IXGBEVF_RX_HDR_SIZE
;
528 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
530 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
533 skb
= rx_buffer_info
->skb
;
534 prefetch(skb
->data
- NET_IP_ALIGN
);
535 rx_buffer_info
->skb
= NULL
;
537 if (rx_buffer_info
->dma
) {
538 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
541 rx_buffer_info
->dma
= 0;
546 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
,
547 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
548 rx_buffer_info
->page_dma
= 0;
549 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
550 rx_buffer_info
->page
,
551 rx_buffer_info
->page_offset
,
554 if ((rx_ring
->rx_buf_len
> (PAGE_SIZE
/ 2)) ||
555 (page_count(rx_buffer_info
->page
) != 1))
556 rx_buffer_info
->page
= NULL
;
558 get_page(rx_buffer_info
->page
);
560 skb
->len
+= upper_len
;
561 skb
->data_len
+= upper_len
;
562 skb
->truesize
+= upper_len
;
566 if (i
== rx_ring
->count
)
569 next_rxd
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
573 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
575 if (!(staterr
& IXGBE_RXD_STAT_EOP
)) {
576 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
577 rx_buffer_info
->skb
= next_buffer
->skb
;
578 rx_buffer_info
->dma
= next_buffer
->dma
;
579 next_buffer
->skb
= skb
;
580 next_buffer
->dma
= 0;
582 skb
->next
= next_buffer
->skb
;
583 skb
->next
->prev
= skb
;
585 adapter
->non_eop_descs
++;
589 /* ERR_MASK will only have valid bits if EOP set */
590 if (unlikely(staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
)) {
591 dev_kfree_skb_irq(skb
);
595 ixgbevf_rx_checksum(adapter
, staterr
, skb
);
597 /* probably a little skewed due to removing CRC */
598 total_rx_bytes
+= skb
->len
;
602 * Work around issue of some types of VM to VM loop back
603 * packets not getting split correctly
605 if (staterr
& IXGBE_RXD_STAT_LB
) {
606 u32 header_fixup_len
= skb
->len
- skb
->data_len
;
607 if (header_fixup_len
< 14)
608 skb_push(skb
, header_fixup_len
);
610 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
612 ixgbevf_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
613 adapter
->netdev
->last_rx
= jiffies
;
616 rx_desc
->wb
.upper
.status_error
= 0;
618 /* return some buffers to hardware, one at a time is too slow */
619 if (cleaned_count
>= IXGBEVF_RX_BUFFER_WRITE
) {
620 ixgbevf_alloc_rx_buffers(adapter
, rx_ring
,
625 /* use prefetched values */
627 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
629 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
632 rx_ring
->next_to_clean
= i
;
633 cleaned_count
= IXGBE_DESC_UNUSED(rx_ring
);
636 ixgbevf_alloc_rx_buffers(adapter
, rx_ring
, cleaned_count
);
638 rx_ring
->total_packets
+= total_rx_packets
;
639 rx_ring
->total_bytes
+= total_rx_bytes
;
640 adapter
->net_stats
.rx_bytes
+= total_rx_bytes
;
641 adapter
->net_stats
.rx_packets
+= total_rx_packets
;
647 * ixgbevf_clean_rxonly - msix (aka one shot) rx clean routine
648 * @napi: napi struct with our devices info in it
649 * @budget: amount of work driver is allowed to do this pass, in packets
651 * This function is optimized for cleaning one queue only on a single
654 static int ixgbevf_clean_rxonly(struct napi_struct
*napi
, int budget
)
656 struct ixgbevf_q_vector
*q_vector
=
657 container_of(napi
, struct ixgbevf_q_vector
, napi
);
658 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
659 struct ixgbevf_ring
*rx_ring
= NULL
;
663 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
664 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
666 ixgbevf_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
668 /* If all Rx work done, exit the polling mode */
669 if (work_done
< budget
) {
671 if (adapter
->itr_setting
& 1)
672 ixgbevf_set_itr_msix(q_vector
);
673 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
674 ixgbevf_irq_enable_queues(adapter
, rx_ring
->v_idx
);
681 * ixgbevf_clean_rxonly_many - msix (aka one shot) rx clean routine
682 * @napi: napi struct with our devices info in it
683 * @budget: amount of work driver is allowed to do this pass, in packets
685 * This function will clean more than one rx queue associated with a
688 static int ixgbevf_clean_rxonly_many(struct napi_struct
*napi
, int budget
)
690 struct ixgbevf_q_vector
*q_vector
=
691 container_of(napi
, struct ixgbevf_q_vector
, napi
);
692 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
693 struct ixgbevf_ring
*rx_ring
= NULL
;
694 int work_done
= 0, i
;
698 /* attempt to distribute budget to each queue fairly, but don't allow
699 * the budget to go below 1 because we'll exit polling */
700 budget
/= (q_vector
->rxr_count
?: 1);
701 budget
= max(budget
, 1);
702 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
703 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
704 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
705 ixgbevf_clean_rx_irq(q_vector
, rx_ring
, &work_done
, budget
);
706 enable_mask
|= rx_ring
->v_idx
;
707 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
711 #ifndef HAVE_NETDEV_NAPI_LIST
712 if (!netif_running(adapter
->netdev
))
716 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
717 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
719 /* If all Rx work done, exit the polling mode */
720 if (work_done
< budget
) {
722 if (adapter
->itr_setting
& 1)
723 ixgbevf_set_itr_msix(q_vector
);
724 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
725 ixgbevf_irq_enable_queues(adapter
, enable_mask
);
733 * ixgbevf_configure_msix - Configure MSI-X hardware
734 * @adapter: board private structure
736 * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X
739 static void ixgbevf_configure_msix(struct ixgbevf_adapter
*adapter
)
741 struct ixgbevf_q_vector
*q_vector
;
742 struct ixgbe_hw
*hw
= &adapter
->hw
;
743 int i
, j
, q_vectors
, v_idx
, r_idx
;
746 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
749 * Populate the IVAR table and set the ITR values to the
750 * corresponding register.
752 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
753 q_vector
= adapter
->q_vector
[v_idx
];
754 /* XXX for_each_bit(...) */
755 r_idx
= find_first_bit(q_vector
->rxr_idx
,
756 adapter
->num_rx_queues
);
758 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
759 j
= adapter
->rx_ring
[r_idx
].reg_idx
;
760 ixgbevf_set_ivar(adapter
, 0, j
, v_idx
);
761 r_idx
= find_next_bit(q_vector
->rxr_idx
,
762 adapter
->num_rx_queues
,
765 r_idx
= find_first_bit(q_vector
->txr_idx
,
766 adapter
->num_tx_queues
);
768 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
769 j
= adapter
->tx_ring
[r_idx
].reg_idx
;
770 ixgbevf_set_ivar(adapter
, 1, j
, v_idx
);
771 r_idx
= find_next_bit(q_vector
->txr_idx
,
772 adapter
->num_tx_queues
,
776 /* if this is a tx only vector halve the interrupt rate */
777 if (q_vector
->txr_count
&& !q_vector
->rxr_count
)
778 q_vector
->eitr
= (adapter
->eitr_param
>> 1);
779 else if (q_vector
->rxr_count
)
781 q_vector
->eitr
= adapter
->eitr_param
;
783 ixgbevf_write_eitr(adapter
, v_idx
, q_vector
->eitr
);
786 ixgbevf_set_ivar(adapter
, -1, 1, v_idx
);
788 /* set up to autoclear timer, and the vectors */
789 mask
= IXGBE_EIMS_ENABLE_MASK
;
790 mask
&= ~IXGBE_EIMS_OTHER
;
791 IXGBE_WRITE_REG(hw
, IXGBE_VTEIAC
, mask
);
798 latency_invalid
= 255
802 * ixgbevf_update_itr - update the dynamic ITR value based on statistics
803 * @adapter: pointer to adapter
804 * @eitr: eitr setting (ints per sec) to give last timeslice
805 * @itr_setting: current throttle rate in ints/second
806 * @packets: the number of packets during this measurement interval
807 * @bytes: the number of bytes during this measurement interval
809 * Stores a new ITR value based on packets and byte
810 * counts during the last interrupt. The advantage of per interrupt
811 * computation is faster updates and more accurate ITR for the current
812 * traffic pattern. Constants in this function were computed
813 * based on theoretical maximum wire speed and thresholds were set based
814 * on testing data as well as attempting to minimize response time
815 * while increasing bulk throughput.
817 static u8
ixgbevf_update_itr(struct ixgbevf_adapter
*adapter
,
818 u32 eitr
, u8 itr_setting
,
819 int packets
, int bytes
)
821 unsigned int retval
= itr_setting
;
826 goto update_itr_done
;
829 /* simple throttlerate management
830 * 0-20MB/s lowest (100000 ints/s)
831 * 20-100MB/s low (20000 ints/s)
832 * 100-1249MB/s bulk (8000 ints/s)
834 /* what was last interrupt timeslice? */
835 timepassed_us
= 1000000/eitr
;
836 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
838 switch (itr_setting
) {
840 if (bytes_perint
> adapter
->eitr_low
)
841 retval
= low_latency
;
844 if (bytes_perint
> adapter
->eitr_high
)
845 retval
= bulk_latency
;
846 else if (bytes_perint
<= adapter
->eitr_low
)
847 retval
= lowest_latency
;
850 if (bytes_perint
<= adapter
->eitr_high
)
851 retval
= low_latency
;
860 * ixgbevf_write_eitr - write VTEITR register in hardware specific way
861 * @adapter: pointer to adapter struct
862 * @v_idx: vector index into q_vector array
863 * @itr_reg: new value to be written in *register* format, not ints/s
865 * This function is made to be called by ethtool and by the driver
866 * when it needs to update VTEITR registers at runtime. Hardware
867 * specific quirks/differences are taken care of here.
869 static void ixgbevf_write_eitr(struct ixgbevf_adapter
*adapter
, int v_idx
,
872 struct ixgbe_hw
*hw
= &adapter
->hw
;
874 itr_reg
= EITR_INTS_PER_SEC_TO_REG(itr_reg
);
877 * set the WDIS bit to not clear the timer bits and cause an
878 * immediate assertion of the interrupt
880 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
882 IXGBE_WRITE_REG(hw
, IXGBE_VTEITR(v_idx
), itr_reg
);
885 static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector
*q_vector
)
887 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
889 u8 current_itr
, ret_itr
;
890 int i
, r_idx
, v_idx
= q_vector
->v_idx
;
891 struct ixgbevf_ring
*rx_ring
, *tx_ring
;
893 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
894 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
895 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
896 ret_itr
= ixgbevf_update_itr(adapter
, q_vector
->eitr
,
898 tx_ring
->total_packets
,
899 tx_ring
->total_bytes
);
900 /* if the result for this queue would decrease interrupt
901 * rate for this vector then use that result */
902 q_vector
->tx_itr
= ((q_vector
->tx_itr
> ret_itr
) ?
903 q_vector
->tx_itr
- 1 : ret_itr
);
904 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
908 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
909 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
910 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
911 ret_itr
= ixgbevf_update_itr(adapter
, q_vector
->eitr
,
913 rx_ring
->total_packets
,
914 rx_ring
->total_bytes
);
915 /* if the result for this queue would decrease interrupt
916 * rate for this vector then use that result */
917 q_vector
->rx_itr
= ((q_vector
->rx_itr
> ret_itr
) ?
918 q_vector
->rx_itr
- 1 : ret_itr
);
919 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
923 current_itr
= max(q_vector
->rx_itr
, q_vector
->tx_itr
);
925 switch (current_itr
) {
926 /* counts and packets in update_itr are dependent on these numbers */
931 new_itr
= 20000; /* aka hwitr = ~200 */
939 if (new_itr
!= q_vector
->eitr
) {
942 /* save the algorithm value here, not the smoothed one */
943 q_vector
->eitr
= new_itr
;
944 /* do an exponential smoothing */
945 new_itr
= ((q_vector
->eitr
* 90)/100) + ((new_itr
* 10)/100);
946 itr_reg
= EITR_INTS_PER_SEC_TO_REG(new_itr
);
947 ixgbevf_write_eitr(adapter
, v_idx
, itr_reg
);
953 static irqreturn_t
ixgbevf_msix_mbx(int irq
, void *data
)
955 struct net_device
*netdev
= data
;
956 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
957 struct ixgbe_hw
*hw
= &adapter
->hw
;
961 eicr
= IXGBE_READ_REG(hw
, IXGBE_VTEICS
);
962 IXGBE_WRITE_REG(hw
, IXGBE_VTEICR
, eicr
);
964 hw
->mbx
.ops
.read(hw
, &msg
, 1);
966 if ((msg
& IXGBE_MBVFICR_VFREQ_MASK
) == IXGBE_PF_CONTROL_MSG
)
967 mod_timer(&adapter
->watchdog_timer
,
968 round_jiffies(jiffies
+ 10));
973 static irqreturn_t
ixgbevf_msix_clean_tx(int irq
, void *data
)
975 struct ixgbevf_q_vector
*q_vector
= data
;
976 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
977 struct ixgbevf_ring
*tx_ring
;
980 if (!q_vector
->txr_count
)
983 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
984 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
985 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
986 tx_ring
->total_bytes
= 0;
987 tx_ring
->total_packets
= 0;
988 ixgbevf_clean_tx_irq(adapter
, tx_ring
);
989 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
993 if (adapter
->itr_setting
& 1)
994 ixgbevf_set_itr_msix(q_vector
);
1000 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1002 * @data: pointer to our q_vector struct for this interrupt vector
1004 static irqreturn_t
ixgbevf_msix_clean_rx(int irq
, void *data
)
1006 struct ixgbevf_q_vector
*q_vector
= data
;
1007 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
1008 struct ixgbe_hw
*hw
= &adapter
->hw
;
1009 struct ixgbevf_ring
*rx_ring
;
1013 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1014 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1015 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1016 rx_ring
->total_bytes
= 0;
1017 rx_ring
->total_packets
= 0;
1018 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1022 if (!q_vector
->rxr_count
)
1025 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1026 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1027 /* disable interrupts on this vector only */
1028 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, rx_ring
->v_idx
);
1029 napi_schedule(&q_vector
->napi
);
1035 static irqreturn_t
ixgbevf_msix_clean_many(int irq
, void *data
)
1037 ixgbevf_msix_clean_rx(irq
, data
);
1038 ixgbevf_msix_clean_tx(irq
, data
);
1043 static inline void map_vector_to_rxq(struct ixgbevf_adapter
*a
, int v_idx
,
1046 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1048 set_bit(r_idx
, q_vector
->rxr_idx
);
1049 q_vector
->rxr_count
++;
1050 a
->rx_ring
[r_idx
].v_idx
= 1 << v_idx
;
1053 static inline void map_vector_to_txq(struct ixgbevf_adapter
*a
, int v_idx
,
1056 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1058 set_bit(t_idx
, q_vector
->txr_idx
);
1059 q_vector
->txr_count
++;
1060 a
->tx_ring
[t_idx
].v_idx
= 1 << v_idx
;
1064 * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
1065 * @adapter: board private structure to initialize
1067 * This function maps descriptor rings to the queue-specific vectors
1068 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1069 * one vector per ring/queue, but on a constrained vector budget, we
1070 * group the rings as "efficiently" as possible. You would add new
1071 * mapping configurations in here.
1073 static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter
*adapter
)
1077 int rxr_idx
= 0, txr_idx
= 0;
1078 int rxr_remaining
= adapter
->num_rx_queues
;
1079 int txr_remaining
= adapter
->num_tx_queues
;
1084 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1087 * The ideal configuration...
1088 * We have enough vectors to map one per queue.
1090 if (q_vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
1091 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
1092 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
1094 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
1095 map_vector_to_txq(adapter
, v_start
, txr_idx
);
1100 * If we don't have enough vectors for a 1-to-1
1101 * mapping, we'll have to group them so there are
1102 * multiple queues per vector.
1104 /* Re-adjusting *qpv takes care of the remainder. */
1105 for (i
= v_start
; i
< q_vectors
; i
++) {
1106 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
1107 for (j
= 0; j
< rqpv
; j
++) {
1108 map_vector_to_rxq(adapter
, i
, rxr_idx
);
1113 for (i
= v_start
; i
< q_vectors
; i
++) {
1114 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
1115 for (j
= 0; j
< tqpv
; j
++) {
1116 map_vector_to_txq(adapter
, i
, txr_idx
);
1127 * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
1128 * @adapter: board private structure
1130 * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
1131 * interrupts from the kernel.
1133 static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter
*adapter
)
1135 struct net_device
*netdev
= adapter
->netdev
;
1136 irqreturn_t (*handler
)(int, void *);
1137 int i
, vector
, q_vectors
, err
;
1140 /* Decrement for Other and TCP Timer vectors */
1141 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1143 #define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
1144 ? &ixgbevf_msix_clean_many : \
1145 (_v)->rxr_count ? &ixgbevf_msix_clean_rx : \
1146 (_v)->txr_count ? &ixgbevf_msix_clean_tx : \
1148 for (vector
= 0; vector
< q_vectors
; vector
++) {
1149 handler
= SET_HANDLER(adapter
->q_vector
[vector
]);
1151 if (handler
== &ixgbevf_msix_clean_rx
) {
1152 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1153 netdev
->name
, "rx", ri
++);
1154 } else if (handler
== &ixgbevf_msix_clean_tx
) {
1155 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1156 netdev
->name
, "tx", ti
++);
1157 } else if (handler
== &ixgbevf_msix_clean_many
) {
1158 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1159 netdev
->name
, "TxRx", vector
);
1161 /* skip this unused q_vector */
1164 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1165 handler
, 0, adapter
->name
[vector
],
1166 adapter
->q_vector
[vector
]);
1168 hw_dbg(&adapter
->hw
,
1169 "request_irq failed for MSIX interrupt "
1170 "Error: %d\n", err
);
1171 goto free_queue_irqs
;
1175 sprintf(adapter
->name
[vector
], "%s:mbx", netdev
->name
);
1176 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1177 &ixgbevf_msix_mbx
, 0, adapter
->name
[vector
], netdev
);
1179 hw_dbg(&adapter
->hw
,
1180 "request_irq for msix_mbx failed: %d\n", err
);
1181 goto free_queue_irqs
;
1187 for (i
= vector
- 1; i
>= 0; i
--)
1188 free_irq(adapter
->msix_entries
[--vector
].vector
,
1189 &(adapter
->q_vector
[i
]));
1190 pci_disable_msix(adapter
->pdev
);
1191 kfree(adapter
->msix_entries
);
1192 adapter
->msix_entries
= NULL
;
1196 static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter
*adapter
)
1198 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1200 for (i
= 0; i
< q_vectors
; i
++) {
1201 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[i
];
1202 bitmap_zero(q_vector
->rxr_idx
, MAX_RX_QUEUES
);
1203 bitmap_zero(q_vector
->txr_idx
, MAX_TX_QUEUES
);
1204 q_vector
->rxr_count
= 0;
1205 q_vector
->txr_count
= 0;
1206 q_vector
->eitr
= adapter
->eitr_param
;
1211 * ixgbevf_request_irq - initialize interrupts
1212 * @adapter: board private structure
1214 * Attempts to configure interrupts using the best available
1215 * capabilities of the hardware and kernel.
1217 static int ixgbevf_request_irq(struct ixgbevf_adapter
*adapter
)
1221 err
= ixgbevf_request_msix_irqs(adapter
);
1224 hw_dbg(&adapter
->hw
,
1225 "request_irq failed, Error %d\n", err
);
1230 static void ixgbevf_free_irq(struct ixgbevf_adapter
*adapter
)
1232 struct net_device
*netdev
= adapter
->netdev
;
1235 q_vectors
= adapter
->num_msix_vectors
;
1239 free_irq(adapter
->msix_entries
[i
].vector
, netdev
);
1242 for (; i
>= 0; i
--) {
1243 free_irq(adapter
->msix_entries
[i
].vector
,
1244 adapter
->q_vector
[i
]);
1247 ixgbevf_reset_q_vectors(adapter
);
1251 * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
1252 * @adapter: board private structure
1254 static inline void ixgbevf_irq_disable(struct ixgbevf_adapter
*adapter
)
1257 struct ixgbe_hw
*hw
= &adapter
->hw
;
1259 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, ~0);
1261 IXGBE_WRITE_FLUSH(hw
);
1263 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
1264 synchronize_irq(adapter
->msix_entries
[i
].vector
);
1268 * ixgbevf_irq_enable - Enable default interrupt generation settings
1269 * @adapter: board private structure
1271 static inline void ixgbevf_irq_enable(struct ixgbevf_adapter
*adapter
,
1272 bool queues
, bool flush
)
1274 struct ixgbe_hw
*hw
= &adapter
->hw
;
1278 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
1281 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, mask
);
1284 ixgbevf_irq_enable_queues(adapter
, qmask
);
1287 IXGBE_WRITE_FLUSH(hw
);
1291 * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
1292 * @adapter: board private structure
1294 * Configure the Tx unit of the MAC after a reset.
1296 static void ixgbevf_configure_tx(struct ixgbevf_adapter
*adapter
)
1299 struct ixgbe_hw
*hw
= &adapter
->hw
;
1300 u32 i
, j
, tdlen
, txctrl
;
1302 /* Setup the HW Tx Head and Tail descriptor pointers */
1303 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1304 struct ixgbevf_ring
*ring
= &adapter
->tx_ring
[i
];
1307 tdlen
= ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
1308 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAL(j
),
1309 (tdba
& DMA_BIT_MASK(32)));
1310 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAH(j
), (tdba
>> 32));
1311 IXGBE_WRITE_REG(hw
, IXGBE_VFTDLEN(j
), tdlen
);
1312 IXGBE_WRITE_REG(hw
, IXGBE_VFTDH(j
), 0);
1313 IXGBE_WRITE_REG(hw
, IXGBE_VFTDT(j
), 0);
1314 adapter
->tx_ring
[i
].head
= IXGBE_VFTDH(j
);
1315 adapter
->tx_ring
[i
].tail
= IXGBE_VFTDT(j
);
1316 /* Disable Tx Head Writeback RO bit, since this hoses
1317 * bookkeeping if things aren't delivered in order.
1319 txctrl
= IXGBE_READ_REG(hw
, IXGBE_VFDCA_TXCTRL(j
));
1320 txctrl
&= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN
;
1321 IXGBE_WRITE_REG(hw
, IXGBE_VFDCA_TXCTRL(j
), txctrl
);
1325 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1327 static void ixgbevf_configure_srrctl(struct ixgbevf_adapter
*adapter
, int index
)
1329 struct ixgbevf_ring
*rx_ring
;
1330 struct ixgbe_hw
*hw
= &adapter
->hw
;
1333 rx_ring
= &adapter
->rx_ring
[index
];
1335 srrctl
= IXGBE_SRRCTL_DROP_EN
;
1337 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1338 u16 bufsz
= IXGBEVF_RXBUFFER_2048
;
1339 /* grow the amount we can receive on large page machines */
1340 if (bufsz
< (PAGE_SIZE
/ 2))
1341 bufsz
= (PAGE_SIZE
/ 2);
1342 /* cap the bufsz at our largest descriptor size */
1343 bufsz
= min((u16
)IXGBEVF_MAX_RXBUFFER
, bufsz
);
1345 srrctl
|= bufsz
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1346 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
1347 srrctl
|= ((IXGBEVF_RX_HDR_SIZE
<<
1348 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
1349 IXGBE_SRRCTL_BSIZEHDR_MASK
);
1351 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1353 if (rx_ring
->rx_buf_len
== MAXIMUM_ETHERNET_VLAN_SIZE
)
1354 srrctl
|= IXGBEVF_RXBUFFER_2048
>>
1355 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1357 srrctl
|= rx_ring
->rx_buf_len
>>
1358 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1360 IXGBE_WRITE_REG(hw
, IXGBE_VFSRRCTL(index
), srrctl
);
1364 * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
1365 * @adapter: board private structure
1367 * Configure the Rx unit of the MAC after a reset.
1369 static void ixgbevf_configure_rx(struct ixgbevf_adapter
*adapter
)
1372 struct ixgbe_hw
*hw
= &adapter
->hw
;
1373 struct net_device
*netdev
= adapter
->netdev
;
1374 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1379 /* Decide whether to use packet split mode or not */
1380 if (netdev
->mtu
> ETH_DATA_LEN
) {
1381 if (adapter
->flags
& IXGBE_FLAG_RX_PS_CAPABLE
)
1382 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
1384 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
1386 if (adapter
->flags
& IXGBE_FLAG_RX_1BUF_CAPABLE
)
1387 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
1389 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
1392 /* Set the RX buffer length according to the mode */
1393 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1394 /* PSRTYPE must be initialized in 82599 */
1395 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
1396 IXGBE_PSRTYPE_UDPHDR
|
1397 IXGBE_PSRTYPE_IPV4HDR
|
1398 IXGBE_PSRTYPE_IPV6HDR
|
1399 IXGBE_PSRTYPE_L2HDR
;
1400 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, psrtype
);
1401 rx_buf_len
= IXGBEVF_RX_HDR_SIZE
;
1403 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, 0);
1404 if (netdev
->mtu
<= ETH_DATA_LEN
)
1405 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1407 rx_buf_len
= ALIGN(max_frame
, 1024);
1410 rdlen
= adapter
->rx_ring
[0].count
* sizeof(union ixgbe_adv_rx_desc
);
1411 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1412 * the Base and Length of the Rx Descriptor Ring */
1413 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1414 rdba
= adapter
->rx_ring
[i
].dma
;
1415 j
= adapter
->rx_ring
[i
].reg_idx
;
1416 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAL(j
),
1417 (rdba
& DMA_BIT_MASK(32)));
1418 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAH(j
), (rdba
>> 32));
1419 IXGBE_WRITE_REG(hw
, IXGBE_VFRDLEN(j
), rdlen
);
1420 IXGBE_WRITE_REG(hw
, IXGBE_VFRDH(j
), 0);
1421 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(j
), 0);
1422 adapter
->rx_ring
[i
].head
= IXGBE_VFRDH(j
);
1423 adapter
->rx_ring
[i
].tail
= IXGBE_VFRDT(j
);
1424 adapter
->rx_ring
[i
].rx_buf_len
= rx_buf_len
;
1426 ixgbevf_configure_srrctl(adapter
, j
);
1430 static void ixgbevf_vlan_rx_register(struct net_device
*netdev
,
1431 struct vlan_group
*grp
)
1433 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1434 struct ixgbe_hw
*hw
= &adapter
->hw
;
1438 adapter
->vlgrp
= grp
;
1440 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1441 j
= adapter
->rx_ring
[i
].reg_idx
;
1442 ctrl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1443 ctrl
|= IXGBE_RXDCTL_VME
;
1444 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), ctrl
);
1448 static void ixgbevf_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
1450 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1451 struct ixgbe_hw
*hw
= &adapter
->hw
;
1452 struct net_device
*v_netdev
;
1454 /* add VID to filter table */
1455 if (hw
->mac
.ops
.set_vfta
)
1456 hw
->mac
.ops
.set_vfta(hw
, vid
, 0, true);
1458 * Copy feature flags from netdev to the vlan netdev for this vid.
1459 * This allows things like TSO to bubble down to our vlan device.
1461 v_netdev
= vlan_group_get_device(adapter
->vlgrp
, vid
);
1462 v_netdev
->features
|= adapter
->netdev
->features
;
1463 vlan_group_set_device(adapter
->vlgrp
, vid
, v_netdev
);
1466 static void ixgbevf_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
1468 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1469 struct ixgbe_hw
*hw
= &adapter
->hw
;
1471 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
1472 ixgbevf_irq_disable(adapter
);
1474 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
1476 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
1477 ixgbevf_irq_enable(adapter
, true, true);
1479 /* remove VID from filter table */
1480 if (hw
->mac
.ops
.set_vfta
)
1481 hw
->mac
.ops
.set_vfta(hw
, vid
, 0, false);
1484 static void ixgbevf_restore_vlan(struct ixgbevf_adapter
*adapter
)
1486 ixgbevf_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
1488 if (adapter
->vlgrp
) {
1490 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
1491 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
1493 ixgbevf_vlan_rx_add_vid(adapter
->netdev
, vid
);
1498 static u8
*ixgbevf_addr_list_itr(struct ixgbe_hw
*hw
, u8
**mc_addr_ptr
,
1501 struct dev_mc_list
*mc_ptr
;
1502 u8
*addr
= *mc_addr_ptr
;
1505 mc_ptr
= container_of(addr
, struct dev_mc_list
, dmi_addr
[0]);
1507 *mc_addr_ptr
= mc_ptr
->next
->dmi_addr
;
1509 *mc_addr_ptr
= NULL
;
1515 * ixgbevf_set_rx_mode - Multicast set
1516 * @netdev: network interface device structure
1518 * The set_rx_method entry point is called whenever the multicast address
1519 * list or the network interface flags are updated. This routine is
1520 * responsible for configuring the hardware for proper multicast mode.
1522 static void ixgbevf_set_rx_mode(struct net_device
*netdev
)
1524 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1525 struct ixgbe_hw
*hw
= &adapter
->hw
;
1526 u8
*addr_list
= NULL
;
1529 /* reprogram multicast list */
1530 addr_count
= netdev
->mc_count
;
1532 addr_list
= netdev
->mc_list
->dmi_addr
;
1533 if (hw
->mac
.ops
.update_mc_addr_list
)
1534 hw
->mac
.ops
.update_mc_addr_list(hw
, addr_list
, addr_count
,
1535 ixgbevf_addr_list_itr
);
1538 static void ixgbevf_napi_enable_all(struct ixgbevf_adapter
*adapter
)
1541 struct ixgbevf_q_vector
*q_vector
;
1542 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1544 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1545 struct napi_struct
*napi
;
1546 q_vector
= adapter
->q_vector
[q_idx
];
1547 if (!q_vector
->rxr_count
)
1549 napi
= &q_vector
->napi
;
1550 if (q_vector
->rxr_count
> 1)
1551 napi
->poll
= &ixgbevf_clean_rxonly_many
;
1557 static void ixgbevf_napi_disable_all(struct ixgbevf_adapter
*adapter
)
1560 struct ixgbevf_q_vector
*q_vector
;
1561 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1563 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1564 q_vector
= adapter
->q_vector
[q_idx
];
1565 if (!q_vector
->rxr_count
)
1567 napi_disable(&q_vector
->napi
);
1571 static void ixgbevf_configure(struct ixgbevf_adapter
*adapter
)
1573 struct net_device
*netdev
= adapter
->netdev
;
1576 ixgbevf_set_rx_mode(netdev
);
1578 ixgbevf_restore_vlan(adapter
);
1580 ixgbevf_configure_tx(adapter
);
1581 ixgbevf_configure_rx(adapter
);
1582 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1583 struct ixgbevf_ring
*ring
= &adapter
->rx_ring
[i
];
1584 ixgbevf_alloc_rx_buffers(adapter
, ring
, ring
->count
);
1585 ring
->next_to_use
= ring
->count
- 1;
1586 writel(ring
->next_to_use
, adapter
->hw
.hw_addr
+ ring
->tail
);
1590 #define IXGBE_MAX_RX_DESC_POLL 10
1591 static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter
*adapter
,
1594 struct ixgbe_hw
*hw
= &adapter
->hw
;
1595 int j
= adapter
->rx_ring
[rxr
].reg_idx
;
1598 for (k
= 0; k
< IXGBE_MAX_RX_DESC_POLL
; k
++) {
1599 if (IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
)) & IXGBE_RXDCTL_ENABLE
)
1604 if (k
>= IXGBE_MAX_RX_DESC_POLL
) {
1605 hw_dbg(hw
, "RXDCTL.ENABLE on Rx queue %d "
1606 "not set within the polling period\n", rxr
);
1609 ixgbevf_release_rx_desc(&adapter
->hw
, &adapter
->rx_ring
[rxr
],
1610 (adapter
->rx_ring
[rxr
].count
- 1));
1613 static int ixgbevf_up_complete(struct ixgbevf_adapter
*adapter
)
1615 struct net_device
*netdev
= adapter
->netdev
;
1616 struct ixgbe_hw
*hw
= &adapter
->hw
;
1618 int num_rx_rings
= adapter
->num_rx_queues
;
1621 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1622 j
= adapter
->tx_ring
[i
].reg_idx
;
1623 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1624 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
1625 txdctl
|= (8 << 16);
1626 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1629 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1630 j
= adapter
->tx_ring
[i
].reg_idx
;
1631 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1632 txdctl
|= IXGBE_TXDCTL_ENABLE
;
1633 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1636 for (i
= 0; i
< num_rx_rings
; i
++) {
1637 j
= adapter
->rx_ring
[i
].reg_idx
;
1638 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1639 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
1640 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), rxdctl
);
1641 ixgbevf_rx_desc_queue_enable(adapter
, i
);
1644 ixgbevf_configure_msix(adapter
);
1646 if (hw
->mac
.ops
.set_rar
) {
1647 if (is_valid_ether_addr(hw
->mac
.addr
))
1648 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
1650 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.perm_addr
, 0);
1653 clear_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1654 ixgbevf_napi_enable_all(adapter
);
1656 /* enable transmits */
1657 netif_tx_start_all_queues(netdev
);
1659 /* bring the link up in the watchdog, this could race with our first
1660 * link up interrupt but shouldn't be a problem */
1661 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1662 adapter
->link_check_timeout
= jiffies
;
1663 mod_timer(&adapter
->watchdog_timer
, jiffies
);
1667 int ixgbevf_up(struct ixgbevf_adapter
*adapter
)
1670 struct ixgbe_hw
*hw
= &adapter
->hw
;
1672 ixgbevf_configure(adapter
);
1674 err
= ixgbevf_up_complete(adapter
);
1676 /* clear any pending interrupts, may auto mask */
1677 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
1679 ixgbevf_irq_enable(adapter
, true, true);
1685 * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
1686 * @adapter: board private structure
1687 * @rx_ring: ring to free buffers from
1689 static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter
*adapter
,
1690 struct ixgbevf_ring
*rx_ring
)
1692 struct pci_dev
*pdev
= adapter
->pdev
;
1696 if (!rx_ring
->rx_buffer_info
)
1699 /* Free all the Rx ring sk_buffs */
1700 for (i
= 0; i
< rx_ring
->count
; i
++) {
1701 struct ixgbevf_rx_buffer
*rx_buffer_info
;
1703 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1704 if (rx_buffer_info
->dma
) {
1705 pci_unmap_single(pdev
, rx_buffer_info
->dma
,
1706 rx_ring
->rx_buf_len
,
1707 PCI_DMA_FROMDEVICE
);
1708 rx_buffer_info
->dma
= 0;
1710 if (rx_buffer_info
->skb
) {
1711 struct sk_buff
*skb
= rx_buffer_info
->skb
;
1712 rx_buffer_info
->skb
= NULL
;
1714 struct sk_buff
*this = skb
;
1716 dev_kfree_skb(this);
1719 if (!rx_buffer_info
->page
)
1721 pci_unmap_page(pdev
, rx_buffer_info
->page_dma
, PAGE_SIZE
/ 2,
1722 PCI_DMA_FROMDEVICE
);
1723 rx_buffer_info
->page_dma
= 0;
1724 put_page(rx_buffer_info
->page
);
1725 rx_buffer_info
->page
= NULL
;
1726 rx_buffer_info
->page_offset
= 0;
1729 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
1730 memset(rx_ring
->rx_buffer_info
, 0, size
);
1732 /* Zero out the descriptor ring */
1733 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1735 rx_ring
->next_to_clean
= 0;
1736 rx_ring
->next_to_use
= 0;
1739 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1741 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1745 * ixgbevf_clean_tx_ring - Free Tx Buffers
1746 * @adapter: board private structure
1747 * @tx_ring: ring to be cleaned
1749 static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter
*adapter
,
1750 struct ixgbevf_ring
*tx_ring
)
1752 struct ixgbevf_tx_buffer
*tx_buffer_info
;
1756 if (!tx_ring
->tx_buffer_info
)
1759 /* Free all the Tx ring sk_buffs */
1761 for (i
= 0; i
< tx_ring
->count
; i
++) {
1762 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
1763 ixgbevf_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
1766 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
1767 memset(tx_ring
->tx_buffer_info
, 0, size
);
1769 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1771 tx_ring
->next_to_use
= 0;
1772 tx_ring
->next_to_clean
= 0;
1775 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1777 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1781 * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
1782 * @adapter: board private structure
1784 static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter
*adapter
)
1788 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1789 ixgbevf_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
1793 * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
1794 * @adapter: board private structure
1796 static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter
*adapter
)
1800 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1801 ixgbevf_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1804 void ixgbevf_down(struct ixgbevf_adapter
*adapter
)
1806 struct net_device
*netdev
= adapter
->netdev
;
1807 struct ixgbe_hw
*hw
= &adapter
->hw
;
1811 /* signal that we are down to the interrupt handler */
1812 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1813 /* disable receives */
1815 netif_tx_disable(netdev
);
1819 netif_tx_stop_all_queues(netdev
);
1821 ixgbevf_irq_disable(adapter
);
1823 ixgbevf_napi_disable_all(adapter
);
1825 del_timer_sync(&adapter
->watchdog_timer
);
1826 /* can't call flush scheduled work here because it can deadlock
1827 * if linkwatch_event tries to acquire the rtnl_lock which we are
1829 while (adapter
->flags
& IXGBE_FLAG_IN_WATCHDOG_TASK
)
1832 /* disable transmits in the hardware now that interrupts are off */
1833 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1834 j
= adapter
->tx_ring
[i
].reg_idx
;
1835 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1836 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
),
1837 (txdctl
& ~IXGBE_TXDCTL_ENABLE
));
1840 netif_carrier_off(netdev
);
1842 if (!pci_channel_offline(adapter
->pdev
))
1843 ixgbevf_reset(adapter
);
1845 ixgbevf_clean_all_tx_rings(adapter
);
1846 ixgbevf_clean_all_rx_rings(adapter
);
1849 void ixgbevf_reinit_locked(struct ixgbevf_adapter
*adapter
)
1851 struct ixgbe_hw
*hw
= &adapter
->hw
;
1853 WARN_ON(in_interrupt());
1855 while (test_and_set_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
1859 * Check if PF is up before re-init. If not then skip until
1860 * later when the PF is up and ready to service requests from
1861 * the VF via mailbox. If the VF is up and running then the
1862 * watchdog task will continue to schedule reset tasks until
1863 * the PF is up and running.
1865 if (!hw
->mac
.ops
.reset_hw(hw
)) {
1866 ixgbevf_down(adapter
);
1867 ixgbevf_up(adapter
);
1870 clear_bit(__IXGBEVF_RESETTING
, &adapter
->state
);
1873 void ixgbevf_reset(struct ixgbevf_adapter
*adapter
)
1875 struct ixgbe_hw
*hw
= &adapter
->hw
;
1876 struct net_device
*netdev
= adapter
->netdev
;
1878 if (hw
->mac
.ops
.reset_hw(hw
))
1879 hw_dbg(hw
, "PF still resetting\n");
1881 hw
->mac
.ops
.init_hw(hw
);
1883 if (is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
1884 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
,
1886 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
,
1891 static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter
*adapter
,
1894 int err
, vector_threshold
;
1896 /* We'll want at least 3 (vector_threshold):
1899 * 3) Other (Link Status Change, etc.)
1901 vector_threshold
= MIN_MSIX_COUNT
;
1903 /* The more we get, the more we will assign to Tx/Rx Cleanup
1904 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1905 * Right now, we simply care about how many we'll get; we'll
1906 * set them up later while requesting irq's.
1908 while (vectors
>= vector_threshold
) {
1909 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1911 if (!err
) /* Success in acquiring all requested vectors. */
1914 vectors
= 0; /* Nasty failure, quit now */
1915 else /* err == number of vectors we should try again with */
1919 if (vectors
< vector_threshold
) {
1920 /* Can't allocate enough MSI-X interrupts? Oh well.
1921 * This just means we'll go with either a single MSI
1922 * vector or fall back to legacy interrupts.
1924 hw_dbg(&adapter
->hw
,
1925 "Unable to allocate MSI-X interrupts\n");
1926 kfree(adapter
->msix_entries
);
1927 adapter
->msix_entries
= NULL
;
1930 * Adjust for only the vectors we'll use, which is minimum
1931 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
1932 * vectors we were allocated.
1934 adapter
->num_msix_vectors
= vectors
;
1939 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
1940 * @adapter: board private structure to initialize
1942 * This is the top level queue allocation routine. The order here is very
1943 * important, starting with the "most" number of features turned on at once,
1944 * and ending with the smallest set of features. This way large combinations
1945 * can be allocated if they're turned on, and smaller combinations are the
1946 * fallthrough conditions.
1949 static void ixgbevf_set_num_queues(struct ixgbevf_adapter
*adapter
)
1951 /* Start with base case */
1952 adapter
->num_rx_queues
= 1;
1953 adapter
->num_tx_queues
= 1;
1954 adapter
->num_rx_pools
= adapter
->num_rx_queues
;
1955 adapter
->num_rx_queues_per_pool
= 1;
1959 * ixgbevf_alloc_queues - Allocate memory for all rings
1960 * @adapter: board private structure to initialize
1962 * We allocate one ring per queue at run-time since we don't know the
1963 * number of queues at compile-time. The polling_netdev array is
1964 * intended for Multiqueue, but should work fine with a single queue.
1966 static int ixgbevf_alloc_queues(struct ixgbevf_adapter
*adapter
)
1970 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
1971 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
1972 if (!adapter
->tx_ring
)
1973 goto err_tx_ring_allocation
;
1975 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
1976 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
1977 if (!adapter
->rx_ring
)
1978 goto err_rx_ring_allocation
;
1980 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1981 adapter
->tx_ring
[i
].count
= adapter
->tx_ring_count
;
1982 adapter
->tx_ring
[i
].queue_index
= i
;
1983 adapter
->tx_ring
[i
].reg_idx
= i
;
1986 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1987 adapter
->rx_ring
[i
].count
= adapter
->rx_ring_count
;
1988 adapter
->rx_ring
[i
].queue_index
= i
;
1989 adapter
->rx_ring
[i
].reg_idx
= i
;
1994 err_rx_ring_allocation
:
1995 kfree(adapter
->tx_ring
);
1996 err_tx_ring_allocation
:
2001 * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
2002 * @adapter: board private structure to initialize
2004 * Attempt to configure the interrupts using the best available
2005 * capabilities of the hardware and the kernel.
2007 static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter
*adapter
)
2010 int vector
, v_budget
;
2013 * It's easy to be greedy for MSI-X vectors, but it really
2014 * doesn't do us much good if we have a lot more vectors
2015 * than CPU's. So let's be conservative and only ask for
2016 * (roughly) twice the number of vectors as there are CPU's.
2018 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
2019 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS
;
2021 /* A failure in MSI-X entry allocation isn't fatal, but it does
2022 * mean we disable MSI-X capabilities of the adapter. */
2023 adapter
->msix_entries
= kcalloc(v_budget
,
2024 sizeof(struct msix_entry
), GFP_KERNEL
);
2025 if (!adapter
->msix_entries
) {
2030 for (vector
= 0; vector
< v_budget
; vector
++)
2031 adapter
->msix_entries
[vector
].entry
= vector
;
2033 ixgbevf_acquire_msix_vectors(adapter
, v_budget
);
2040 * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
2041 * @adapter: board private structure to initialize
2043 * We allocate one q_vector per queue interrupt. If allocation fails we
2046 static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter
*adapter
)
2048 int q_idx
, num_q_vectors
;
2049 struct ixgbevf_q_vector
*q_vector
;
2051 int (*poll
)(struct napi_struct
*, int);
2053 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2054 napi_vectors
= adapter
->num_rx_queues
;
2055 poll
= &ixgbevf_clean_rxonly
;
2057 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
2058 q_vector
= kzalloc(sizeof(struct ixgbevf_q_vector
), GFP_KERNEL
);
2061 q_vector
->adapter
= adapter
;
2062 q_vector
->v_idx
= q_idx
;
2063 q_vector
->eitr
= adapter
->eitr_param
;
2064 if (q_idx
< napi_vectors
)
2065 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
2067 adapter
->q_vector
[q_idx
] = q_vector
;
2075 q_vector
= adapter
->q_vector
[q_idx
];
2076 netif_napi_del(&q_vector
->napi
);
2078 adapter
->q_vector
[q_idx
] = NULL
;
2084 * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
2085 * @adapter: board private structure to initialize
2087 * This function frees the memory allocated to the q_vectors. In addition if
2088 * NAPI is enabled it will delete any references to the NAPI struct prior
2089 * to freeing the q_vector.
2091 static void ixgbevf_free_q_vectors(struct ixgbevf_adapter
*adapter
)
2093 int q_idx
, num_q_vectors
;
2096 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2097 napi_vectors
= adapter
->num_rx_queues
;
2099 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
2100 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
2102 adapter
->q_vector
[q_idx
] = NULL
;
2103 if (q_idx
< napi_vectors
)
2104 netif_napi_del(&q_vector
->napi
);
2110 * ixgbevf_reset_interrupt_capability - Reset MSIX setup
2111 * @adapter: board private structure
2114 static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter
*adapter
)
2116 pci_disable_msix(adapter
->pdev
);
2117 kfree(adapter
->msix_entries
);
2118 adapter
->msix_entries
= NULL
;
2124 * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
2125 * @adapter: board private structure to initialize
2128 static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter
*adapter
)
2132 /* Number of supported queues */
2133 ixgbevf_set_num_queues(adapter
);
2135 err
= ixgbevf_set_interrupt_capability(adapter
);
2137 hw_dbg(&adapter
->hw
,
2138 "Unable to setup interrupt capabilities\n");
2139 goto err_set_interrupt
;
2142 err
= ixgbevf_alloc_q_vectors(adapter
);
2144 hw_dbg(&adapter
->hw
, "Unable to allocate memory for queue "
2146 goto err_alloc_q_vectors
;
2149 err
= ixgbevf_alloc_queues(adapter
);
2151 printk(KERN_ERR
"Unable to allocate memory for queues\n");
2152 goto err_alloc_queues
;
2155 hw_dbg(&adapter
->hw
, "Multiqueue %s: Rx Queue count = %u, "
2156 "Tx Queue count = %u\n",
2157 (adapter
->num_rx_queues
> 1) ? "Enabled" :
2158 "Disabled", adapter
->num_rx_queues
, adapter
->num_tx_queues
);
2160 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2164 ixgbevf_free_q_vectors(adapter
);
2165 err_alloc_q_vectors
:
2166 ixgbevf_reset_interrupt_capability(adapter
);
2172 * ixgbevf_sw_init - Initialize general software structures
2173 * (struct ixgbevf_adapter)
2174 * @adapter: board private structure to initialize
2176 * ixgbevf_sw_init initializes the Adapter private data structure.
2177 * Fields are initialized based on PCI device information and
2178 * OS network device settings (MTU size).
2180 static int __devinit
ixgbevf_sw_init(struct ixgbevf_adapter
*adapter
)
2182 struct ixgbe_hw
*hw
= &adapter
->hw
;
2183 struct pci_dev
*pdev
= adapter
->pdev
;
2186 /* PCI config space info */
2188 hw
->vendor_id
= pdev
->vendor
;
2189 hw
->device_id
= pdev
->device
;
2190 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2191 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2192 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2194 hw
->mbx
.ops
.init_params(hw
);
2195 hw
->mac
.max_tx_queues
= MAX_TX_QUEUES
;
2196 hw
->mac
.max_rx_queues
= MAX_RX_QUEUES
;
2197 err
= hw
->mac
.ops
.reset_hw(hw
);
2199 dev_info(&pdev
->dev
,
2200 "PF still in reset state, assigning new address\n");
2201 random_ether_addr(hw
->mac
.addr
);
2203 err
= hw
->mac
.ops
.init_hw(hw
);
2205 printk(KERN_ERR
"init_shared_code failed: %d\n", err
);
2210 /* Enable dynamic interrupt throttling rates */
2211 adapter
->eitr_param
= 20000;
2212 adapter
->itr_setting
= 1;
2214 /* set defaults for eitr in MegaBytes */
2215 adapter
->eitr_low
= 10;
2216 adapter
->eitr_high
= 20;
2218 /* set default ring sizes */
2219 adapter
->tx_ring_count
= IXGBEVF_DEFAULT_TXD
;
2220 adapter
->rx_ring_count
= IXGBEVF_DEFAULT_RXD
;
2222 /* enable rx csum by default */
2223 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
2225 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2231 static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter
*adapter
)
2233 struct ixgbe_hw
*hw
= &adapter
->hw
;
2235 adapter
->stats
.last_vfgprc
= IXGBE_READ_REG(hw
, IXGBE_VFGPRC
);
2236 adapter
->stats
.last_vfgorc
= IXGBE_READ_REG(hw
, IXGBE_VFGORC_LSB
);
2237 adapter
->stats
.last_vfgorc
|=
2238 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGORC_MSB
))) << 32);
2239 adapter
->stats
.last_vfgptc
= IXGBE_READ_REG(hw
, IXGBE_VFGPTC
);
2240 adapter
->stats
.last_vfgotc
= IXGBE_READ_REG(hw
, IXGBE_VFGOTC_LSB
);
2241 adapter
->stats
.last_vfgotc
|=
2242 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGOTC_MSB
))) << 32);
2243 adapter
->stats
.last_vfmprc
= IXGBE_READ_REG(hw
, IXGBE_VFMPRC
);
2245 adapter
->stats
.base_vfgprc
= adapter
->stats
.last_vfgprc
;
2246 adapter
->stats
.base_vfgorc
= adapter
->stats
.last_vfgorc
;
2247 adapter
->stats
.base_vfgptc
= adapter
->stats
.last_vfgptc
;
2248 adapter
->stats
.base_vfgotc
= adapter
->stats
.last_vfgotc
;
2249 adapter
->stats
.base_vfmprc
= adapter
->stats
.last_vfmprc
;
2252 #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
2254 u32 current_counter = IXGBE_READ_REG(hw, reg); \
2255 if (current_counter < last_counter) \
2256 counter += 0x100000000LL; \
2257 last_counter = current_counter; \
2258 counter &= 0xFFFFFFFF00000000LL; \
2259 counter |= current_counter; \
2262 #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
2264 u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
2265 u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
2266 u64 current_counter = (current_counter_msb << 32) | \
2267 current_counter_lsb; \
2268 if (current_counter < last_counter) \
2269 counter += 0x1000000000LL; \
2270 last_counter = current_counter; \
2271 counter &= 0xFFFFFFF000000000LL; \
2272 counter |= current_counter; \
2275 * ixgbevf_update_stats - Update the board statistics counters.
2276 * @adapter: board private structure
2278 void ixgbevf_update_stats(struct ixgbevf_adapter
*adapter
)
2280 struct ixgbe_hw
*hw
= &adapter
->hw
;
2282 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC
, adapter
->stats
.last_vfgprc
,
2283 adapter
->stats
.vfgprc
);
2284 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC
, adapter
->stats
.last_vfgptc
,
2285 adapter
->stats
.vfgptc
);
2286 UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB
, IXGBE_VFGORC_MSB
,
2287 adapter
->stats
.last_vfgorc
,
2288 adapter
->stats
.vfgorc
);
2289 UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB
, IXGBE_VFGOTC_MSB
,
2290 adapter
->stats
.last_vfgotc
,
2291 adapter
->stats
.vfgotc
);
2292 UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC
, adapter
->stats
.last_vfmprc
,
2293 adapter
->stats
.vfmprc
);
2295 /* Fill out the OS statistics structure */
2296 adapter
->net_stats
.multicast
= adapter
->stats
.vfmprc
-
2297 adapter
->stats
.base_vfmprc
;
2301 * ixgbevf_watchdog - Timer Call-back
2302 * @data: pointer to adapter cast into an unsigned long
2304 static void ixgbevf_watchdog(unsigned long data
)
2306 struct ixgbevf_adapter
*adapter
= (struct ixgbevf_adapter
*)data
;
2307 struct ixgbe_hw
*hw
= &adapter
->hw
;
2312 * Do the watchdog outside of interrupt context due to the lovely
2313 * delays that some of the newer hardware requires
2316 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2317 goto watchdog_short_circuit
;
2319 /* get one bit for every active tx/rx interrupt vector */
2320 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
2321 struct ixgbevf_q_vector
*qv
= adapter
->q_vector
[i
];
2322 if (qv
->rxr_count
|| qv
->txr_count
)
2326 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, (u32
)eics
);
2328 watchdog_short_circuit
:
2329 schedule_work(&adapter
->watchdog_task
);
2333 * ixgbevf_tx_timeout - Respond to a Tx Hang
2334 * @netdev: network interface device structure
2336 static void ixgbevf_tx_timeout(struct net_device
*netdev
)
2338 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2340 /* Do the reset outside of interrupt context */
2341 schedule_work(&adapter
->reset_task
);
2344 static void ixgbevf_reset_task(struct work_struct
*work
)
2346 struct ixgbevf_adapter
*adapter
;
2347 adapter
= container_of(work
, struct ixgbevf_adapter
, reset_task
);
2349 /* If we're already down or resetting, just bail */
2350 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
) ||
2351 test_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
2354 adapter
->tx_timeout_count
++;
2356 ixgbevf_reinit_locked(adapter
);
2360 * ixgbevf_watchdog_task - worker thread to bring link up
2361 * @work: pointer to work_struct containing our data
2363 static void ixgbevf_watchdog_task(struct work_struct
*work
)
2365 struct ixgbevf_adapter
*adapter
= container_of(work
,
2366 struct ixgbevf_adapter
,
2368 struct net_device
*netdev
= adapter
->netdev
;
2369 struct ixgbe_hw
*hw
= &adapter
->hw
;
2370 u32 link_speed
= adapter
->link_speed
;
2371 bool link_up
= adapter
->link_up
;
2373 adapter
->flags
|= IXGBE_FLAG_IN_WATCHDOG_TASK
;
2376 * Always check the link on the watchdog because we have
2379 if (hw
->mac
.ops
.check_link
) {
2380 if ((hw
->mac
.ops
.check_link(hw
, &link_speed
,
2381 &link_up
, false)) != 0) {
2382 adapter
->link_up
= link_up
;
2383 adapter
->link_speed
= link_speed
;
2384 netif_carrier_off(netdev
);
2385 netif_tx_stop_all_queues(netdev
);
2386 schedule_work(&adapter
->reset_task
);
2390 /* always assume link is up, if no check link
2392 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
2395 adapter
->link_up
= link_up
;
2396 adapter
->link_speed
= link_speed
;
2399 if (!netif_carrier_ok(netdev
)) {
2400 hw_dbg(&adapter
->hw
, "NIC Link is Up %s, ",
2401 ((link_speed
== IXGBE_LINK_SPEED_10GB_FULL
) ?
2402 "10 Gbps" : "1 Gbps"));
2403 netif_carrier_on(netdev
);
2404 netif_tx_wake_all_queues(netdev
);
2406 /* Force detection of hung controller */
2407 adapter
->detect_tx_hung
= true;
2410 adapter
->link_up
= false;
2411 adapter
->link_speed
= 0;
2412 if (netif_carrier_ok(netdev
)) {
2413 hw_dbg(&adapter
->hw
, "NIC Link is Down\n");
2414 netif_carrier_off(netdev
);
2415 netif_tx_stop_all_queues(netdev
);
2420 ixgbevf_update_stats(adapter
);
2422 /* Force detection of hung controller every watchdog period */
2423 adapter
->detect_tx_hung
= true;
2425 /* Reset the timer */
2426 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2427 mod_timer(&adapter
->watchdog_timer
,
2428 round_jiffies(jiffies
+ (2 * HZ
)));
2430 adapter
->flags
&= ~IXGBE_FLAG_IN_WATCHDOG_TASK
;
2434 * ixgbevf_free_tx_resources - Free Tx Resources per Queue
2435 * @adapter: board private structure
2436 * @tx_ring: Tx descriptor ring for a specific queue
2438 * Free all transmit software resources
2440 void ixgbevf_free_tx_resources(struct ixgbevf_adapter
*adapter
,
2441 struct ixgbevf_ring
*tx_ring
)
2443 struct pci_dev
*pdev
= adapter
->pdev
;
2445 ixgbevf_clean_tx_ring(adapter
, tx_ring
);
2447 vfree(tx_ring
->tx_buffer_info
);
2448 tx_ring
->tx_buffer_info
= NULL
;
2450 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
2452 tx_ring
->desc
= NULL
;
2456 * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
2457 * @adapter: board private structure
2459 * Free all transmit software resources
2461 static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2465 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2466 if (adapter
->tx_ring
[i
].desc
)
2467 ixgbevf_free_tx_resources(adapter
,
2468 &adapter
->tx_ring
[i
]);
2473 * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
2474 * @adapter: board private structure
2475 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2477 * Return 0 on success, negative on failure
2479 int ixgbevf_setup_tx_resources(struct ixgbevf_adapter
*adapter
,
2480 struct ixgbevf_ring
*tx_ring
)
2482 struct pci_dev
*pdev
= adapter
->pdev
;
2485 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
2486 tx_ring
->tx_buffer_info
= vmalloc(size
);
2487 if (!tx_ring
->tx_buffer_info
)
2489 memset(tx_ring
->tx_buffer_info
, 0, size
);
2491 /* round up to nearest 4K */
2492 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
2493 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
2495 tx_ring
->desc
= pci_alloc_consistent(pdev
, tx_ring
->size
,
2500 tx_ring
->next_to_use
= 0;
2501 tx_ring
->next_to_clean
= 0;
2502 tx_ring
->work_limit
= tx_ring
->count
;
2506 vfree(tx_ring
->tx_buffer_info
);
2507 tx_ring
->tx_buffer_info
= NULL
;
2508 hw_dbg(&adapter
->hw
, "Unable to allocate memory for the transmit "
2509 "descriptor ring\n");
2514 * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
2515 * @adapter: board private structure
2517 * If this function returns with an error, then it's possible one or
2518 * more of the rings is populated (while the rest are not). It is the
2519 * callers duty to clean those orphaned rings.
2521 * Return 0 on success, negative on failure
2523 static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2527 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2528 err
= ixgbevf_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
2531 hw_dbg(&adapter
->hw
,
2532 "Allocation for Tx Queue %u failed\n", i
);
2540 * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
2541 * @adapter: board private structure
2542 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2544 * Returns 0 on success, negative on failure
2546 int ixgbevf_setup_rx_resources(struct ixgbevf_adapter
*adapter
,
2547 struct ixgbevf_ring
*rx_ring
)
2549 struct pci_dev
*pdev
= adapter
->pdev
;
2552 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
2553 rx_ring
->rx_buffer_info
= vmalloc(size
);
2554 if (!rx_ring
->rx_buffer_info
) {
2555 hw_dbg(&adapter
->hw
,
2556 "Unable to vmalloc buffer memory for "
2557 "the receive descriptor ring\n");
2560 memset(rx_ring
->rx_buffer_info
, 0, size
);
2562 /* Round up to nearest 4K */
2563 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
2564 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
2566 rx_ring
->desc
= pci_alloc_consistent(pdev
, rx_ring
->size
,
2569 if (!rx_ring
->desc
) {
2570 hw_dbg(&adapter
->hw
,
2571 "Unable to allocate memory for "
2572 "the receive descriptor ring\n");
2573 vfree(rx_ring
->rx_buffer_info
);
2574 rx_ring
->rx_buffer_info
= NULL
;
2578 rx_ring
->next_to_clean
= 0;
2579 rx_ring
->next_to_use
= 0;
2587 * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
2588 * @adapter: board private structure
2590 * If this function returns with an error, then it's possible one or
2591 * more of the rings is populated (while the rest are not). It is the
2592 * callers duty to clean those orphaned rings.
2594 * Return 0 on success, negative on failure
2596 static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2600 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2601 err
= ixgbevf_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2604 hw_dbg(&adapter
->hw
,
2605 "Allocation for Rx Queue %u failed\n", i
);
2612 * ixgbevf_free_rx_resources - Free Rx Resources
2613 * @adapter: board private structure
2614 * @rx_ring: ring to clean the resources from
2616 * Free all receive software resources
2618 void ixgbevf_free_rx_resources(struct ixgbevf_adapter
*adapter
,
2619 struct ixgbevf_ring
*rx_ring
)
2621 struct pci_dev
*pdev
= adapter
->pdev
;
2623 ixgbevf_clean_rx_ring(adapter
, rx_ring
);
2625 vfree(rx_ring
->rx_buffer_info
);
2626 rx_ring
->rx_buffer_info
= NULL
;
2628 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
2630 rx_ring
->desc
= NULL
;
2634 * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
2635 * @adapter: board private structure
2637 * Free all receive software resources
2639 static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2643 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2644 if (adapter
->rx_ring
[i
].desc
)
2645 ixgbevf_free_rx_resources(adapter
,
2646 &adapter
->rx_ring
[i
]);
2650 * ixgbevf_open - Called when a network interface is made active
2651 * @netdev: network interface device structure
2653 * Returns 0 on success, negative value on failure
2655 * The open entry point is called when a network interface is made
2656 * active by the system (IFF_UP). At this point all resources needed
2657 * for transmit and receive operations are allocated, the interrupt
2658 * handler is registered with the OS, the watchdog timer is started,
2659 * and the stack is notified that the interface is ready.
2661 static int ixgbevf_open(struct net_device
*netdev
)
2663 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2664 struct ixgbe_hw
*hw
= &adapter
->hw
;
2667 /* disallow open during test */
2668 if (test_bit(__IXGBEVF_TESTING
, &adapter
->state
))
2671 if (hw
->adapter_stopped
) {
2672 ixgbevf_reset(adapter
);
2673 /* if adapter is still stopped then PF isn't up and
2674 * the vf can't start. */
2675 if (hw
->adapter_stopped
) {
2676 err
= IXGBE_ERR_MBX
;
2677 printk(KERN_ERR
"Unable to start - perhaps the PF"
2678 "Driver isn't up yet\n");
2679 goto err_setup_reset
;
2683 /* allocate transmit descriptors */
2684 err
= ixgbevf_setup_all_tx_resources(adapter
);
2688 /* allocate receive descriptors */
2689 err
= ixgbevf_setup_all_rx_resources(adapter
);
2693 ixgbevf_configure(adapter
);
2696 * Map the Tx/Rx rings to the vectors we were allotted.
2697 * if request_irq will be called in this function map_rings
2698 * must be called *before* up_complete
2700 ixgbevf_map_rings_to_vectors(adapter
);
2702 err
= ixgbevf_up_complete(adapter
);
2706 /* clear any pending interrupts, may auto mask */
2707 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
2708 err
= ixgbevf_request_irq(adapter
);
2712 ixgbevf_irq_enable(adapter
, true, true);
2717 ixgbevf_down(adapter
);
2719 ixgbevf_free_irq(adapter
);
2721 ixgbevf_free_all_rx_resources(adapter
);
2723 ixgbevf_free_all_tx_resources(adapter
);
2724 ixgbevf_reset(adapter
);
2732 * ixgbevf_close - Disables a network interface
2733 * @netdev: network interface device structure
2735 * Returns 0, this is not allowed to fail
2737 * The close entry point is called when an interface is de-activated
2738 * by the OS. The hardware is still under the drivers control, but
2739 * needs to be disabled. A global MAC reset is issued to stop the
2740 * hardware, and all transmit and receive resources are freed.
2742 static int ixgbevf_close(struct net_device
*netdev
)
2744 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2746 ixgbevf_down(adapter
);
2747 ixgbevf_free_irq(adapter
);
2749 ixgbevf_free_all_tx_resources(adapter
);
2750 ixgbevf_free_all_rx_resources(adapter
);
2755 static int ixgbevf_tso(struct ixgbevf_adapter
*adapter
,
2756 struct ixgbevf_ring
*tx_ring
,
2757 struct sk_buff
*skb
, u32 tx_flags
, u8
*hdr_len
)
2759 struct ixgbe_adv_tx_context_desc
*context_desc
;
2762 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2763 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
;
2764 u32 mss_l4len_idx
, l4len
;
2766 if (skb_is_gso(skb
)) {
2767 if (skb_header_cloned(skb
)) {
2768 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2772 l4len
= tcp_hdrlen(skb
);
2775 if (skb
->protocol
== htons(ETH_P_IP
)) {
2776 struct iphdr
*iph
= ip_hdr(skb
);
2779 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2783 adapter
->hw_tso_ctxt
++;
2784 } else if (skb_is_gso_v6(skb
)) {
2785 ipv6_hdr(skb
)->payload_len
= 0;
2786 tcp_hdr(skb
)->check
=
2787 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2788 &ipv6_hdr(skb
)->daddr
,
2790 adapter
->hw_tso6_ctxt
++;
2793 i
= tx_ring
->next_to_use
;
2795 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2796 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2798 /* VLAN MACLEN IPLEN */
2799 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2801 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
2802 vlan_macip_lens
|= ((skb_network_offset(skb
)) <<
2803 IXGBE_ADVTXD_MACLEN_SHIFT
);
2804 *hdr_len
+= skb_network_offset(skb
);
2806 (skb_transport_header(skb
) - skb_network_header(skb
));
2808 (skb_transport_header(skb
) - skb_network_header(skb
));
2809 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2810 context_desc
->seqnum_seed
= 0;
2812 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2813 type_tucmd_mlhl
= (IXGBE_TXD_CMD_DEXT
|
2814 IXGBE_ADVTXD_DTYP_CTXT
);
2816 if (skb
->protocol
== htons(ETH_P_IP
))
2817 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2818 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2819 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2823 (skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
);
2824 mss_l4len_idx
|= (l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
);
2825 /* use index 1 for TSO */
2826 mss_l4len_idx
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
2827 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
2829 tx_buffer_info
->time_stamp
= jiffies
;
2830 tx_buffer_info
->next_to_watch
= i
;
2833 if (i
== tx_ring
->count
)
2835 tx_ring
->next_to_use
= i
;
2843 static bool ixgbevf_tx_csum(struct ixgbevf_adapter
*adapter
,
2844 struct ixgbevf_ring
*tx_ring
,
2845 struct sk_buff
*skb
, u32 tx_flags
)
2847 struct ixgbe_adv_tx_context_desc
*context_desc
;
2849 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2850 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
2852 if (skb
->ip_summed
== CHECKSUM_PARTIAL
||
2853 (tx_flags
& IXGBE_TX_FLAGS_VLAN
)) {
2854 i
= tx_ring
->next_to_use
;
2855 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2856 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2858 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2859 vlan_macip_lens
|= (tx_flags
&
2860 IXGBE_TX_FLAGS_VLAN_MASK
);
2861 vlan_macip_lens
|= (skb_network_offset(skb
) <<
2862 IXGBE_ADVTXD_MACLEN_SHIFT
);
2863 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2864 vlan_macip_lens
|= (skb_transport_header(skb
) -
2865 skb_network_header(skb
));
2867 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2868 context_desc
->seqnum_seed
= 0;
2870 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
2871 IXGBE_ADVTXD_DTYP_CTXT
);
2873 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2874 switch (skb
->protocol
) {
2875 case __constant_htons(ETH_P_IP
):
2876 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2877 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
2879 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2881 case __constant_htons(ETH_P_IPV6
):
2882 /* XXX what about other V6 headers?? */
2883 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
2885 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2888 if (unlikely(net_ratelimit())) {
2890 "partial checksum but "
2898 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2899 /* use index zero for tx checksum offload */
2900 context_desc
->mss_l4len_idx
= 0;
2902 tx_buffer_info
->time_stamp
= jiffies
;
2903 tx_buffer_info
->next_to_watch
= i
;
2905 adapter
->hw_csum_tx_good
++;
2907 if (i
== tx_ring
->count
)
2909 tx_ring
->next_to_use
= i
;
2917 static int ixgbevf_tx_map(struct ixgbevf_adapter
*adapter
,
2918 struct ixgbevf_ring
*tx_ring
,
2919 struct sk_buff
*skb
, u32 tx_flags
,
2922 struct pci_dev
*pdev
= adapter
->pdev
;
2923 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2925 unsigned int total
= skb
->len
;
2926 unsigned int offset
= 0, size
, count
= 0, i
;
2927 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2930 i
= tx_ring
->next_to_use
;
2932 len
= min(skb_headlen(skb
), total
);
2934 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2935 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2937 tx_buffer_info
->length
= size
;
2938 tx_buffer_info
->mapped_as_page
= false;
2939 tx_buffer_info
->dma
= pci_map_single(adapter
->pdev
,
2941 size
, PCI_DMA_TODEVICE
);
2942 if (pci_dma_mapping_error(pdev
, tx_buffer_info
->dma
))
2944 tx_buffer_info
->time_stamp
= jiffies
;
2945 tx_buffer_info
->next_to_watch
= i
;
2952 if (i
== tx_ring
->count
)
2956 for (f
= 0; f
< nr_frags
; f
++) {
2957 struct skb_frag_struct
*frag
;
2959 frag
= &skb_shinfo(skb
)->frags
[f
];
2960 len
= min((unsigned int)frag
->size
, total
);
2961 offset
= frag
->page_offset
;
2964 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2965 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2967 tx_buffer_info
->length
= size
;
2968 tx_buffer_info
->dma
= pci_map_page(adapter
->pdev
,
2973 tx_buffer_info
->mapped_as_page
= true;
2974 if (pci_dma_mapping_error(pdev
, tx_buffer_info
->dma
))
2976 tx_buffer_info
->time_stamp
= jiffies
;
2977 tx_buffer_info
->next_to_watch
= i
;
2984 if (i
== tx_ring
->count
)
2992 i
= tx_ring
->count
- 1;
2995 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
2996 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
3001 dev_err(&pdev
->dev
, "TX DMA map failed\n");
3003 /* clear timestamp and dma mappings for failed tx_buffer_info map */
3004 tx_buffer_info
->dma
= 0;
3005 tx_buffer_info
->time_stamp
= 0;
3006 tx_buffer_info
->next_to_watch
= 0;
3009 /* clear timestamp and dma mappings for remaining portion of packet */
3010 while (count
>= 0) {
3014 i
+= tx_ring
->count
;
3015 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3016 ixgbevf_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
3022 static void ixgbevf_tx_queue(struct ixgbevf_adapter
*adapter
,
3023 struct ixgbevf_ring
*tx_ring
, int tx_flags
,
3024 int count
, u32 paylen
, u8 hdr_len
)
3026 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
3027 struct ixgbevf_tx_buffer
*tx_buffer_info
;
3028 u32 olinfo_status
= 0, cmd_type_len
= 0;
3031 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
3033 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
3035 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
3037 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
3038 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
3040 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
3041 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
3043 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
3044 IXGBE_ADVTXD_POPTS_SHIFT
;
3046 /* use index 1 context for tso */
3047 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
3048 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
3049 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
3050 IXGBE_ADVTXD_POPTS_SHIFT
;
3052 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
3053 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
3054 IXGBE_ADVTXD_POPTS_SHIFT
;
3056 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
3058 i
= tx_ring
->next_to_use
;
3060 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3061 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
3062 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
3063 tx_desc
->read
.cmd_type_len
=
3064 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
3065 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
3067 if (i
== tx_ring
->count
)
3071 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
3074 * Force memory writes to complete before letting h/w
3075 * know there are new descriptors to fetch. (Only
3076 * applicable for weak-ordered memory model archs,
3081 tx_ring
->next_to_use
= i
;
3082 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3085 static int __ixgbevf_maybe_stop_tx(struct net_device
*netdev
,
3086 struct ixgbevf_ring
*tx_ring
, int size
)
3088 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3090 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
3091 /* Herbert's original patch had:
3092 * smp_mb__after_netif_stop_queue();
3093 * but since that doesn't exist yet, just open code it. */
3096 /* We need to check again in a case another CPU has just
3097 * made room available. */
3098 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
3101 /* A reprieve! - use start_queue because it doesn't call schedule */
3102 netif_start_subqueue(netdev
, tx_ring
->queue_index
);
3103 ++adapter
->restart_queue
;
3107 static int ixgbevf_maybe_stop_tx(struct net_device
*netdev
,
3108 struct ixgbevf_ring
*tx_ring
, int size
)
3110 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
3112 return __ixgbevf_maybe_stop_tx(netdev
, tx_ring
, size
);
3115 static int ixgbevf_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
3117 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3118 struct ixgbevf_ring
*tx_ring
;
3120 unsigned int tx_flags
= 0;
3127 tx_ring
= &adapter
->tx_ring
[r_idx
];
3129 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
3130 tx_flags
|= vlan_tx_tag_get(skb
);
3131 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
3132 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
3135 /* four things can cause us to need a context descriptor */
3136 if (skb_is_gso(skb
) ||
3137 (skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
3138 (tx_flags
& IXGBE_TX_FLAGS_VLAN
))
3141 count
+= TXD_USE_COUNT(skb_headlen(skb
));
3142 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
3143 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
3145 if (ixgbevf_maybe_stop_tx(netdev
, tx_ring
, count
)) {
3147 return NETDEV_TX_BUSY
;
3150 first
= tx_ring
->next_to_use
;
3152 if (skb
->protocol
== htons(ETH_P_IP
))
3153 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
3154 tso
= ixgbevf_tso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
3156 dev_kfree_skb_any(skb
);
3157 return NETDEV_TX_OK
;
3161 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
3162 else if (ixgbevf_tx_csum(adapter
, tx_ring
, skb
, tx_flags
) &&
3163 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3164 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
3166 ixgbevf_tx_queue(adapter
, tx_ring
, tx_flags
,
3167 ixgbevf_tx_map(adapter
, tx_ring
, skb
, tx_flags
, first
),
3170 netdev
->trans_start
= jiffies
;
3172 ixgbevf_maybe_stop_tx(netdev
, tx_ring
, DESC_NEEDED
);
3174 return NETDEV_TX_OK
;
3178 * ixgbevf_get_stats - Get System Network Statistics
3179 * @netdev: network interface device structure
3181 * Returns the address of the device statistics structure.
3182 * The statistics are actually updated from the timer callback.
3184 static struct net_device_stats
*ixgbevf_get_stats(struct net_device
*netdev
)
3186 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3188 /* only return the current stats */
3189 return &adapter
->net_stats
;
3193 * ixgbevf_set_mac - Change the Ethernet Address of the NIC
3194 * @netdev: network interface device structure
3195 * @p: pointer to an address structure
3197 * Returns 0 on success, negative on failure
3199 static int ixgbevf_set_mac(struct net_device
*netdev
, void *p
)
3201 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3202 struct ixgbe_hw
*hw
= &adapter
->hw
;
3203 struct sockaddr
*addr
= p
;
3205 if (!is_valid_ether_addr(addr
->sa_data
))
3206 return -EADDRNOTAVAIL
;
3208 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3209 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3211 if (hw
->mac
.ops
.set_rar
)
3212 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
3218 * ixgbevf_change_mtu - Change the Maximum Transfer Unit
3219 * @netdev: network interface device structure
3220 * @new_mtu: new value for maximum frame size
3222 * Returns 0 on success, negative on failure
3224 static int ixgbevf_change_mtu(struct net_device
*netdev
, int new_mtu
)
3226 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3227 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3229 /* MTU < 68 is an error and causes problems on some kernels */
3230 if ((new_mtu
< 68) || (max_frame
> MAXIMUM_ETHERNET_VLAN_SIZE
))
3233 hw_dbg(&adapter
->hw
, "changing MTU from %d to %d\n",
3234 netdev
->mtu
, new_mtu
);
3235 /* must set new MTU before calling down or up */
3236 netdev
->mtu
= new_mtu
;
3238 if (netif_running(netdev
))
3239 ixgbevf_reinit_locked(adapter
);
3244 static void ixgbevf_shutdown(struct pci_dev
*pdev
)
3246 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3247 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3249 netif_device_detach(netdev
);
3251 if (netif_running(netdev
)) {
3252 ixgbevf_down(adapter
);
3253 ixgbevf_free_irq(adapter
);
3254 ixgbevf_free_all_tx_resources(adapter
);
3255 ixgbevf_free_all_rx_resources(adapter
);
3259 pci_save_state(pdev
);
3262 pci_disable_device(pdev
);
3265 #ifdef HAVE_NET_DEVICE_OPS
3266 static const struct net_device_ops ixgbe_netdev_ops
= {
3267 .ndo_open
= &ixgbevf_open
,
3268 .ndo_stop
= &ixgbevf_close
,
3269 .ndo_start_xmit
= &ixgbevf_xmit_frame
,
3270 .ndo_get_stats
= &ixgbevf_get_stats
,
3271 .ndo_set_rx_mode
= &ixgbevf_set_rx_mode
,
3272 .ndo_set_multicast_list
= &ixgbevf_set_rx_mode
,
3273 .ndo_validate_addr
= eth_validate_addr
,
3274 .ndo_set_mac_address
= &ixgbevf_set_mac
,
3275 .ndo_change_mtu
= &ixgbevf_change_mtu
,
3276 .ndo_tx_timeout
= &ixgbevf_tx_timeout
,
3277 .ndo_vlan_rx_register
= &ixgbevf_vlan_rx_register
,
3278 .ndo_vlan_rx_add_vid
= &ixgbevf_vlan_rx_add_vid
,
3279 .ndo_vlan_rx_kill_vid
= &ixgbevf_vlan_rx_kill_vid
,
3281 #endif /* HAVE_NET_DEVICE_OPS */
3283 static void ixgbevf_assign_netdev_ops(struct net_device
*dev
)
3285 struct ixgbevf_adapter
*adapter
;
3286 adapter
= netdev_priv(dev
);
3287 #ifdef HAVE_NET_DEVICE_OPS
3288 dev
->netdev_ops
= &ixgbe_netdev_ops
;
3289 #else /* HAVE_NET_DEVICE_OPS */
3290 dev
->open
= &ixgbevf_open
;
3291 dev
->stop
= &ixgbevf_close
;
3293 dev
->hard_start_xmit
= &ixgbevf_xmit_frame
;
3295 dev
->get_stats
= &ixgbevf_get_stats
;
3296 dev
->set_multicast_list
= &ixgbevf_set_rx_mode
;
3297 dev
->set_mac_address
= &ixgbevf_set_mac
;
3298 dev
->change_mtu
= &ixgbevf_change_mtu
;
3299 dev
->tx_timeout
= &ixgbevf_tx_timeout
;
3300 dev
->vlan_rx_register
= &ixgbevf_vlan_rx_register
;
3301 dev
->vlan_rx_add_vid
= &ixgbevf_vlan_rx_add_vid
;
3302 dev
->vlan_rx_kill_vid
= &ixgbevf_vlan_rx_kill_vid
;
3303 #endif /* HAVE_NET_DEVICE_OPS */
3304 ixgbevf_set_ethtool_ops(dev
);
3305 dev
->watchdog_timeo
= 5 * HZ
;
3309 * ixgbevf_probe - Device Initialization Routine
3310 * @pdev: PCI device information struct
3311 * @ent: entry in ixgbevf_pci_tbl
3313 * Returns 0 on success, negative on failure
3315 * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
3316 * The OS initialization, configuring of the adapter private structure,
3317 * and a hardware reset occur.
3319 static int __devinit
ixgbevf_probe(struct pci_dev
*pdev
,
3320 const struct pci_device_id
*ent
)
3322 struct net_device
*netdev
;
3323 struct ixgbevf_adapter
*adapter
= NULL
;
3324 struct ixgbe_hw
*hw
= NULL
;
3325 const struct ixgbevf_info
*ii
= ixgbevf_info_tbl
[ent
->driver_data
];
3326 static int cards_found
;
3327 int err
, pci_using_dac
;
3329 err
= pci_enable_device(pdev
);
3333 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
3334 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
3337 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
3339 err
= pci_set_consistent_dma_mask(pdev
,
3342 dev_err(&pdev
->dev
, "No usable DMA "
3343 "configuration, aborting\n");
3350 err
= pci_request_regions(pdev
, ixgbevf_driver_name
);
3352 dev_err(&pdev
->dev
, "pci_request_regions failed 0x%x\n", err
);
3356 pci_set_master(pdev
);
3359 netdev
= alloc_etherdev_mq(sizeof(struct ixgbevf_adapter
),
3362 netdev
= alloc_etherdev(sizeof(struct ixgbevf_adapter
));
3366 goto err_alloc_etherdev
;
3369 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3371 pci_set_drvdata(pdev
, netdev
);
3372 adapter
= netdev_priv(netdev
);
3374 adapter
->netdev
= netdev
;
3375 adapter
->pdev
= pdev
;
3378 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
3381 * call save state here in standalone driver because it relies on
3382 * adapter struct to exist, and needs to call netdev_priv
3384 pci_save_state(pdev
);
3386 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
3387 pci_resource_len(pdev
, 0));
3393 ixgbevf_assign_netdev_ops(netdev
);
3395 adapter
->bd_number
= cards_found
;
3398 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
3399 hw
->mac
.type
= ii
->mac
;
3401 memcpy(&hw
->mbx
.ops
, &ixgbevf_mbx_ops
,
3402 sizeof(struct ixgbe_mac_operations
));
3404 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_CAPABLE
;
3405 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
3406 adapter
->flags
|= IXGBE_FLAG_RX_1BUF_CAPABLE
;
3408 /* setup the private structure */
3409 err
= ixgbevf_sw_init(adapter
);
3411 ixgbevf_init_last_counter_stats(adapter
);
3413 #ifdef MAX_SKB_FRAGS
3414 netdev
->features
= NETIF_F_SG
|
3416 NETIF_F_HW_VLAN_TX
|
3417 NETIF_F_HW_VLAN_RX
|
3418 NETIF_F_HW_VLAN_FILTER
;
3420 netdev
->features
|= NETIF_F_IPV6_CSUM
;
3421 netdev
->features
|= NETIF_F_TSO
;
3422 netdev
->features
|= NETIF_F_TSO6
;
3423 netdev
->vlan_features
|= NETIF_F_TSO
;
3424 netdev
->vlan_features
|= NETIF_F_TSO6
;
3425 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
3426 netdev
->vlan_features
|= NETIF_F_SG
;
3429 netdev
->features
|= NETIF_F_HIGHDMA
;
3431 #endif /* MAX_SKB_FRAGS */
3433 /* The HW MAC address was set and/or determined in sw_init */
3434 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3435 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3437 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
3438 printk(KERN_ERR
"invalid MAC address\n");
3443 init_timer(&adapter
->watchdog_timer
);
3444 adapter
->watchdog_timer
.function
= &ixgbevf_watchdog
;
3445 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
3447 INIT_WORK(&adapter
->reset_task
, ixgbevf_reset_task
);
3448 INIT_WORK(&adapter
->watchdog_task
, ixgbevf_watchdog_task
);
3450 err
= ixgbevf_init_interrupt_scheme(adapter
);
3454 /* pick up the PCI bus settings for reporting later */
3455 if (hw
->mac
.ops
.get_bus_info
)
3456 hw
->mac
.ops
.get_bus_info(hw
);
3459 netif_carrier_off(netdev
);
3460 netif_tx_stop_all_queues(netdev
);
3462 strcpy(netdev
->name
, "eth%d");
3464 err
= register_netdev(netdev
);
3468 adapter
->netdev_registered
= true;
3470 /* print the MAC address */
3471 hw_dbg(hw
, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
3472 netdev
->dev_addr
[0],
3473 netdev
->dev_addr
[1],
3474 netdev
->dev_addr
[2],
3475 netdev
->dev_addr
[3],
3476 netdev
->dev_addr
[4],
3477 netdev
->dev_addr
[5]);
3479 hw_dbg(hw
, "MAC: %d\n", hw
->mac
.type
);
3481 hw_dbg(hw
, "LRO is disabled \n");
3483 hw_dbg(hw
, "Intel(R) 82599 Virtual Function\n");
3489 ixgbevf_reset_interrupt_capability(adapter
);
3490 iounmap(hw
->hw_addr
);
3492 free_netdev(netdev
);
3494 pci_release_regions(pdev
);
3497 pci_disable_device(pdev
);
3502 * ixgbevf_remove - Device Removal Routine
3503 * @pdev: PCI device information struct
3505 * ixgbevf_remove is called by the PCI subsystem to alert the driver
3506 * that it should release a PCI device. The could be caused by a
3507 * Hot-Plug event, or because the driver is going to be removed from
3510 static void __devexit
ixgbevf_remove(struct pci_dev
*pdev
)
3512 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3513 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3515 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
3517 del_timer_sync(&adapter
->watchdog_timer
);
3519 cancel_work_sync(&adapter
->watchdog_task
);
3521 flush_scheduled_work();
3523 if (adapter
->netdev_registered
) {
3524 unregister_netdev(netdev
);
3525 adapter
->netdev_registered
= false;
3528 ixgbevf_reset_interrupt_capability(adapter
);
3530 iounmap(adapter
->hw
.hw_addr
);
3531 pci_release_regions(pdev
);
3533 hw_dbg(&adapter
->hw
, "Remove complete\n");
3535 kfree(adapter
->tx_ring
);
3536 kfree(adapter
->rx_ring
);
3538 free_netdev(netdev
);
3540 pci_disable_device(pdev
);
3543 static struct pci_driver ixgbevf_driver
= {
3544 .name
= ixgbevf_driver_name
,
3545 .id_table
= ixgbevf_pci_tbl
,
3546 .probe
= ixgbevf_probe
,
3547 .remove
= __devexit_p(ixgbevf_remove
),
3548 .shutdown
= ixgbevf_shutdown
,
3552 * ixgbe_init_module - Driver Registration Routine
3554 * ixgbe_init_module is the first routine called when the driver is
3555 * loaded. All it does is register with the PCI subsystem.
3557 static int __init
ixgbevf_init_module(void)
3560 printk(KERN_INFO
"ixgbevf: %s - version %s\n", ixgbevf_driver_string
,
3561 ixgbevf_driver_version
);
3563 printk(KERN_INFO
"%s\n", ixgbevf_copyright
);
3565 ret
= pci_register_driver(&ixgbevf_driver
);
3569 module_init(ixgbevf_init_module
);
3572 * ixgbe_exit_module - Driver Exit Cleanup Routine
3574 * ixgbe_exit_module is called just before the driver is removed
3577 static void __exit
ixgbevf_exit_module(void)
3579 pci_unregister_driver(&ixgbevf_driver
);
3584 * ixgbe_get_hw_dev_name - return device name string
3585 * used by hardware layer to print debugging information
3587 char *ixgbevf_get_hw_dev_name(struct ixgbe_hw
*hw
)
3589 struct ixgbevf_adapter
*adapter
= hw
->back
;
3590 return adapter
->netdev
->name
;
3594 module_exit(ixgbevf_exit_module
);
3596 /* ixgbevf_main.c */