1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
29 /******************************************************************************
30 Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
31 ******************************************************************************/
33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35 #include <linux/types.h>
36 #include <linux/bitops.h>
37 #include <linux/module.h>
38 #include <linux/pci.h>
39 #include <linux/netdevice.h>
40 #include <linux/vmalloc.h>
41 #include <linux/string.h>
44 #include <linux/tcp.h>
45 #include <linux/sctp.h>
46 #include <linux/ipv6.h>
47 #include <linux/slab.h>
48 #include <net/checksum.h>
49 #include <net/ip6_checksum.h>
50 #include <linux/ethtool.h>
52 #include <linux/if_vlan.h>
53 #include <linux/prefetch.h>
57 const char ixgbevf_driver_name[] = "ixgbevf";
58 static const char ixgbevf_driver_string[] =
59 "Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver";
61 #define DRV_VERSION "2.11.3-k"
62 const char ixgbevf_driver_version[] = DRV_VERSION;
63 static char ixgbevf_copyright[] =
64 "Copyright (c) 2009 - 2012 Intel Corporation.";
66 static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
67 [board_82599_vf] = &ixgbevf_82599_vf_info,
68 [board_X540_vf] = &ixgbevf_X540_vf_info,
71 /* ixgbevf_pci_tbl - PCI Device ID Table
73 * Wildcard entries (PCI_ANY_ID) should come last
74 * Last entry must be all 0s
76 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
77 * Class, Class Mask, private data (not used) }
79 static DEFINE_PCI_DEVICE_TABLE(ixgbevf_pci_tbl) = {
80 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF), board_82599_vf },
81 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF), board_X540_vf },
82 /* required last entry */
85 MODULE_DEVICE_TABLE(pci, ixgbevf_pci_tbl);
87 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
88 MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver");
89 MODULE_LICENSE("GPL");
90 MODULE_VERSION(DRV_VERSION);
92 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
93 static int debug = -1;
94 module_param(debug, int, 0);
95 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
98 static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector);
99 static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter);
101 static inline void ixgbevf_release_rx_desc(struct ixgbevf_ring *rx_ring,
104 rx_ring->next_to_use = val;
107 * Force memory writes to complete before letting h/w
108 * know there are new descriptors to fetch. (Only
109 * applicable for weak-ordered memory model archs,
113 writel(val, rx_ring->tail);
117 * ixgbevf_set_ivar - set IVAR registers - maps interrupt causes to vectors
118 * @adapter: pointer to adapter struct
119 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
120 * @queue: queue to map the corresponding interrupt to
121 * @msix_vector: the vector to map to the corresponding queue
123 static void ixgbevf_set_ivar(struct ixgbevf_adapter *adapter, s8 direction,
124 u8 queue, u8 msix_vector)
127 struct ixgbe_hw *hw = &adapter->hw;
128 if (direction == -1) {
130 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
131 ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
134 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar);
136 /* tx or rx causes */
137 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
138 index = ((16 * (queue & 1)) + (8 * direction));
139 ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
140 ivar &= ~(0xFF << index);
141 ivar |= (msix_vector << index);
142 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), ivar);
146 static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_ring *tx_ring,
147 struct ixgbevf_tx_buffer
150 if (tx_buffer_info->dma) {
151 if (tx_buffer_info->mapped_as_page)
152 dma_unmap_page(tx_ring->dev,
154 tx_buffer_info->length,
157 dma_unmap_single(tx_ring->dev,
159 tx_buffer_info->length,
161 tx_buffer_info->dma = 0;
163 if (tx_buffer_info->skb) {
164 dev_kfree_skb_any(tx_buffer_info->skb);
165 tx_buffer_info->skb = NULL;
167 tx_buffer_info->time_stamp = 0;
168 /* tx_buffer_info must be completely set up in the transmit path */
171 #define IXGBE_MAX_TXD_PWR 14
172 #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
174 /* Tx Descriptors needed, worst case */
175 #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD)
176 #define DESC_NEEDED (MAX_SKB_FRAGS + 4)
178 static void ixgbevf_tx_timeout(struct net_device *netdev);
181 * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes
182 * @q_vector: board private structure
183 * @tx_ring: tx ring to clean
185 static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector *q_vector,
186 struct ixgbevf_ring *tx_ring)
188 struct ixgbevf_adapter *adapter = q_vector->adapter;
189 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
190 struct ixgbevf_tx_buffer *tx_buffer_info;
191 unsigned int i, count = 0;
192 unsigned int total_bytes = 0, total_packets = 0;
194 if (test_bit(__IXGBEVF_DOWN, &adapter->state))
197 i = tx_ring->next_to_clean;
198 tx_buffer_info = &tx_ring->tx_buffer_info[i];
199 eop_desc = tx_buffer_info->next_to_watch;
202 bool cleaned = false;
204 /* if next_to_watch is not set then there is no work pending */
208 /* prevent any other reads prior to eop_desc */
209 read_barrier_depends();
211 /* if DD is not set pending work has not been completed */
212 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
215 /* clear next_to_watch to prevent false hangs */
216 tx_buffer_info->next_to_watch = NULL;
218 for ( ; !cleaned; count++) {
220 tx_desc = IXGBEVF_TX_DESC(tx_ring, i);
221 cleaned = (tx_desc == eop_desc);
222 skb = tx_buffer_info->skb;
224 if (cleaned && skb) {
225 unsigned int segs, bytecount;
227 /* gso_segs is currently only valid for tcp */
228 segs = skb_shinfo(skb)->gso_segs ?: 1;
229 /* multiply data chunks by size of headers */
230 bytecount = ((segs - 1) * skb_headlen(skb)) +
232 total_packets += segs;
233 total_bytes += bytecount;
236 ixgbevf_unmap_and_free_tx_resource(tx_ring,
239 tx_desc->wb.status = 0;
242 if (i == tx_ring->count)
245 tx_buffer_info = &tx_ring->tx_buffer_info[i];
248 eop_desc = tx_buffer_info->next_to_watch;
249 } while (count < tx_ring->count);
251 tx_ring->next_to_clean = i;
253 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
254 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
255 (ixgbevf_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
256 /* Make sure that anybody stopping the queue after this
257 * sees the new next_to_clean.
260 if (__netif_subqueue_stopped(tx_ring->netdev,
261 tx_ring->queue_index) &&
262 !test_bit(__IXGBEVF_DOWN, &adapter->state)) {
263 netif_wake_subqueue(tx_ring->netdev,
264 tx_ring->queue_index);
265 ++adapter->restart_queue;
269 u64_stats_update_begin(&tx_ring->syncp);
270 tx_ring->total_bytes += total_bytes;
271 tx_ring->total_packets += total_packets;
272 u64_stats_update_end(&tx_ring->syncp);
273 q_vector->tx.total_bytes += total_bytes;
274 q_vector->tx.total_packets += total_packets;
276 return count < tx_ring->count;
280 * ixgbevf_receive_skb - Send a completed packet up the stack
281 * @q_vector: structure containing interrupt and ring information
282 * @skb: packet to send up
283 * @status: hardware indication of status of receive
284 * @rx_desc: rx descriptor
286 static void ixgbevf_receive_skb(struct ixgbevf_q_vector *q_vector,
287 struct sk_buff *skb, u8 status,
288 union ixgbe_adv_rx_desc *rx_desc)
290 struct ixgbevf_adapter *adapter = q_vector->adapter;
291 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
292 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
294 if (is_vlan && test_bit(tag & VLAN_VID_MASK, adapter->active_vlans))
295 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
297 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
298 napi_gro_receive(&q_vector->napi, skb);
304 * ixgbevf_rx_skb - Helper function to determine proper Rx method
305 * @q_vector: structure containing interrupt and ring information
306 * @skb: packet to send up
307 * @status: hardware indication of status of receive
308 * @rx_desc: rx descriptor
310 static void ixgbevf_rx_skb(struct ixgbevf_q_vector *q_vector,
311 struct sk_buff *skb, u8 status,
312 union ixgbe_adv_rx_desc *rx_desc)
314 #ifdef CONFIG_NET_RX_BUSY_POLL
315 skb_mark_napi_id(skb, &q_vector->napi);
317 if (ixgbevf_qv_busy_polling(q_vector)) {
318 netif_receive_skb(skb);
319 /* exit early if we busy polled */
322 #endif /* CONFIG_NET_RX_BUSY_POLL */
324 ixgbevf_receive_skb(q_vector, skb, status, rx_desc);
328 * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum
329 * @ring: pointer to Rx descriptor ring structure
330 * @status_err: hardware indication of status of receive
331 * @skb: skb currently being received and modified
333 static inline void ixgbevf_rx_checksum(struct ixgbevf_ring *ring,
334 u32 status_err, struct sk_buff *skb)
336 skb_checksum_none_assert(skb);
338 /* Rx csum disabled */
339 if (!(ring->netdev->features & NETIF_F_RXCSUM))
342 /* if IP and error */
343 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
344 (status_err & IXGBE_RXDADV_ERR_IPE)) {
345 ring->hw_csum_rx_error++;
349 if (!(status_err & IXGBE_RXD_STAT_L4CS))
352 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
353 ring->hw_csum_rx_error++;
357 /* It must be a TCP or UDP packet with a valid checksum */
358 skb->ip_summed = CHECKSUM_UNNECESSARY;
359 ring->hw_csum_rx_good++;
363 * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split
364 * @adapter: address of board private structure
366 static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter *adapter,
367 struct ixgbevf_ring *rx_ring,
370 struct pci_dev *pdev = adapter->pdev;
371 union ixgbe_adv_rx_desc *rx_desc;
372 struct ixgbevf_rx_buffer *bi;
373 unsigned int i = rx_ring->next_to_use;
375 bi = &rx_ring->rx_buffer_info[i];
377 while (cleaned_count--) {
378 rx_desc = IXGBEVF_RX_DESC(rx_ring, i);
383 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
384 rx_ring->rx_buf_len);
386 adapter->alloc_rx_buff_failed++;
391 bi->dma = dma_map_single(&pdev->dev, skb->data,
394 if (dma_mapping_error(&pdev->dev, bi->dma)) {
397 dev_err(&pdev->dev, "RX DMA map failed\n");
401 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
404 if (i == rx_ring->count)
406 bi = &rx_ring->rx_buffer_info[i];
410 if (rx_ring->next_to_use != i)
411 ixgbevf_release_rx_desc(rx_ring, i);
414 static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter *adapter,
417 struct ixgbe_hw *hw = &adapter->hw;
419 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, qmask);
422 static int ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector,
423 struct ixgbevf_ring *rx_ring,
426 struct ixgbevf_adapter *adapter = q_vector->adapter;
427 struct pci_dev *pdev = adapter->pdev;
428 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
429 struct ixgbevf_rx_buffer *rx_buffer_info, *next_buffer;
433 int cleaned_count = 0;
434 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
436 i = rx_ring->next_to_clean;
437 rx_desc = IXGBEVF_RX_DESC(rx_ring, i);
438 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
439 rx_buffer_info = &rx_ring->rx_buffer_info[i];
441 while (staterr & IXGBE_RXD_STAT_DD) {
446 rmb(); /* read descriptor and rx_buffer_info after status DD */
447 len = le16_to_cpu(rx_desc->wb.upper.length);
448 skb = rx_buffer_info->skb;
449 prefetch(skb->data - NET_IP_ALIGN);
450 rx_buffer_info->skb = NULL;
452 if (rx_buffer_info->dma) {
453 dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
456 rx_buffer_info->dma = 0;
461 if (i == rx_ring->count)
464 next_rxd = IXGBEVF_RX_DESC(rx_ring, i);
468 next_buffer = &rx_ring->rx_buffer_info[i];
470 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
471 skb->next = next_buffer->skb;
472 IXGBE_CB(skb->next)->prev = skb;
473 adapter->non_eop_descs++;
477 /* we should not be chaining buffers, if we did drop the skb */
478 if (IXGBE_CB(skb)->prev) {
480 struct sk_buff *this = skb;
481 skb = IXGBE_CB(skb)->prev;
487 /* ERR_MASK will only have valid bits if EOP set */
488 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
489 dev_kfree_skb_irq(skb);
493 ixgbevf_rx_checksum(rx_ring, staterr, skb);
495 /* probably a little skewed due to removing CRC */
496 total_rx_bytes += skb->len;
499 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
501 /* Workaround hardware that can't do proper VEPA multicast
504 if ((skb->pkt_type & (PACKET_BROADCAST | PACKET_MULTICAST)) &&
505 ether_addr_equal(adapter->netdev->dev_addr,
506 eth_hdr(skb)->h_source)) {
507 dev_kfree_skb_irq(skb);
511 ixgbevf_rx_skb(q_vector, skb, staterr, rx_desc);
514 rx_desc->wb.upper.status_error = 0;
516 /* return some buffers to hardware, one at a time is too slow */
517 if (cleaned_count >= IXGBEVF_RX_BUFFER_WRITE) {
518 ixgbevf_alloc_rx_buffers(adapter, rx_ring,
523 /* use prefetched values */
525 rx_buffer_info = &rx_ring->rx_buffer_info[i];
527 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
530 rx_ring->next_to_clean = i;
531 cleaned_count = ixgbevf_desc_unused(rx_ring);
534 ixgbevf_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
536 u64_stats_update_begin(&rx_ring->syncp);
537 rx_ring->total_packets += total_rx_packets;
538 rx_ring->total_bytes += total_rx_bytes;
539 u64_stats_update_end(&rx_ring->syncp);
540 q_vector->rx.total_packets += total_rx_packets;
541 q_vector->rx.total_bytes += total_rx_bytes;
543 return total_rx_packets;
547 * ixgbevf_poll - NAPI polling calback
548 * @napi: napi struct with our devices info in it
549 * @budget: amount of work driver is allowed to do this pass, in packets
551 * This function will clean more than one or more rings associated with a
554 static int ixgbevf_poll(struct napi_struct *napi, int budget)
556 struct ixgbevf_q_vector *q_vector =
557 container_of(napi, struct ixgbevf_q_vector, napi);
558 struct ixgbevf_adapter *adapter = q_vector->adapter;
559 struct ixgbevf_ring *ring;
561 bool clean_complete = true;
563 ixgbevf_for_each_ring(ring, q_vector->tx)
564 clean_complete &= ixgbevf_clean_tx_irq(q_vector, ring);
566 #ifdef CONFIG_NET_RX_BUSY_POLL
567 if (!ixgbevf_qv_lock_napi(q_vector))
571 /* attempt to distribute budget to each queue fairly, but don't allow
572 * the budget to go below 1 because we'll exit polling */
573 if (q_vector->rx.count > 1)
574 per_ring_budget = max(budget/q_vector->rx.count, 1);
576 per_ring_budget = budget;
578 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
579 ixgbevf_for_each_ring(ring, q_vector->rx)
580 clean_complete &= (ixgbevf_clean_rx_irq(q_vector, ring,
583 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
585 #ifdef CONFIG_NET_RX_BUSY_POLL
586 ixgbevf_qv_unlock_napi(q_vector);
589 /* If all work not completed, return budget and keep polling */
592 /* all work done, exit the polling mode */
594 if (adapter->rx_itr_setting & 1)
595 ixgbevf_set_itr(q_vector);
596 if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
597 ixgbevf_irq_enable_queues(adapter,
598 1 << q_vector->v_idx);
604 * ixgbevf_write_eitr - write VTEITR register in hardware specific way
605 * @q_vector: structure containing interrupt and ring information
607 void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector)
609 struct ixgbevf_adapter *adapter = q_vector->adapter;
610 struct ixgbe_hw *hw = &adapter->hw;
611 int v_idx = q_vector->v_idx;
612 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
615 * set the WDIS bit to not clear the timer bits and cause an
616 * immediate assertion of the interrupt
618 itr_reg |= IXGBE_EITR_CNT_WDIS;
620 IXGBE_WRITE_REG(hw, IXGBE_VTEITR(v_idx), itr_reg);
623 #ifdef CONFIG_NET_RX_BUSY_POLL
624 /* must be called with local_bh_disable()d */
625 static int ixgbevf_busy_poll_recv(struct napi_struct *napi)
627 struct ixgbevf_q_vector *q_vector =
628 container_of(napi, struct ixgbevf_q_vector, napi);
629 struct ixgbevf_adapter *adapter = q_vector->adapter;
630 struct ixgbevf_ring *ring;
633 if (test_bit(__IXGBEVF_DOWN, &adapter->state))
634 return LL_FLUSH_FAILED;
636 if (!ixgbevf_qv_lock_poll(q_vector))
637 return LL_FLUSH_BUSY;
639 ixgbevf_for_each_ring(ring, q_vector->rx) {
640 found = ixgbevf_clean_rx_irq(q_vector, ring, 4);
641 #ifdef BP_EXTENDED_STATS
643 ring->bp_cleaned += found;
651 ixgbevf_qv_unlock_poll(q_vector);
655 #endif /* CONFIG_NET_RX_BUSY_POLL */
658 * ixgbevf_configure_msix - Configure MSI-X hardware
659 * @adapter: board private structure
661 * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X
664 static void ixgbevf_configure_msix(struct ixgbevf_adapter *adapter)
666 struct ixgbevf_q_vector *q_vector;
667 int q_vectors, v_idx;
669 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
670 adapter->eims_enable_mask = 0;
673 * Populate the IVAR table and set the ITR values to the
674 * corresponding register.
676 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
677 struct ixgbevf_ring *ring;
678 q_vector = adapter->q_vector[v_idx];
680 ixgbevf_for_each_ring(ring, q_vector->rx)
681 ixgbevf_set_ivar(adapter, 0, ring->reg_idx, v_idx);
683 ixgbevf_for_each_ring(ring, q_vector->tx)
684 ixgbevf_set_ivar(adapter, 1, ring->reg_idx, v_idx);
686 if (q_vector->tx.ring && !q_vector->rx.ring) {
688 if (adapter->tx_itr_setting == 1)
689 q_vector->itr = IXGBE_10K_ITR;
691 q_vector->itr = adapter->tx_itr_setting;
693 /* rx or rx/tx vector */
694 if (adapter->rx_itr_setting == 1)
695 q_vector->itr = IXGBE_20K_ITR;
697 q_vector->itr = adapter->rx_itr_setting;
700 /* add q_vector eims value to global eims_enable_mask */
701 adapter->eims_enable_mask |= 1 << v_idx;
703 ixgbevf_write_eitr(q_vector);
706 ixgbevf_set_ivar(adapter, -1, 1, v_idx);
707 /* setup eims_other and add value to global eims_enable_mask */
708 adapter->eims_other = 1 << v_idx;
709 adapter->eims_enable_mask |= adapter->eims_other;
716 latency_invalid = 255
720 * ixgbevf_update_itr - update the dynamic ITR value based on statistics
721 * @q_vector: structure containing interrupt and ring information
722 * @ring_container: structure containing ring performance data
724 * Stores a new ITR value based on packets and byte
725 * counts during the last interrupt. The advantage of per interrupt
726 * computation is faster updates and more accurate ITR for the current
727 * traffic pattern. Constants in this function were computed
728 * based on theoretical maximum wire speed and thresholds were set based
729 * on testing data as well as attempting to minimize response time
730 * while increasing bulk throughput.
732 static void ixgbevf_update_itr(struct ixgbevf_q_vector *q_vector,
733 struct ixgbevf_ring_container *ring_container)
735 int bytes = ring_container->total_bytes;
736 int packets = ring_container->total_packets;
739 u8 itr_setting = ring_container->itr;
744 /* simple throttlerate management
745 * 0-20MB/s lowest (100000 ints/s)
746 * 20-100MB/s low (20000 ints/s)
747 * 100-1249MB/s bulk (8000 ints/s)
749 /* what was last interrupt timeslice? */
750 timepassed_us = q_vector->itr >> 2;
751 bytes_perint = bytes / timepassed_us; /* bytes/usec */
753 switch (itr_setting) {
755 if (bytes_perint > 10)
756 itr_setting = low_latency;
759 if (bytes_perint > 20)
760 itr_setting = bulk_latency;
761 else if (bytes_perint <= 10)
762 itr_setting = lowest_latency;
765 if (bytes_perint <= 20)
766 itr_setting = low_latency;
770 /* clear work counters since we have the values we need */
771 ring_container->total_bytes = 0;
772 ring_container->total_packets = 0;
774 /* write updated itr to ring container */
775 ring_container->itr = itr_setting;
778 static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector)
780 u32 new_itr = q_vector->itr;
783 ixgbevf_update_itr(q_vector, &q_vector->tx);
784 ixgbevf_update_itr(q_vector, &q_vector->rx);
786 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
788 switch (current_itr) {
789 /* counts and packets in update_itr are dependent on these numbers */
791 new_itr = IXGBE_100K_ITR;
794 new_itr = IXGBE_20K_ITR;
798 new_itr = IXGBE_8K_ITR;
802 if (new_itr != q_vector->itr) {
803 /* do an exponential smoothing */
804 new_itr = (10 * new_itr * q_vector->itr) /
805 ((9 * new_itr) + q_vector->itr);
807 /* save the algorithm value here */
808 q_vector->itr = new_itr;
810 ixgbevf_write_eitr(q_vector);
814 static irqreturn_t ixgbevf_msix_other(int irq, void *data)
816 struct ixgbevf_adapter *adapter = data;
817 struct ixgbe_hw *hw = &adapter->hw;
819 hw->mac.get_link_status = 1;
821 if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
822 mod_timer(&adapter->watchdog_timer, jiffies);
824 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_other);
830 * ixgbevf_msix_clean_rings - single unshared vector rx clean (all queues)
832 * @data: pointer to our q_vector struct for this interrupt vector
834 static irqreturn_t ixgbevf_msix_clean_rings(int irq, void *data)
836 struct ixgbevf_q_vector *q_vector = data;
838 /* EIAM disabled interrupts (on this vector) for us */
839 if (q_vector->rx.ring || q_vector->tx.ring)
840 napi_schedule(&q_vector->napi);
845 static inline void map_vector_to_rxq(struct ixgbevf_adapter *a, int v_idx,
848 struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx];
850 a->rx_ring[r_idx].next = q_vector->rx.ring;
851 q_vector->rx.ring = &a->rx_ring[r_idx];
852 q_vector->rx.count++;
855 static inline void map_vector_to_txq(struct ixgbevf_adapter *a, int v_idx,
858 struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx];
860 a->tx_ring[t_idx].next = q_vector->tx.ring;
861 q_vector->tx.ring = &a->tx_ring[t_idx];
862 q_vector->tx.count++;
866 * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors
867 * @adapter: board private structure to initialize
869 * This function maps descriptor rings to the queue-specific vectors
870 * we were allotted through the MSI-X enabling code. Ideally, we'd have
871 * one vector per ring/queue, but on a constrained vector budget, we
872 * group the rings as "efficiently" as possible. You would add new
873 * mapping configurations in here.
875 static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter *adapter)
879 int rxr_idx = 0, txr_idx = 0;
880 int rxr_remaining = adapter->num_rx_queues;
881 int txr_remaining = adapter->num_tx_queues;
886 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
889 * The ideal configuration...
890 * We have enough vectors to map one per queue.
892 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
893 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
894 map_vector_to_rxq(adapter, v_start, rxr_idx);
896 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
897 map_vector_to_txq(adapter, v_start, txr_idx);
902 * If we don't have enough vectors for a 1-to-1
903 * mapping, we'll have to group them so there are
904 * multiple queues per vector.
906 /* Re-adjusting *qpv takes care of the remainder. */
907 for (i = v_start; i < q_vectors; i++) {
908 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
909 for (j = 0; j < rqpv; j++) {
910 map_vector_to_rxq(adapter, i, rxr_idx);
915 for (i = v_start; i < q_vectors; i++) {
916 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
917 for (j = 0; j < tqpv; j++) {
918 map_vector_to_txq(adapter, i, txr_idx);
929 * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts
930 * @adapter: board private structure
932 * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests
933 * interrupts from the kernel.
935 static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter *adapter)
937 struct net_device *netdev = adapter->netdev;
938 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
942 for (vector = 0; vector < q_vectors; vector++) {
943 struct ixgbevf_q_vector *q_vector = adapter->q_vector[vector];
944 struct msix_entry *entry = &adapter->msix_entries[vector];
946 if (q_vector->tx.ring && q_vector->rx.ring) {
947 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
948 "%s-%s-%d", netdev->name, "TxRx", ri++);
950 } else if (q_vector->rx.ring) {
951 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
952 "%s-%s-%d", netdev->name, "rx", ri++);
953 } else if (q_vector->tx.ring) {
954 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
955 "%s-%s-%d", netdev->name, "tx", ti++);
957 /* skip this unused q_vector */
960 err = request_irq(entry->vector, &ixgbevf_msix_clean_rings, 0,
961 q_vector->name, q_vector);
964 "request_irq failed for MSIX interrupt "
966 goto free_queue_irqs;
970 err = request_irq(adapter->msix_entries[vector].vector,
971 &ixgbevf_msix_other, 0, netdev->name, adapter);
974 "request_irq for msix_other failed: %d\n", err);
975 goto free_queue_irqs;
983 free_irq(adapter->msix_entries[vector].vector,
984 adapter->q_vector[vector]);
986 /* This failure is non-recoverable - it indicates the system is
987 * out of MSIX vector resources and the VF driver cannot run
988 * without them. Set the number of msix vectors to zero
989 * indicating that not enough can be allocated. The error
990 * will be returned to the user indicating device open failed.
991 * Any further attempts to force the driver to open will also
992 * fail. The only way to recover is to unload the driver and
993 * reload it again. If the system has recovered some MSIX
994 * vectors then it may succeed.
996 adapter->num_msix_vectors = 0;
1000 static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter *adapter)
1002 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1004 for (i = 0; i < q_vectors; i++) {
1005 struct ixgbevf_q_vector *q_vector = adapter->q_vector[i];
1006 q_vector->rx.ring = NULL;
1007 q_vector->tx.ring = NULL;
1008 q_vector->rx.count = 0;
1009 q_vector->tx.count = 0;
1014 * ixgbevf_request_irq - initialize interrupts
1015 * @adapter: board private structure
1017 * Attempts to configure interrupts using the best available
1018 * capabilities of the hardware and kernel.
1020 static int ixgbevf_request_irq(struct ixgbevf_adapter *adapter)
1024 err = ixgbevf_request_msix_irqs(adapter);
1027 hw_dbg(&adapter->hw,
1028 "request_irq failed, Error %d\n", err);
1033 static void ixgbevf_free_irq(struct ixgbevf_adapter *adapter)
1037 q_vectors = adapter->num_msix_vectors;
1040 free_irq(adapter->msix_entries[i].vector, adapter);
1043 for (; i >= 0; i--) {
1044 /* free only the irqs that were actually requested */
1045 if (!adapter->q_vector[i]->rx.ring &&
1046 !adapter->q_vector[i]->tx.ring)
1049 free_irq(adapter->msix_entries[i].vector,
1050 adapter->q_vector[i]);
1053 ixgbevf_reset_q_vectors(adapter);
1057 * ixgbevf_irq_disable - Mask off interrupt generation on the NIC
1058 * @adapter: board private structure
1060 static inline void ixgbevf_irq_disable(struct ixgbevf_adapter *adapter)
1062 struct ixgbe_hw *hw = &adapter->hw;
1065 IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, 0);
1066 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, ~0);
1067 IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, 0);
1069 IXGBE_WRITE_FLUSH(hw);
1071 for (i = 0; i < adapter->num_msix_vectors; i++)
1072 synchronize_irq(adapter->msix_entries[i].vector);
1076 * ixgbevf_irq_enable - Enable default interrupt generation settings
1077 * @adapter: board private structure
1079 static inline void ixgbevf_irq_enable(struct ixgbevf_adapter *adapter)
1081 struct ixgbe_hw *hw = &adapter->hw;
1083 IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, adapter->eims_enable_mask);
1084 IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, adapter->eims_enable_mask);
1085 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_enable_mask);
1089 * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset
1090 * @adapter: board private structure
1092 * Configure the Tx unit of the MAC after a reset.
1094 static void ixgbevf_configure_tx(struct ixgbevf_adapter *adapter)
1097 struct ixgbe_hw *hw = &adapter->hw;
1098 u32 i, j, tdlen, txctrl;
1100 /* Setup the HW Tx Head and Tail descriptor pointers */
1101 for (i = 0; i < adapter->num_tx_queues; i++) {
1102 struct ixgbevf_ring *ring = &adapter->tx_ring[i];
1105 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
1106 IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(j),
1107 (tdba & DMA_BIT_MASK(32)));
1108 IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(j), (tdba >> 32));
1109 IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(j), tdlen);
1110 IXGBE_WRITE_REG(hw, IXGBE_VFTDH(j), 0);
1111 IXGBE_WRITE_REG(hw, IXGBE_VFTDT(j), 0);
1112 ring->tail = hw->hw_addr + IXGBE_VFTDT(j);
1113 ring->next_to_clean = 0;
1114 ring->next_to_use = 0;
1115 /* Disable Tx Head Writeback RO bit, since this hoses
1116 * bookkeeping if things aren't delivered in order.
1118 txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(j));
1119 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
1120 IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(j), txctrl);
1124 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
1126 static void ixgbevf_configure_srrctl(struct ixgbevf_adapter *adapter, int index)
1128 struct ixgbevf_ring *rx_ring;
1129 struct ixgbe_hw *hw = &adapter->hw;
1132 rx_ring = &adapter->rx_ring[index];
1134 srrctl = IXGBE_SRRCTL_DROP_EN;
1136 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1138 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
1139 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1141 IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(index), srrctl);
1144 static void ixgbevf_setup_psrtype(struct ixgbevf_adapter *adapter)
1146 struct ixgbe_hw *hw = &adapter->hw;
1148 /* PSRTYPE must be initialized in 82599 */
1149 u32 psrtype = IXGBE_PSRTYPE_TCPHDR | IXGBE_PSRTYPE_UDPHDR |
1150 IXGBE_PSRTYPE_IPV4HDR | IXGBE_PSRTYPE_IPV6HDR |
1151 IXGBE_PSRTYPE_L2HDR;
1153 if (adapter->num_rx_queues > 1)
1156 IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype);
1159 static void ixgbevf_set_rx_buffer_len(struct ixgbevf_adapter *adapter)
1161 struct ixgbe_hw *hw = &adapter->hw;
1162 struct net_device *netdev = adapter->netdev;
1163 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1167 /* notify the PF of our intent to use this size of frame */
1168 ixgbevf_rlpml_set_vf(hw, max_frame);
1170 /* PF will allow an extra 4 bytes past for vlan tagged frames */
1171 max_frame += VLAN_HLEN;
1174 * Allocate buffer sizes that fit well into 32K and
1175 * take into account max frame size of 9.5K
1177 if ((hw->mac.type == ixgbe_mac_X540_vf) &&
1178 (max_frame <= MAXIMUM_ETHERNET_VLAN_SIZE))
1179 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1180 else if (max_frame <= IXGBEVF_RXBUFFER_2K)
1181 rx_buf_len = IXGBEVF_RXBUFFER_2K;
1182 else if (max_frame <= IXGBEVF_RXBUFFER_4K)
1183 rx_buf_len = IXGBEVF_RXBUFFER_4K;
1184 else if (max_frame <= IXGBEVF_RXBUFFER_8K)
1185 rx_buf_len = IXGBEVF_RXBUFFER_8K;
1187 rx_buf_len = IXGBEVF_RXBUFFER_10K;
1189 for (i = 0; i < adapter->num_rx_queues; i++)
1190 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
1194 * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset
1195 * @adapter: board private structure
1197 * Configure the Rx unit of the MAC after a reset.
1199 static void ixgbevf_configure_rx(struct ixgbevf_adapter *adapter)
1202 struct ixgbe_hw *hw = &adapter->hw;
1206 ixgbevf_setup_psrtype(adapter);
1208 /* set_rx_buffer_len must be called before ring initialization */
1209 ixgbevf_set_rx_buffer_len(adapter);
1211 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1212 * the Base and Length of the Rx Descriptor Ring */
1213 for (i = 0; i < adapter->num_rx_queues; i++) {
1214 struct ixgbevf_ring *ring = &adapter->rx_ring[i];
1217 rdlen = ring->count * sizeof(union ixgbe_adv_rx_desc);
1218 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(j),
1219 (rdba & DMA_BIT_MASK(32)));
1220 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(j), (rdba >> 32));
1221 IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(j), rdlen);
1222 IXGBE_WRITE_REG(hw, IXGBE_VFRDH(j), 0);
1223 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(j), 0);
1224 ring->tail = hw->hw_addr + IXGBE_VFRDT(j);
1225 ring->next_to_clean = 0;
1226 ring->next_to_use = 0;
1228 ixgbevf_configure_srrctl(adapter, j);
1232 static int ixgbevf_vlan_rx_add_vid(struct net_device *netdev,
1233 __be16 proto, u16 vid)
1235 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
1236 struct ixgbe_hw *hw = &adapter->hw;
1239 spin_lock_bh(&adapter->mbx_lock);
1241 /* add VID to filter table */
1242 err = hw->mac.ops.set_vfta(hw, vid, 0, true);
1244 spin_unlock_bh(&adapter->mbx_lock);
1246 /* translate error return types so error makes sense */
1247 if (err == IXGBE_ERR_MBX)
1250 if (err == IXGBE_ERR_INVALID_ARGUMENT)
1253 set_bit(vid, adapter->active_vlans);
1258 static int ixgbevf_vlan_rx_kill_vid(struct net_device *netdev,
1259 __be16 proto, u16 vid)
1261 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
1262 struct ixgbe_hw *hw = &adapter->hw;
1263 int err = -EOPNOTSUPP;
1265 spin_lock_bh(&adapter->mbx_lock);
1267 /* remove VID from filter table */
1268 err = hw->mac.ops.set_vfta(hw, vid, 0, false);
1270 spin_unlock_bh(&adapter->mbx_lock);
1272 clear_bit(vid, adapter->active_vlans);
1277 static void ixgbevf_restore_vlan(struct ixgbevf_adapter *adapter)
1281 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
1282 ixgbevf_vlan_rx_add_vid(adapter->netdev,
1283 htons(ETH_P_8021Q), vid);
1286 static int ixgbevf_write_uc_addr_list(struct net_device *netdev)
1288 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
1289 struct ixgbe_hw *hw = &adapter->hw;
1292 if ((netdev_uc_count(netdev)) > 10) {
1293 pr_err("Too many unicast filters - No Space\n");
1297 if (!netdev_uc_empty(netdev)) {
1298 struct netdev_hw_addr *ha;
1299 netdev_for_each_uc_addr(ha, netdev) {
1300 hw->mac.ops.set_uc_addr(hw, ++count, ha->addr);
1305 * If the list is empty then send message to PF driver to
1306 * clear all macvlans on this VF.
1308 hw->mac.ops.set_uc_addr(hw, 0, NULL);
1315 * ixgbevf_set_rx_mode - Multicast and unicast set
1316 * @netdev: network interface device structure
1318 * The set_rx_method entry point is called whenever the multicast address
1319 * list, unicast address list or the network interface flags are updated.
1320 * This routine is responsible for configuring the hardware for proper
1321 * multicast mode and configuring requested unicast filters.
1323 static void ixgbevf_set_rx_mode(struct net_device *netdev)
1325 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
1326 struct ixgbe_hw *hw = &adapter->hw;
1328 spin_lock_bh(&adapter->mbx_lock);
1330 /* reprogram multicast list */
1331 hw->mac.ops.update_mc_addr_list(hw, netdev);
1333 ixgbevf_write_uc_addr_list(netdev);
1335 spin_unlock_bh(&adapter->mbx_lock);
1338 static void ixgbevf_napi_enable_all(struct ixgbevf_adapter *adapter)
1341 struct ixgbevf_q_vector *q_vector;
1342 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1344 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1345 q_vector = adapter->q_vector[q_idx];
1346 #ifdef CONFIG_NET_RX_BUSY_POLL
1347 ixgbevf_qv_init_lock(adapter->q_vector[q_idx]);
1349 napi_enable(&q_vector->napi);
1353 static void ixgbevf_napi_disable_all(struct ixgbevf_adapter *adapter)
1356 struct ixgbevf_q_vector *q_vector;
1357 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1359 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1360 q_vector = adapter->q_vector[q_idx];
1361 napi_disable(&q_vector->napi);
1362 #ifdef CONFIG_NET_RX_BUSY_POLL
1363 while (!ixgbevf_qv_disable(adapter->q_vector[q_idx])) {
1364 pr_info("QV %d locked\n", q_idx);
1365 usleep_range(1000, 20000);
1367 #endif /* CONFIG_NET_RX_BUSY_POLL */
1371 static void ixgbevf_configure(struct ixgbevf_adapter *adapter)
1373 struct net_device *netdev = adapter->netdev;
1376 ixgbevf_set_rx_mode(netdev);
1378 ixgbevf_restore_vlan(adapter);
1380 ixgbevf_configure_tx(adapter);
1381 ixgbevf_configure_rx(adapter);
1382 for (i = 0; i < adapter->num_rx_queues; i++) {
1383 struct ixgbevf_ring *ring = &adapter->rx_ring[i];
1384 ixgbevf_alloc_rx_buffers(adapter, ring,
1385 ixgbevf_desc_unused(ring));
1389 #define IXGBEVF_MAX_RX_DESC_POLL 10
1390 static void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter *adapter,
1393 struct ixgbe_hw *hw = &adapter->hw;
1394 int wait_loop = IXGBEVF_MAX_RX_DESC_POLL;
1396 int j = adapter->rx_ring[rxr].reg_idx;
1399 usleep_range(1000, 2000);
1400 rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j));
1401 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
1404 hw_dbg(hw, "RXDCTL.ENABLE queue %d not set while polling\n",
1407 ixgbevf_release_rx_desc(&adapter->rx_ring[rxr],
1408 (adapter->rx_ring[rxr].count - 1));
1411 static void ixgbevf_disable_rx_queue(struct ixgbevf_adapter *adapter,
1412 struct ixgbevf_ring *ring)
1414 struct ixgbe_hw *hw = &adapter->hw;
1415 int wait_loop = IXGBEVF_MAX_RX_DESC_POLL;
1417 u8 reg_idx = ring->reg_idx;
1419 rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(reg_idx));
1420 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
1422 /* write value back with RXDCTL.ENABLE bit cleared */
1423 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(reg_idx), rxdctl);
1425 /* the hardware may take up to 100us to really disable the rx queue */
1428 rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(reg_idx));
1429 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
1432 hw_dbg(hw, "RXDCTL.ENABLE queue %d not cleared while polling\n",
1436 static void ixgbevf_save_reset_stats(struct ixgbevf_adapter *adapter)
1438 /* Only save pre-reset stats if there are some */
1439 if (adapter->stats.vfgprc || adapter->stats.vfgptc) {
1440 adapter->stats.saved_reset_vfgprc += adapter->stats.vfgprc -
1441 adapter->stats.base_vfgprc;
1442 adapter->stats.saved_reset_vfgptc += adapter->stats.vfgptc -
1443 adapter->stats.base_vfgptc;
1444 adapter->stats.saved_reset_vfgorc += adapter->stats.vfgorc -
1445 adapter->stats.base_vfgorc;
1446 adapter->stats.saved_reset_vfgotc += adapter->stats.vfgotc -
1447 adapter->stats.base_vfgotc;
1448 adapter->stats.saved_reset_vfmprc += adapter->stats.vfmprc -
1449 adapter->stats.base_vfmprc;
1453 static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter *adapter)
1455 struct ixgbe_hw *hw = &adapter->hw;
1457 adapter->stats.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC);
1458 adapter->stats.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB);
1459 adapter->stats.last_vfgorc |=
1460 (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32);
1461 adapter->stats.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC);
1462 adapter->stats.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB);
1463 adapter->stats.last_vfgotc |=
1464 (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32);
1465 adapter->stats.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC);
1467 adapter->stats.base_vfgprc = adapter->stats.last_vfgprc;
1468 adapter->stats.base_vfgorc = adapter->stats.last_vfgorc;
1469 adapter->stats.base_vfgptc = adapter->stats.last_vfgptc;
1470 adapter->stats.base_vfgotc = adapter->stats.last_vfgotc;
1471 adapter->stats.base_vfmprc = adapter->stats.last_vfmprc;
1474 static void ixgbevf_negotiate_api(struct ixgbevf_adapter *adapter)
1476 struct ixgbe_hw *hw = &adapter->hw;
1477 int api[] = { ixgbe_mbox_api_11,
1479 ixgbe_mbox_api_unknown };
1480 int err = 0, idx = 0;
1482 spin_lock_bh(&adapter->mbx_lock);
1484 while (api[idx] != ixgbe_mbox_api_unknown) {
1485 err = ixgbevf_negotiate_api_version(hw, api[idx]);
1491 spin_unlock_bh(&adapter->mbx_lock);
1494 static void ixgbevf_up_complete(struct ixgbevf_adapter *adapter)
1496 struct net_device *netdev = adapter->netdev;
1497 struct ixgbe_hw *hw = &adapter->hw;
1499 int num_rx_rings = adapter->num_rx_queues;
1502 for (i = 0; i < adapter->num_tx_queues; i++) {
1503 j = adapter->tx_ring[i].reg_idx;
1504 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
1505 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
1506 txdctl |= (8 << 16);
1507 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
1510 for (i = 0; i < adapter->num_tx_queues; i++) {
1511 j = adapter->tx_ring[i].reg_idx;
1512 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
1513 txdctl |= IXGBE_TXDCTL_ENABLE;
1514 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl);
1517 for (i = 0; i < num_rx_rings; i++) {
1518 j = adapter->rx_ring[i].reg_idx;
1519 rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j));
1520 rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME;
1521 if (hw->mac.type == ixgbe_mac_X540_vf) {
1522 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
1523 rxdctl |= ((netdev->mtu + ETH_HLEN + ETH_FCS_LEN) |
1524 IXGBE_RXDCTL_RLPML_EN);
1526 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(j), rxdctl);
1527 ixgbevf_rx_desc_queue_enable(adapter, i);
1530 ixgbevf_configure_msix(adapter);
1532 spin_lock_bh(&adapter->mbx_lock);
1534 if (is_valid_ether_addr(hw->mac.addr))
1535 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
1537 hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0);
1539 spin_unlock_bh(&adapter->mbx_lock);
1541 clear_bit(__IXGBEVF_DOWN, &adapter->state);
1542 ixgbevf_napi_enable_all(adapter);
1544 /* enable transmits */
1545 netif_tx_start_all_queues(netdev);
1547 ixgbevf_save_reset_stats(adapter);
1548 ixgbevf_init_last_counter_stats(adapter);
1550 hw->mac.get_link_status = 1;
1551 mod_timer(&adapter->watchdog_timer, jiffies);
1554 static int ixgbevf_reset_queues(struct ixgbevf_adapter *adapter)
1556 struct ixgbe_hw *hw = &adapter->hw;
1557 struct ixgbevf_ring *rx_ring;
1558 unsigned int def_q = 0;
1559 unsigned int num_tcs = 0;
1560 unsigned int num_rx_queues = 1;
1563 spin_lock_bh(&adapter->mbx_lock);
1565 /* fetch queue configuration from the PF */
1566 err = ixgbevf_get_queues(hw, &num_tcs, &def_q);
1568 spin_unlock_bh(&adapter->mbx_lock);
1574 /* update default Tx ring register index */
1575 adapter->tx_ring[0].reg_idx = def_q;
1577 /* we need as many queues as traffic classes */
1578 num_rx_queues = num_tcs;
1581 /* nothing to do if we have the correct number of queues */
1582 if (adapter->num_rx_queues == num_rx_queues)
1585 /* allocate new rings */
1586 rx_ring = kcalloc(num_rx_queues,
1587 sizeof(struct ixgbevf_ring), GFP_KERNEL);
1591 /* setup ring fields */
1592 for (i = 0; i < num_rx_queues; i++) {
1593 rx_ring[i].count = adapter->rx_ring_count;
1594 rx_ring[i].queue_index = i;
1595 rx_ring[i].reg_idx = i;
1596 rx_ring[i].dev = &adapter->pdev->dev;
1597 rx_ring[i].netdev = adapter->netdev;
1599 /* allocate resources on the ring */
1600 err = ixgbevf_setup_rx_resources(adapter, &rx_ring[i]);
1604 ixgbevf_free_rx_resources(adapter, &rx_ring[i]);
1611 /* free the existing rings and queues */
1612 ixgbevf_free_all_rx_resources(adapter);
1613 adapter->num_rx_queues = 0;
1614 kfree(adapter->rx_ring);
1616 /* move new rings into position on the adapter struct */
1617 adapter->rx_ring = rx_ring;
1618 adapter->num_rx_queues = num_rx_queues;
1620 /* reset ring to vector mapping */
1621 ixgbevf_reset_q_vectors(adapter);
1622 ixgbevf_map_rings_to_vectors(adapter);
1627 void ixgbevf_up(struct ixgbevf_adapter *adapter)
1629 struct ixgbe_hw *hw = &adapter->hw;
1631 ixgbevf_reset_queues(adapter);
1633 ixgbevf_configure(adapter);
1635 ixgbevf_up_complete(adapter);
1637 /* clear any pending interrupts, may auto mask */
1638 IXGBE_READ_REG(hw, IXGBE_VTEICR);
1640 ixgbevf_irq_enable(adapter);
1644 * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue
1645 * @adapter: board private structure
1646 * @rx_ring: ring to free buffers from
1648 static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter *adapter,
1649 struct ixgbevf_ring *rx_ring)
1651 struct pci_dev *pdev = adapter->pdev;
1655 if (!rx_ring->rx_buffer_info)
1658 /* Free all the Rx ring sk_buffs */
1659 for (i = 0; i < rx_ring->count; i++) {
1660 struct ixgbevf_rx_buffer *rx_buffer_info;
1662 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1663 if (rx_buffer_info->dma) {
1664 dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
1665 rx_ring->rx_buf_len,
1667 rx_buffer_info->dma = 0;
1669 if (rx_buffer_info->skb) {
1670 struct sk_buff *skb = rx_buffer_info->skb;
1671 rx_buffer_info->skb = NULL;
1673 struct sk_buff *this = skb;
1674 skb = IXGBE_CB(skb)->prev;
1675 dev_kfree_skb(this);
1680 size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count;
1681 memset(rx_ring->rx_buffer_info, 0, size);
1683 /* Zero out the descriptor ring */
1684 memset(rx_ring->desc, 0, rx_ring->size);
1688 * ixgbevf_clean_tx_ring - Free Tx Buffers
1689 * @adapter: board private structure
1690 * @tx_ring: ring to be cleaned
1692 static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter *adapter,
1693 struct ixgbevf_ring *tx_ring)
1695 struct ixgbevf_tx_buffer *tx_buffer_info;
1699 if (!tx_ring->tx_buffer_info)
1702 /* Free all the Tx ring sk_buffs */
1703 for (i = 0; i < tx_ring->count; i++) {
1704 tx_buffer_info = &tx_ring->tx_buffer_info[i];
1705 ixgbevf_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
1708 size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count;
1709 memset(tx_ring->tx_buffer_info, 0, size);
1711 memset(tx_ring->desc, 0, tx_ring->size);
1715 * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues
1716 * @adapter: board private structure
1718 static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter *adapter)
1722 for (i = 0; i < adapter->num_rx_queues; i++)
1723 ixgbevf_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1727 * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues
1728 * @adapter: board private structure
1730 static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter *adapter)
1734 for (i = 0; i < adapter->num_tx_queues; i++)
1735 ixgbevf_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1738 void ixgbevf_down(struct ixgbevf_adapter *adapter)
1740 struct net_device *netdev = adapter->netdev;
1741 struct ixgbe_hw *hw = &adapter->hw;
1745 /* signal that we are down to the interrupt handler */
1746 set_bit(__IXGBEVF_DOWN, &adapter->state);
1748 /* disable all enabled rx queues */
1749 for (i = 0; i < adapter->num_rx_queues; i++)
1750 ixgbevf_disable_rx_queue(adapter, &adapter->rx_ring[i]);
1752 netif_tx_disable(netdev);
1756 netif_tx_stop_all_queues(netdev);
1758 ixgbevf_irq_disable(adapter);
1760 ixgbevf_napi_disable_all(adapter);
1762 del_timer_sync(&adapter->watchdog_timer);
1763 /* can't call flush scheduled work here because it can deadlock
1764 * if linkwatch_event tries to acquire the rtnl_lock which we are
1766 while (adapter->flags & IXGBE_FLAG_IN_WATCHDOG_TASK)
1769 /* disable transmits in the hardware now that interrupts are off */
1770 for (i = 0; i < adapter->num_tx_queues; i++) {
1771 j = adapter->tx_ring[i].reg_idx;
1772 txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j));
1773 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j),
1774 (txdctl & ~IXGBE_TXDCTL_ENABLE));
1777 netif_carrier_off(netdev);
1779 if (!pci_channel_offline(adapter->pdev))
1780 ixgbevf_reset(adapter);
1782 ixgbevf_clean_all_tx_rings(adapter);
1783 ixgbevf_clean_all_rx_rings(adapter);
1786 void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter)
1788 WARN_ON(in_interrupt());
1790 while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state))
1793 ixgbevf_down(adapter);
1794 ixgbevf_up(adapter);
1796 clear_bit(__IXGBEVF_RESETTING, &adapter->state);
1799 void ixgbevf_reset(struct ixgbevf_adapter *adapter)
1801 struct ixgbe_hw *hw = &adapter->hw;
1802 struct net_device *netdev = adapter->netdev;
1804 if (hw->mac.ops.reset_hw(hw)) {
1805 hw_dbg(hw, "PF still resetting\n");
1807 hw->mac.ops.init_hw(hw);
1808 ixgbevf_negotiate_api(adapter);
1811 if (is_valid_ether_addr(adapter->hw.mac.addr)) {
1812 memcpy(netdev->dev_addr, adapter->hw.mac.addr,
1814 memcpy(netdev->perm_addr, adapter->hw.mac.addr,
1819 static int ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter *adapter,
1823 int vector_threshold;
1825 /* We'll want at least 2 (vector_threshold):
1826 * 1) TxQ[0] + RxQ[0] handler
1827 * 2) Other (Link Status Change, etc.)
1829 vector_threshold = MIN_MSIX_COUNT;
1831 /* The more we get, the more we will assign to Tx/Rx Cleanup
1832 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1833 * Right now, we simply care about how many we'll get; we'll
1834 * set them up later while requesting irq's.
1836 while (vectors >= vector_threshold) {
1837 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
1839 if (!err || err < 0) /* Success or a nasty failure. */
1841 else /* err == number of vectors we should try again with */
1845 if (vectors < vector_threshold)
1849 dev_err(&adapter->pdev->dev,
1850 "Unable to allocate MSI-X interrupts\n");
1851 kfree(adapter->msix_entries);
1852 adapter->msix_entries = NULL;
1855 * Adjust for only the vectors we'll use, which is minimum
1856 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
1857 * vectors we were allocated.
1859 adapter->num_msix_vectors = vectors;
1866 * ixgbevf_set_num_queues - Allocate queues for device, feature dependent
1867 * @adapter: board private structure to initialize
1869 * This is the top level queue allocation routine. The order here is very
1870 * important, starting with the "most" number of features turned on at once,
1871 * and ending with the smallest set of features. This way large combinations
1872 * can be allocated if they're turned on, and smaller combinations are the
1873 * fallthrough conditions.
1876 static void ixgbevf_set_num_queues(struct ixgbevf_adapter *adapter)
1878 /* Start with base case */
1879 adapter->num_rx_queues = 1;
1880 adapter->num_tx_queues = 1;
1884 * ixgbevf_alloc_queues - Allocate memory for all rings
1885 * @adapter: board private structure to initialize
1887 * We allocate one ring per queue at run-time since we don't know the
1888 * number of queues at compile-time. The polling_netdev array is
1889 * intended for Multiqueue, but should work fine with a single queue.
1891 static int ixgbevf_alloc_queues(struct ixgbevf_adapter *adapter)
1895 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1896 sizeof(struct ixgbevf_ring), GFP_KERNEL);
1897 if (!adapter->tx_ring)
1898 goto err_tx_ring_allocation;
1900 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1901 sizeof(struct ixgbevf_ring), GFP_KERNEL);
1902 if (!adapter->rx_ring)
1903 goto err_rx_ring_allocation;
1905 for (i = 0; i < adapter->num_tx_queues; i++) {
1906 adapter->tx_ring[i].count = adapter->tx_ring_count;
1907 adapter->tx_ring[i].queue_index = i;
1908 /* reg_idx may be remapped later by DCB config */
1909 adapter->tx_ring[i].reg_idx = i;
1910 adapter->tx_ring[i].dev = &adapter->pdev->dev;
1911 adapter->tx_ring[i].netdev = adapter->netdev;
1914 for (i = 0; i < adapter->num_rx_queues; i++) {
1915 adapter->rx_ring[i].count = adapter->rx_ring_count;
1916 adapter->rx_ring[i].queue_index = i;
1917 adapter->rx_ring[i].reg_idx = i;
1918 adapter->rx_ring[i].dev = &adapter->pdev->dev;
1919 adapter->rx_ring[i].netdev = adapter->netdev;
1924 err_rx_ring_allocation:
1925 kfree(adapter->tx_ring);
1926 err_tx_ring_allocation:
1931 * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported
1932 * @adapter: board private structure to initialize
1934 * Attempt to configure the interrupts using the best available
1935 * capabilities of the hardware and the kernel.
1937 static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter *adapter)
1939 struct net_device *netdev = adapter->netdev;
1941 int vector, v_budget;
1944 * It's easy to be greedy for MSI-X vectors, but it really
1945 * doesn't do us much good if we have a lot more vectors
1946 * than CPU's. So let's be conservative and only ask for
1947 * (roughly) the same number of vectors as there are CPU's.
1948 * The default is to use pairs of vectors.
1950 v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
1951 v_budget = min_t(int, v_budget, num_online_cpus());
1952 v_budget += NON_Q_VECTORS;
1954 /* A failure in MSI-X entry allocation isn't fatal, but it does
1955 * mean we disable MSI-X capabilities of the adapter. */
1956 adapter->msix_entries = kcalloc(v_budget,
1957 sizeof(struct msix_entry), GFP_KERNEL);
1958 if (!adapter->msix_entries) {
1963 for (vector = 0; vector < v_budget; vector++)
1964 adapter->msix_entries[vector].entry = vector;
1966 err = ixgbevf_acquire_msix_vectors(adapter, v_budget);
1970 err = netif_set_real_num_tx_queues(netdev, adapter->num_tx_queues);
1974 err = netif_set_real_num_rx_queues(netdev, adapter->num_rx_queues);
1981 * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors
1982 * @adapter: board private structure to initialize
1984 * We allocate one q_vector per queue interrupt. If allocation fails we
1987 static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter *adapter)
1989 int q_idx, num_q_vectors;
1990 struct ixgbevf_q_vector *q_vector;
1992 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1994 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1995 q_vector = kzalloc(sizeof(struct ixgbevf_q_vector), GFP_KERNEL);
1998 q_vector->adapter = adapter;
1999 q_vector->v_idx = q_idx;
2000 netif_napi_add(adapter->netdev, &q_vector->napi,
2002 #ifdef CONFIG_NET_RX_BUSY_POLL
2003 napi_hash_add(&q_vector->napi);
2005 adapter->q_vector[q_idx] = q_vector;
2013 q_vector = adapter->q_vector[q_idx];
2014 #ifdef CONFIG_NET_RX_BUSY_POLL
2015 napi_hash_del(&q_vector->napi);
2017 netif_napi_del(&q_vector->napi);
2019 adapter->q_vector[q_idx] = NULL;
2025 * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors
2026 * @adapter: board private structure to initialize
2028 * This function frees the memory allocated to the q_vectors. In addition if
2029 * NAPI is enabled it will delete any references to the NAPI struct prior
2030 * to freeing the q_vector.
2032 static void ixgbevf_free_q_vectors(struct ixgbevf_adapter *adapter)
2034 int q_idx, num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2036 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
2037 struct ixgbevf_q_vector *q_vector = adapter->q_vector[q_idx];
2039 adapter->q_vector[q_idx] = NULL;
2040 #ifdef CONFIG_NET_RX_BUSY_POLL
2041 napi_hash_del(&q_vector->napi);
2043 netif_napi_del(&q_vector->napi);
2049 * ixgbevf_reset_interrupt_capability - Reset MSIX setup
2050 * @adapter: board private structure
2053 static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter *adapter)
2055 pci_disable_msix(adapter->pdev);
2056 kfree(adapter->msix_entries);
2057 adapter->msix_entries = NULL;
2061 * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init
2062 * @adapter: board private structure to initialize
2065 static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter *adapter)
2069 /* Number of supported queues */
2070 ixgbevf_set_num_queues(adapter);
2072 err = ixgbevf_set_interrupt_capability(adapter);
2074 hw_dbg(&adapter->hw,
2075 "Unable to setup interrupt capabilities\n");
2076 goto err_set_interrupt;
2079 err = ixgbevf_alloc_q_vectors(adapter);
2081 hw_dbg(&adapter->hw, "Unable to allocate memory for queue "
2083 goto err_alloc_q_vectors;
2086 err = ixgbevf_alloc_queues(adapter);
2088 pr_err("Unable to allocate memory for queues\n");
2089 goto err_alloc_queues;
2092 hw_dbg(&adapter->hw, "Multiqueue %s: Rx Queue count = %u, "
2093 "Tx Queue count = %u\n",
2094 (adapter->num_rx_queues > 1) ? "Enabled" :
2095 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
2097 set_bit(__IXGBEVF_DOWN, &adapter->state);
2101 ixgbevf_free_q_vectors(adapter);
2102 err_alloc_q_vectors:
2103 ixgbevf_reset_interrupt_capability(adapter);
2109 * ixgbevf_clear_interrupt_scheme - Clear the current interrupt scheme settings
2110 * @adapter: board private structure to clear interrupt scheme on
2112 * We go through and clear interrupt specific resources and reset the structure
2113 * to pre-load conditions
2115 static void ixgbevf_clear_interrupt_scheme(struct ixgbevf_adapter *adapter)
2117 adapter->num_tx_queues = 0;
2118 adapter->num_rx_queues = 0;
2120 ixgbevf_free_q_vectors(adapter);
2121 ixgbevf_reset_interrupt_capability(adapter);
2125 * ixgbevf_sw_init - Initialize general software structures
2126 * (struct ixgbevf_adapter)
2127 * @adapter: board private structure to initialize
2129 * ixgbevf_sw_init initializes the Adapter private data structure.
2130 * Fields are initialized based on PCI device information and
2131 * OS network device settings (MTU size).
2133 static int ixgbevf_sw_init(struct ixgbevf_adapter *adapter)
2135 struct ixgbe_hw *hw = &adapter->hw;
2136 struct pci_dev *pdev = adapter->pdev;
2137 struct net_device *netdev = adapter->netdev;
2140 /* PCI config space info */
2142 hw->vendor_id = pdev->vendor;
2143 hw->device_id = pdev->device;
2144 hw->revision_id = pdev->revision;
2145 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2146 hw->subsystem_device_id = pdev->subsystem_device;
2148 hw->mbx.ops.init_params(hw);
2150 /* assume legacy case in which PF would only give VF 2 queues */
2151 hw->mac.max_tx_queues = 2;
2152 hw->mac.max_rx_queues = 2;
2154 /* lock to protect mailbox accesses */
2155 spin_lock_init(&adapter->mbx_lock);
2157 err = hw->mac.ops.reset_hw(hw);
2159 dev_info(&pdev->dev,
2160 "PF still in reset state. Is the PF interface up?\n");
2162 err = hw->mac.ops.init_hw(hw);
2164 pr_err("init_shared_code failed: %d\n", err);
2167 ixgbevf_negotiate_api(adapter);
2168 err = hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
2170 dev_info(&pdev->dev, "Error reading MAC address\n");
2171 else if (is_zero_ether_addr(adapter->hw.mac.addr))
2172 dev_info(&pdev->dev,
2173 "MAC address not assigned by administrator.\n");
2174 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
2177 if (!is_valid_ether_addr(netdev->dev_addr)) {
2178 dev_info(&pdev->dev, "Assigning random MAC address\n");
2179 eth_hw_addr_random(netdev);
2180 memcpy(hw->mac.addr, netdev->dev_addr, netdev->addr_len);
2183 /* Enable dynamic interrupt throttling rates */
2184 adapter->rx_itr_setting = 1;
2185 adapter->tx_itr_setting = 1;
2187 /* set default ring sizes */
2188 adapter->tx_ring_count = IXGBEVF_DEFAULT_TXD;
2189 adapter->rx_ring_count = IXGBEVF_DEFAULT_RXD;
2191 set_bit(__IXGBEVF_DOWN, &adapter->state);
2198 #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \
2200 u32 current_counter = IXGBE_READ_REG(hw, reg); \
2201 if (current_counter < last_counter) \
2202 counter += 0x100000000LL; \
2203 last_counter = current_counter; \
2204 counter &= 0xFFFFFFFF00000000LL; \
2205 counter |= current_counter; \
2208 #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
2210 u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \
2211 u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \
2212 u64 current_counter = (current_counter_msb << 32) | \
2213 current_counter_lsb; \
2214 if (current_counter < last_counter) \
2215 counter += 0x1000000000LL; \
2216 last_counter = current_counter; \
2217 counter &= 0xFFFFFFF000000000LL; \
2218 counter |= current_counter; \
2221 * ixgbevf_update_stats - Update the board statistics counters.
2222 * @adapter: board private structure
2224 void ixgbevf_update_stats(struct ixgbevf_adapter *adapter)
2226 struct ixgbe_hw *hw = &adapter->hw;
2229 if (!adapter->link_up)
2232 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC, adapter->stats.last_vfgprc,
2233 adapter->stats.vfgprc);
2234 UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC, adapter->stats.last_vfgptc,
2235 adapter->stats.vfgptc);
2236 UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
2237 adapter->stats.last_vfgorc,
2238 adapter->stats.vfgorc);
2239 UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
2240 adapter->stats.last_vfgotc,
2241 adapter->stats.vfgotc);
2242 UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC, adapter->stats.last_vfmprc,
2243 adapter->stats.vfmprc);
2245 for (i = 0; i < adapter->num_rx_queues; i++) {
2246 adapter->hw_csum_rx_error +=
2247 adapter->rx_ring[i].hw_csum_rx_error;
2248 adapter->hw_csum_rx_good +=
2249 adapter->rx_ring[i].hw_csum_rx_good;
2250 adapter->rx_ring[i].hw_csum_rx_error = 0;
2251 adapter->rx_ring[i].hw_csum_rx_good = 0;
2256 * ixgbevf_watchdog - Timer Call-back
2257 * @data: pointer to adapter cast into an unsigned long
2259 static void ixgbevf_watchdog(unsigned long data)
2261 struct ixgbevf_adapter *adapter = (struct ixgbevf_adapter *)data;
2262 struct ixgbe_hw *hw = &adapter->hw;
2267 * Do the watchdog outside of interrupt context due to the lovely
2268 * delays that some of the newer hardware requires
2271 if (test_bit(__IXGBEVF_DOWN, &adapter->state))
2272 goto watchdog_short_circuit;
2274 /* get one bit for every active tx/rx interrupt vector */
2275 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
2276 struct ixgbevf_q_vector *qv = adapter->q_vector[i];
2277 if (qv->rx.ring || qv->tx.ring)
2281 IXGBE_WRITE_REG(hw, IXGBE_VTEICS, eics);
2283 watchdog_short_circuit:
2284 schedule_work(&adapter->watchdog_task);
2288 * ixgbevf_tx_timeout - Respond to a Tx Hang
2289 * @netdev: network interface device structure
2291 static void ixgbevf_tx_timeout(struct net_device *netdev)
2293 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
2295 /* Do the reset outside of interrupt context */
2296 schedule_work(&adapter->reset_task);
2299 static void ixgbevf_reset_task(struct work_struct *work)
2301 struct ixgbevf_adapter *adapter;
2302 adapter = container_of(work, struct ixgbevf_adapter, reset_task);
2304 /* If we're already down or resetting, just bail */
2305 if (test_bit(__IXGBEVF_DOWN, &adapter->state) ||
2306 test_bit(__IXGBEVF_RESETTING, &adapter->state))
2309 adapter->tx_timeout_count++;
2311 ixgbevf_reinit_locked(adapter);
2315 * ixgbevf_watchdog_task - worker thread to bring link up
2316 * @work: pointer to work_struct containing our data
2318 static void ixgbevf_watchdog_task(struct work_struct *work)
2320 struct ixgbevf_adapter *adapter = container_of(work,
2321 struct ixgbevf_adapter,
2323 struct net_device *netdev = adapter->netdev;
2324 struct ixgbe_hw *hw = &adapter->hw;
2325 u32 link_speed = adapter->link_speed;
2326 bool link_up = adapter->link_up;
2329 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
2332 * Always check the link on the watchdog because we have
2335 spin_lock_bh(&adapter->mbx_lock);
2337 need_reset = hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
2339 spin_unlock_bh(&adapter->mbx_lock);
2342 adapter->link_up = link_up;
2343 adapter->link_speed = link_speed;
2344 netif_carrier_off(netdev);
2345 netif_tx_stop_all_queues(netdev);
2346 schedule_work(&adapter->reset_task);
2349 adapter->link_up = link_up;
2350 adapter->link_speed = link_speed;
2353 if (!netif_carrier_ok(netdev)) {
2354 char *link_speed_string;
2355 switch (link_speed) {
2356 case IXGBE_LINK_SPEED_10GB_FULL:
2357 link_speed_string = "10 Gbps";
2359 case IXGBE_LINK_SPEED_1GB_FULL:
2360 link_speed_string = "1 Gbps";
2362 case IXGBE_LINK_SPEED_100_FULL:
2363 link_speed_string = "100 Mbps";
2366 link_speed_string = "unknown speed";
2369 dev_info(&adapter->pdev->dev,
2370 "NIC Link is Up, %s\n", link_speed_string);
2371 netif_carrier_on(netdev);
2372 netif_tx_wake_all_queues(netdev);
2375 adapter->link_up = false;
2376 adapter->link_speed = 0;
2377 if (netif_carrier_ok(netdev)) {
2378 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
2379 netif_carrier_off(netdev);
2380 netif_tx_stop_all_queues(netdev);
2384 ixgbevf_update_stats(adapter);
2387 /* Reset the timer */
2388 if (!test_bit(__IXGBEVF_DOWN, &adapter->state))
2389 mod_timer(&adapter->watchdog_timer,
2390 round_jiffies(jiffies + (2 * HZ)));
2392 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
2396 * ixgbevf_free_tx_resources - Free Tx Resources per Queue
2397 * @adapter: board private structure
2398 * @tx_ring: Tx descriptor ring for a specific queue
2400 * Free all transmit software resources
2402 void ixgbevf_free_tx_resources(struct ixgbevf_adapter *adapter,
2403 struct ixgbevf_ring *tx_ring)
2405 struct pci_dev *pdev = adapter->pdev;
2407 ixgbevf_clean_tx_ring(adapter, tx_ring);
2409 vfree(tx_ring->tx_buffer_info);
2410 tx_ring->tx_buffer_info = NULL;
2412 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
2415 tx_ring->desc = NULL;
2419 * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues
2420 * @adapter: board private structure
2422 * Free all transmit software resources
2424 static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter *adapter)
2428 for (i = 0; i < adapter->num_tx_queues; i++)
2429 if (adapter->tx_ring[i].desc)
2430 ixgbevf_free_tx_resources(adapter,
2431 &adapter->tx_ring[i]);
2436 * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors)
2437 * @adapter: board private structure
2438 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2440 * Return 0 on success, negative on failure
2442 int ixgbevf_setup_tx_resources(struct ixgbevf_adapter *adapter,
2443 struct ixgbevf_ring *tx_ring)
2445 struct pci_dev *pdev = adapter->pdev;
2448 size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count;
2449 tx_ring->tx_buffer_info = vzalloc(size);
2450 if (!tx_ring->tx_buffer_info)
2453 /* round up to nearest 4K */
2454 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
2455 tx_ring->size = ALIGN(tx_ring->size, 4096);
2457 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
2458 &tx_ring->dma, GFP_KERNEL);
2465 vfree(tx_ring->tx_buffer_info);
2466 tx_ring->tx_buffer_info = NULL;
2467 hw_dbg(&adapter->hw, "Unable to allocate memory for the transmit "
2468 "descriptor ring\n");
2473 * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources
2474 * @adapter: board private structure
2476 * If this function returns with an error, then it's possible one or
2477 * more of the rings is populated (while the rest are not). It is the
2478 * callers duty to clean those orphaned rings.
2480 * Return 0 on success, negative on failure
2482 static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter *adapter)
2486 for (i = 0; i < adapter->num_tx_queues; i++) {
2487 err = ixgbevf_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2490 hw_dbg(&adapter->hw,
2491 "Allocation for Tx Queue %u failed\n", i);
2499 * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors)
2500 * @adapter: board private structure
2501 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2503 * Returns 0 on success, negative on failure
2505 int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter,
2506 struct ixgbevf_ring *rx_ring)
2508 struct pci_dev *pdev = adapter->pdev;
2511 size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count;
2512 rx_ring->rx_buffer_info = vzalloc(size);
2513 if (!rx_ring->rx_buffer_info)
2516 /* Round up to nearest 4K */
2517 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2518 rx_ring->size = ALIGN(rx_ring->size, 4096);
2520 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
2521 &rx_ring->dma, GFP_KERNEL);
2523 if (!rx_ring->desc) {
2524 vfree(rx_ring->rx_buffer_info);
2525 rx_ring->rx_buffer_info = NULL;
2535 * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources
2536 * @adapter: board private structure
2538 * If this function returns with an error, then it's possible one or
2539 * more of the rings is populated (while the rest are not). It is the
2540 * callers duty to clean those orphaned rings.
2542 * Return 0 on success, negative on failure
2544 static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter *adapter)
2548 for (i = 0; i < adapter->num_rx_queues; i++) {
2549 err = ixgbevf_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2552 hw_dbg(&adapter->hw,
2553 "Allocation for Rx Queue %u failed\n", i);
2560 * ixgbevf_free_rx_resources - Free Rx Resources
2561 * @adapter: board private structure
2562 * @rx_ring: ring to clean the resources from
2564 * Free all receive software resources
2566 void ixgbevf_free_rx_resources(struct ixgbevf_adapter *adapter,
2567 struct ixgbevf_ring *rx_ring)
2569 struct pci_dev *pdev = adapter->pdev;
2571 ixgbevf_clean_rx_ring(adapter, rx_ring);
2573 vfree(rx_ring->rx_buffer_info);
2574 rx_ring->rx_buffer_info = NULL;
2576 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2579 rx_ring->desc = NULL;
2583 * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues
2584 * @adapter: board private structure
2586 * Free all receive software resources
2588 static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter)
2592 for (i = 0; i < adapter->num_rx_queues; i++)
2593 if (adapter->rx_ring[i].desc)
2594 ixgbevf_free_rx_resources(adapter,
2595 &adapter->rx_ring[i]);
2598 static int ixgbevf_setup_queues(struct ixgbevf_adapter *adapter)
2600 struct ixgbe_hw *hw = &adapter->hw;
2601 struct ixgbevf_ring *rx_ring;
2602 unsigned int def_q = 0;
2603 unsigned int num_tcs = 0;
2604 unsigned int num_rx_queues = 1;
2607 spin_lock_bh(&adapter->mbx_lock);
2609 /* fetch queue configuration from the PF */
2610 err = ixgbevf_get_queues(hw, &num_tcs, &def_q);
2612 spin_unlock_bh(&adapter->mbx_lock);
2618 /* update default Tx ring register index */
2619 adapter->tx_ring[0].reg_idx = def_q;
2621 /* we need as many queues as traffic classes */
2622 num_rx_queues = num_tcs;
2625 /* nothing to do if we have the correct number of queues */
2626 if (adapter->num_rx_queues == num_rx_queues)
2629 /* allocate new rings */
2630 rx_ring = kcalloc(num_rx_queues,
2631 sizeof(struct ixgbevf_ring), GFP_KERNEL);
2635 /* setup ring fields */
2636 for (i = 0; i < num_rx_queues; i++) {
2637 rx_ring[i].count = adapter->rx_ring_count;
2638 rx_ring[i].queue_index = i;
2639 rx_ring[i].reg_idx = i;
2640 rx_ring[i].dev = &adapter->pdev->dev;
2641 rx_ring[i].netdev = adapter->netdev;
2644 /* free the existing ring and queues */
2645 adapter->num_rx_queues = 0;
2646 kfree(adapter->rx_ring);
2648 /* move new rings into position on the adapter struct */
2649 adapter->rx_ring = rx_ring;
2650 adapter->num_rx_queues = num_rx_queues;
2656 * ixgbevf_open - Called when a network interface is made active
2657 * @netdev: network interface device structure
2659 * Returns 0 on success, negative value on failure
2661 * The open entry point is called when a network interface is made
2662 * active by the system (IFF_UP). At this point all resources needed
2663 * for transmit and receive operations are allocated, the interrupt
2664 * handler is registered with the OS, the watchdog timer is started,
2665 * and the stack is notified that the interface is ready.
2667 static int ixgbevf_open(struct net_device *netdev)
2669 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
2670 struct ixgbe_hw *hw = &adapter->hw;
2673 /* A previous failure to open the device because of a lack of
2674 * available MSIX vector resources may have reset the number
2675 * of msix vectors variable to zero. The only way to recover
2676 * is to unload/reload the driver and hope that the system has
2677 * been able to recover some MSIX vector resources.
2679 if (!adapter->num_msix_vectors)
2682 /* disallow open during test */
2683 if (test_bit(__IXGBEVF_TESTING, &adapter->state))
2686 if (hw->adapter_stopped) {
2687 ixgbevf_reset(adapter);
2688 /* if adapter is still stopped then PF isn't up and
2689 * the vf can't start. */
2690 if (hw->adapter_stopped) {
2691 err = IXGBE_ERR_MBX;
2692 pr_err("Unable to start - perhaps the PF Driver isn't "
2694 goto err_setup_reset;
2698 /* setup queue reg_idx and Rx queue count */
2699 err = ixgbevf_setup_queues(adapter);
2701 goto err_setup_queues;
2703 /* allocate transmit descriptors */
2704 err = ixgbevf_setup_all_tx_resources(adapter);
2708 /* allocate receive descriptors */
2709 err = ixgbevf_setup_all_rx_resources(adapter);
2713 ixgbevf_configure(adapter);
2716 * Map the Tx/Rx rings to the vectors we were allotted.
2717 * if request_irq will be called in this function map_rings
2718 * must be called *before* up_complete
2720 ixgbevf_map_rings_to_vectors(adapter);
2722 ixgbevf_up_complete(adapter);
2724 /* clear any pending interrupts, may auto mask */
2725 IXGBE_READ_REG(hw, IXGBE_VTEICR);
2726 err = ixgbevf_request_irq(adapter);
2730 ixgbevf_irq_enable(adapter);
2735 ixgbevf_down(adapter);
2737 ixgbevf_free_all_rx_resources(adapter);
2739 ixgbevf_free_all_tx_resources(adapter);
2741 ixgbevf_reset(adapter);
2749 * ixgbevf_close - Disables a network interface
2750 * @netdev: network interface device structure
2752 * Returns 0, this is not allowed to fail
2754 * The close entry point is called when an interface is de-activated
2755 * by the OS. The hardware is still under the drivers control, but
2756 * needs to be disabled. A global MAC reset is issued to stop the
2757 * hardware, and all transmit and receive resources are freed.
2759 static int ixgbevf_close(struct net_device *netdev)
2761 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
2763 ixgbevf_down(adapter);
2764 ixgbevf_free_irq(adapter);
2766 ixgbevf_free_all_tx_resources(adapter);
2767 ixgbevf_free_all_rx_resources(adapter);
2772 static void ixgbevf_tx_ctxtdesc(struct ixgbevf_ring *tx_ring,
2773 u32 vlan_macip_lens, u32 type_tucmd,
2776 struct ixgbe_adv_tx_context_desc *context_desc;
2777 u16 i = tx_ring->next_to_use;
2779 context_desc = IXGBEVF_TX_CTXTDESC(tx_ring, i);
2782 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
2784 /* set bits to identify this as an advanced context descriptor */
2785 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
2787 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
2788 context_desc->seqnum_seed = 0;
2789 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
2790 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
2793 static int ixgbevf_tso(struct ixgbevf_ring *tx_ring,
2794 struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
2796 u32 vlan_macip_lens, type_tucmd;
2797 u32 mss_l4len_idx, l4len;
2799 if (!skb_is_gso(skb))
2802 if (skb_header_cloned(skb)) {
2803 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2808 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2809 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
2811 if (skb->protocol == htons(ETH_P_IP)) {
2812 struct iphdr *iph = ip_hdr(skb);
2815 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2819 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
2820 } else if (skb_is_gso_v6(skb)) {
2821 ipv6_hdr(skb)->payload_len = 0;
2822 tcp_hdr(skb)->check =
2823 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2824 &ipv6_hdr(skb)->daddr,
2828 /* compute header lengths */
2829 l4len = tcp_hdrlen(skb);
2831 *hdr_len = skb_transport_offset(skb) + l4len;
2833 /* mss_l4len_id: use 1 as index for TSO */
2834 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
2835 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
2836 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
2838 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
2839 vlan_macip_lens = skb_network_header_len(skb);
2840 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
2841 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
2843 ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens,
2844 type_tucmd, mss_l4len_idx);
2849 static bool ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring,
2850 struct sk_buff *skb, u32 tx_flags)
2852 u32 vlan_macip_lens = 0;
2853 u32 mss_l4len_idx = 0;
2856 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2858 switch (skb->protocol) {
2859 case __constant_htons(ETH_P_IP):
2860 vlan_macip_lens |= skb_network_header_len(skb);
2861 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
2862 l4_hdr = ip_hdr(skb)->protocol;
2864 case __constant_htons(ETH_P_IPV6):
2865 vlan_macip_lens |= skb_network_header_len(skb);
2866 l4_hdr = ipv6_hdr(skb)->nexthdr;
2869 if (unlikely(net_ratelimit())) {
2870 dev_warn(tx_ring->dev,
2871 "partial checksum but proto=%x!\n",
2879 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
2880 mss_l4len_idx = tcp_hdrlen(skb) <<
2881 IXGBE_ADVTXD_L4LEN_SHIFT;
2884 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
2885 mss_l4len_idx = sizeof(struct sctphdr) <<
2886 IXGBE_ADVTXD_L4LEN_SHIFT;
2889 mss_l4len_idx = sizeof(struct udphdr) <<
2890 IXGBE_ADVTXD_L4LEN_SHIFT;
2893 if (unlikely(net_ratelimit())) {
2894 dev_warn(tx_ring->dev,
2895 "partial checksum but l4 proto=%x!\n",
2902 /* vlan_macip_lens: MACLEN, VLAN tag */
2903 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
2904 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
2906 ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens,
2907 type_tucmd, mss_l4len_idx);
2909 return (skb->ip_summed == CHECKSUM_PARTIAL);
2912 static int ixgbevf_tx_map(struct ixgbevf_ring *tx_ring,
2913 struct sk_buff *skb, u32 tx_flags)
2915 struct ixgbevf_tx_buffer *tx_buffer_info;
2917 unsigned int total = skb->len;
2918 unsigned int offset = 0, size;
2920 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
2924 i = tx_ring->next_to_use;
2926 len = min(skb_headlen(skb), total);
2928 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2929 size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD);
2931 tx_buffer_info->length = size;
2932 tx_buffer_info->mapped_as_page = false;
2933 tx_buffer_info->dma = dma_map_single(tx_ring->dev,
2935 size, DMA_TO_DEVICE);
2936 if (dma_mapping_error(tx_ring->dev, tx_buffer_info->dma))
2944 if (i == tx_ring->count)
2948 for (f = 0; f < nr_frags; f++) {
2949 const struct skb_frag_struct *frag;
2951 frag = &skb_shinfo(skb)->frags[f];
2952 len = min((unsigned int)skb_frag_size(frag), total);
2956 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2957 size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD);
2959 tx_buffer_info->length = size;
2960 tx_buffer_info->dma =
2961 skb_frag_dma_map(tx_ring->dev, frag,
2962 offset, size, DMA_TO_DEVICE);
2963 if (dma_mapping_error(tx_ring->dev,
2964 tx_buffer_info->dma))
2966 tx_buffer_info->mapped_as_page = true;
2973 if (i == tx_ring->count)
2981 i = tx_ring->count - 1;
2984 tx_ring->tx_buffer_info[i].skb = skb;
2989 dev_err(tx_ring->dev, "TX DMA map failed\n");
2991 /* clear timestamp and dma mappings for failed tx_buffer_info map */
2992 tx_buffer_info->dma = 0;
2995 /* clear timestamp and dma mappings for remaining portion of packet */
2996 while (count >= 0) {
3000 i += tx_ring->count;
3001 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3002 ixgbevf_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
3008 static void ixgbevf_tx_queue(struct ixgbevf_ring *tx_ring, int tx_flags,
3009 int count, unsigned int first, u32 paylen,
3012 union ixgbe_adv_tx_desc *tx_desc = NULL;
3013 struct ixgbevf_tx_buffer *tx_buffer_info;
3014 u32 olinfo_status = 0, cmd_type_len = 0;
3017 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3019 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3021 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3023 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3024 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3026 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3027 olinfo_status |= IXGBE_ADVTXD_POPTS_TXSM;
3029 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3030 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3032 /* use index 1 context for tso */
3033 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
3034 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3035 olinfo_status |= IXGBE_ADVTXD_POPTS_IXSM;
3039 * Check Context must be set if Tx switch is enabled, which it
3040 * always is for case where virtual functions are running
3042 olinfo_status |= IXGBE_ADVTXD_CC;
3044 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3046 i = tx_ring->next_to_use;
3048 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3049 tx_desc = IXGBEVF_TX_DESC(tx_ring, i);
3050 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3051 tx_desc->read.cmd_type_len =
3052 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
3053 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
3055 if (i == tx_ring->count)
3059 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3061 tx_ring->tx_buffer_info[first].time_stamp = jiffies;
3063 /* Force memory writes to complete before letting h/w
3064 * know there are new descriptors to fetch. (Only
3065 * applicable for weak-ordered memory model archs,
3070 tx_ring->tx_buffer_info[first].next_to_watch = tx_desc;
3071 tx_ring->next_to_use = i;
3074 static int __ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size)
3076 struct ixgbevf_adapter *adapter = netdev_priv(tx_ring->netdev);
3078 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
3079 /* Herbert's original patch had:
3080 * smp_mb__after_netif_stop_queue();
3081 * but since that doesn't exist yet, just open code it. */
3084 /* We need to check again in a case another CPU has just
3085 * made room available. */
3086 if (likely(ixgbevf_desc_unused(tx_ring) < size))
3089 /* A reprieve! - use start_queue because it doesn't call schedule */
3090 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
3091 ++adapter->restart_queue;
3095 static int ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size)
3097 if (likely(ixgbevf_desc_unused(tx_ring) >= size))
3099 return __ixgbevf_maybe_stop_tx(tx_ring, size);
3102 static int ixgbevf_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3104 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3105 struct ixgbevf_ring *tx_ring;
3107 unsigned int tx_flags = 0;
3110 u16 count = TXD_USE_COUNT(skb_headlen(skb));
3111 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
3114 u8 *dst_mac = skb_header_pointer(skb, 0, 0, NULL);
3115 if (!dst_mac || is_link_local_ether_addr(dst_mac)) {
3117 return NETDEV_TX_OK;
3120 tx_ring = &adapter->tx_ring[r_idx];
3123 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
3124 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
3125 * + 2 desc gap to keep tail from touching head,
3126 * + 1 desc for context descriptor,
3127 * otherwise try next time
3129 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
3130 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
3131 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3133 count += skb_shinfo(skb)->nr_frags;
3135 if (ixgbevf_maybe_stop_tx(tx_ring, count + 3)) {
3137 return NETDEV_TX_BUSY;
3140 if (vlan_tx_tag_present(skb)) {
3141 tx_flags |= vlan_tx_tag_get(skb);
3142 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3143 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3146 first = tx_ring->next_to_use;
3148 if (skb->protocol == htons(ETH_P_IP))
3149 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3150 tso = ixgbevf_tso(tx_ring, skb, tx_flags, &hdr_len);
3152 dev_kfree_skb_any(skb);
3153 return NETDEV_TX_OK;
3157 tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM;
3158 else if (ixgbevf_tx_csum(tx_ring, skb, tx_flags))
3159 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3161 ixgbevf_tx_queue(tx_ring, tx_flags,
3162 ixgbevf_tx_map(tx_ring, skb, tx_flags),
3163 first, skb->len, hdr_len);
3165 writel(tx_ring->next_to_use, tx_ring->tail);
3167 ixgbevf_maybe_stop_tx(tx_ring, DESC_NEEDED);
3169 return NETDEV_TX_OK;
3173 * ixgbevf_set_mac - Change the Ethernet Address of the NIC
3174 * @netdev: network interface device structure
3175 * @p: pointer to an address structure
3177 * Returns 0 on success, negative on failure
3179 static int ixgbevf_set_mac(struct net_device *netdev, void *p)
3181 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3182 struct ixgbe_hw *hw = &adapter->hw;
3183 struct sockaddr *addr = p;
3185 if (!is_valid_ether_addr(addr->sa_data))
3186 return -EADDRNOTAVAIL;
3188 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
3189 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
3191 spin_lock_bh(&adapter->mbx_lock);
3193 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0);
3195 spin_unlock_bh(&adapter->mbx_lock);
3201 * ixgbevf_change_mtu - Change the Maximum Transfer Unit
3202 * @netdev: network interface device structure
3203 * @new_mtu: new value for maximum frame size
3205 * Returns 0 on success, negative on failure
3207 static int ixgbevf_change_mtu(struct net_device *netdev, int new_mtu)
3209 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3210 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3211 int max_possible_frame = MAXIMUM_ETHERNET_VLAN_SIZE;
3213 switch (adapter->hw.api_version) {
3214 case ixgbe_mbox_api_11:
3215 max_possible_frame = IXGBE_MAX_JUMBO_FRAME_SIZE;
3218 if (adapter->hw.mac.type == ixgbe_mac_X540_vf)
3219 max_possible_frame = IXGBE_MAX_JUMBO_FRAME_SIZE;
3223 /* MTU < 68 is an error and causes problems on some kernels */
3224 if ((new_mtu < 68) || (max_frame > max_possible_frame))
3227 hw_dbg(&adapter->hw, "changing MTU from %d to %d\n",
3228 netdev->mtu, new_mtu);
3229 /* must set new MTU before calling down or up */
3230 netdev->mtu = new_mtu;
3232 if (netif_running(netdev))
3233 ixgbevf_reinit_locked(adapter);
3238 static int ixgbevf_suspend(struct pci_dev *pdev, pm_message_t state)
3240 struct net_device *netdev = pci_get_drvdata(pdev);
3241 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3246 netif_device_detach(netdev);
3248 if (netif_running(netdev)) {
3250 ixgbevf_down(adapter);
3251 ixgbevf_free_irq(adapter);
3252 ixgbevf_free_all_tx_resources(adapter);
3253 ixgbevf_free_all_rx_resources(adapter);
3257 ixgbevf_clear_interrupt_scheme(adapter);
3260 retval = pci_save_state(pdev);
3265 pci_disable_device(pdev);
3271 static int ixgbevf_resume(struct pci_dev *pdev)
3273 struct ixgbevf_adapter *adapter = pci_get_drvdata(pdev);
3274 struct net_device *netdev = adapter->netdev;
3277 pci_set_power_state(pdev, PCI_D0);
3278 pci_restore_state(pdev);
3280 * pci_restore_state clears dev->state_saved so call
3281 * pci_save_state to restore it.
3283 pci_save_state(pdev);
3285 err = pci_enable_device_mem(pdev);
3287 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
3290 pci_set_master(pdev);
3292 ixgbevf_reset(adapter);
3295 err = ixgbevf_init_interrupt_scheme(adapter);
3298 dev_err(&pdev->dev, "Cannot initialize interrupts\n");
3302 if (netif_running(netdev)) {
3303 err = ixgbevf_open(netdev);
3308 netif_device_attach(netdev);
3313 #endif /* CONFIG_PM */
3314 static void ixgbevf_shutdown(struct pci_dev *pdev)
3316 ixgbevf_suspend(pdev, PMSG_SUSPEND);
3319 static struct rtnl_link_stats64 *ixgbevf_get_stats(struct net_device *netdev,
3320 struct rtnl_link_stats64 *stats)
3322 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3325 const struct ixgbevf_ring *ring;
3328 ixgbevf_update_stats(adapter);
3330 stats->multicast = adapter->stats.vfmprc - adapter->stats.base_vfmprc;
3332 for (i = 0; i < adapter->num_rx_queues; i++) {
3333 ring = &adapter->rx_ring[i];
3335 start = u64_stats_fetch_begin_bh(&ring->syncp);
3336 bytes = ring->total_bytes;
3337 packets = ring->total_packets;
3338 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
3339 stats->rx_bytes += bytes;
3340 stats->rx_packets += packets;
3343 for (i = 0; i < adapter->num_tx_queues; i++) {
3344 ring = &adapter->tx_ring[i];
3346 start = u64_stats_fetch_begin_bh(&ring->syncp);
3347 bytes = ring->total_bytes;
3348 packets = ring->total_packets;
3349 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
3350 stats->tx_bytes += bytes;
3351 stats->tx_packets += packets;
3357 static const struct net_device_ops ixgbevf_netdev_ops = {
3358 .ndo_open = ixgbevf_open,
3359 .ndo_stop = ixgbevf_close,
3360 .ndo_start_xmit = ixgbevf_xmit_frame,
3361 .ndo_set_rx_mode = ixgbevf_set_rx_mode,
3362 .ndo_get_stats64 = ixgbevf_get_stats,
3363 .ndo_validate_addr = eth_validate_addr,
3364 .ndo_set_mac_address = ixgbevf_set_mac,
3365 .ndo_change_mtu = ixgbevf_change_mtu,
3366 .ndo_tx_timeout = ixgbevf_tx_timeout,
3367 .ndo_vlan_rx_add_vid = ixgbevf_vlan_rx_add_vid,
3368 .ndo_vlan_rx_kill_vid = ixgbevf_vlan_rx_kill_vid,
3369 #ifdef CONFIG_NET_RX_BUSY_POLL
3370 .ndo_busy_poll = ixgbevf_busy_poll_recv,
3374 static void ixgbevf_assign_netdev_ops(struct net_device *dev)
3376 dev->netdev_ops = &ixgbevf_netdev_ops;
3377 ixgbevf_set_ethtool_ops(dev);
3378 dev->watchdog_timeo = 5 * HZ;
3382 * ixgbevf_probe - Device Initialization Routine
3383 * @pdev: PCI device information struct
3384 * @ent: entry in ixgbevf_pci_tbl
3386 * Returns 0 on success, negative on failure
3388 * ixgbevf_probe initializes an adapter identified by a pci_dev structure.
3389 * The OS initialization, configuring of the adapter private structure,
3390 * and a hardware reset occur.
3392 static int ixgbevf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3394 struct net_device *netdev;
3395 struct ixgbevf_adapter *adapter = NULL;
3396 struct ixgbe_hw *hw = NULL;
3397 const struct ixgbevf_info *ii = ixgbevf_info_tbl[ent->driver_data];
3398 static int cards_found;
3399 int err, pci_using_dac;
3401 err = pci_enable_device(pdev);
3405 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
3408 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
3410 dev_err(&pdev->dev, "No usable DMA "
3411 "configuration, aborting\n");
3417 err = pci_request_regions(pdev, ixgbevf_driver_name);
3419 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
3423 pci_set_master(pdev);
3425 netdev = alloc_etherdev_mq(sizeof(struct ixgbevf_adapter),
3429 goto err_alloc_etherdev;
3432 SET_NETDEV_DEV(netdev, &pdev->dev);
3434 pci_set_drvdata(pdev, netdev);
3435 adapter = netdev_priv(netdev);
3437 adapter->netdev = netdev;
3438 adapter->pdev = pdev;
3441 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
3444 * call save state here in standalone driver because it relies on
3445 * adapter struct to exist, and needs to call netdev_priv
3447 pci_save_state(pdev);
3449 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
3450 pci_resource_len(pdev, 0));
3456 ixgbevf_assign_netdev_ops(netdev);
3458 adapter->bd_number = cards_found;
3461 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
3462 hw->mac.type = ii->mac;
3464 memcpy(&hw->mbx.ops, &ixgbevf_mbx_ops,
3465 sizeof(struct ixgbe_mbx_operations));
3467 /* setup the private structure */
3468 err = ixgbevf_sw_init(adapter);
3472 /* The HW MAC address was set and/or determined in sw_init */
3473 if (!is_valid_ether_addr(netdev->dev_addr)) {
3474 pr_err("invalid MAC address\n");
3479 netdev->hw_features = NETIF_F_SG |
3486 netdev->features = netdev->hw_features |
3487 NETIF_F_HW_VLAN_CTAG_TX |
3488 NETIF_F_HW_VLAN_CTAG_RX |
3489 NETIF_F_HW_VLAN_CTAG_FILTER;
3491 netdev->vlan_features |= NETIF_F_TSO;
3492 netdev->vlan_features |= NETIF_F_TSO6;
3493 netdev->vlan_features |= NETIF_F_IP_CSUM;
3494 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
3495 netdev->vlan_features |= NETIF_F_SG;
3498 netdev->features |= NETIF_F_HIGHDMA;
3500 netdev->priv_flags |= IFF_UNICAST_FLT;
3502 init_timer(&adapter->watchdog_timer);
3503 adapter->watchdog_timer.function = ixgbevf_watchdog;
3504 adapter->watchdog_timer.data = (unsigned long)adapter;
3506 INIT_WORK(&adapter->reset_task, ixgbevf_reset_task);
3507 INIT_WORK(&adapter->watchdog_task, ixgbevf_watchdog_task);
3509 err = ixgbevf_init_interrupt_scheme(adapter);
3513 strcpy(netdev->name, "eth%d");
3515 err = register_netdev(netdev);
3519 netif_carrier_off(netdev);
3521 ixgbevf_init_last_counter_stats(adapter);
3523 /* print the MAC address */
3524 hw_dbg(hw, "%pM\n", netdev->dev_addr);
3526 hw_dbg(hw, "MAC: %d\n", hw->mac.type);
3528 hw_dbg(hw, "Intel(R) 82599 Virtual Function\n");
3533 ixgbevf_clear_interrupt_scheme(adapter);
3535 ixgbevf_reset_interrupt_capability(adapter);
3536 iounmap(hw->hw_addr);
3538 free_netdev(netdev);
3540 pci_release_regions(pdev);
3543 pci_disable_device(pdev);
3548 * ixgbevf_remove - Device Removal Routine
3549 * @pdev: PCI device information struct
3551 * ixgbevf_remove is called by the PCI subsystem to alert the driver
3552 * that it should release a PCI device. The could be caused by a
3553 * Hot-Plug event, or because the driver is going to be removed from
3556 static void ixgbevf_remove(struct pci_dev *pdev)
3558 struct net_device *netdev = pci_get_drvdata(pdev);
3559 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3561 set_bit(__IXGBEVF_DOWN, &adapter->state);
3563 del_timer_sync(&adapter->watchdog_timer);
3565 cancel_work_sync(&adapter->reset_task);
3566 cancel_work_sync(&adapter->watchdog_task);
3568 if (netdev->reg_state == NETREG_REGISTERED)
3569 unregister_netdev(netdev);
3571 ixgbevf_clear_interrupt_scheme(adapter);
3572 ixgbevf_reset_interrupt_capability(adapter);
3574 iounmap(adapter->hw.hw_addr);
3575 pci_release_regions(pdev);
3577 hw_dbg(&adapter->hw, "Remove complete\n");
3579 kfree(adapter->tx_ring);
3580 kfree(adapter->rx_ring);
3582 free_netdev(netdev);
3584 pci_disable_device(pdev);
3588 * ixgbevf_io_error_detected - called when PCI error is detected
3589 * @pdev: Pointer to PCI device
3590 * @state: The current pci connection state
3592 * This function is called after a PCI bus error affecting
3593 * this device has been detected.
3595 static pci_ers_result_t ixgbevf_io_error_detected(struct pci_dev *pdev,
3596 pci_channel_state_t state)
3598 struct net_device *netdev = pci_get_drvdata(pdev);
3599 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3601 netif_device_detach(netdev);
3603 if (state == pci_channel_io_perm_failure)
3604 return PCI_ERS_RESULT_DISCONNECT;
3606 if (netif_running(netdev))
3607 ixgbevf_down(adapter);
3609 pci_disable_device(pdev);
3611 /* Request a slot slot reset. */
3612 return PCI_ERS_RESULT_NEED_RESET;
3616 * ixgbevf_io_slot_reset - called after the pci bus has been reset.
3617 * @pdev: Pointer to PCI device
3619 * Restart the card from scratch, as if from a cold-boot. Implementation
3620 * resembles the first-half of the ixgbevf_resume routine.
3622 static pci_ers_result_t ixgbevf_io_slot_reset(struct pci_dev *pdev)
3624 struct net_device *netdev = pci_get_drvdata(pdev);
3625 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3627 if (pci_enable_device_mem(pdev)) {
3629 "Cannot re-enable PCI device after reset.\n");
3630 return PCI_ERS_RESULT_DISCONNECT;
3633 pci_set_master(pdev);
3635 ixgbevf_reset(adapter);
3637 return PCI_ERS_RESULT_RECOVERED;
3641 * ixgbevf_io_resume - called when traffic can start flowing again.
3642 * @pdev: Pointer to PCI device
3644 * This callback is called when the error recovery driver tells us that
3645 * its OK to resume normal operation. Implementation resembles the
3646 * second-half of the ixgbevf_resume routine.
3648 static void ixgbevf_io_resume(struct pci_dev *pdev)
3650 struct net_device *netdev = pci_get_drvdata(pdev);
3651 struct ixgbevf_adapter *adapter = netdev_priv(netdev);
3653 if (netif_running(netdev))
3654 ixgbevf_up(adapter);
3656 netif_device_attach(netdev);
3659 /* PCI Error Recovery (ERS) */
3660 static const struct pci_error_handlers ixgbevf_err_handler = {
3661 .error_detected = ixgbevf_io_error_detected,
3662 .slot_reset = ixgbevf_io_slot_reset,
3663 .resume = ixgbevf_io_resume,
3666 static struct pci_driver ixgbevf_driver = {
3667 .name = ixgbevf_driver_name,
3668 .id_table = ixgbevf_pci_tbl,
3669 .probe = ixgbevf_probe,
3670 .remove = ixgbevf_remove,
3672 /* Power Management Hooks */
3673 .suspend = ixgbevf_suspend,
3674 .resume = ixgbevf_resume,
3676 .shutdown = ixgbevf_shutdown,
3677 .err_handler = &ixgbevf_err_handler
3681 * ixgbevf_init_module - Driver Registration Routine
3683 * ixgbevf_init_module is the first routine called when the driver is
3684 * loaded. All it does is register with the PCI subsystem.
3686 static int __init ixgbevf_init_module(void)
3689 pr_info("%s - version %s\n", ixgbevf_driver_string,
3690 ixgbevf_driver_version);
3692 pr_info("%s\n", ixgbevf_copyright);
3694 ret = pci_register_driver(&ixgbevf_driver);
3698 module_init(ixgbevf_init_module);
3701 * ixgbevf_exit_module - Driver Exit Cleanup Routine
3703 * ixgbevf_exit_module is called just before the driver is removed
3706 static void __exit ixgbevf_exit_module(void)
3708 pci_unregister_driver(&ixgbevf_driver);
3713 * ixgbevf_get_hw_dev_name - return device name string
3714 * used by hardware layer to print debugging information
3716 char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw)
3718 struct ixgbevf_adapter *adapter = hw->back;
3719 return adapter->netdev->name;
3723 module_exit(ixgbevf_exit_module);
3725 /* ixgbevf_main.c */