1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 - 2014 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
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
28 #include "i40e_prototype.h"
29 static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
30 static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
31 static void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter);
32 static void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter);
33 static int i40evf_close(struct net_device *netdev);
35 char i40evf_driver_name[] = "i40evf";
36 static const char i40evf_driver_string[] =
37 "Intel(R) XL710 X710 Virtual Function Network Driver";
39 #define DRV_VERSION "0.9.27"
40 const char i40evf_driver_version[] = DRV_VERSION;
41 static const char i40evf_copyright[] =
42 "Copyright (c) 2013 - 2014 Intel Corporation.";
44 /* i40evf_pci_tbl - PCI Device ID Table
46 * Wildcard entries (PCI_ANY_ID) should come last
47 * Last entry must be all 0s
49 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
50 * Class, Class Mask, private data (not used) }
52 static DEFINE_PCI_DEVICE_TABLE(i40evf_pci_tbl) = {
53 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
54 /* required last entry */
58 MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
60 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
61 MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
62 MODULE_LICENSE("GPL");
63 MODULE_VERSION(DRV_VERSION);
66 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
67 * @hw: pointer to the HW structure
68 * @mem: ptr to mem struct to fill out
69 * @size: size of memory requested
70 * @alignment: what to align the allocation to
72 i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
73 struct i40e_dma_mem *mem,
74 u64 size, u32 alignment)
76 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
79 return I40E_ERR_PARAM;
81 mem->size = ALIGN(size, alignment);
82 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
83 (dma_addr_t *)&mem->pa, GFP_KERNEL);
87 return I40E_ERR_NO_MEMORY;
91 * i40evf_free_dma_mem_d - OS specific memory free for shared code
92 * @hw: pointer to the HW structure
93 * @mem: ptr to mem struct to free
95 i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
97 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
100 return I40E_ERR_PARAM;
101 dma_free_coherent(&adapter->pdev->dev, mem->size,
102 mem->va, (dma_addr_t)mem->pa);
107 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
108 * @hw: pointer to the HW structure
109 * @mem: ptr to mem struct to fill out
110 * @size: size of memory requested
112 i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
113 struct i40e_virt_mem *mem, u32 size)
116 return I40E_ERR_PARAM;
119 mem->va = kzalloc(size, GFP_KERNEL);
124 return I40E_ERR_NO_MEMORY;
128 * i40evf_free_virt_mem_d - OS specific memory free for shared code
129 * @hw: pointer to the HW structure
130 * @mem: ptr to mem struct to free
132 i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
133 struct i40e_virt_mem *mem)
136 return I40E_ERR_PARAM;
138 /* it's ok to kfree a NULL pointer */
145 * i40evf_debug_d - OS dependent version of debug printing
146 * @hw: pointer to the HW structure
147 * @mask: debug level mask
148 * @fmt_str: printf-type format description
150 void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
155 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
158 va_start(argptr, fmt_str);
159 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
162 /* the debug string is already formatted with a newline */
167 * i40evf_tx_timeout - Respond to a Tx Hang
168 * @netdev: network interface device structure
170 static void i40evf_tx_timeout(struct net_device *netdev)
172 struct i40evf_adapter *adapter = netdev_priv(netdev);
174 adapter->tx_timeout_count++;
175 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
176 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
177 schedule_work(&adapter->reset_task);
182 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
183 * @adapter: board private structure
185 static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
187 struct i40e_hw *hw = &adapter->hw;
188 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
191 rd32(hw, I40E_VFGEN_RSTAT);
193 synchronize_irq(adapter->msix_entries[0].vector);
197 * i40evf_misc_irq_enable - Enable default interrupt generation settings
198 * @adapter: board private structure
200 static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
202 struct i40e_hw *hw = &adapter->hw;
203 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
204 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
205 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA_ADMINQ_MASK);
208 rd32(hw, I40E_VFGEN_RSTAT);
212 * i40evf_irq_disable - Mask off interrupt generation on the NIC
213 * @adapter: board private structure
215 static void i40evf_irq_disable(struct i40evf_adapter *adapter)
218 struct i40e_hw *hw = &adapter->hw;
220 if (!adapter->msix_entries)
223 for (i = 1; i < adapter->num_msix_vectors; i++) {
224 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
225 synchronize_irq(adapter->msix_entries[i].vector);
228 rd32(hw, I40E_VFGEN_RSTAT);
233 * i40evf_irq_enable_queues - Enable interrupt for specified queues
234 * @adapter: board private structure
235 * @mask: bitmap of queues to enable
237 void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
239 struct i40e_hw *hw = &adapter->hw;
242 for (i = 1; i < adapter->num_msix_vectors; i++) {
243 if (mask & (1 << (i - 1))) {
244 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
245 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
246 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
252 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
253 * @adapter: board private structure
254 * @mask: bitmap of vectors to trigger
256 static void i40evf_fire_sw_int(struct i40evf_adapter *adapter,
259 struct i40e_hw *hw = &adapter->hw;
263 for (i = 1; i < adapter->num_msix_vectors; i++) {
264 if (mask & (1 << i)) {
265 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
266 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
267 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
268 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
274 * i40evf_irq_enable - Enable default interrupt generation settings
275 * @adapter: board private structure
277 void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
279 struct i40e_hw *hw = &adapter->hw;
281 i40evf_irq_enable_queues(adapter, ~0);
284 rd32(hw, I40E_VFGEN_RSTAT);
288 * i40evf_msix_aq - Interrupt handler for vector 0
289 * @irq: interrupt number
290 * @data: pointer to netdev
292 static irqreturn_t i40evf_msix_aq(int irq, void *data)
294 struct net_device *netdev = data;
295 struct i40evf_adapter *adapter = netdev_priv(netdev);
296 struct i40e_hw *hw = &adapter->hw;
300 /* handle non-queue interrupts */
301 val = rd32(hw, I40E_VFINT_ICR01);
302 ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1);
305 val = rd32(hw, I40E_VFINT_DYN_CTL01);
306 val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
307 wr32(hw, I40E_VFINT_DYN_CTL01, val);
309 /* re-enable interrupt causes */
310 wr32(hw, I40E_VFINT_ICR0_ENA1, ena_mask);
311 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK);
313 /* schedule work on the private workqueue */
314 schedule_work(&adapter->adminq_task);
320 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
321 * @irq: interrupt number
322 * @data: pointer to a q_vector
324 static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
326 struct i40e_q_vector *q_vector = data;
328 if (!q_vector->tx.ring && !q_vector->rx.ring)
331 napi_schedule(&q_vector->napi);
337 * i40evf_map_vector_to_rxq - associate irqs with rx queues
338 * @adapter: board private structure
339 * @v_idx: interrupt number
340 * @r_idx: queue number
343 i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
345 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
346 struct i40e_ring *rx_ring = adapter->rx_rings[r_idx];
348 rx_ring->q_vector = q_vector;
349 rx_ring->next = q_vector->rx.ring;
350 rx_ring->vsi = &adapter->vsi;
351 q_vector->rx.ring = rx_ring;
352 q_vector->rx.count++;
353 q_vector->rx.latency_range = I40E_LOW_LATENCY;
357 * i40evf_map_vector_to_txq - associate irqs with tx queues
358 * @adapter: board private structure
359 * @v_idx: interrupt number
360 * @t_idx: queue number
363 i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
365 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
366 struct i40e_ring *tx_ring = adapter->tx_rings[t_idx];
368 tx_ring->q_vector = q_vector;
369 tx_ring->next = q_vector->tx.ring;
370 tx_ring->vsi = &adapter->vsi;
371 q_vector->tx.ring = tx_ring;
372 q_vector->tx.count++;
373 q_vector->tx.latency_range = I40E_LOW_LATENCY;
374 q_vector->num_ringpairs++;
375 q_vector->ring_mask |= (1 << t_idx);
379 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
380 * @adapter: board private structure to initialize
382 * This function maps descriptor rings to the queue-specific vectors
383 * we were allotted through the MSI-X enabling code. Ideally, we'd have
384 * one vector per ring/queue, but on a constrained vector budget, we
385 * group the rings as "efficiently" as possible. You would add new
386 * mapping configurations in here.
388 static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
392 int rxr_idx = 0, txr_idx = 0;
393 int rxr_remaining = adapter->vsi_res->num_queue_pairs;
394 int txr_remaining = adapter->vsi_res->num_queue_pairs;
399 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
401 /* The ideal configuration...
402 * We have enough vectors to map one per queue.
404 if (q_vectors == (rxr_remaining * 2)) {
405 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
406 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
408 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
409 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
413 /* If we don't have enough vectors for a 1-to-1
414 * mapping, we'll have to group them so there are
415 * multiple queues per vector.
416 * Re-adjusting *qpv takes care of the remainder.
418 for (i = v_start; i < q_vectors; i++) {
419 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
420 for (j = 0; j < rqpv; j++) {
421 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
426 for (i = v_start; i < q_vectors; i++) {
427 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
428 for (j = 0; j < tqpv; j++) {
429 i40evf_map_vector_to_txq(adapter, i, txr_idx);
436 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
442 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
443 * @adapter: board private structure
445 * Allocates MSI-X vectors for tx and rx handling, and requests
446 * interrupts from the kernel.
449 i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
451 int vector, err, q_vectors;
452 int rx_int_idx = 0, tx_int_idx = 0;
454 i40evf_irq_disable(adapter);
455 /* Decrement for Other and TCP Timer vectors */
456 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
458 for (vector = 0; vector < q_vectors; vector++) {
459 struct i40e_q_vector *q_vector = adapter->q_vector[vector];
461 if (q_vector->tx.ring && q_vector->rx.ring) {
462 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
463 "i40evf-%s-%s-%d", basename,
464 "TxRx", rx_int_idx++);
466 } else if (q_vector->rx.ring) {
467 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
468 "i40evf-%s-%s-%d", basename,
470 } else if (q_vector->tx.ring) {
471 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
472 "i40evf-%s-%s-%d", basename,
475 /* skip this unused q_vector */
479 adapter->msix_entries[vector + NONQ_VECS].vector,
480 i40evf_msix_clean_rings,
485 dev_info(&adapter->pdev->dev,
486 "%s: request_irq failed, error: %d\n",
488 goto free_queue_irqs;
490 /* assign the mask for this irq */
491 irq_set_affinity_hint(
492 adapter->msix_entries[vector + NONQ_VECS].vector,
493 q_vector->affinity_mask);
501 irq_set_affinity_hint(
502 adapter->msix_entries[vector + NONQ_VECS].vector,
504 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
505 adapter->q_vector[vector]);
511 * i40evf_request_misc_irq - Initialize MSI-X interrupts
512 * @adapter: board private structure
514 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
515 * vector is only for the admin queue, and stays active even when the netdev
518 static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
520 struct net_device *netdev = adapter->netdev;
523 sprintf(adapter->misc_vector_name, "i40evf:mbx");
524 err = request_irq(adapter->msix_entries[0].vector,
526 adapter->misc_vector_name, netdev);
528 dev_err(&adapter->pdev->dev,
529 "request_irq for %s failed: %d\n",
530 adapter->misc_vector_name, err);
531 free_irq(adapter->msix_entries[0].vector, netdev);
537 * i40evf_free_traffic_irqs - Free MSI-X interrupts
538 * @adapter: board private structure
540 * Frees all MSI-X vectors other than 0.
542 static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
546 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
548 for (i = 0; i < q_vectors; i++) {
549 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
551 free_irq(adapter->msix_entries[i+1].vector,
552 adapter->q_vector[i]);
557 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
558 * @adapter: board private structure
560 * Frees MSI-X vector 0.
562 static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
564 struct net_device *netdev = adapter->netdev;
566 free_irq(adapter->msix_entries[0].vector, netdev);
570 * i40evf_configure_tx - Configure Transmit Unit after Reset
571 * @adapter: board private structure
573 * Configure the Tx unit of the MAC after a reset.
575 static void i40evf_configure_tx(struct i40evf_adapter *adapter)
577 struct i40e_hw *hw = &adapter->hw;
579 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
580 adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i);
584 * i40evf_configure_rx - Configure Receive Unit after Reset
585 * @adapter: board private structure
587 * Configure the Rx unit of the MAC after a reset.
589 static void i40evf_configure_rx(struct i40evf_adapter *adapter)
591 struct i40e_hw *hw = &adapter->hw;
592 struct net_device *netdev = adapter->netdev;
593 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
598 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
599 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
601 /* Decide whether to use packet split mode or not */
602 if (netdev->mtu > ETH_DATA_LEN) {
603 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
604 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
606 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
608 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
609 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
611 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
614 /* Set the RX buffer length according to the mode */
615 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
616 rx_buf_len = I40E_RX_HDR_SIZE;
618 if (netdev->mtu <= ETH_DATA_LEN)
619 rx_buf_len = I40EVF_RXBUFFER_2048;
621 rx_buf_len = ALIGN(max_frame, 1024);
624 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
625 adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i);
626 adapter->rx_rings[i]->rx_buf_len = rx_buf_len;
631 * i40evf_find_vlan - Search filter list for specific vlan filter
632 * @adapter: board private structure
635 * Returns ptr to the filter object or NULL
638 i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
640 struct i40evf_vlan_filter *f;
642 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
650 * i40evf_add_vlan - Add a vlan filter to the list
651 * @adapter: board private structure
654 * Returns ptr to the filter object or NULL when no memory available.
657 i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
659 struct i40evf_vlan_filter *f;
661 f = i40evf_find_vlan(adapter, vlan);
663 f = kzalloc(sizeof(*f), GFP_ATOMIC);
669 INIT_LIST_HEAD(&f->list);
670 list_add(&f->list, &adapter->vlan_filter_list);
672 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
679 * i40evf_del_vlan - Remove a vlan filter from the list
680 * @adapter: board private structure
683 static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
685 struct i40evf_vlan_filter *f;
687 f = i40evf_find_vlan(adapter, vlan);
690 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
695 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
696 * @netdev: network device struct
699 static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
700 __always_unused __be16 proto, u16 vid)
702 struct i40evf_adapter *adapter = netdev_priv(netdev);
704 if (i40evf_add_vlan(adapter, vid) == NULL)
710 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
711 * @netdev: network device struct
714 static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
715 __always_unused __be16 proto, u16 vid)
717 struct i40evf_adapter *adapter = netdev_priv(netdev);
719 i40evf_del_vlan(adapter, vid);
724 * i40evf_find_filter - Search filter list for specific mac filter
725 * @adapter: board private structure
726 * @macaddr: the MAC address
728 * Returns ptr to the filter object or NULL
731 i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
734 struct i40evf_mac_filter *f;
739 list_for_each_entry(f, &adapter->mac_filter_list, list) {
740 if (ether_addr_equal(macaddr, f->macaddr))
747 * i40e_add_filter - Add a mac filter to the filter list
748 * @adapter: board private structure
749 * @macaddr: the MAC address
751 * Returns ptr to the filter object or NULL when no memory available.
754 i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
757 struct i40evf_mac_filter *f;
762 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
763 &adapter->crit_section))
766 f = i40evf_find_filter(adapter, macaddr);
768 f = kzalloc(sizeof(*f), GFP_ATOMIC);
770 clear_bit(__I40EVF_IN_CRITICAL_TASK,
771 &adapter->crit_section);
775 memcpy(f->macaddr, macaddr, ETH_ALEN);
777 list_add(&f->list, &adapter->mac_filter_list);
779 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
782 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
787 * i40evf_set_mac - NDO callback to set port mac address
788 * @netdev: network interface device structure
789 * @p: pointer to an address structure
791 * Returns 0 on success, negative on failure
793 static int i40evf_set_mac(struct net_device *netdev, void *p)
795 struct i40evf_adapter *adapter = netdev_priv(netdev);
796 struct i40e_hw *hw = &adapter->hw;
797 struct i40evf_mac_filter *f;
798 struct sockaddr *addr = p;
800 if (!is_valid_ether_addr(addr->sa_data))
801 return -EADDRNOTAVAIL;
803 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
806 f = i40evf_add_filter(adapter, addr->sa_data);
808 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
809 memcpy(netdev->dev_addr, adapter->hw.mac.addr,
813 return (f == NULL) ? -ENOMEM : 0;
817 * i40evf_set_rx_mode - NDO callback to set the netdev filters
818 * @netdev: network interface device structure
820 static void i40evf_set_rx_mode(struct net_device *netdev)
822 struct i40evf_adapter *adapter = netdev_priv(netdev);
823 struct i40evf_mac_filter *f, *ftmp;
824 struct netdev_hw_addr *uca;
825 struct netdev_hw_addr *mca;
827 /* add addr if not already in the filter list */
828 netdev_for_each_uc_addr(uca, netdev) {
829 i40evf_add_filter(adapter, uca->addr);
831 netdev_for_each_mc_addr(mca, netdev) {
832 i40evf_add_filter(adapter, mca->addr);
835 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
836 &adapter->crit_section))
838 /* remove filter if not in netdev list */
839 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
842 if (is_multicast_ether_addr(f->macaddr)) {
843 netdev_for_each_mc_addr(mca, netdev) {
844 if (ether_addr_equal(mca->addr, f->macaddr)) {
850 netdev_for_each_uc_addr(uca, netdev) {
851 if (ether_addr_equal(uca->addr, f->macaddr)) {
859 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
862 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
866 * i40evf_napi_enable_all - enable NAPI on all queue vectors
867 * @adapter: board private structure
869 static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
872 struct i40e_q_vector *q_vector;
873 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
875 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
876 struct napi_struct *napi;
877 q_vector = adapter->q_vector[q_idx];
878 napi = &q_vector->napi;
884 * i40evf_napi_disable_all - disable NAPI on all queue vectors
885 * @adapter: board private structure
887 static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
890 struct i40e_q_vector *q_vector;
891 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
893 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
894 q_vector = adapter->q_vector[q_idx];
895 napi_disable(&q_vector->napi);
900 * i40evf_configure - set up transmit and receive data structures
901 * @adapter: board private structure
903 static void i40evf_configure(struct i40evf_adapter *adapter)
905 struct net_device *netdev = adapter->netdev;
908 i40evf_set_rx_mode(netdev);
910 i40evf_configure_tx(adapter);
911 i40evf_configure_rx(adapter);
912 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
914 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
915 struct i40e_ring *ring = adapter->rx_rings[i];
916 i40evf_alloc_rx_buffers(ring, ring->count);
917 ring->next_to_use = ring->count - 1;
918 writel(ring->next_to_use, ring->tail);
923 * i40evf_up_complete - Finish the last steps of bringing up a connection
924 * @adapter: board private structure
926 static int i40evf_up_complete(struct i40evf_adapter *adapter)
928 adapter->state = __I40EVF_RUNNING;
929 clear_bit(__I40E_DOWN, &adapter->vsi.state);
931 i40evf_napi_enable_all(adapter);
933 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
934 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
939 * i40evf_clean_all_rx_rings - Free Rx Buffers for all queues
940 * @adapter: board private structure
942 static void i40evf_clean_all_rx_rings(struct i40evf_adapter *adapter)
946 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
947 i40evf_clean_rx_ring(adapter->rx_rings[i]);
951 * i40evf_clean_all_tx_rings - Free Tx Buffers for all queues
952 * @adapter: board private structure
954 static void i40evf_clean_all_tx_rings(struct i40evf_adapter *adapter)
958 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
959 i40evf_clean_tx_ring(adapter->tx_rings[i]);
963 * i40e_down - Shutdown the connection processing
964 * @adapter: board private structure
966 void i40evf_down(struct i40evf_adapter *adapter)
968 struct net_device *netdev = adapter->netdev;
969 struct i40evf_mac_filter *f;
971 /* remove all MAC filters */
972 list_for_each_entry(f, &adapter->mac_filter_list, list) {
975 /* remove all VLAN filters */
976 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
979 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
980 adapter->state != __I40EVF_RESETTING) {
981 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
982 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
983 /* disable receives */
984 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
985 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
988 netif_tx_disable(netdev);
990 netif_tx_stop_all_queues(netdev);
992 i40evf_irq_disable(adapter);
994 i40evf_napi_disable_all(adapter);
996 netif_carrier_off(netdev);
998 i40evf_clean_all_tx_rings(adapter);
999 i40evf_clean_all_rx_rings(adapter);
1003 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1004 * @adapter: board private structure
1005 * @vectors: number of vectors to request
1007 * Work with the OS to set up the MSIX vectors needed.
1009 * Returns 0 on success, negative on failure
1012 i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1014 int err, vector_threshold;
1016 /* We'll want at least 3 (vector_threshold):
1017 * 0) Other (Admin Queue and link, mostly)
1021 vector_threshold = MIN_MSIX_COUNT;
1023 /* The more we get, the more we will assign to Tx/Rx Cleanup
1024 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1025 * Right now, we simply care about how many we'll get; we'll
1026 * set them up later while requesting irq's.
1028 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1029 vector_threshold, vectors);
1031 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
1032 kfree(adapter->msix_entries);
1033 adapter->msix_entries = NULL;
1037 /* Adjust for only the vectors we'll use, which is minimum
1038 * of max_msix_q_vectors + NONQ_VECS, or the number of
1039 * vectors we were allocated.
1041 adapter->num_msix_vectors = err;
1046 * i40evf_free_queues - Free memory for all rings
1047 * @adapter: board private structure to initialize
1049 * Free all of the memory associated with queue pairs.
1051 static void i40evf_free_queues(struct i40evf_adapter *adapter)
1055 if (!adapter->vsi_res)
1057 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1058 if (adapter->tx_rings[i])
1059 kfree_rcu(adapter->tx_rings[i], rcu);
1060 adapter->tx_rings[i] = NULL;
1061 adapter->rx_rings[i] = NULL;
1066 * i40evf_alloc_queues - Allocate memory for all rings
1067 * @adapter: board private structure to initialize
1069 * We allocate one ring per queue at run-time since we don't know the
1070 * number of queues at compile-time. The polling_netdev array is
1071 * intended for Multiqueue, but should work fine with a single queue.
1073 static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1077 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1078 struct i40e_ring *tx_ring;
1079 struct i40e_ring *rx_ring;
1081 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
1085 tx_ring->queue_index = i;
1086 tx_ring->netdev = adapter->netdev;
1087 tx_ring->dev = &adapter->pdev->dev;
1088 tx_ring->count = adapter->tx_desc_count;
1089 adapter->tx_rings[i] = tx_ring;
1091 rx_ring = &tx_ring[1];
1092 rx_ring->queue_index = i;
1093 rx_ring->netdev = adapter->netdev;
1094 rx_ring->dev = &adapter->pdev->dev;
1095 rx_ring->count = adapter->rx_desc_count;
1096 adapter->rx_rings[i] = rx_ring;
1102 i40evf_free_queues(adapter);
1107 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1108 * @adapter: board private structure to initialize
1110 * Attempt to configure the interrupts using the best available
1111 * capabilities of the hardware and the kernel.
1113 static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1115 int vector, v_budget;
1119 if (!adapter->vsi_res) {
1123 pairs = adapter->vsi_res->num_queue_pairs;
1125 /* It's easy to be greedy for MSI-X vectors, but it really
1126 * doesn't do us much good if we have a lot more vectors
1127 * than CPU's. So let's be conservative and only ask for
1128 * (roughly) twice the number of vectors as there are CPU's.
1130 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1131 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
1133 adapter->msix_entries = kcalloc(v_budget,
1134 sizeof(struct msix_entry), GFP_KERNEL);
1135 if (!adapter->msix_entries) {
1140 for (vector = 0; vector < v_budget; vector++)
1141 adapter->msix_entries[vector].entry = vector;
1143 i40evf_acquire_msix_vectors(adapter, v_budget);
1146 adapter->netdev->real_num_tx_queues = pairs;
1151 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1152 * @adapter: board private structure to initialize
1154 * We allocate one q_vector per queue interrupt. If allocation fails we
1157 static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1159 int q_idx, num_q_vectors;
1160 struct i40e_q_vector *q_vector;
1162 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1164 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1165 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
1168 q_vector->adapter = adapter;
1169 q_vector->vsi = &adapter->vsi;
1170 q_vector->v_idx = q_idx;
1171 netif_napi_add(adapter->netdev, &q_vector->napi,
1172 i40evf_napi_poll, NAPI_POLL_WEIGHT);
1173 adapter->q_vector[q_idx] = q_vector;
1181 q_vector = adapter->q_vector[q_idx];
1182 netif_napi_del(&q_vector->napi);
1184 adapter->q_vector[q_idx] = NULL;
1190 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1191 * @adapter: board private structure to initialize
1193 * This function frees the memory allocated to the q_vectors. In addition if
1194 * NAPI is enabled it will delete any references to the NAPI struct prior
1195 * to freeing the q_vector.
1197 static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1199 int q_idx, num_q_vectors;
1202 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1203 napi_vectors = adapter->vsi_res->num_queue_pairs;
1205 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1206 struct i40e_q_vector *q_vector = adapter->q_vector[q_idx];
1208 adapter->q_vector[q_idx] = NULL;
1209 if (q_idx < napi_vectors)
1210 netif_napi_del(&q_vector->napi);
1216 * i40evf_reset_interrupt_capability - Reset MSIX setup
1217 * @adapter: board private structure
1220 void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1222 pci_disable_msix(adapter->pdev);
1223 kfree(adapter->msix_entries);
1224 adapter->msix_entries = NULL;
1228 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1229 * @adapter: board private structure to initialize
1232 int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1236 err = i40evf_set_interrupt_capability(adapter);
1238 dev_err(&adapter->pdev->dev,
1239 "Unable to setup interrupt capabilities\n");
1240 goto err_set_interrupt;
1243 err = i40evf_alloc_q_vectors(adapter);
1245 dev_err(&adapter->pdev->dev,
1246 "Unable to allocate memory for queue vectors\n");
1247 goto err_alloc_q_vectors;
1250 err = i40evf_alloc_queues(adapter);
1252 dev_err(&adapter->pdev->dev,
1253 "Unable to allocate memory for queues\n");
1254 goto err_alloc_queues;
1257 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
1258 (adapter->vsi_res->num_queue_pairs > 1) ? "Enabled" :
1259 "Disabled", adapter->vsi_res->num_queue_pairs);
1263 i40evf_free_q_vectors(adapter);
1264 err_alloc_q_vectors:
1265 i40evf_reset_interrupt_capability(adapter);
1271 * i40evf_watchdog_timer - Periodic call-back timer
1272 * @data: pointer to adapter disguised as unsigned long
1274 static void i40evf_watchdog_timer(unsigned long data)
1276 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
1277 schedule_work(&adapter->watchdog_task);
1278 /* timer will be rescheduled in watchdog task */
1282 * i40evf_watchdog_task - Periodic call-back task
1283 * @work: pointer to work_struct
1285 static void i40evf_watchdog_task(struct work_struct *work)
1287 struct i40evf_adapter *adapter = container_of(work,
1288 struct i40evf_adapter,
1290 struct i40e_hw *hw = &adapter->hw;
1292 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
1293 goto restart_watchdog;
1295 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1296 if ((rd32(hw, I40E_VFGEN_RSTAT) & 0x3) == I40E_VFR_VFACTIVE) {
1297 /* A chance for redemption! */
1298 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1299 adapter->state = __I40EVF_STARTUP;
1300 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1301 schedule_delayed_work(&adapter->init_task, 10);
1302 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1303 &adapter->crit_section);
1304 /* Don't reschedule the watchdog, since we've restarted
1305 * the init task. When init_task contacts the PF and
1306 * gets everything set up again, it'll restart the
1307 * watchdog for us. Down, boy. Sit. Stay. Woof.
1311 adapter->aq_pending = 0;
1312 adapter->aq_required = 0;
1313 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1317 if ((adapter->state < __I40EVF_DOWN) ||
1318 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
1321 /* check for reset */
1322 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) &&
1323 (rd32(hw, I40E_VFGEN_RSTAT) & 0x3) != I40E_VFR_VFACTIVE) {
1324 adapter->state = __I40EVF_RESETTING;
1325 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1326 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
1327 schedule_work(&adapter->reset_task);
1328 adapter->aq_pending = 0;
1329 adapter->aq_required = 0;
1330 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1334 /* Process admin queue tasks. After init, everything gets done
1335 * here so we don't race on the admin queue.
1337 if (adapter->aq_pending)
1340 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1341 i40evf_map_queues(adapter);
1345 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1346 i40evf_add_ether_addrs(adapter);
1350 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1351 i40evf_add_vlans(adapter);
1355 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1356 i40evf_del_ether_addrs(adapter);
1360 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1361 i40evf_del_vlans(adapter);
1365 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1366 i40evf_disable_queues(adapter);
1370 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1371 i40evf_configure_queues(adapter);
1375 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1376 i40evf_enable_queues(adapter);
1380 if (adapter->state == __I40EVF_RUNNING)
1381 i40evf_request_stats(adapter);
1383 i40evf_irq_enable(adapter, true);
1384 i40evf_fire_sw_int(adapter, 0xFF);
1387 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1389 if (adapter->aq_required)
1390 mod_timer(&adapter->watchdog_timer,
1391 jiffies + msecs_to_jiffies(20));
1393 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
1394 schedule_work(&adapter->adminq_task);
1398 * i40evf_configure_rss - increment to next available tx queue
1399 * @adapter: board private structure
1402 * Helper function for RSS programming to increment through available
1403 * queus. Returns the next queue value.
1405 static int next_queue(struct i40evf_adapter *adapter, int j)
1409 return j >= adapter->vsi_res->num_queue_pairs ? 0 : j;
1413 * i40evf_configure_rss - Prepare for RSS if used
1414 * @adapter: board private structure
1416 static void i40evf_configure_rss(struct i40evf_adapter *adapter)
1418 struct i40e_hw *hw = &adapter->hw;
1423 /* Set of random keys generated using kernel random number generator */
1424 static const u32 seed[I40E_VFQF_HKEY_MAX_INDEX + 1] = {
1425 0x794221b4, 0xbca0c5ab, 0x6cd5ebd9, 0x1ada6127,
1426 0x983b3aa1, 0x1c4e71eb, 0x7f6328b2, 0xfcdc0da0,
1427 0xc135cafa, 0x7a6f7e2d, 0xe7102d28, 0x163cd12e,
1430 /* Hash type is configured by the PF - we just supply the key */
1432 /* Fill out hash function seed */
1433 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1434 wr32(hw, I40E_VFQF_HKEY(i), seed[i]);
1436 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1437 hena = I40E_DEFAULT_RSS_HENA;
1438 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1439 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1441 /* Populate the LUT with max no. of queues in round robin fashion */
1442 j = adapter->vsi_res->num_queue_pairs;
1443 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) {
1444 j = next_queue(adapter, j);
1446 j = next_queue(adapter, j);
1448 j = next_queue(adapter, j);
1450 j = next_queue(adapter, j);
1452 wr32(hw, I40E_VFQF_HLUT(i), lut);
1457 #define I40EVF_RESET_WAIT_MS 100
1458 #define I40EVF_RESET_WAIT_COUNT 200
1460 * i40evf_reset_task - Call-back task to handle hardware reset
1461 * @work: pointer to work_struct
1463 * During reset we need to shut down and reinitialize the admin queue
1464 * before we can use it to communicate with the PF again. We also clear
1465 * and reinit the rings because that context is lost as well.
1467 static void i40evf_reset_task(struct work_struct *work)
1469 struct i40evf_adapter *adapter = container_of(work,
1470 struct i40evf_adapter,
1472 struct i40e_hw *hw = &adapter->hw;
1476 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1477 &adapter->crit_section))
1480 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
1481 dev_info(&adapter->pdev->dev, "Requesting reset from PF\n");
1482 i40evf_request_reset(adapter);
1485 /* poll until we see the reset actually happen */
1486 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1487 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1488 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1489 if (rstat_val != I40E_VFR_VFACTIVE)
1492 msleep(I40EVF_RESET_WAIT_MS);
1494 if (i == I40EVF_RESET_WAIT_COUNT) {
1495 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1496 goto continue_reset; /* act like the reset happened */
1499 /* wait until the reset is complete and the PF is responding to us */
1500 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1501 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1502 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1503 if (rstat_val == I40E_VFR_VFACTIVE)
1506 msleep(I40EVF_RESET_WAIT_MS);
1508 if (i == I40EVF_RESET_WAIT_COUNT) {
1509 /* reset never finished */
1510 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
1512 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1514 if (netif_running(adapter->netdev)) {
1515 set_bit(__I40E_DOWN, &adapter->vsi.state);
1516 i40evf_down(adapter);
1517 i40evf_free_traffic_irqs(adapter);
1518 i40evf_free_all_tx_resources(adapter);
1519 i40evf_free_all_rx_resources(adapter);
1521 i40evf_free_misc_irq(adapter);
1522 i40evf_reset_interrupt_capability(adapter);
1523 i40evf_free_queues(adapter);
1524 kfree(adapter->vf_res);
1525 i40evf_shutdown_adminq(hw);
1526 adapter->netdev->flags &= ~IFF_UP;
1527 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1528 return; /* Do not attempt to reinit. It's dead, Jim. */
1532 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1534 i40evf_down(adapter);
1535 adapter->state = __I40EVF_RESETTING;
1537 /* kill and reinit the admin queue */
1538 if (i40evf_shutdown_adminq(hw))
1539 dev_warn(&adapter->pdev->dev,
1540 "%s: Failed to destroy the Admin Queue resources\n",
1542 err = i40evf_init_adminq(hw);
1544 dev_info(&adapter->pdev->dev, "%s: init_adminq failed: %d\n",
1547 adapter->aq_pending = 0;
1548 adapter->aq_required = 0;
1549 i40evf_map_queues(adapter);
1550 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1552 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1554 if (netif_running(adapter->netdev)) {
1555 /* allocate transmit descriptors */
1556 err = i40evf_setup_all_tx_resources(adapter);
1560 /* allocate receive descriptors */
1561 err = i40evf_setup_all_rx_resources(adapter);
1565 i40evf_configure(adapter);
1567 err = i40evf_up_complete(adapter);
1571 i40evf_irq_enable(adapter, true);
1575 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
1576 i40evf_close(adapter->netdev);
1580 * i40evf_adminq_task - worker thread to clean the admin queue
1581 * @work: pointer to work_struct containing our data
1583 static void i40evf_adminq_task(struct work_struct *work)
1585 struct i40evf_adapter *adapter =
1586 container_of(work, struct i40evf_adapter, adminq_task);
1587 struct i40e_hw *hw = &adapter->hw;
1588 struct i40e_arq_event_info event;
1589 struct i40e_virtchnl_msg *v_msg;
1593 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
1596 event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
1597 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
1601 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1603 ret = i40evf_clean_arq_element(hw, &event, &pending);
1605 break; /* No event to process or error cleaning ARQ */
1607 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1608 v_msg->v_retval, event.msg_buf,
1611 dev_info(&adapter->pdev->dev,
1612 "%s: ARQ: Pending events %d\n",
1614 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
1618 /* re-enable Admin queue interrupt cause */
1619 i40evf_misc_irq_enable(adapter);
1621 kfree(event.msg_buf);
1625 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1626 * @adapter: board private structure
1628 * Free all transmit software resources
1630 static void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
1634 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
1635 if (adapter->tx_rings[i]->desc)
1636 i40evf_free_tx_resources(adapter->tx_rings[i]);
1641 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1642 * @adapter: board private structure
1644 * If this function returns with an error, then it's possible one or
1645 * more of the rings is populated (while the rest are not). It is the
1646 * callers duty to clean those orphaned rings.
1648 * Return 0 on success, negative on failure
1650 static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
1654 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1655 adapter->tx_rings[i]->count = adapter->tx_desc_count;
1656 err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
1659 dev_err(&adapter->pdev->dev,
1660 "%s: Allocation for Tx Queue %u failed\n",
1669 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1670 * @adapter: board private structure
1672 * If this function returns with an error, then it's possible one or
1673 * more of the rings is populated (while the rest are not). It is the
1674 * callers duty to clean those orphaned rings.
1676 * Return 0 on success, negative on failure
1678 static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
1682 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1683 adapter->rx_rings[i]->count = adapter->rx_desc_count;
1684 err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
1687 dev_err(&adapter->pdev->dev,
1688 "%s: Allocation for Rx Queue %u failed\n",
1696 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1697 * @adapter: board private structure
1699 * Free all receive software resources
1701 static void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
1705 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
1706 if (adapter->rx_rings[i]->desc)
1707 i40evf_free_rx_resources(adapter->rx_rings[i]);
1711 * i40evf_open - Called when a network interface is made active
1712 * @netdev: network interface device structure
1714 * Returns 0 on success, negative value on failure
1716 * The open entry point is called when a network interface is made
1717 * active by the system (IFF_UP). At this point all resources needed
1718 * for transmit and receive operations are allocated, the interrupt
1719 * handler is registered with the OS, the watchdog timer is started,
1720 * and the stack is notified that the interface is ready.
1722 static int i40evf_open(struct net_device *netdev)
1724 struct i40evf_adapter *adapter = netdev_priv(netdev);
1727 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1728 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
1731 if (adapter->state != __I40EVF_DOWN)
1734 /* allocate transmit descriptors */
1735 err = i40evf_setup_all_tx_resources(adapter);
1739 /* allocate receive descriptors */
1740 err = i40evf_setup_all_rx_resources(adapter);
1744 /* clear any pending interrupts, may auto mask */
1745 err = i40evf_request_traffic_irqs(adapter, netdev->name);
1749 i40evf_configure(adapter);
1751 err = i40evf_up_complete(adapter);
1755 i40evf_irq_enable(adapter, true);
1760 i40evf_down(adapter);
1761 i40evf_free_traffic_irqs(adapter);
1763 i40evf_free_all_rx_resources(adapter);
1765 i40evf_free_all_tx_resources(adapter);
1771 * i40evf_close - Disables a network interface
1772 * @netdev: network interface device structure
1774 * Returns 0, this is not allowed to fail
1776 * The close entry point is called when an interface is de-activated
1777 * by the OS. The hardware is still under the drivers control, but
1778 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1779 * are freed, along with all transmit and receive resources.
1781 static int i40evf_close(struct net_device *netdev)
1783 struct i40evf_adapter *adapter = netdev_priv(netdev);
1785 if (adapter->state <= __I40EVF_DOWN)
1788 /* signal that we are down to the interrupt handler */
1789 adapter->state = __I40EVF_DOWN;
1791 set_bit(__I40E_DOWN, &adapter->vsi.state);
1793 i40evf_down(adapter);
1794 i40evf_free_traffic_irqs(adapter);
1796 i40evf_free_all_tx_resources(adapter);
1797 i40evf_free_all_rx_resources(adapter);
1803 * i40evf_get_stats - Get System Network Statistics
1804 * @netdev: network interface device structure
1806 * Returns the address of the device statistics structure.
1807 * The statistics are actually updated from the timer callback.
1809 static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
1811 struct i40evf_adapter *adapter = netdev_priv(netdev);
1813 /* only return the current stats */
1814 return &adapter->net_stats;
1818 * i40evf_reinit_locked - Software reinit
1819 * @adapter: board private structure
1821 * Reinititalizes the ring structures in response to a software configuration
1822 * change. Roughly the same as close followed by open, but skips releasing
1823 * and reallocating the interrupts.
1825 void i40evf_reinit_locked(struct i40evf_adapter *adapter)
1827 struct net_device *netdev = adapter->netdev;
1830 WARN_ON(in_interrupt());
1832 i40evf_down(adapter);
1834 /* allocate transmit descriptors */
1835 err = i40evf_setup_all_tx_resources(adapter);
1839 /* allocate receive descriptors */
1840 err = i40evf_setup_all_rx_resources(adapter);
1844 i40evf_configure(adapter);
1846 err = i40evf_up_complete(adapter);
1850 i40evf_irq_enable(adapter, true);
1854 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
1855 i40evf_close(netdev);
1859 * i40evf_change_mtu - Change the Maximum Transfer Unit
1860 * @netdev: network interface device structure
1861 * @new_mtu: new value for maximum frame size
1863 * Returns 0 on success, negative on failure
1865 static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
1867 struct i40evf_adapter *adapter = netdev_priv(netdev);
1868 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
1870 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1873 /* must set new MTU before calling down or up */
1874 netdev->mtu = new_mtu;
1875 i40evf_reinit_locked(adapter);
1879 static const struct net_device_ops i40evf_netdev_ops = {
1880 .ndo_open = i40evf_open,
1881 .ndo_stop = i40evf_close,
1882 .ndo_start_xmit = i40evf_xmit_frame,
1883 .ndo_get_stats = i40evf_get_stats,
1884 .ndo_set_rx_mode = i40evf_set_rx_mode,
1885 .ndo_validate_addr = eth_validate_addr,
1886 .ndo_set_mac_address = i40evf_set_mac,
1887 .ndo_change_mtu = i40evf_change_mtu,
1888 .ndo_tx_timeout = i40evf_tx_timeout,
1889 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
1890 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
1894 * i40evf_check_reset_complete - check that VF reset is complete
1895 * @hw: pointer to hw struct
1897 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
1899 static int i40evf_check_reset_complete(struct i40e_hw *hw)
1904 for (i = 0; i < 100; i++) {
1905 rstat = rd32(hw, I40E_VFGEN_RSTAT);
1906 if (rstat == I40E_VFR_VFACTIVE)
1914 * i40evf_init_task - worker thread to perform delayed initialization
1915 * @work: pointer to work_struct containing our data
1917 * This task completes the work that was begun in probe. Due to the nature
1918 * of VF-PF communications, we may need to wait tens of milliseconds to get
1919 * reponses back from the PF. Rather than busy-wait in probe and bog down the
1920 * whole system, we'll do it in a task so we can sleep.
1921 * This task only runs during driver init. Once we've established
1922 * communications with the PF driver and set up our netdev, the watchdog
1925 static void i40evf_init_task(struct work_struct *work)
1927 struct i40evf_adapter *adapter = container_of(work,
1928 struct i40evf_adapter,
1930 struct net_device *netdev = adapter->netdev;
1931 struct i40evf_mac_filter *f;
1932 struct i40e_hw *hw = &adapter->hw;
1933 struct pci_dev *pdev = adapter->pdev;
1936 switch (adapter->state) {
1937 case __I40EVF_STARTUP:
1938 /* driver loaded, probe complete */
1939 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1940 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1941 err = i40e_set_mac_type(hw);
1943 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
1947 err = i40evf_check_reset_complete(hw);
1949 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
1953 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
1954 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
1955 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
1956 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
1958 err = i40evf_init_adminq(hw);
1960 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
1964 err = i40evf_send_api_ver(adapter);
1966 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
1967 i40evf_shutdown_adminq(hw);
1970 adapter->state = __I40EVF_INIT_VERSION_CHECK;
1973 case __I40EVF_INIT_VERSION_CHECK:
1974 if (!i40evf_asq_done(hw)) {
1975 dev_err(&pdev->dev, "Admin queue command never completed\n");
1979 /* aq msg sent, awaiting reply */
1980 err = i40evf_verify_api_ver(adapter);
1982 dev_info(&pdev->dev, "Unable to verify API version (%d), retrying\n",
1986 err = i40evf_send_vf_config_msg(adapter);
1988 dev_err(&pdev->dev, "Unable send config request (%d)\n",
1992 adapter->state = __I40EVF_INIT_GET_RESOURCES;
1995 case __I40EVF_INIT_GET_RESOURCES:
1996 /* aq msg sent, awaiting reply */
1997 if (!adapter->vf_res) {
1998 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2000 sizeof(struct i40e_virtchnl_vsi_resource));
2001 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
2002 if (!adapter->vf_res)
2005 err = i40evf_get_vf_config(adapter);
2006 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
2009 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2013 adapter->state = __I40EVF_INIT_SW;
2018 /* got VF config message back from PF, now we can parse it */
2019 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2020 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2021 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2023 if (!adapter->vsi_res) {
2024 dev_err(&pdev->dev, "No LAN VSI found\n");
2028 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2030 netdev->netdev_ops = &i40evf_netdev_ops;
2031 i40evf_set_ethtool_ops(netdev);
2032 netdev->watchdog_timeo = 5 * HZ;
2033 netdev->features |= NETIF_F_HIGHDMA |
2043 if (adapter->vf_res->vf_offload_flags
2044 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
2045 netdev->vlan_features = netdev->features;
2046 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2047 NETIF_F_HW_VLAN_CTAG_RX |
2048 NETIF_F_HW_VLAN_CTAG_FILTER;
2051 /* copy netdev features into list of user selectable features */
2052 netdev->hw_features |= netdev->features;
2053 netdev->hw_features &= ~NETIF_F_RXCSUM;
2055 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
2056 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
2057 adapter->hw.mac.addr);
2058 random_ether_addr(adapter->hw.mac.addr);
2060 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
2061 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
2063 INIT_LIST_HEAD(&adapter->mac_filter_list);
2064 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2065 f = kzalloc(sizeof(*f), GFP_ATOMIC);
2069 memcpy(f->macaddr, adapter->hw.mac.addr, ETH_ALEN);
2071 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
2073 list_add(&f->list, &adapter->mac_filter_list);
2075 init_timer(&adapter->watchdog_timer);
2076 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2077 adapter->watchdog_timer.data = (unsigned long)adapter;
2078 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2080 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2081 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
2082 err = i40evf_init_interrupt_scheme(adapter);
2085 i40evf_map_rings_to_vectors(adapter);
2086 i40evf_configure_rss(adapter);
2087 err = i40evf_request_misc_irq(adapter);
2091 netif_carrier_off(netdev);
2093 adapter->vsi.id = adapter->vsi_res->vsi_id;
2094 adapter->vsi.seid = adapter->vsi_res->vsi_id; /* dummy */
2095 adapter->vsi.back = adapter;
2096 adapter->vsi.base_vector = 1;
2097 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2098 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2099 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2100 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2101 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2102 adapter->vsi.netdev = adapter->netdev;
2104 if (!adapter->netdev_registered) {
2105 err = register_netdev(netdev);
2110 adapter->netdev_registered = true;
2112 netif_tx_stop_all_queues(netdev);
2114 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
2115 if (netdev->features & NETIF_F_GRO)
2116 dev_info(&pdev->dev, "GRO is enabled\n");
2118 dev_info(&pdev->dev, "%s\n", i40evf_driver_string);
2119 adapter->state = __I40EVF_DOWN;
2120 set_bit(__I40E_DOWN, &adapter->vsi.state);
2121 i40evf_misc_irq_enable(adapter);
2124 schedule_delayed_work(&adapter->init_task,
2125 msecs_to_jiffies(50));
2129 i40evf_free_misc_irq(adapter);
2131 i40evf_reset_interrupt_capability(adapter);
2133 kfree(adapter->vf_res);
2134 adapter->vf_res = NULL;
2136 /* Things went into the weeds, so try again later */
2137 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
2138 dev_err(&pdev->dev, "Failed to communicate with PF; giving up\n");
2139 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
2140 return; /* do not reschedule */
2142 schedule_delayed_work(&adapter->init_task, HZ * 3);
2146 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2147 * @pdev: pci device structure
2149 static void i40evf_shutdown(struct pci_dev *pdev)
2151 struct net_device *netdev = pci_get_drvdata(pdev);
2153 netif_device_detach(netdev);
2155 if (netif_running(netdev))
2156 i40evf_close(netdev);
2159 pci_save_state(pdev);
2162 pci_disable_device(pdev);
2166 * i40evf_probe - Device Initialization Routine
2167 * @pdev: PCI device information struct
2168 * @ent: entry in i40evf_pci_tbl
2170 * Returns 0 on success, negative on failure
2172 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2173 * The OS initialization, configuring of the adapter private structure,
2174 * and a hardware reset occur.
2176 static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2178 struct net_device *netdev;
2179 struct i40evf_adapter *adapter = NULL;
2180 struct i40e_hw *hw = NULL;
2183 err = pci_enable_device(pdev);
2187 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2189 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2192 "DMA configuration failed: 0x%x\n", err);
2197 err = pci_request_regions(pdev, i40evf_driver_name);
2200 "pci_request_regions failed 0x%x\n", err);
2204 pci_enable_pcie_error_reporting(pdev);
2206 pci_set_master(pdev);
2208 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter),
2212 goto err_alloc_etherdev;
2215 SET_NETDEV_DEV(netdev, &pdev->dev);
2217 pci_set_drvdata(pdev, netdev);
2218 adapter = netdev_priv(netdev);
2220 adapter->netdev = netdev;
2221 adapter->pdev = pdev;
2226 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2227 adapter->state = __I40EVF_STARTUP;
2229 /* Call save state here because it relies on the adapter struct. */
2230 pci_save_state(pdev);
2232 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2233 pci_resource_len(pdev, 0));
2238 hw->vendor_id = pdev->vendor;
2239 hw->device_id = pdev->device;
2240 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2241 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2242 hw->subsystem_device_id = pdev->subsystem_device;
2243 hw->bus.device = PCI_SLOT(pdev->devfn);
2244 hw->bus.func = PCI_FUNC(pdev->devfn);
2246 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2247 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2248 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2249 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
2250 schedule_delayed_work(&adapter->init_task, 10);
2255 free_netdev(netdev);
2257 pci_release_regions(pdev);
2260 pci_disable_device(pdev);
2266 * i40evf_suspend - Power management suspend routine
2267 * @pdev: PCI device information struct
2270 * Called when the system (VM) is entering sleep/suspend.
2272 static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2274 struct net_device *netdev = pci_get_drvdata(pdev);
2275 struct i40evf_adapter *adapter = netdev_priv(netdev);
2278 netif_device_detach(netdev);
2280 if (netif_running(netdev)) {
2282 i40evf_down(adapter);
2285 i40evf_free_misc_irq(adapter);
2286 i40evf_reset_interrupt_capability(adapter);
2288 retval = pci_save_state(pdev);
2292 pci_disable_device(pdev);
2298 * i40evf_resume - Power managment resume routine
2299 * @pdev: PCI device information struct
2301 * Called when the system (VM) is resumed from sleep/suspend.
2303 static int i40evf_resume(struct pci_dev *pdev)
2305 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2306 struct net_device *netdev = adapter->netdev;
2309 pci_set_power_state(pdev, PCI_D0);
2310 pci_restore_state(pdev);
2311 /* pci_restore_state clears dev->state_saved so call
2312 * pci_save_state to restore it.
2314 pci_save_state(pdev);
2316 err = pci_enable_device_mem(pdev);
2318 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2321 pci_set_master(pdev);
2324 err = i40evf_set_interrupt_capability(adapter);
2326 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2329 err = i40evf_request_misc_irq(adapter);
2332 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2336 schedule_work(&adapter->reset_task);
2338 netif_device_attach(netdev);
2343 #endif /* CONFIG_PM */
2345 * i40evf_remove - Device Removal Routine
2346 * @pdev: PCI device information struct
2348 * i40evf_remove is called by the PCI subsystem to alert the driver
2349 * that it should release a PCI device. The could be caused by a
2350 * Hot-Plug event, or because the driver is going to be removed from
2353 static void i40evf_remove(struct pci_dev *pdev)
2355 struct net_device *netdev = pci_get_drvdata(pdev);
2356 struct i40evf_adapter *adapter = netdev_priv(netdev);
2357 struct i40e_hw *hw = &adapter->hw;
2359 cancel_delayed_work_sync(&adapter->init_task);
2360 cancel_work_sync(&adapter->reset_task);
2362 if (adapter->netdev_registered) {
2363 unregister_netdev(netdev);
2364 adapter->netdev_registered = false;
2366 adapter->state = __I40EVF_REMOVE;
2368 if (adapter->msix_entries) {
2369 i40evf_misc_irq_disable(adapter);
2370 i40evf_free_misc_irq(adapter);
2371 i40evf_reset_interrupt_capability(adapter);
2374 del_timer_sync(&adapter->watchdog_timer);
2375 flush_scheduled_work();
2377 if (hw->aq.asq.count)
2378 i40evf_shutdown_adminq(hw);
2380 iounmap(hw->hw_addr);
2381 pci_release_regions(pdev);
2383 i40evf_free_queues(adapter);
2384 kfree(adapter->vf_res);
2386 free_netdev(netdev);
2388 pci_disable_pcie_error_reporting(pdev);
2390 pci_disable_device(pdev);
2393 static struct pci_driver i40evf_driver = {
2394 .name = i40evf_driver_name,
2395 .id_table = i40evf_pci_tbl,
2396 .probe = i40evf_probe,
2397 .remove = i40evf_remove,
2399 .suspend = i40evf_suspend,
2400 .resume = i40evf_resume,
2402 .shutdown = i40evf_shutdown,
2406 * i40e_init_module - Driver Registration Routine
2408 * i40e_init_module is the first routine called when the driver is
2409 * loaded. All it does is register with the PCI subsystem.
2411 static int __init i40evf_init_module(void)
2414 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
2415 i40evf_driver_version);
2417 pr_info("%s\n", i40evf_copyright);
2419 ret = pci_register_driver(&i40evf_driver);
2423 module_init(i40evf_init_module);
2426 * i40e_exit_module - Driver Exit Cleanup Routine
2428 * i40e_exit_module is called just before the driver is removed
2431 static void __exit i40evf_exit_module(void)
2433 pci_unregister_driver(&i40evf_driver);
2436 module_exit(i40evf_exit_module);