1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2009 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
29 /******************************************************************************
30 Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
31 ******************************************************************************/
32 #include <linux/types.h>
33 #include <linux/module.h>
34 #include <linux/pci.h>
35 #include <linux/netdevice.h>
36 #include <linux/vmalloc.h>
37 #include <linux/string.h>
40 #include <linux/tcp.h>
41 #include <linux/ipv6.h>
42 #include <linux/slab.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <linux/ethtool.h>
46 #include <linux/if_vlan.h>
50 char ixgbevf_driver_name
[] = "ixgbevf";
51 static const char ixgbevf_driver_string
[] =
52 "Intel(R) 82599 Virtual Function";
54 #define DRV_VERSION "1.0.0-k0"
55 const char ixgbevf_driver_version
[] = DRV_VERSION
;
56 static char ixgbevf_copyright
[] = "Copyright (c) 2009 Intel Corporation.";
58 static const struct ixgbevf_info
*ixgbevf_info_tbl
[] = {
59 [board_82599_vf
] = &ixgbevf_vf_info
,
62 /* ixgbevf_pci_tbl - PCI Device ID Table
64 * Wildcard entries (PCI_ANY_ID) should come last
65 * Last entry must be all 0s
67 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
68 * Class, Class Mask, private data (not used) }
70 static struct pci_device_id ixgbevf_pci_tbl
[] = {
71 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_VF
),
74 /* required last entry */
77 MODULE_DEVICE_TABLE(pci
, ixgbevf_pci_tbl
);
79 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
80 MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
81 MODULE_LICENSE("GPL");
82 MODULE_VERSION(DRV_VERSION
);
84 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
87 static void ixgbevf_set_itr_msix(struct ixgbevf_q_vector
*q_vector
);
88 static void ixgbevf_write_eitr(struct ixgbevf_adapter
*adapter
, int v_idx
,
91 static inline void ixgbevf_release_rx_desc(struct ixgbe_hw
*hw
,
92 struct ixgbevf_ring
*rx_ring
,
96 * Force memory writes to complete before letting h/w
97 * know there are new descriptors to fetch. (Only
98 * applicable for weak-ordered memory model archs,
102 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(rx_ring
->reg_idx
), val
);
106 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
107 * @adapter: pointer to adapter struct
108 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
109 * @queue: queue to map the corresponding interrupt to
110 * @msix_vector: the vector to map to the corresponding queue
113 static void ixgbevf_set_ivar(struct ixgbevf_adapter
*adapter
, s8 direction
,
114 u8 queue
, u8 msix_vector
)
117 struct ixgbe_hw
*hw
= &adapter
->hw
;
118 if (direction
== -1) {
120 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
121 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR_MISC
);
124 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR_MISC
, ivar
);
126 /* tx or rx causes */
127 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
128 index
= ((16 * (queue
& 1)) + (8 * direction
));
129 ivar
= IXGBE_READ_REG(hw
, IXGBE_VTIVAR(queue
>> 1));
130 ivar
&= ~(0xFF << index
);
131 ivar
|= (msix_vector
<< index
);
132 IXGBE_WRITE_REG(hw
, IXGBE_VTIVAR(queue
>> 1), ivar
);
136 static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_adapter
*adapter
,
137 struct ixgbevf_tx_buffer
140 if (tx_buffer_info
->dma
) {
141 if (tx_buffer_info
->mapped_as_page
)
142 dma_unmap_page(&adapter
->pdev
->dev
,
144 tx_buffer_info
->length
,
147 dma_unmap_single(&adapter
->pdev
->dev
,
149 tx_buffer_info
->length
,
151 tx_buffer_info
->dma
= 0;
153 if (tx_buffer_info
->skb
) {
154 dev_kfree_skb_any(tx_buffer_info
->skb
);
155 tx_buffer_info
->skb
= NULL
;
157 tx_buffer_info
->time_stamp
= 0;
158 /* tx_buffer_info must be completely set up in the transmit path */
161 static inline bool ixgbevf_check_tx_hang(struct ixgbevf_adapter
*adapter
,
162 struct ixgbevf_ring
*tx_ring
,
165 struct ixgbe_hw
*hw
= &adapter
->hw
;
168 /* Detect a transmit hang in hardware, this serializes the
169 * check with the clearing of time_stamp and movement of eop */
170 head
= readl(hw
->hw_addr
+ tx_ring
->head
);
171 tail
= readl(hw
->hw_addr
+ tx_ring
->tail
);
172 adapter
->detect_tx_hung
= false;
173 if ((head
!= tail
) &&
174 tx_ring
->tx_buffer_info
[eop
].time_stamp
&&
175 time_after(jiffies
, tx_ring
->tx_buffer_info
[eop
].time_stamp
+ HZ
)) {
176 /* detected Tx unit hang */
177 union ixgbe_adv_tx_desc
*tx_desc
;
178 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
179 printk(KERN_ERR
"Detected Tx Unit Hang\n"
181 " TDH, TDT <%x>, <%x>\n"
182 " next_to_use <%x>\n"
183 " next_to_clean <%x>\n"
184 "tx_buffer_info[next_to_clean]\n"
185 " time_stamp <%lx>\n"
187 tx_ring
->queue_index
,
189 tx_ring
->next_to_use
, eop
,
190 tx_ring
->tx_buffer_info
[eop
].time_stamp
, jiffies
);
197 #define IXGBE_MAX_TXD_PWR 14
198 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
200 /* Tx Descriptors needed, worst case */
201 #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
202 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
204 #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
205 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
207 #define DESC_NEEDED TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD)
210 static void ixgbevf_tx_timeout(struct net_device
*netdev
);
213 * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
214 * @adapter: board private structure
215 * @tx_ring: tx ring to clean
217 static bool ixgbevf_clean_tx_irq(struct ixgbevf_adapter
*adapter
,
218 struct ixgbevf_ring
*tx_ring
)
220 struct net_device
*netdev
= adapter
->netdev
;
221 struct ixgbe_hw
*hw
= &adapter
->hw
;
222 union ixgbe_adv_tx_desc
*tx_desc
, *eop_desc
;
223 struct ixgbevf_tx_buffer
*tx_buffer_info
;
224 unsigned int i
, eop
, count
= 0;
225 unsigned int total_bytes
= 0, total_packets
= 0;
227 i
= tx_ring
->next_to_clean
;
228 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
229 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
231 while ((eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)) &&
232 (count
< tx_ring
->work_limit
)) {
233 bool cleaned
= false;
234 for ( ; !cleaned
; count
++) {
236 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
237 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
238 cleaned
= (i
== eop
);
239 skb
= tx_buffer_info
->skb
;
241 if (cleaned
&& skb
) {
242 unsigned int segs
, bytecount
;
244 /* gso_segs is currently only valid for tcp */
245 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
246 /* multiply data chunks by size of headers */
247 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
249 total_packets
+= segs
;
250 total_bytes
+= bytecount
;
253 ixgbevf_unmap_and_free_tx_resource(adapter
,
256 tx_desc
->wb
.status
= 0;
259 if (i
== tx_ring
->count
)
263 eop
= tx_ring
->tx_buffer_info
[i
].next_to_watch
;
264 eop_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, eop
);
267 tx_ring
->next_to_clean
= i
;
269 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
270 if (unlikely(count
&& netif_carrier_ok(netdev
) &&
271 (IXGBE_DESC_UNUSED(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
272 /* Make sure that anybody stopping the queue after this
273 * sees the new next_to_clean.
277 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
278 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
279 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
280 ++adapter
->restart_queue
;
283 if (netif_queue_stopped(netdev
) &&
284 !test_bit(__IXGBEVF_DOWN
, &adapter
->state
)) {
285 netif_wake_queue(netdev
);
286 ++adapter
->restart_queue
;
291 if (adapter
->detect_tx_hung
) {
292 if (ixgbevf_check_tx_hang(adapter
, tx_ring
, i
)) {
293 /* schedule immediate reset if we believe we hung */
295 "tx hang %d detected, resetting adapter\n",
296 adapter
->tx_timeout_count
+ 1);
297 ixgbevf_tx_timeout(adapter
->netdev
);
301 /* re-arm the interrupt */
302 if ((count
>= tx_ring
->work_limit
) &&
303 (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))) {
304 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, tx_ring
->v_idx
);
307 tx_ring
->total_bytes
+= total_bytes
;
308 tx_ring
->total_packets
+= total_packets
;
310 adapter
->net_stats
.tx_bytes
+= total_bytes
;
311 adapter
->net_stats
.tx_packets
+= total_packets
;
313 return (count
< tx_ring
->work_limit
);
317 * ixgbevf_receive_skb - Send a completed packet up the stack
318 * @q_vector: structure containing interrupt and ring information
319 * @skb: packet to send up
320 * @status: hardware indication of status of receive
321 * @rx_ring: rx descriptor ring (for a specific queue) to setup
322 * @rx_desc: rx descriptor
324 static void ixgbevf_receive_skb(struct ixgbevf_q_vector
*q_vector
,
325 struct sk_buff
*skb
, u8 status
,
326 struct ixgbevf_ring
*ring
,
327 union ixgbe_adv_rx_desc
*rx_desc
)
329 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
330 bool is_vlan
= (status
& IXGBE_RXD_STAT_VP
);
331 u16 tag
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
334 if (!(adapter
->flags
& IXGBE_FLAG_IN_NETPOLL
)) {
335 if (adapter
->vlgrp
&& is_vlan
)
336 vlan_gro_receive(&q_vector
->napi
,
340 napi_gro_receive(&q_vector
->napi
, skb
);
342 if (adapter
->vlgrp
&& is_vlan
)
343 ret
= vlan_hwaccel_rx(skb
, adapter
->vlgrp
, tag
);
350 * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
351 * @adapter: address of board private structure
352 * @status_err: hardware indication of status of receive
353 * @skb: skb currently being received and modified
355 static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter
*adapter
,
356 u32 status_err
, struct sk_buff
*skb
)
358 skb
->ip_summed
= CHECKSUM_NONE
;
360 /* Rx csum disabled */
361 if (!(adapter
->flags
& IXGBE_FLAG_RX_CSUM_ENABLED
))
364 /* if IP and error */
365 if ((status_err
& IXGBE_RXD_STAT_IPCS
) &&
366 (status_err
& IXGBE_RXDADV_ERR_IPE
)) {
367 adapter
->hw_csum_rx_error
++;
371 if (!(status_err
& IXGBE_RXD_STAT_L4CS
))
374 if (status_err
& IXGBE_RXDADV_ERR_TCPE
) {
375 adapter
->hw_csum_rx_error
++;
379 /* It must be a TCP or UDP packet with a valid checksum */
380 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
381 adapter
->hw_csum_rx_good
++;
385 * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
386 * @adapter: address of board private structure
388 static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter
*adapter
,
389 struct ixgbevf_ring
*rx_ring
,
392 struct pci_dev
*pdev
= adapter
->pdev
;
393 union ixgbe_adv_rx_desc
*rx_desc
;
394 struct ixgbevf_rx_buffer
*bi
;
397 unsigned int bufsz
= rx_ring
->rx_buf_len
+ NET_IP_ALIGN
;
399 i
= rx_ring
->next_to_use
;
400 bi
= &rx_ring
->rx_buffer_info
[i
];
402 while (cleaned_count
--) {
403 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
406 (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
)) {
408 bi
->page
= netdev_alloc_page(adapter
->netdev
);
410 adapter
->alloc_rx_page_failed
++;
415 /* use a half page if we're re-using */
416 bi
->page_offset
^= (PAGE_SIZE
/ 2);
419 bi
->page_dma
= dma_map_page(&pdev
->dev
, bi
->page
,
427 skb
= netdev_alloc_skb(adapter
->netdev
,
431 adapter
->alloc_rx_buff_failed
++;
436 * Make buffer alignment 2 beyond a 16 byte boundary
437 * this will result in a 16 byte aligned IP header after
438 * the 14 byte MAC header is removed
440 skb_reserve(skb
, NET_IP_ALIGN
);
445 bi
->dma
= dma_map_single(&pdev
->dev
, skb
->data
,
449 /* Refresh the desc even if buffer_addrs didn't change because
450 * each write-back erases this info. */
451 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
452 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->page_dma
);
453 rx_desc
->read
.hdr_addr
= cpu_to_le64(bi
->dma
);
455 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
);
459 if (i
== rx_ring
->count
)
461 bi
= &rx_ring
->rx_buffer_info
[i
];
465 if (rx_ring
->next_to_use
!= i
) {
466 rx_ring
->next_to_use
= i
;
468 i
= (rx_ring
->count
- 1);
470 ixgbevf_release_rx_desc(&adapter
->hw
, rx_ring
, i
);
474 static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter
*adapter
,
478 struct ixgbe_hw
*hw
= &adapter
->hw
;
480 mask
= (qmask
& 0xFFFFFFFF);
481 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, mask
);
484 static inline u16
ixgbevf_get_hdr_info(union ixgbe_adv_rx_desc
*rx_desc
)
486 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
489 static inline u16
ixgbevf_get_pkt_info(union ixgbe_adv_rx_desc
*rx_desc
)
491 return rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
494 static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector
*q_vector
,
495 struct ixgbevf_ring
*rx_ring
,
496 int *work_done
, int work_to_do
)
498 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
499 struct pci_dev
*pdev
= adapter
->pdev
;
500 union ixgbe_adv_rx_desc
*rx_desc
, *next_rxd
;
501 struct ixgbevf_rx_buffer
*rx_buffer_info
, *next_buffer
;
506 bool cleaned
= false;
507 int cleaned_count
= 0;
508 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
510 i
= rx_ring
->next_to_clean
;
511 rx_desc
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
512 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
513 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
515 while (staterr
& IXGBE_RXD_STAT_DD
) {
517 if (*work_done
>= work_to_do
)
521 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
522 hdr_info
= le16_to_cpu(ixgbevf_get_hdr_info(rx_desc
));
523 len
= (hdr_info
& IXGBE_RXDADV_HDRBUFLEN_MASK
) >>
524 IXGBE_RXDADV_HDRBUFLEN_SHIFT
;
525 if (hdr_info
& IXGBE_RXDADV_SPH
)
526 adapter
->rx_hdr_split
++;
527 if (len
> IXGBEVF_RX_HDR_SIZE
)
528 len
= IXGBEVF_RX_HDR_SIZE
;
529 upper_len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
531 len
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
534 skb
= rx_buffer_info
->skb
;
535 prefetch(skb
->data
- NET_IP_ALIGN
);
536 rx_buffer_info
->skb
= NULL
;
538 if (rx_buffer_info
->dma
) {
539 dma_unmap_single(&pdev
->dev
, rx_buffer_info
->dma
,
542 rx_buffer_info
->dma
= 0;
547 dma_unmap_page(&pdev
->dev
, rx_buffer_info
->page_dma
,
548 PAGE_SIZE
/ 2, DMA_FROM_DEVICE
);
549 rx_buffer_info
->page_dma
= 0;
550 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
551 rx_buffer_info
->page
,
552 rx_buffer_info
->page_offset
,
555 if ((rx_ring
->rx_buf_len
> (PAGE_SIZE
/ 2)) ||
556 (page_count(rx_buffer_info
->page
) != 1))
557 rx_buffer_info
->page
= NULL
;
559 get_page(rx_buffer_info
->page
);
561 skb
->len
+= upper_len
;
562 skb
->data_len
+= upper_len
;
563 skb
->truesize
+= upper_len
;
567 if (i
== rx_ring
->count
)
570 next_rxd
= IXGBE_RX_DESC_ADV(*rx_ring
, i
);
574 next_buffer
= &rx_ring
->rx_buffer_info
[i
];
576 if (!(staterr
& IXGBE_RXD_STAT_EOP
)) {
577 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
578 rx_buffer_info
->skb
= next_buffer
->skb
;
579 rx_buffer_info
->dma
= next_buffer
->dma
;
580 next_buffer
->skb
= skb
;
581 next_buffer
->dma
= 0;
583 skb
->next
= next_buffer
->skb
;
584 skb
->next
->prev
= skb
;
586 adapter
->non_eop_descs
++;
590 /* ERR_MASK will only have valid bits if EOP set */
591 if (unlikely(staterr
& IXGBE_RXDADV_ERR_FRAME_ERR_MASK
)) {
592 dev_kfree_skb_irq(skb
);
596 ixgbevf_rx_checksum(adapter
, staterr
, skb
);
598 /* probably a little skewed due to removing CRC */
599 total_rx_bytes
+= skb
->len
;
603 * Work around issue of some types of VM to VM loop back
604 * packets not getting split correctly
606 if (staterr
& IXGBE_RXD_STAT_LB
) {
607 u32 header_fixup_len
= skb_headlen(skb
);
608 if (header_fixup_len
< 14)
609 skb_push(skb
, header_fixup_len
);
611 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
613 ixgbevf_receive_skb(q_vector
, skb
, staterr
, rx_ring
, rx_desc
);
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_set_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
);
951 static irqreturn_t
ixgbevf_msix_mbx(int irq
, void *data
)
953 struct net_device
*netdev
= data
;
954 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
955 struct ixgbe_hw
*hw
= &adapter
->hw
;
959 eicr
= IXGBE_READ_REG(hw
, IXGBE_VTEICS
);
960 IXGBE_WRITE_REG(hw
, IXGBE_VTEICR
, eicr
);
962 if (!hw
->mbx
.ops
.check_for_ack(hw
)) {
964 * checking for the ack clears the PFACK bit. Place
965 * it back in the v2p_mailbox cache so that anyone
966 * polling for an ack will not miss it. Also
967 * avoid the read below because the code to read
968 * the mailbox will also clear the ack bit. This was
969 * causing lost acks. Just cache the bit and exit
972 hw
->mbx
.v2p_mailbox
|= IXGBE_VFMAILBOX_PFACK
;
976 /* Not an ack interrupt, go ahead and read the message */
977 hw
->mbx
.ops
.read(hw
, &msg
, 1);
979 if ((msg
& IXGBE_MBVFICR_VFREQ_MASK
) == IXGBE_PF_CONTROL_MSG
)
980 mod_timer(&adapter
->watchdog_timer
,
981 round_jiffies(jiffies
+ 1));
987 static irqreturn_t
ixgbevf_msix_clean_tx(int irq
, void *data
)
989 struct ixgbevf_q_vector
*q_vector
= data
;
990 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
991 struct ixgbevf_ring
*tx_ring
;
994 if (!q_vector
->txr_count
)
997 r_idx
= find_first_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
);
998 for (i
= 0; i
< q_vector
->txr_count
; i
++) {
999 tx_ring
= &(adapter
->tx_ring
[r_idx
]);
1000 tx_ring
->total_bytes
= 0;
1001 tx_ring
->total_packets
= 0;
1002 ixgbevf_clean_tx_irq(adapter
, tx_ring
);
1003 r_idx
= find_next_bit(q_vector
->txr_idx
, adapter
->num_tx_queues
,
1007 if (adapter
->itr_setting
& 1)
1008 ixgbevf_set_itr_msix(q_vector
);
1014 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1016 * @data: pointer to our q_vector struct for this interrupt vector
1018 static irqreturn_t
ixgbevf_msix_clean_rx(int irq
, void *data
)
1020 struct ixgbevf_q_vector
*q_vector
= data
;
1021 struct ixgbevf_adapter
*adapter
= q_vector
->adapter
;
1022 struct ixgbe_hw
*hw
= &adapter
->hw
;
1023 struct ixgbevf_ring
*rx_ring
;
1027 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1028 for (i
= 0; i
< q_vector
->rxr_count
; i
++) {
1029 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1030 rx_ring
->total_bytes
= 0;
1031 rx_ring
->total_packets
= 0;
1032 r_idx
= find_next_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
,
1036 if (!q_vector
->rxr_count
)
1039 r_idx
= find_first_bit(q_vector
->rxr_idx
, adapter
->num_rx_queues
);
1040 rx_ring
= &(adapter
->rx_ring
[r_idx
]);
1041 /* disable interrupts on this vector only */
1042 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, rx_ring
->v_idx
);
1043 napi_schedule(&q_vector
->napi
);
1049 static irqreturn_t
ixgbevf_msix_clean_many(int irq
, void *data
)
1051 ixgbevf_msix_clean_rx(irq
, data
);
1052 ixgbevf_msix_clean_tx(irq
, data
);
1057 static inline void map_vector_to_rxq(struct ixgbevf_adapter
*a
, int v_idx
,
1060 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1062 set_bit(r_idx
, q_vector
->rxr_idx
);
1063 q_vector
->rxr_count
++;
1064 a
->rx_ring
[r_idx
].v_idx
= 1 << v_idx
;
1067 static inline void map_vector_to_txq(struct ixgbevf_adapter
*a
, int v_idx
,
1070 struct ixgbevf_q_vector
*q_vector
= a
->q_vector
[v_idx
];
1072 set_bit(t_idx
, q_vector
->txr_idx
);
1073 q_vector
->txr_count
++;
1074 a
->tx_ring
[t_idx
].v_idx
= 1 << v_idx
;
1078 * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
1079 * @adapter: board private structure to initialize
1081 * This function maps descriptor rings to the queue-specific vectors
1082 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1083 * one vector per ring/queue, but on a constrained vector budget, we
1084 * group the rings as "efficiently" as possible. You would add new
1085 * mapping configurations in here.
1087 static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter
*adapter
)
1091 int rxr_idx
= 0, txr_idx
= 0;
1092 int rxr_remaining
= adapter
->num_rx_queues
;
1093 int txr_remaining
= adapter
->num_tx_queues
;
1098 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1101 * The ideal configuration...
1102 * We have enough vectors to map one per queue.
1104 if (q_vectors
== adapter
->num_rx_queues
+ adapter
->num_tx_queues
) {
1105 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
1106 map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
1108 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
1109 map_vector_to_txq(adapter
, v_start
, txr_idx
);
1114 * If we don't have enough vectors for a 1-to-1
1115 * mapping, we'll have to group them so there are
1116 * multiple queues per vector.
1118 /* Re-adjusting *qpv takes care of the remainder. */
1119 for (i
= v_start
; i
< q_vectors
; i
++) {
1120 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
1121 for (j
= 0; j
< rqpv
; j
++) {
1122 map_vector_to_rxq(adapter
, i
, rxr_idx
);
1127 for (i
= v_start
; i
< q_vectors
; i
++) {
1128 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
1129 for (j
= 0; j
< tqpv
; j
++) {
1130 map_vector_to_txq(adapter
, i
, txr_idx
);
1141 * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
1142 * @adapter: board private structure
1144 * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
1145 * interrupts from the kernel.
1147 static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter
*adapter
)
1149 struct net_device
*netdev
= adapter
->netdev
;
1150 irqreturn_t (*handler
)(int, void *);
1151 int i
, vector
, q_vectors
, err
;
1154 /* Decrement for Other and TCP Timer vectors */
1155 q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1157 #define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
1158 ? &ixgbevf_msix_clean_many : \
1159 (_v)->rxr_count ? &ixgbevf_msix_clean_rx : \
1160 (_v)->txr_count ? &ixgbevf_msix_clean_tx : \
1162 for (vector
= 0; vector
< q_vectors
; vector
++) {
1163 handler
= SET_HANDLER(adapter
->q_vector
[vector
]);
1165 if (handler
== &ixgbevf_msix_clean_rx
) {
1166 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1167 netdev
->name
, "rx", ri
++);
1168 } else if (handler
== &ixgbevf_msix_clean_tx
) {
1169 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1170 netdev
->name
, "tx", ti
++);
1171 } else if (handler
== &ixgbevf_msix_clean_many
) {
1172 sprintf(adapter
->name
[vector
], "%s-%s-%d",
1173 netdev
->name
, "TxRx", vector
);
1175 /* skip this unused q_vector */
1178 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1179 handler
, 0, adapter
->name
[vector
],
1180 adapter
->q_vector
[vector
]);
1182 hw_dbg(&adapter
->hw
,
1183 "request_irq failed for MSIX interrupt "
1184 "Error: %d\n", err
);
1185 goto free_queue_irqs
;
1189 sprintf(adapter
->name
[vector
], "%s:mbx", netdev
->name
);
1190 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
1191 &ixgbevf_msix_mbx
, 0, adapter
->name
[vector
], netdev
);
1193 hw_dbg(&adapter
->hw
,
1194 "request_irq for msix_mbx failed: %d\n", err
);
1195 goto free_queue_irqs
;
1201 for (i
= vector
- 1; i
>= 0; i
--)
1202 free_irq(adapter
->msix_entries
[--vector
].vector
,
1203 &(adapter
->q_vector
[i
]));
1204 pci_disable_msix(adapter
->pdev
);
1205 kfree(adapter
->msix_entries
);
1206 adapter
->msix_entries
= NULL
;
1210 static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter
*adapter
)
1212 int i
, q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1214 for (i
= 0; i
< q_vectors
; i
++) {
1215 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[i
];
1216 bitmap_zero(q_vector
->rxr_idx
, MAX_RX_QUEUES
);
1217 bitmap_zero(q_vector
->txr_idx
, MAX_TX_QUEUES
);
1218 q_vector
->rxr_count
= 0;
1219 q_vector
->txr_count
= 0;
1220 q_vector
->eitr
= adapter
->eitr_param
;
1225 * ixgbevf_request_irq - initialize interrupts
1226 * @adapter: board private structure
1228 * Attempts to configure interrupts using the best available
1229 * capabilities of the hardware and kernel.
1231 static int ixgbevf_request_irq(struct ixgbevf_adapter
*adapter
)
1235 err
= ixgbevf_request_msix_irqs(adapter
);
1238 hw_dbg(&adapter
->hw
,
1239 "request_irq failed, Error %d\n", err
);
1244 static void ixgbevf_free_irq(struct ixgbevf_adapter
*adapter
)
1246 struct net_device
*netdev
= adapter
->netdev
;
1249 q_vectors
= adapter
->num_msix_vectors
;
1253 free_irq(adapter
->msix_entries
[i
].vector
, netdev
);
1256 for (; i
>= 0; i
--) {
1257 free_irq(adapter
->msix_entries
[i
].vector
,
1258 adapter
->q_vector
[i
]);
1261 ixgbevf_reset_q_vectors(adapter
);
1265 * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
1266 * @adapter: board private structure
1268 static inline void ixgbevf_irq_disable(struct ixgbevf_adapter
*adapter
)
1271 struct ixgbe_hw
*hw
= &adapter
->hw
;
1273 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, ~0);
1275 IXGBE_WRITE_FLUSH(hw
);
1277 for (i
= 0; i
< adapter
->num_msix_vectors
; i
++)
1278 synchronize_irq(adapter
->msix_entries
[i
].vector
);
1282 * ixgbevf_irq_enable - Enable default interrupt generation settings
1283 * @adapter: board private structure
1285 static inline void ixgbevf_irq_enable(struct ixgbevf_adapter
*adapter
,
1286 bool queues
, bool flush
)
1288 struct ixgbe_hw
*hw
= &adapter
->hw
;
1292 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
1295 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMS
, mask
);
1298 ixgbevf_irq_enable_queues(adapter
, qmask
);
1301 IXGBE_WRITE_FLUSH(hw
);
1305 * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
1306 * @adapter: board private structure
1308 * Configure the Tx unit of the MAC after a reset.
1310 static void ixgbevf_configure_tx(struct ixgbevf_adapter
*adapter
)
1313 struct ixgbe_hw
*hw
= &adapter
->hw
;
1314 u32 i
, j
, tdlen
, txctrl
;
1316 /* Setup the HW Tx Head and Tail descriptor pointers */
1317 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1318 struct ixgbevf_ring
*ring
= &adapter
->tx_ring
[i
];
1321 tdlen
= ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
1322 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAL(j
),
1323 (tdba
& DMA_BIT_MASK(32)));
1324 IXGBE_WRITE_REG(hw
, IXGBE_VFTDBAH(j
), (tdba
>> 32));
1325 IXGBE_WRITE_REG(hw
, IXGBE_VFTDLEN(j
), tdlen
);
1326 IXGBE_WRITE_REG(hw
, IXGBE_VFTDH(j
), 0);
1327 IXGBE_WRITE_REG(hw
, IXGBE_VFTDT(j
), 0);
1328 adapter
->tx_ring
[i
].head
= IXGBE_VFTDH(j
);
1329 adapter
->tx_ring
[i
].tail
= IXGBE_VFTDT(j
);
1330 /* Disable Tx Head Writeback RO bit, since this hoses
1331 * bookkeeping if things aren't delivered in order.
1333 txctrl
= IXGBE_READ_REG(hw
, IXGBE_VFDCA_TXCTRL(j
));
1334 txctrl
&= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN
;
1335 IXGBE_WRITE_REG(hw
, IXGBE_VFDCA_TXCTRL(j
), txctrl
);
1339 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1341 static void ixgbevf_configure_srrctl(struct ixgbevf_adapter
*adapter
, int index
)
1343 struct ixgbevf_ring
*rx_ring
;
1344 struct ixgbe_hw
*hw
= &adapter
->hw
;
1347 rx_ring
= &adapter
->rx_ring
[index
];
1349 srrctl
= IXGBE_SRRCTL_DROP_EN
;
1351 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1352 u16 bufsz
= IXGBEVF_RXBUFFER_2048
;
1353 /* grow the amount we can receive on large page machines */
1354 if (bufsz
< (PAGE_SIZE
/ 2))
1355 bufsz
= (PAGE_SIZE
/ 2);
1356 /* cap the bufsz at our largest descriptor size */
1357 bufsz
= min((u16
)IXGBEVF_MAX_RXBUFFER
, bufsz
);
1359 srrctl
|= bufsz
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1360 srrctl
|= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
1361 srrctl
|= ((IXGBEVF_RX_HDR_SIZE
<<
1362 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
) &
1363 IXGBE_SRRCTL_BSIZEHDR_MASK
);
1365 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1367 if (rx_ring
->rx_buf_len
== MAXIMUM_ETHERNET_VLAN_SIZE
)
1368 srrctl
|= IXGBEVF_RXBUFFER_2048
>>
1369 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1371 srrctl
|= rx_ring
->rx_buf_len
>>
1372 IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
1374 IXGBE_WRITE_REG(hw
, IXGBE_VFSRRCTL(index
), srrctl
);
1378 * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
1379 * @adapter: board private structure
1381 * Configure the Rx unit of the MAC after a reset.
1383 static void ixgbevf_configure_rx(struct ixgbevf_adapter
*adapter
)
1386 struct ixgbe_hw
*hw
= &adapter
->hw
;
1387 struct net_device
*netdev
= adapter
->netdev
;
1388 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1393 /* Decide whether to use packet split mode or not */
1394 if (netdev
->mtu
> ETH_DATA_LEN
) {
1395 if (adapter
->flags
& IXGBE_FLAG_RX_PS_CAPABLE
)
1396 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
1398 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
1400 if (adapter
->flags
& IXGBE_FLAG_RX_1BUF_CAPABLE
)
1401 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
1403 adapter
->flags
|= IXGBE_FLAG_RX_PS_ENABLED
;
1406 /* Set the RX buffer length according to the mode */
1407 if (adapter
->flags
& IXGBE_FLAG_RX_PS_ENABLED
) {
1408 /* PSRTYPE must be initialized in 82599 */
1409 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
1410 IXGBE_PSRTYPE_UDPHDR
|
1411 IXGBE_PSRTYPE_IPV4HDR
|
1412 IXGBE_PSRTYPE_IPV6HDR
|
1413 IXGBE_PSRTYPE_L2HDR
;
1414 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, psrtype
);
1415 rx_buf_len
= IXGBEVF_RX_HDR_SIZE
;
1417 IXGBE_WRITE_REG(hw
, IXGBE_VFPSRTYPE
, 0);
1418 if (netdev
->mtu
<= ETH_DATA_LEN
)
1419 rx_buf_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1421 rx_buf_len
= ALIGN(max_frame
, 1024);
1424 rdlen
= adapter
->rx_ring
[0].count
* sizeof(union ixgbe_adv_rx_desc
);
1425 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1426 * the Base and Length of the Rx Descriptor Ring */
1427 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1428 rdba
= adapter
->rx_ring
[i
].dma
;
1429 j
= adapter
->rx_ring
[i
].reg_idx
;
1430 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAL(j
),
1431 (rdba
& DMA_BIT_MASK(32)));
1432 IXGBE_WRITE_REG(hw
, IXGBE_VFRDBAH(j
), (rdba
>> 32));
1433 IXGBE_WRITE_REG(hw
, IXGBE_VFRDLEN(j
), rdlen
);
1434 IXGBE_WRITE_REG(hw
, IXGBE_VFRDH(j
), 0);
1435 IXGBE_WRITE_REG(hw
, IXGBE_VFRDT(j
), 0);
1436 adapter
->rx_ring
[i
].head
= IXGBE_VFRDH(j
);
1437 adapter
->rx_ring
[i
].tail
= IXGBE_VFRDT(j
);
1438 adapter
->rx_ring
[i
].rx_buf_len
= rx_buf_len
;
1440 ixgbevf_configure_srrctl(adapter
, j
);
1444 static void ixgbevf_vlan_rx_register(struct net_device
*netdev
,
1445 struct vlan_group
*grp
)
1447 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1448 struct ixgbe_hw
*hw
= &adapter
->hw
;
1452 adapter
->vlgrp
= grp
;
1454 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1455 j
= adapter
->rx_ring
[i
].reg_idx
;
1456 ctrl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1457 ctrl
|= IXGBE_RXDCTL_VME
;
1458 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), ctrl
);
1462 static void ixgbevf_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
1464 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1465 struct ixgbe_hw
*hw
= &adapter
->hw
;
1466 struct net_device
*v_netdev
;
1468 /* add VID to filter table */
1469 if (hw
->mac
.ops
.set_vfta
)
1470 hw
->mac
.ops
.set_vfta(hw
, vid
, 0, true);
1472 * Copy feature flags from netdev to the vlan netdev for this vid.
1473 * This allows things like TSO to bubble down to our vlan device.
1475 v_netdev
= vlan_group_get_device(adapter
->vlgrp
, vid
);
1476 v_netdev
->features
|= adapter
->netdev
->features
;
1477 vlan_group_set_device(adapter
->vlgrp
, vid
, v_netdev
);
1480 static void ixgbevf_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
1482 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1483 struct ixgbe_hw
*hw
= &adapter
->hw
;
1485 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
1486 ixgbevf_irq_disable(adapter
);
1488 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
1490 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
1491 ixgbevf_irq_enable(adapter
, true, true);
1493 /* remove VID from filter table */
1494 if (hw
->mac
.ops
.set_vfta
)
1495 hw
->mac
.ops
.set_vfta(hw
, vid
, 0, false);
1498 static void ixgbevf_restore_vlan(struct ixgbevf_adapter
*adapter
)
1500 ixgbevf_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
1502 if (adapter
->vlgrp
) {
1504 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
1505 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
1507 ixgbevf_vlan_rx_add_vid(adapter
->netdev
, vid
);
1513 * ixgbevf_set_rx_mode - Multicast set
1514 * @netdev: network interface device structure
1516 * The set_rx_method entry point is called whenever the multicast address
1517 * list or the network interface flags are updated. This routine is
1518 * responsible for configuring the hardware for proper multicast mode.
1520 static void ixgbevf_set_rx_mode(struct net_device
*netdev
)
1522 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
1523 struct ixgbe_hw
*hw
= &adapter
->hw
;
1525 /* reprogram multicast list */
1526 if (hw
->mac
.ops
.update_mc_addr_list
)
1527 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
1530 static void ixgbevf_napi_enable_all(struct ixgbevf_adapter
*adapter
)
1533 struct ixgbevf_q_vector
*q_vector
;
1534 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1536 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1537 struct napi_struct
*napi
;
1538 q_vector
= adapter
->q_vector
[q_idx
];
1539 if (!q_vector
->rxr_count
)
1541 napi
= &q_vector
->napi
;
1542 if (q_vector
->rxr_count
> 1)
1543 napi
->poll
= &ixgbevf_clean_rxonly_many
;
1549 static void ixgbevf_napi_disable_all(struct ixgbevf_adapter
*adapter
)
1552 struct ixgbevf_q_vector
*q_vector
;
1553 int q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
1555 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
1556 q_vector
= adapter
->q_vector
[q_idx
];
1557 if (!q_vector
->rxr_count
)
1559 napi_disable(&q_vector
->napi
);
1563 static void ixgbevf_configure(struct ixgbevf_adapter
*adapter
)
1565 struct net_device
*netdev
= adapter
->netdev
;
1568 ixgbevf_set_rx_mode(netdev
);
1570 ixgbevf_restore_vlan(adapter
);
1572 ixgbevf_configure_tx(adapter
);
1573 ixgbevf_configure_rx(adapter
);
1574 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1575 struct ixgbevf_ring
*ring
= &adapter
->rx_ring
[i
];
1576 ixgbevf_alloc_rx_buffers(adapter
, ring
, ring
->count
);
1577 ring
->next_to_use
= ring
->count
- 1;
1578 writel(ring
->next_to_use
, adapter
->hw
.hw_addr
+ ring
->tail
);
1582 #define IXGBE_MAX_RX_DESC_POLL 10
1583 static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter
*adapter
,
1586 struct ixgbe_hw
*hw
= &adapter
->hw
;
1587 int j
= adapter
->rx_ring
[rxr
].reg_idx
;
1590 for (k
= 0; k
< IXGBE_MAX_RX_DESC_POLL
; k
++) {
1591 if (IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
)) & IXGBE_RXDCTL_ENABLE
)
1596 if (k
>= IXGBE_MAX_RX_DESC_POLL
) {
1597 hw_dbg(hw
, "RXDCTL.ENABLE on Rx queue %d "
1598 "not set within the polling period\n", rxr
);
1601 ixgbevf_release_rx_desc(&adapter
->hw
, &adapter
->rx_ring
[rxr
],
1602 (adapter
->rx_ring
[rxr
].count
- 1));
1605 static void ixgbevf_save_reset_stats(struct ixgbevf_adapter
*adapter
)
1607 /* Only save pre-reset stats if there are some */
1608 if (adapter
->stats
.vfgprc
|| adapter
->stats
.vfgptc
) {
1609 adapter
->stats
.saved_reset_vfgprc
+= adapter
->stats
.vfgprc
-
1610 adapter
->stats
.base_vfgprc
;
1611 adapter
->stats
.saved_reset_vfgptc
+= adapter
->stats
.vfgptc
-
1612 adapter
->stats
.base_vfgptc
;
1613 adapter
->stats
.saved_reset_vfgorc
+= adapter
->stats
.vfgorc
-
1614 adapter
->stats
.base_vfgorc
;
1615 adapter
->stats
.saved_reset_vfgotc
+= adapter
->stats
.vfgotc
-
1616 adapter
->stats
.base_vfgotc
;
1617 adapter
->stats
.saved_reset_vfmprc
+= adapter
->stats
.vfmprc
-
1618 adapter
->stats
.base_vfmprc
;
1622 static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter
*adapter
)
1624 struct ixgbe_hw
*hw
= &adapter
->hw
;
1626 adapter
->stats
.last_vfgprc
= IXGBE_READ_REG(hw
, IXGBE_VFGPRC
);
1627 adapter
->stats
.last_vfgorc
= IXGBE_READ_REG(hw
, IXGBE_VFGORC_LSB
);
1628 adapter
->stats
.last_vfgorc
|=
1629 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGORC_MSB
))) << 32);
1630 adapter
->stats
.last_vfgptc
= IXGBE_READ_REG(hw
, IXGBE_VFGPTC
);
1631 adapter
->stats
.last_vfgotc
= IXGBE_READ_REG(hw
, IXGBE_VFGOTC_LSB
);
1632 adapter
->stats
.last_vfgotc
|=
1633 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_VFGOTC_MSB
))) << 32);
1634 adapter
->stats
.last_vfmprc
= IXGBE_READ_REG(hw
, IXGBE_VFMPRC
);
1636 adapter
->stats
.base_vfgprc
= adapter
->stats
.last_vfgprc
;
1637 adapter
->stats
.base_vfgorc
= adapter
->stats
.last_vfgorc
;
1638 adapter
->stats
.base_vfgptc
= adapter
->stats
.last_vfgptc
;
1639 adapter
->stats
.base_vfgotc
= adapter
->stats
.last_vfgotc
;
1640 adapter
->stats
.base_vfmprc
= adapter
->stats
.last_vfmprc
;
1643 static int ixgbevf_up_complete(struct ixgbevf_adapter
*adapter
)
1645 struct net_device
*netdev
= adapter
->netdev
;
1646 struct ixgbe_hw
*hw
= &adapter
->hw
;
1648 int num_rx_rings
= adapter
->num_rx_queues
;
1651 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1652 j
= adapter
->tx_ring
[i
].reg_idx
;
1653 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1654 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
1655 txdctl
|= (8 << 16);
1656 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1659 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1660 j
= adapter
->tx_ring
[i
].reg_idx
;
1661 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1662 txdctl
|= IXGBE_TXDCTL_ENABLE
;
1663 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
), txdctl
);
1666 for (i
= 0; i
< num_rx_rings
; i
++) {
1667 j
= adapter
->rx_ring
[i
].reg_idx
;
1668 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(j
));
1669 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
1670 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(j
), rxdctl
);
1671 ixgbevf_rx_desc_queue_enable(adapter
, i
);
1674 ixgbevf_configure_msix(adapter
);
1676 if (hw
->mac
.ops
.set_rar
) {
1677 if (is_valid_ether_addr(hw
->mac
.addr
))
1678 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
1680 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.perm_addr
, 0);
1683 clear_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1684 ixgbevf_napi_enable_all(adapter
);
1686 /* enable transmits */
1687 netif_tx_start_all_queues(netdev
);
1689 ixgbevf_save_reset_stats(adapter
);
1690 ixgbevf_init_last_counter_stats(adapter
);
1692 /* bring the link up in the watchdog, this could race with our first
1693 * link up interrupt but shouldn't be a problem */
1694 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
1695 adapter
->link_check_timeout
= jiffies
;
1696 mod_timer(&adapter
->watchdog_timer
, jiffies
);
1700 int ixgbevf_up(struct ixgbevf_adapter
*adapter
)
1703 struct ixgbe_hw
*hw
= &adapter
->hw
;
1705 ixgbevf_configure(adapter
);
1707 err
= ixgbevf_up_complete(adapter
);
1709 /* clear any pending interrupts, may auto mask */
1710 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
1712 ixgbevf_irq_enable(adapter
, true, true);
1718 * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
1719 * @adapter: board private structure
1720 * @rx_ring: ring to free buffers from
1722 static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter
*adapter
,
1723 struct ixgbevf_ring
*rx_ring
)
1725 struct pci_dev
*pdev
= adapter
->pdev
;
1729 if (!rx_ring
->rx_buffer_info
)
1732 /* Free all the Rx ring sk_buffs */
1733 for (i
= 0; i
< rx_ring
->count
; i
++) {
1734 struct ixgbevf_rx_buffer
*rx_buffer_info
;
1736 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
1737 if (rx_buffer_info
->dma
) {
1738 dma_unmap_single(&pdev
->dev
, rx_buffer_info
->dma
,
1739 rx_ring
->rx_buf_len
,
1741 rx_buffer_info
->dma
= 0;
1743 if (rx_buffer_info
->skb
) {
1744 struct sk_buff
*skb
= rx_buffer_info
->skb
;
1745 rx_buffer_info
->skb
= NULL
;
1747 struct sk_buff
*this = skb
;
1749 dev_kfree_skb(this);
1752 if (!rx_buffer_info
->page
)
1754 dma_unmap_page(&pdev
->dev
, rx_buffer_info
->page_dma
,
1755 PAGE_SIZE
/ 2, DMA_FROM_DEVICE
);
1756 rx_buffer_info
->page_dma
= 0;
1757 put_page(rx_buffer_info
->page
);
1758 rx_buffer_info
->page
= NULL
;
1759 rx_buffer_info
->page_offset
= 0;
1762 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
1763 memset(rx_ring
->rx_buffer_info
, 0, size
);
1765 /* Zero out the descriptor ring */
1766 memset(rx_ring
->desc
, 0, rx_ring
->size
);
1768 rx_ring
->next_to_clean
= 0;
1769 rx_ring
->next_to_use
= 0;
1772 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
1774 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
1778 * ixgbevf_clean_tx_ring - Free Tx Buffers
1779 * @adapter: board private structure
1780 * @tx_ring: ring to be cleaned
1782 static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter
*adapter
,
1783 struct ixgbevf_ring
*tx_ring
)
1785 struct ixgbevf_tx_buffer
*tx_buffer_info
;
1789 if (!tx_ring
->tx_buffer_info
)
1792 /* Free all the Tx ring sk_buffs */
1794 for (i
= 0; i
< tx_ring
->count
; i
++) {
1795 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
1796 ixgbevf_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
1799 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
1800 memset(tx_ring
->tx_buffer_info
, 0, size
);
1802 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1804 tx_ring
->next_to_use
= 0;
1805 tx_ring
->next_to_clean
= 0;
1808 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1810 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1814 * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
1815 * @adapter: board private structure
1817 static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter
*adapter
)
1821 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1822 ixgbevf_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
1826 * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
1827 * @adapter: board private structure
1829 static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter
*adapter
)
1833 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1834 ixgbevf_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1837 void ixgbevf_down(struct ixgbevf_adapter
*adapter
)
1839 struct net_device
*netdev
= adapter
->netdev
;
1840 struct ixgbe_hw
*hw
= &adapter
->hw
;
1844 /* signal that we are down to the interrupt handler */
1845 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
1846 /* disable receives */
1848 netif_tx_disable(netdev
);
1852 netif_tx_stop_all_queues(netdev
);
1854 ixgbevf_irq_disable(adapter
);
1856 ixgbevf_napi_disable_all(adapter
);
1858 del_timer_sync(&adapter
->watchdog_timer
);
1859 /* can't call flush scheduled work here because it can deadlock
1860 * if linkwatch_event tries to acquire the rtnl_lock which we are
1862 while (adapter
->flags
& IXGBE_FLAG_IN_WATCHDOG_TASK
)
1865 /* disable transmits in the hardware now that interrupts are off */
1866 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1867 j
= adapter
->tx_ring
[i
].reg_idx
;
1868 txdctl
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(j
));
1869 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(j
),
1870 (txdctl
& ~IXGBE_TXDCTL_ENABLE
));
1873 netif_carrier_off(netdev
);
1875 if (!pci_channel_offline(adapter
->pdev
))
1876 ixgbevf_reset(adapter
);
1878 ixgbevf_clean_all_tx_rings(adapter
);
1879 ixgbevf_clean_all_rx_rings(adapter
);
1882 void ixgbevf_reinit_locked(struct ixgbevf_adapter
*adapter
)
1884 struct ixgbe_hw
*hw
= &adapter
->hw
;
1886 WARN_ON(in_interrupt());
1888 while (test_and_set_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
1892 * Check if PF is up before re-init. If not then skip until
1893 * later when the PF is up and ready to service requests from
1894 * the VF via mailbox. If the VF is up and running then the
1895 * watchdog task will continue to schedule reset tasks until
1896 * the PF is up and running.
1898 if (!hw
->mac
.ops
.reset_hw(hw
)) {
1899 ixgbevf_down(adapter
);
1900 ixgbevf_up(adapter
);
1903 clear_bit(__IXGBEVF_RESETTING
, &adapter
->state
);
1906 void ixgbevf_reset(struct ixgbevf_adapter
*adapter
)
1908 struct ixgbe_hw
*hw
= &adapter
->hw
;
1909 struct net_device
*netdev
= adapter
->netdev
;
1911 if (hw
->mac
.ops
.reset_hw(hw
))
1912 hw_dbg(hw
, "PF still resetting\n");
1914 hw
->mac
.ops
.init_hw(hw
);
1916 if (is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
1917 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
,
1919 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
,
1924 static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter
*adapter
,
1927 int err
, vector_threshold
;
1929 /* We'll want at least 3 (vector_threshold):
1932 * 3) Other (Link Status Change, etc.)
1934 vector_threshold
= MIN_MSIX_COUNT
;
1936 /* The more we get, the more we will assign to Tx/Rx Cleanup
1937 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1938 * Right now, we simply care about how many we'll get; we'll
1939 * set them up later while requesting irq's.
1941 while (vectors
>= vector_threshold
) {
1942 err
= pci_enable_msix(adapter
->pdev
, adapter
->msix_entries
,
1944 if (!err
) /* Success in acquiring all requested vectors. */
1947 vectors
= 0; /* Nasty failure, quit now */
1948 else /* err == number of vectors we should try again with */
1952 if (vectors
< vector_threshold
) {
1953 /* Can't allocate enough MSI-X interrupts? Oh well.
1954 * This just means we'll go with either a single MSI
1955 * vector or fall back to legacy interrupts.
1957 hw_dbg(&adapter
->hw
,
1958 "Unable to allocate MSI-X interrupts\n");
1959 kfree(adapter
->msix_entries
);
1960 adapter
->msix_entries
= NULL
;
1963 * Adjust for only the vectors we'll use, which is minimum
1964 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
1965 * vectors we were allocated.
1967 adapter
->num_msix_vectors
= vectors
;
1972 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
1973 * @adapter: board private structure to initialize
1975 * This is the top level queue allocation routine. The order here is very
1976 * important, starting with the "most" number of features turned on at once,
1977 * and ending with the smallest set of features. This way large combinations
1978 * can be allocated if they're turned on, and smaller combinations are the
1979 * fallthrough conditions.
1982 static void ixgbevf_set_num_queues(struct ixgbevf_adapter
*adapter
)
1984 /* Start with base case */
1985 adapter
->num_rx_queues
= 1;
1986 adapter
->num_tx_queues
= 1;
1987 adapter
->num_rx_pools
= adapter
->num_rx_queues
;
1988 adapter
->num_rx_queues_per_pool
= 1;
1992 * ixgbevf_alloc_queues - Allocate memory for all rings
1993 * @adapter: board private structure to initialize
1995 * We allocate one ring per queue at run-time since we don't know the
1996 * number of queues at compile-time. The polling_netdev array is
1997 * intended for Multiqueue, but should work fine with a single queue.
1999 static int ixgbevf_alloc_queues(struct ixgbevf_adapter
*adapter
)
2003 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
2004 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
2005 if (!adapter
->tx_ring
)
2006 goto err_tx_ring_allocation
;
2008 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
2009 sizeof(struct ixgbevf_ring
), GFP_KERNEL
);
2010 if (!adapter
->rx_ring
)
2011 goto err_rx_ring_allocation
;
2013 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2014 adapter
->tx_ring
[i
].count
= adapter
->tx_ring_count
;
2015 adapter
->tx_ring
[i
].queue_index
= i
;
2016 adapter
->tx_ring
[i
].reg_idx
= i
;
2019 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2020 adapter
->rx_ring
[i
].count
= adapter
->rx_ring_count
;
2021 adapter
->rx_ring
[i
].queue_index
= i
;
2022 adapter
->rx_ring
[i
].reg_idx
= i
;
2027 err_rx_ring_allocation
:
2028 kfree(adapter
->tx_ring
);
2029 err_tx_ring_allocation
:
2034 * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
2035 * @adapter: board private structure to initialize
2037 * Attempt to configure the interrupts using the best available
2038 * capabilities of the hardware and the kernel.
2040 static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter
*adapter
)
2043 int vector
, v_budget
;
2046 * It's easy to be greedy for MSI-X vectors, but it really
2047 * doesn't do us much good if we have a lot more vectors
2048 * than CPU's. So let's be conservative and only ask for
2049 * (roughly) twice the number of vectors as there are CPU's.
2051 v_budget
= min(adapter
->num_rx_queues
+ adapter
->num_tx_queues
,
2052 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS
;
2054 /* A failure in MSI-X entry allocation isn't fatal, but it does
2055 * mean we disable MSI-X capabilities of the adapter. */
2056 adapter
->msix_entries
= kcalloc(v_budget
,
2057 sizeof(struct msix_entry
), GFP_KERNEL
);
2058 if (!adapter
->msix_entries
) {
2063 for (vector
= 0; vector
< v_budget
; vector
++)
2064 adapter
->msix_entries
[vector
].entry
= vector
;
2066 ixgbevf_acquire_msix_vectors(adapter
, v_budget
);
2073 * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
2074 * @adapter: board private structure to initialize
2076 * We allocate one q_vector per queue interrupt. If allocation fails we
2079 static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter
*adapter
)
2081 int q_idx
, num_q_vectors
;
2082 struct ixgbevf_q_vector
*q_vector
;
2084 int (*poll
)(struct napi_struct
*, int);
2086 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2087 napi_vectors
= adapter
->num_rx_queues
;
2088 poll
= &ixgbevf_clean_rxonly
;
2090 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
2091 q_vector
= kzalloc(sizeof(struct ixgbevf_q_vector
), GFP_KERNEL
);
2094 q_vector
->adapter
= adapter
;
2095 q_vector
->v_idx
= q_idx
;
2096 q_vector
->eitr
= adapter
->eitr_param
;
2097 if (q_idx
< napi_vectors
)
2098 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
2100 adapter
->q_vector
[q_idx
] = q_vector
;
2108 q_vector
= adapter
->q_vector
[q_idx
];
2109 netif_napi_del(&q_vector
->napi
);
2111 adapter
->q_vector
[q_idx
] = NULL
;
2117 * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
2118 * @adapter: board private structure to initialize
2120 * This function frees the memory allocated to the q_vectors. In addition if
2121 * NAPI is enabled it will delete any references to the NAPI struct prior
2122 * to freeing the q_vector.
2124 static void ixgbevf_free_q_vectors(struct ixgbevf_adapter
*adapter
)
2126 int q_idx
, num_q_vectors
;
2129 num_q_vectors
= adapter
->num_msix_vectors
- NON_Q_VECTORS
;
2130 napi_vectors
= adapter
->num_rx_queues
;
2132 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
2133 struct ixgbevf_q_vector
*q_vector
= adapter
->q_vector
[q_idx
];
2135 adapter
->q_vector
[q_idx
] = NULL
;
2136 if (q_idx
< napi_vectors
)
2137 netif_napi_del(&q_vector
->napi
);
2143 * ixgbevf_reset_interrupt_capability - Reset MSIX setup
2144 * @adapter: board private structure
2147 static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter
*adapter
)
2149 pci_disable_msix(adapter
->pdev
);
2150 kfree(adapter
->msix_entries
);
2151 adapter
->msix_entries
= NULL
;
2155 * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
2156 * @adapter: board private structure to initialize
2159 static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter
*adapter
)
2163 /* Number of supported queues */
2164 ixgbevf_set_num_queues(adapter
);
2166 err
= ixgbevf_set_interrupt_capability(adapter
);
2168 hw_dbg(&adapter
->hw
,
2169 "Unable to setup interrupt capabilities\n");
2170 goto err_set_interrupt
;
2173 err
= ixgbevf_alloc_q_vectors(adapter
);
2175 hw_dbg(&adapter
->hw
, "Unable to allocate memory for queue "
2177 goto err_alloc_q_vectors
;
2180 err
= ixgbevf_alloc_queues(adapter
);
2182 printk(KERN_ERR
"Unable to allocate memory for queues\n");
2183 goto err_alloc_queues
;
2186 hw_dbg(&adapter
->hw
, "Multiqueue %s: Rx Queue count = %u, "
2187 "Tx Queue count = %u\n",
2188 (adapter
->num_rx_queues
> 1) ? "Enabled" :
2189 "Disabled", adapter
->num_rx_queues
, adapter
->num_tx_queues
);
2191 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2195 ixgbevf_free_q_vectors(adapter
);
2196 err_alloc_q_vectors
:
2197 ixgbevf_reset_interrupt_capability(adapter
);
2203 * ixgbevf_sw_init - Initialize general software structures
2204 * (struct ixgbevf_adapter)
2205 * @adapter: board private structure to initialize
2207 * ixgbevf_sw_init initializes the Adapter private data structure.
2208 * Fields are initialized based on PCI device information and
2209 * OS network device settings (MTU size).
2211 static int __devinit
ixgbevf_sw_init(struct ixgbevf_adapter
*adapter
)
2213 struct ixgbe_hw
*hw
= &adapter
->hw
;
2214 struct pci_dev
*pdev
= adapter
->pdev
;
2217 /* PCI config space info */
2219 hw
->vendor_id
= pdev
->vendor
;
2220 hw
->device_id
= pdev
->device
;
2221 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2222 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2223 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2225 hw
->mbx
.ops
.init_params(hw
);
2226 hw
->mac
.max_tx_queues
= MAX_TX_QUEUES
;
2227 hw
->mac
.max_rx_queues
= MAX_RX_QUEUES
;
2228 err
= hw
->mac
.ops
.reset_hw(hw
);
2230 dev_info(&pdev
->dev
,
2231 "PF still in reset state, assigning new address\n");
2232 random_ether_addr(hw
->mac
.addr
);
2234 err
= hw
->mac
.ops
.init_hw(hw
);
2236 printk(KERN_ERR
"init_shared_code failed: %d\n", err
);
2241 /* Enable dynamic interrupt throttling rates */
2242 adapter
->eitr_param
= 20000;
2243 adapter
->itr_setting
= 1;
2245 /* set defaults for eitr in MegaBytes */
2246 adapter
->eitr_low
= 10;
2247 adapter
->eitr_high
= 20;
2249 /* set default ring sizes */
2250 adapter
->tx_ring_count
= IXGBEVF_DEFAULT_TXD
;
2251 adapter
->rx_ring_count
= IXGBEVF_DEFAULT_RXD
;
2253 /* enable rx csum by default */
2254 adapter
->flags
|= IXGBE_FLAG_RX_CSUM_ENABLED
;
2256 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
2262 #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
2264 u32 current_counter = IXGBE_READ_REG(hw, reg); \
2265 if (current_counter < last_counter) \
2266 counter += 0x100000000LL; \
2267 last_counter = current_counter; \
2268 counter &= 0xFFFFFFFF00000000LL; \
2269 counter |= current_counter; \
2272 #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
2274 u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
2275 u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
2276 u64 current_counter = (current_counter_msb << 32) | \
2277 current_counter_lsb; \
2278 if (current_counter < last_counter) \
2279 counter += 0x1000000000LL; \
2280 last_counter = current_counter; \
2281 counter &= 0xFFFFFFF000000000LL; \
2282 counter |= current_counter; \
2285 * ixgbevf_update_stats - Update the board statistics counters.
2286 * @adapter: board private structure
2288 void ixgbevf_update_stats(struct ixgbevf_adapter
*adapter
)
2290 struct ixgbe_hw
*hw
= &adapter
->hw
;
2292 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC
, adapter
->stats
.last_vfgprc
,
2293 adapter
->stats
.vfgprc
);
2294 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC
, adapter
->stats
.last_vfgptc
,
2295 adapter
->stats
.vfgptc
);
2296 UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB
, IXGBE_VFGORC_MSB
,
2297 adapter
->stats
.last_vfgorc
,
2298 adapter
->stats
.vfgorc
);
2299 UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB
, IXGBE_VFGOTC_MSB
,
2300 adapter
->stats
.last_vfgotc
,
2301 adapter
->stats
.vfgotc
);
2302 UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC
, adapter
->stats
.last_vfmprc
,
2303 adapter
->stats
.vfmprc
);
2305 /* Fill out the OS statistics structure */
2306 adapter
->net_stats
.multicast
= adapter
->stats
.vfmprc
-
2307 adapter
->stats
.base_vfmprc
;
2311 * ixgbevf_watchdog - Timer Call-back
2312 * @data: pointer to adapter cast into an unsigned long
2314 static void ixgbevf_watchdog(unsigned long data
)
2316 struct ixgbevf_adapter
*adapter
= (struct ixgbevf_adapter
*)data
;
2317 struct ixgbe_hw
*hw
= &adapter
->hw
;
2322 * Do the watchdog outside of interrupt context due to the lovely
2323 * delays that some of the newer hardware requires
2326 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2327 goto watchdog_short_circuit
;
2329 /* get one bit for every active tx/rx interrupt vector */
2330 for (i
= 0; i
< adapter
->num_msix_vectors
- NON_Q_VECTORS
; i
++) {
2331 struct ixgbevf_q_vector
*qv
= adapter
->q_vector
[i
];
2332 if (qv
->rxr_count
|| qv
->txr_count
)
2336 IXGBE_WRITE_REG(hw
, IXGBE_VTEICS
, (u32
)eics
);
2338 watchdog_short_circuit
:
2339 schedule_work(&adapter
->watchdog_task
);
2343 * ixgbevf_tx_timeout - Respond to a Tx Hang
2344 * @netdev: network interface device structure
2346 static void ixgbevf_tx_timeout(struct net_device
*netdev
)
2348 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2350 /* Do the reset outside of interrupt context */
2351 schedule_work(&adapter
->reset_task
);
2354 static void ixgbevf_reset_task(struct work_struct
*work
)
2356 struct ixgbevf_adapter
*adapter
;
2357 adapter
= container_of(work
, struct ixgbevf_adapter
, reset_task
);
2359 /* If we're already down or resetting, just bail */
2360 if (test_bit(__IXGBEVF_DOWN
, &adapter
->state
) ||
2361 test_bit(__IXGBEVF_RESETTING
, &adapter
->state
))
2364 adapter
->tx_timeout_count
++;
2366 ixgbevf_reinit_locked(adapter
);
2370 * ixgbevf_watchdog_task - worker thread to bring link up
2371 * @work: pointer to work_struct containing our data
2373 static void ixgbevf_watchdog_task(struct work_struct
*work
)
2375 struct ixgbevf_adapter
*adapter
= container_of(work
,
2376 struct ixgbevf_adapter
,
2378 struct net_device
*netdev
= adapter
->netdev
;
2379 struct ixgbe_hw
*hw
= &adapter
->hw
;
2380 u32 link_speed
= adapter
->link_speed
;
2381 bool link_up
= adapter
->link_up
;
2383 adapter
->flags
|= IXGBE_FLAG_IN_WATCHDOG_TASK
;
2386 * Always check the link on the watchdog because we have
2389 if (hw
->mac
.ops
.check_link
) {
2390 if ((hw
->mac
.ops
.check_link(hw
, &link_speed
,
2391 &link_up
, false)) != 0) {
2392 adapter
->link_up
= link_up
;
2393 adapter
->link_speed
= link_speed
;
2394 netif_carrier_off(netdev
);
2395 netif_tx_stop_all_queues(netdev
);
2396 schedule_work(&adapter
->reset_task
);
2400 /* always assume link is up, if no check link
2402 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
2405 adapter
->link_up
= link_up
;
2406 adapter
->link_speed
= link_speed
;
2409 if (!netif_carrier_ok(netdev
)) {
2410 hw_dbg(&adapter
->hw
, "NIC Link is Up, %u Gbps\n",
2411 (link_speed
== IXGBE_LINK_SPEED_10GB_FULL
) ?
2413 netif_carrier_on(netdev
);
2414 netif_tx_wake_all_queues(netdev
);
2416 /* Force detection of hung controller */
2417 adapter
->detect_tx_hung
= true;
2420 adapter
->link_up
= false;
2421 adapter
->link_speed
= 0;
2422 if (netif_carrier_ok(netdev
)) {
2423 hw_dbg(&adapter
->hw
, "NIC Link is Down\n");
2424 netif_carrier_off(netdev
);
2425 netif_tx_stop_all_queues(netdev
);
2429 ixgbevf_update_stats(adapter
);
2432 /* Force detection of hung controller every watchdog period */
2433 adapter
->detect_tx_hung
= true;
2435 /* Reset the timer */
2436 if (!test_bit(__IXGBEVF_DOWN
, &adapter
->state
))
2437 mod_timer(&adapter
->watchdog_timer
,
2438 round_jiffies(jiffies
+ (2 * HZ
)));
2440 adapter
->flags
&= ~IXGBE_FLAG_IN_WATCHDOG_TASK
;
2444 * ixgbevf_free_tx_resources - Free Tx Resources per Queue
2445 * @adapter: board private structure
2446 * @tx_ring: Tx descriptor ring for a specific queue
2448 * Free all transmit software resources
2450 void ixgbevf_free_tx_resources(struct ixgbevf_adapter
*adapter
,
2451 struct ixgbevf_ring
*tx_ring
)
2453 struct pci_dev
*pdev
= adapter
->pdev
;
2455 ixgbevf_clean_tx_ring(adapter
, tx_ring
);
2457 vfree(tx_ring
->tx_buffer_info
);
2458 tx_ring
->tx_buffer_info
= NULL
;
2460 dma_free_coherent(&pdev
->dev
, tx_ring
->size
, tx_ring
->desc
,
2463 tx_ring
->desc
= NULL
;
2467 * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
2468 * @adapter: board private structure
2470 * Free all transmit software resources
2472 static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2476 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2477 if (adapter
->tx_ring
[i
].desc
)
2478 ixgbevf_free_tx_resources(adapter
,
2479 &adapter
->tx_ring
[i
]);
2484 * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
2485 * @adapter: board private structure
2486 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2488 * Return 0 on success, negative on failure
2490 int ixgbevf_setup_tx_resources(struct ixgbevf_adapter
*adapter
,
2491 struct ixgbevf_ring
*tx_ring
)
2493 struct pci_dev
*pdev
= adapter
->pdev
;
2496 size
= sizeof(struct ixgbevf_tx_buffer
) * tx_ring
->count
;
2497 tx_ring
->tx_buffer_info
= vmalloc(size
);
2498 if (!tx_ring
->tx_buffer_info
)
2500 memset(tx_ring
->tx_buffer_info
, 0, size
);
2502 /* round up to nearest 4K */
2503 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
2504 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
2506 tx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, tx_ring
->size
,
2507 &tx_ring
->dma
, GFP_KERNEL
);
2511 tx_ring
->next_to_use
= 0;
2512 tx_ring
->next_to_clean
= 0;
2513 tx_ring
->work_limit
= tx_ring
->count
;
2517 vfree(tx_ring
->tx_buffer_info
);
2518 tx_ring
->tx_buffer_info
= NULL
;
2519 hw_dbg(&adapter
->hw
, "Unable to allocate memory for the transmit "
2520 "descriptor ring\n");
2525 * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
2526 * @adapter: board private structure
2528 * If this function returns with an error, then it's possible one or
2529 * more of the rings is populated (while the rest are not). It is the
2530 * callers duty to clean those orphaned rings.
2532 * Return 0 on success, negative on failure
2534 static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter
*adapter
)
2538 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2539 err
= ixgbevf_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
2542 hw_dbg(&adapter
->hw
,
2543 "Allocation for Tx Queue %u failed\n", i
);
2551 * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
2552 * @adapter: board private structure
2553 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2555 * Returns 0 on success, negative on failure
2557 int ixgbevf_setup_rx_resources(struct ixgbevf_adapter
*adapter
,
2558 struct ixgbevf_ring
*rx_ring
)
2560 struct pci_dev
*pdev
= adapter
->pdev
;
2563 size
= sizeof(struct ixgbevf_rx_buffer
) * rx_ring
->count
;
2564 rx_ring
->rx_buffer_info
= vmalloc(size
);
2565 if (!rx_ring
->rx_buffer_info
) {
2566 hw_dbg(&adapter
->hw
,
2567 "Unable to vmalloc buffer memory for "
2568 "the receive descriptor ring\n");
2571 memset(rx_ring
->rx_buffer_info
, 0, size
);
2573 /* Round up to nearest 4K */
2574 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
2575 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
2577 rx_ring
->desc
= dma_alloc_coherent(&pdev
->dev
, rx_ring
->size
,
2578 &rx_ring
->dma
, GFP_KERNEL
);
2580 if (!rx_ring
->desc
) {
2581 hw_dbg(&adapter
->hw
,
2582 "Unable to allocate memory for "
2583 "the receive descriptor ring\n");
2584 vfree(rx_ring
->rx_buffer_info
);
2585 rx_ring
->rx_buffer_info
= NULL
;
2589 rx_ring
->next_to_clean
= 0;
2590 rx_ring
->next_to_use
= 0;
2598 * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
2599 * @adapter: board private structure
2601 * If this function returns with an error, then it's possible one or
2602 * more of the rings is populated (while the rest are not). It is the
2603 * callers duty to clean those orphaned rings.
2605 * Return 0 on success, negative on failure
2607 static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2611 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2612 err
= ixgbevf_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
2615 hw_dbg(&adapter
->hw
,
2616 "Allocation for Rx Queue %u failed\n", i
);
2623 * ixgbevf_free_rx_resources - Free Rx Resources
2624 * @adapter: board private structure
2625 * @rx_ring: ring to clean the resources from
2627 * Free all receive software resources
2629 void ixgbevf_free_rx_resources(struct ixgbevf_adapter
*adapter
,
2630 struct ixgbevf_ring
*rx_ring
)
2632 struct pci_dev
*pdev
= adapter
->pdev
;
2634 ixgbevf_clean_rx_ring(adapter
, rx_ring
);
2636 vfree(rx_ring
->rx_buffer_info
);
2637 rx_ring
->rx_buffer_info
= NULL
;
2639 dma_free_coherent(&pdev
->dev
, rx_ring
->size
, rx_ring
->desc
,
2642 rx_ring
->desc
= NULL
;
2646 * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
2647 * @adapter: board private structure
2649 * Free all receive software resources
2651 static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter
*adapter
)
2655 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2656 if (adapter
->rx_ring
[i
].desc
)
2657 ixgbevf_free_rx_resources(adapter
,
2658 &adapter
->rx_ring
[i
]);
2662 * ixgbevf_open - Called when a network interface is made active
2663 * @netdev: network interface device structure
2665 * Returns 0 on success, negative value on failure
2667 * The open entry point is called when a network interface is made
2668 * active by the system (IFF_UP). At this point all resources needed
2669 * for transmit and receive operations are allocated, the interrupt
2670 * handler is registered with the OS, the watchdog timer is started,
2671 * and the stack is notified that the interface is ready.
2673 static int ixgbevf_open(struct net_device
*netdev
)
2675 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2676 struct ixgbe_hw
*hw
= &adapter
->hw
;
2679 /* disallow open during test */
2680 if (test_bit(__IXGBEVF_TESTING
, &adapter
->state
))
2683 if (hw
->adapter_stopped
) {
2684 ixgbevf_reset(adapter
);
2685 /* if adapter is still stopped then PF isn't up and
2686 * the vf can't start. */
2687 if (hw
->adapter_stopped
) {
2688 err
= IXGBE_ERR_MBX
;
2689 printk(KERN_ERR
"Unable to start - perhaps the PF"
2690 " Driver isn't up yet\n");
2691 goto err_setup_reset
;
2695 /* allocate transmit descriptors */
2696 err
= ixgbevf_setup_all_tx_resources(adapter
);
2700 /* allocate receive descriptors */
2701 err
= ixgbevf_setup_all_rx_resources(adapter
);
2705 ixgbevf_configure(adapter
);
2708 * Map the Tx/Rx rings to the vectors we were allotted.
2709 * if request_irq will be called in this function map_rings
2710 * must be called *before* up_complete
2712 ixgbevf_map_rings_to_vectors(adapter
);
2714 err
= ixgbevf_up_complete(adapter
);
2718 /* clear any pending interrupts, may auto mask */
2719 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
2720 err
= ixgbevf_request_irq(adapter
);
2724 ixgbevf_irq_enable(adapter
, true, true);
2729 ixgbevf_down(adapter
);
2731 ixgbevf_free_irq(adapter
);
2733 ixgbevf_free_all_rx_resources(adapter
);
2735 ixgbevf_free_all_tx_resources(adapter
);
2736 ixgbevf_reset(adapter
);
2744 * ixgbevf_close - Disables a network interface
2745 * @netdev: network interface device structure
2747 * Returns 0, this is not allowed to fail
2749 * The close entry point is called when an interface is de-activated
2750 * by the OS. The hardware is still under the drivers control, but
2751 * needs to be disabled. A global MAC reset is issued to stop the
2752 * hardware, and all transmit and receive resources are freed.
2754 static int ixgbevf_close(struct net_device
*netdev
)
2756 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
2758 ixgbevf_down(adapter
);
2759 ixgbevf_free_irq(adapter
);
2761 ixgbevf_free_all_tx_resources(adapter
);
2762 ixgbevf_free_all_rx_resources(adapter
);
2767 static int ixgbevf_tso(struct ixgbevf_adapter
*adapter
,
2768 struct ixgbevf_ring
*tx_ring
,
2769 struct sk_buff
*skb
, u32 tx_flags
, u8
*hdr_len
)
2771 struct ixgbe_adv_tx_context_desc
*context_desc
;
2774 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2775 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
;
2776 u32 mss_l4len_idx
, l4len
;
2778 if (skb_is_gso(skb
)) {
2779 if (skb_header_cloned(skb
)) {
2780 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2784 l4len
= tcp_hdrlen(skb
);
2787 if (skb
->protocol
== htons(ETH_P_IP
)) {
2788 struct iphdr
*iph
= ip_hdr(skb
);
2791 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2795 adapter
->hw_tso_ctxt
++;
2796 } else if (skb_is_gso_v6(skb
)) {
2797 ipv6_hdr(skb
)->payload_len
= 0;
2798 tcp_hdr(skb
)->check
=
2799 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2800 &ipv6_hdr(skb
)->daddr
,
2802 adapter
->hw_tso6_ctxt
++;
2805 i
= tx_ring
->next_to_use
;
2807 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2808 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2810 /* VLAN MACLEN IPLEN */
2811 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2813 (tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
);
2814 vlan_macip_lens
|= ((skb_network_offset(skb
)) <<
2815 IXGBE_ADVTXD_MACLEN_SHIFT
);
2816 *hdr_len
+= skb_network_offset(skb
);
2818 (skb_transport_header(skb
) - skb_network_header(skb
));
2820 (skb_transport_header(skb
) - skb_network_header(skb
));
2821 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2822 context_desc
->seqnum_seed
= 0;
2824 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2825 type_tucmd_mlhl
= (IXGBE_TXD_CMD_DEXT
|
2826 IXGBE_ADVTXD_DTYP_CTXT
);
2828 if (skb
->protocol
== htons(ETH_P_IP
))
2829 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2830 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2831 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2835 (skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
);
2836 mss_l4len_idx
|= (l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
);
2837 /* use index 1 for TSO */
2838 mss_l4len_idx
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
2839 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
2841 tx_buffer_info
->time_stamp
= jiffies
;
2842 tx_buffer_info
->next_to_watch
= i
;
2845 if (i
== tx_ring
->count
)
2847 tx_ring
->next_to_use
= i
;
2855 static bool ixgbevf_tx_csum(struct ixgbevf_adapter
*adapter
,
2856 struct ixgbevf_ring
*tx_ring
,
2857 struct sk_buff
*skb
, u32 tx_flags
)
2859 struct ixgbe_adv_tx_context_desc
*context_desc
;
2861 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2862 u32 vlan_macip_lens
= 0, type_tucmd_mlhl
= 0;
2864 if (skb
->ip_summed
== CHECKSUM_PARTIAL
||
2865 (tx_flags
& IXGBE_TX_FLAGS_VLAN
)) {
2866 i
= tx_ring
->next_to_use
;
2867 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2868 context_desc
= IXGBE_TX_CTXTDESC_ADV(*tx_ring
, i
);
2870 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
2871 vlan_macip_lens
|= (tx_flags
&
2872 IXGBE_TX_FLAGS_VLAN_MASK
);
2873 vlan_macip_lens
|= (skb_network_offset(skb
) <<
2874 IXGBE_ADVTXD_MACLEN_SHIFT
);
2875 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2876 vlan_macip_lens
|= (skb_transport_header(skb
) -
2877 skb_network_header(skb
));
2879 context_desc
->vlan_macip_lens
= cpu_to_le32(vlan_macip_lens
);
2880 context_desc
->seqnum_seed
= 0;
2882 type_tucmd_mlhl
|= (IXGBE_TXD_CMD_DEXT
|
2883 IXGBE_ADVTXD_DTYP_CTXT
);
2885 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2886 switch (skb
->protocol
) {
2887 case __constant_htons(ETH_P_IP
):
2888 type_tucmd_mlhl
|= IXGBE_ADVTXD_TUCMD_IPV4
;
2889 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
2891 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2893 case __constant_htons(ETH_P_IPV6
):
2894 /* XXX what about other V6 headers?? */
2895 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
2897 IXGBE_ADVTXD_TUCMD_L4T_TCP
;
2900 if (unlikely(net_ratelimit())) {
2902 "partial checksum but "
2910 context_desc
->type_tucmd_mlhl
= cpu_to_le32(type_tucmd_mlhl
);
2911 /* use index zero for tx checksum offload */
2912 context_desc
->mss_l4len_idx
= 0;
2914 tx_buffer_info
->time_stamp
= jiffies
;
2915 tx_buffer_info
->next_to_watch
= i
;
2917 adapter
->hw_csum_tx_good
++;
2919 if (i
== tx_ring
->count
)
2921 tx_ring
->next_to_use
= i
;
2929 static int ixgbevf_tx_map(struct ixgbevf_adapter
*adapter
,
2930 struct ixgbevf_ring
*tx_ring
,
2931 struct sk_buff
*skb
, u32 tx_flags
,
2934 struct pci_dev
*pdev
= adapter
->pdev
;
2935 struct ixgbevf_tx_buffer
*tx_buffer_info
;
2937 unsigned int total
= skb
->len
;
2938 unsigned int offset
= 0, size
, count
= 0;
2939 unsigned int nr_frags
= skb_shinfo(skb
)->nr_frags
;
2943 i
= tx_ring
->next_to_use
;
2945 len
= min(skb_headlen(skb
), total
);
2947 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2948 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2950 tx_buffer_info
->length
= size
;
2951 tx_buffer_info
->mapped_as_page
= false;
2952 tx_buffer_info
->dma
= dma_map_single(&adapter
->pdev
->dev
,
2954 size
, DMA_TO_DEVICE
);
2955 if (dma_mapping_error(&pdev
->dev
, tx_buffer_info
->dma
))
2957 tx_buffer_info
->time_stamp
= jiffies
;
2958 tx_buffer_info
->next_to_watch
= i
;
2965 if (i
== tx_ring
->count
)
2969 for (f
= 0; f
< nr_frags
; f
++) {
2970 struct skb_frag_struct
*frag
;
2972 frag
= &skb_shinfo(skb
)->frags
[f
];
2973 len
= min((unsigned int)frag
->size
, total
);
2974 offset
= frag
->page_offset
;
2977 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
2978 size
= min(len
, (unsigned int)IXGBE_MAX_DATA_PER_TXD
);
2980 tx_buffer_info
->length
= size
;
2981 tx_buffer_info
->dma
= dma_map_page(&adapter
->pdev
->dev
,
2986 tx_buffer_info
->mapped_as_page
= true;
2987 if (dma_mapping_error(&pdev
->dev
, tx_buffer_info
->dma
))
2989 tx_buffer_info
->time_stamp
= jiffies
;
2990 tx_buffer_info
->next_to_watch
= i
;
2997 if (i
== tx_ring
->count
)
3005 i
= tx_ring
->count
- 1;
3008 tx_ring
->tx_buffer_info
[i
].skb
= skb
;
3009 tx_ring
->tx_buffer_info
[first
].next_to_watch
= i
;
3014 dev_err(&pdev
->dev
, "TX DMA map failed\n");
3016 /* clear timestamp and dma mappings for failed tx_buffer_info map */
3017 tx_buffer_info
->dma
= 0;
3018 tx_buffer_info
->time_stamp
= 0;
3019 tx_buffer_info
->next_to_watch
= 0;
3022 /* clear timestamp and dma mappings for remaining portion of packet */
3023 while (count
>= 0) {
3027 i
+= tx_ring
->count
;
3028 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3029 ixgbevf_unmap_and_free_tx_resource(adapter
, tx_buffer_info
);
3035 static void ixgbevf_tx_queue(struct ixgbevf_adapter
*adapter
,
3036 struct ixgbevf_ring
*tx_ring
, int tx_flags
,
3037 int count
, u32 paylen
, u8 hdr_len
)
3039 union ixgbe_adv_tx_desc
*tx_desc
= NULL
;
3040 struct ixgbevf_tx_buffer
*tx_buffer_info
;
3041 u32 olinfo_status
= 0, cmd_type_len
= 0;
3044 u32 txd_cmd
= IXGBE_TXD_CMD_EOP
| IXGBE_TXD_CMD_RS
| IXGBE_TXD_CMD_IFCS
;
3046 cmd_type_len
|= IXGBE_ADVTXD_DTYP_DATA
;
3048 cmd_type_len
|= IXGBE_ADVTXD_DCMD_IFCS
| IXGBE_ADVTXD_DCMD_DEXT
;
3050 if (tx_flags
& IXGBE_TX_FLAGS_VLAN
)
3051 cmd_type_len
|= IXGBE_ADVTXD_DCMD_VLE
;
3053 if (tx_flags
& IXGBE_TX_FLAGS_TSO
) {
3054 cmd_type_len
|= IXGBE_ADVTXD_DCMD_TSE
;
3056 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
3057 IXGBE_ADVTXD_POPTS_SHIFT
;
3059 /* use index 1 context for tso */
3060 olinfo_status
|= (1 << IXGBE_ADVTXD_IDX_SHIFT
);
3061 if (tx_flags
& IXGBE_TX_FLAGS_IPV4
)
3062 olinfo_status
|= IXGBE_TXD_POPTS_IXSM
<<
3063 IXGBE_ADVTXD_POPTS_SHIFT
;
3065 } else if (tx_flags
& IXGBE_TX_FLAGS_CSUM
)
3066 olinfo_status
|= IXGBE_TXD_POPTS_TXSM
<<
3067 IXGBE_ADVTXD_POPTS_SHIFT
;
3069 olinfo_status
|= ((paylen
- hdr_len
) << IXGBE_ADVTXD_PAYLEN_SHIFT
);
3071 i
= tx_ring
->next_to_use
;
3073 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
3074 tx_desc
= IXGBE_TX_DESC_ADV(*tx_ring
, i
);
3075 tx_desc
->read
.buffer_addr
= cpu_to_le64(tx_buffer_info
->dma
);
3076 tx_desc
->read
.cmd_type_len
=
3077 cpu_to_le32(cmd_type_len
| tx_buffer_info
->length
);
3078 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
3080 if (i
== tx_ring
->count
)
3084 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(txd_cmd
);
3087 * Force memory writes to complete before letting h/w
3088 * know there are new descriptors to fetch. (Only
3089 * applicable for weak-ordered memory model archs,
3094 tx_ring
->next_to_use
= i
;
3095 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3098 static int __ixgbevf_maybe_stop_tx(struct net_device
*netdev
,
3099 struct ixgbevf_ring
*tx_ring
, int size
)
3101 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3103 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
3104 /* Herbert's original patch had:
3105 * smp_mb__after_netif_stop_queue();
3106 * but since that doesn't exist yet, just open code it. */
3109 /* We need to check again in a case another CPU has just
3110 * made room available. */
3111 if (likely(IXGBE_DESC_UNUSED(tx_ring
) < size
))
3114 /* A reprieve! - use start_queue because it doesn't call schedule */
3115 netif_start_subqueue(netdev
, tx_ring
->queue_index
);
3116 ++adapter
->restart_queue
;
3120 static int ixgbevf_maybe_stop_tx(struct net_device
*netdev
,
3121 struct ixgbevf_ring
*tx_ring
, int size
)
3123 if (likely(IXGBE_DESC_UNUSED(tx_ring
) >= size
))
3125 return __ixgbevf_maybe_stop_tx(netdev
, tx_ring
, size
);
3128 static int ixgbevf_xmit_frame(struct sk_buff
*skb
, struct net_device
*netdev
)
3130 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3131 struct ixgbevf_ring
*tx_ring
;
3133 unsigned int tx_flags
= 0;
3140 tx_ring
= &adapter
->tx_ring
[r_idx
];
3142 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
3143 tx_flags
|= vlan_tx_tag_get(skb
);
3144 tx_flags
<<= IXGBE_TX_FLAGS_VLAN_SHIFT
;
3145 tx_flags
|= IXGBE_TX_FLAGS_VLAN
;
3148 /* four things can cause us to need a context descriptor */
3149 if (skb_is_gso(skb
) ||
3150 (skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
3151 (tx_flags
& IXGBE_TX_FLAGS_VLAN
))
3154 count
+= TXD_USE_COUNT(skb_headlen(skb
));
3155 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
3156 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
3158 if (ixgbevf_maybe_stop_tx(netdev
, tx_ring
, count
)) {
3160 return NETDEV_TX_BUSY
;
3163 first
= tx_ring
->next_to_use
;
3165 if (skb
->protocol
== htons(ETH_P_IP
))
3166 tx_flags
|= IXGBE_TX_FLAGS_IPV4
;
3167 tso
= ixgbevf_tso(adapter
, tx_ring
, skb
, tx_flags
, &hdr_len
);
3169 dev_kfree_skb_any(skb
);
3170 return NETDEV_TX_OK
;
3174 tx_flags
|= IXGBE_TX_FLAGS_TSO
;
3175 else if (ixgbevf_tx_csum(adapter
, tx_ring
, skb
, tx_flags
) &&
3176 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3177 tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
3179 ixgbevf_tx_queue(adapter
, tx_ring
, tx_flags
,
3180 ixgbevf_tx_map(adapter
, tx_ring
, skb
, tx_flags
, first
),
3183 ixgbevf_maybe_stop_tx(netdev
, tx_ring
, DESC_NEEDED
);
3185 return NETDEV_TX_OK
;
3189 * ixgbevf_get_stats - Get System Network Statistics
3190 * @netdev: network interface device structure
3192 * Returns the address of the device statistics structure.
3193 * The statistics are actually updated from the timer callback.
3195 static struct net_device_stats
*ixgbevf_get_stats(struct net_device
*netdev
)
3197 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3199 /* only return the current stats */
3200 return &adapter
->net_stats
;
3204 * ixgbevf_set_mac - Change the Ethernet Address of the NIC
3205 * @netdev: network interface device structure
3206 * @p: pointer to an address structure
3208 * Returns 0 on success, negative on failure
3210 static int ixgbevf_set_mac(struct net_device
*netdev
, void *p
)
3212 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3213 struct ixgbe_hw
*hw
= &adapter
->hw
;
3214 struct sockaddr
*addr
= p
;
3216 if (!is_valid_ether_addr(addr
->sa_data
))
3217 return -EADDRNOTAVAIL
;
3219 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
3220 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
3222 if (hw
->mac
.ops
.set_rar
)
3223 hw
->mac
.ops
.set_rar(hw
, 0, hw
->mac
.addr
, 0);
3229 * ixgbevf_change_mtu - Change the Maximum Transfer Unit
3230 * @netdev: network interface device structure
3231 * @new_mtu: new value for maximum frame size
3233 * Returns 0 on success, negative on failure
3235 static int ixgbevf_change_mtu(struct net_device
*netdev
, int new_mtu
)
3237 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3238 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3240 /* MTU < 68 is an error and causes problems on some kernels */
3241 if ((new_mtu
< 68) || (max_frame
> MAXIMUM_ETHERNET_VLAN_SIZE
))
3244 hw_dbg(&adapter
->hw
, "changing MTU from %d to %d\n",
3245 netdev
->mtu
, new_mtu
);
3246 /* must set new MTU before calling down or up */
3247 netdev
->mtu
= new_mtu
;
3249 if (netif_running(netdev
))
3250 ixgbevf_reinit_locked(adapter
);
3255 static void ixgbevf_shutdown(struct pci_dev
*pdev
)
3257 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3258 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3260 netif_device_detach(netdev
);
3262 if (netif_running(netdev
)) {
3263 ixgbevf_down(adapter
);
3264 ixgbevf_free_irq(adapter
);
3265 ixgbevf_free_all_tx_resources(adapter
);
3266 ixgbevf_free_all_rx_resources(adapter
);
3270 pci_save_state(pdev
);
3273 pci_disable_device(pdev
);
3276 static const struct net_device_ops ixgbe_netdev_ops
= {
3277 .ndo_open
= &ixgbevf_open
,
3278 .ndo_stop
= &ixgbevf_close
,
3279 .ndo_start_xmit
= &ixgbevf_xmit_frame
,
3280 .ndo_get_stats
= &ixgbevf_get_stats
,
3281 .ndo_set_rx_mode
= &ixgbevf_set_rx_mode
,
3282 .ndo_set_multicast_list
= &ixgbevf_set_rx_mode
,
3283 .ndo_validate_addr
= eth_validate_addr
,
3284 .ndo_set_mac_address
= &ixgbevf_set_mac
,
3285 .ndo_change_mtu
= &ixgbevf_change_mtu
,
3286 .ndo_tx_timeout
= &ixgbevf_tx_timeout
,
3287 .ndo_vlan_rx_register
= &ixgbevf_vlan_rx_register
,
3288 .ndo_vlan_rx_add_vid
= &ixgbevf_vlan_rx_add_vid
,
3289 .ndo_vlan_rx_kill_vid
= &ixgbevf_vlan_rx_kill_vid
,
3292 static void ixgbevf_assign_netdev_ops(struct net_device
*dev
)
3294 struct ixgbevf_adapter
*adapter
;
3295 adapter
= netdev_priv(dev
);
3296 dev
->netdev_ops
= &ixgbe_netdev_ops
;
3297 ixgbevf_set_ethtool_ops(dev
);
3298 dev
->watchdog_timeo
= 5 * HZ
;
3302 * ixgbevf_probe - Device Initialization Routine
3303 * @pdev: PCI device information struct
3304 * @ent: entry in ixgbevf_pci_tbl
3306 * Returns 0 on success, negative on failure
3308 * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
3309 * The OS initialization, configuring of the adapter private structure,
3310 * and a hardware reset occur.
3312 static int __devinit
ixgbevf_probe(struct pci_dev
*pdev
,
3313 const struct pci_device_id
*ent
)
3315 struct net_device
*netdev
;
3316 struct ixgbevf_adapter
*adapter
= NULL
;
3317 struct ixgbe_hw
*hw
= NULL
;
3318 const struct ixgbevf_info
*ii
= ixgbevf_info_tbl
[ent
->driver_data
];
3319 static int cards_found
;
3320 int err
, pci_using_dac
;
3322 err
= pci_enable_device(pdev
);
3326 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64)) &&
3327 !dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
3330 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
3332 err
= dma_set_coherent_mask(&pdev
->dev
,
3335 dev_err(&pdev
->dev
, "No usable DMA "
3336 "configuration, aborting\n");
3343 err
= pci_request_regions(pdev
, ixgbevf_driver_name
);
3345 dev_err(&pdev
->dev
, "pci_request_regions failed 0x%x\n", err
);
3349 pci_set_master(pdev
);
3352 netdev
= alloc_etherdev_mq(sizeof(struct ixgbevf_adapter
),
3355 netdev
= alloc_etherdev(sizeof(struct ixgbevf_adapter
));
3359 goto err_alloc_etherdev
;
3362 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3364 pci_set_drvdata(pdev
, netdev
);
3365 adapter
= netdev_priv(netdev
);
3367 adapter
->netdev
= netdev
;
3368 adapter
->pdev
= pdev
;
3371 adapter
->msg_enable
= (1 << DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
3374 * call save state here in standalone driver because it relies on
3375 * adapter struct to exist, and needs to call netdev_priv
3377 pci_save_state(pdev
);
3379 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
3380 pci_resource_len(pdev
, 0));
3386 ixgbevf_assign_netdev_ops(netdev
);
3388 adapter
->bd_number
= cards_found
;
3391 memcpy(&hw
->mac
.ops
, ii
->mac_ops
, sizeof(hw
->mac
.ops
));
3392 hw
->mac
.type
= ii
->mac
;
3394 memcpy(&hw
->mbx
.ops
, &ixgbevf_mbx_ops
,
3395 sizeof(struct ixgbe_mac_operations
));
3397 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_CAPABLE
;
3398 adapter
->flags
&= ~IXGBE_FLAG_RX_PS_ENABLED
;
3399 adapter
->flags
|= IXGBE_FLAG_RX_1BUF_CAPABLE
;
3401 /* setup the private structure */
3402 err
= ixgbevf_sw_init(adapter
);
3404 #ifdef MAX_SKB_FRAGS
3405 netdev
->features
= NETIF_F_SG
|
3407 NETIF_F_HW_VLAN_TX
|
3408 NETIF_F_HW_VLAN_RX
|
3409 NETIF_F_HW_VLAN_FILTER
;
3411 netdev
->features
|= NETIF_F_IPV6_CSUM
;
3412 netdev
->features
|= NETIF_F_TSO
;
3413 netdev
->features
|= NETIF_F_TSO6
;
3414 netdev
->vlan_features
|= NETIF_F_TSO
;
3415 netdev
->vlan_features
|= NETIF_F_TSO6
;
3416 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
3417 netdev
->vlan_features
|= NETIF_F_SG
;
3420 netdev
->features
|= NETIF_F_HIGHDMA
;
3422 #endif /* MAX_SKB_FRAGS */
3424 /* The HW MAC address was set and/or determined in sw_init */
3425 memcpy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3426 memcpy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
, netdev
->addr_len
);
3428 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
3429 printk(KERN_ERR
"invalid MAC address\n");
3434 init_timer(&adapter
->watchdog_timer
);
3435 adapter
->watchdog_timer
.function
= &ixgbevf_watchdog
;
3436 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
3438 INIT_WORK(&adapter
->reset_task
, ixgbevf_reset_task
);
3439 INIT_WORK(&adapter
->watchdog_task
, ixgbevf_watchdog_task
);
3441 err
= ixgbevf_init_interrupt_scheme(adapter
);
3445 /* pick up the PCI bus settings for reporting later */
3446 if (hw
->mac
.ops
.get_bus_info
)
3447 hw
->mac
.ops
.get_bus_info(hw
);
3450 netif_carrier_off(netdev
);
3451 netif_tx_stop_all_queues(netdev
);
3453 strcpy(netdev
->name
, "eth%d");
3455 err
= register_netdev(netdev
);
3459 adapter
->netdev_registered
= true;
3461 ixgbevf_init_last_counter_stats(adapter
);
3463 /* print the MAC address */
3464 hw_dbg(hw
, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
3465 netdev
->dev_addr
[0],
3466 netdev
->dev_addr
[1],
3467 netdev
->dev_addr
[2],
3468 netdev
->dev_addr
[3],
3469 netdev
->dev_addr
[4],
3470 netdev
->dev_addr
[5]);
3472 hw_dbg(hw
, "MAC: %d\n", hw
->mac
.type
);
3474 hw_dbg(hw
, "LRO is disabled\n");
3476 hw_dbg(hw
, "Intel(R) 82599 Virtual Function\n");
3482 ixgbevf_reset_interrupt_capability(adapter
);
3483 iounmap(hw
->hw_addr
);
3485 free_netdev(netdev
);
3487 pci_release_regions(pdev
);
3490 pci_disable_device(pdev
);
3495 * ixgbevf_remove - Device Removal Routine
3496 * @pdev: PCI device information struct
3498 * ixgbevf_remove is called by the PCI subsystem to alert the driver
3499 * that it should release a PCI device. The could be caused by a
3500 * Hot-Plug event, or because the driver is going to be removed from
3503 static void __devexit
ixgbevf_remove(struct pci_dev
*pdev
)
3505 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3506 struct ixgbevf_adapter
*adapter
= netdev_priv(netdev
);
3508 set_bit(__IXGBEVF_DOWN
, &adapter
->state
);
3510 del_timer_sync(&adapter
->watchdog_timer
);
3512 cancel_work_sync(&adapter
->watchdog_task
);
3514 flush_scheduled_work();
3516 if (adapter
->netdev_registered
) {
3517 unregister_netdev(netdev
);
3518 adapter
->netdev_registered
= false;
3521 ixgbevf_reset_interrupt_capability(adapter
);
3523 iounmap(adapter
->hw
.hw_addr
);
3524 pci_release_regions(pdev
);
3526 hw_dbg(&adapter
->hw
, "Remove complete\n");
3528 kfree(adapter
->tx_ring
);
3529 kfree(adapter
->rx_ring
);
3531 free_netdev(netdev
);
3533 pci_disable_device(pdev
);
3536 static struct pci_driver ixgbevf_driver
= {
3537 .name
= ixgbevf_driver_name
,
3538 .id_table
= ixgbevf_pci_tbl
,
3539 .probe
= ixgbevf_probe
,
3540 .remove
= __devexit_p(ixgbevf_remove
),
3541 .shutdown
= ixgbevf_shutdown
,
3545 * ixgbe_init_module - Driver Registration Routine
3547 * ixgbe_init_module is the first routine called when the driver is
3548 * loaded. All it does is register with the PCI subsystem.
3550 static int __init
ixgbevf_init_module(void)
3553 printk(KERN_INFO
"ixgbevf: %s - version %s\n", ixgbevf_driver_string
,
3554 ixgbevf_driver_version
);
3556 printk(KERN_INFO
"%s\n", ixgbevf_copyright
);
3558 ret
= pci_register_driver(&ixgbevf_driver
);
3562 module_init(ixgbevf_init_module
);
3565 * ixgbe_exit_module - Driver Exit Cleanup Routine
3567 * ixgbe_exit_module is called just before the driver is removed
3570 static void __exit
ixgbevf_exit_module(void)
3572 pci_unregister_driver(&ixgbevf_driver
);
3577 * ixgbe_get_hw_dev_name - return device name string
3578 * used by hardware layer to print debugging information
3580 char *ixgbevf_get_hw_dev_name(struct ixgbe_hw
*hw
)
3582 struct ixgbevf_adapter
*adapter
= hw
->back
;
3583 return adapter
->netdev
->name
;
3587 module_exit(ixgbevf_exit_module
);
3589 /* ixgbevf_main.c */