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.23"
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 dev_info(&adapter->pdev->dev, "TX timeout detected.\n");
176 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
177 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
178 schedule_work(&adapter->reset_task);
183 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
184 * @adapter: board private structure
186 static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
188 struct i40e_hw *hw = &adapter->hw;
189 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
192 rd32(hw, I40E_VFGEN_RSTAT);
194 synchronize_irq(adapter->msix_entries[0].vector);
198 * i40evf_misc_irq_enable - Enable default interrupt generation settings
199 * @adapter: board private structure
201 static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
203 struct i40e_hw *hw = &adapter->hw;
204 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
205 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
206 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA_ADMINQ_MASK);
209 rd32(hw, I40E_VFGEN_RSTAT);
213 * i40evf_irq_disable - Mask off interrupt generation on the NIC
214 * @adapter: board private structure
216 static void i40evf_irq_disable(struct i40evf_adapter *adapter)
219 struct i40e_hw *hw = &adapter->hw;
221 if (!adapter->msix_entries)
224 for (i = 1; i < adapter->num_msix_vectors; i++) {
225 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
226 synchronize_irq(adapter->msix_entries[i].vector);
229 rd32(hw, I40E_VFGEN_RSTAT);
234 * i40evf_irq_enable_queues - Enable interrupt for specified queues
235 * @adapter: board private structure
236 * @mask: bitmap of queues to enable
238 void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
240 struct i40e_hw *hw = &adapter->hw;
243 for (i = 1; i < adapter->num_msix_vectors; i++) {
244 if (mask & (1 << (i - 1))) {
245 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
246 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
247 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
253 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
254 * @adapter: board private structure
255 * @mask: bitmap of vectors to trigger
257 static void i40evf_fire_sw_int(struct i40evf_adapter *adapter,
260 struct i40e_hw *hw = &adapter->hw;
264 for (i = 1; i < adapter->num_msix_vectors; i++) {
265 if (mask & (1 << i)) {
266 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
267 dyn_ctl |= I40E_VFINT_DYN_CTLN_SWINT_TRIG_MASK |
268 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK;
269 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
275 * i40evf_irq_enable - Enable default interrupt generation settings
276 * @adapter: board private structure
278 void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
280 struct i40e_hw *hw = &adapter->hw;
282 i40evf_irq_enable_queues(adapter, ~0);
285 rd32(hw, I40E_VFGEN_RSTAT);
289 * i40evf_msix_aq - Interrupt handler for vector 0
290 * @irq: interrupt number
291 * @data: pointer to netdev
293 static irqreturn_t i40evf_msix_aq(int irq, void *data)
295 struct net_device *netdev = data;
296 struct i40evf_adapter *adapter = netdev_priv(netdev);
297 struct i40e_hw *hw = &adapter->hw;
301 /* handle non-queue interrupts */
302 val = rd32(hw, I40E_VFINT_ICR01);
303 ena_mask = rd32(hw, I40E_VFINT_ICR0_ENA1);
306 val = rd32(hw, I40E_VFINT_DYN_CTL01);
307 val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK;
308 wr32(hw, I40E_VFINT_DYN_CTL01, val);
310 /* re-enable interrupt causes */
311 wr32(hw, I40E_VFINT_ICR0_ENA1, ena_mask);
312 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK);
314 /* schedule work on the private workqueue */
315 schedule_work(&adapter->adminq_task);
321 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
322 * @irq: interrupt number
323 * @data: pointer to a q_vector
325 static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
327 struct i40e_q_vector *q_vector = data;
329 if (!q_vector->tx.ring && !q_vector->rx.ring)
332 napi_schedule(&q_vector->napi);
338 * i40evf_map_vector_to_rxq - associate irqs with rx queues
339 * @adapter: board private structure
340 * @v_idx: interrupt number
341 * @r_idx: queue number
344 i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
346 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
347 struct i40e_ring *rx_ring = adapter->rx_rings[r_idx];
349 rx_ring->q_vector = q_vector;
350 rx_ring->next = q_vector->rx.ring;
351 rx_ring->vsi = &adapter->vsi;
352 q_vector->rx.ring = rx_ring;
353 q_vector->rx.count++;
354 q_vector->rx.latency_range = I40E_LOW_LATENCY;
358 * i40evf_map_vector_to_txq - associate irqs with tx queues
359 * @adapter: board private structure
360 * @v_idx: interrupt number
361 * @t_idx: queue number
364 i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
366 struct i40e_q_vector *q_vector = adapter->q_vector[v_idx];
367 struct i40e_ring *tx_ring = adapter->tx_rings[t_idx];
369 tx_ring->q_vector = q_vector;
370 tx_ring->next = q_vector->tx.ring;
371 tx_ring->vsi = &adapter->vsi;
372 q_vector->tx.ring = tx_ring;
373 q_vector->tx.count++;
374 q_vector->tx.latency_range = I40E_LOW_LATENCY;
375 q_vector->num_ringpairs++;
376 q_vector->ring_mask |= (1 << t_idx);
380 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
381 * @adapter: board private structure to initialize
383 * This function maps descriptor rings to the queue-specific vectors
384 * we were allotted through the MSI-X enabling code. Ideally, we'd have
385 * one vector per ring/queue, but on a constrained vector budget, we
386 * group the rings as "efficiently" as possible. You would add new
387 * mapping configurations in here.
389 static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
393 int rxr_idx = 0, txr_idx = 0;
394 int rxr_remaining = adapter->vsi_res->num_queue_pairs;
395 int txr_remaining = adapter->vsi_res->num_queue_pairs;
400 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
402 /* The ideal configuration...
403 * We have enough vectors to map one per queue.
405 if (q_vectors == (rxr_remaining * 2)) {
406 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
407 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
409 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
410 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
414 /* If we don't have enough vectors for a 1-to-1
415 * mapping, we'll have to group them so there are
416 * multiple queues per vector.
417 * Re-adjusting *qpv takes care of the remainder.
419 for (i = v_start; i < q_vectors; i++) {
420 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
421 for (j = 0; j < rqpv; j++) {
422 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
427 for (i = v_start; i < q_vectors; i++) {
428 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
429 for (j = 0; j < tqpv; j++) {
430 i40evf_map_vector_to_txq(adapter, i, txr_idx);
437 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
443 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
444 * @adapter: board private structure
446 * Allocates MSI-X vectors for tx and rx handling, and requests
447 * interrupts from the kernel.
450 i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
452 int vector, err, q_vectors;
453 int rx_int_idx = 0, tx_int_idx = 0;
455 i40evf_irq_disable(adapter);
456 /* Decrement for Other and TCP Timer vectors */
457 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
459 for (vector = 0; vector < q_vectors; vector++) {
460 struct i40e_q_vector *q_vector = adapter->q_vector[vector];
462 if (q_vector->tx.ring && q_vector->rx.ring) {
463 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
464 "i40evf-%s-%s-%d", basename,
465 "TxRx", rx_int_idx++);
467 } else if (q_vector->rx.ring) {
468 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
469 "i40evf-%s-%s-%d", basename,
471 } else if (q_vector->tx.ring) {
472 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
473 "i40evf-%s-%s-%d", basename,
476 /* skip this unused q_vector */
480 adapter->msix_entries[vector + NONQ_VECS].vector,
481 i40evf_msix_clean_rings,
486 dev_info(&adapter->pdev->dev,
487 "%s: request_irq failed, error: %d\n",
489 goto free_queue_irqs;
491 /* assign the mask for this irq */
492 irq_set_affinity_hint(
493 adapter->msix_entries[vector + NONQ_VECS].vector,
494 q_vector->affinity_mask);
502 irq_set_affinity_hint(
503 adapter->msix_entries[vector + NONQ_VECS].vector,
505 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
506 adapter->q_vector[vector]);
512 * i40evf_request_misc_irq - Initialize MSI-X interrupts
513 * @adapter: board private structure
515 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
516 * vector is only for the admin queue, and stays active even when the netdev
519 static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
521 struct net_device *netdev = adapter->netdev;
524 sprintf(adapter->misc_vector_name, "i40evf:mbx");
525 err = request_irq(adapter->msix_entries[0].vector,
527 adapter->misc_vector_name, netdev);
529 dev_err(&adapter->pdev->dev,
530 "request_irq for %s failed: %d\n",
531 adapter->misc_vector_name, err);
532 free_irq(adapter->msix_entries[0].vector, netdev);
538 * i40evf_free_traffic_irqs - Free MSI-X interrupts
539 * @adapter: board private structure
541 * Frees all MSI-X vectors other than 0.
543 static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
547 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
549 for (i = 0; i < q_vectors; i++) {
550 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
552 free_irq(adapter->msix_entries[i+1].vector,
553 adapter->q_vector[i]);
558 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
559 * @adapter: board private structure
561 * Frees MSI-X vector 0.
563 static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
565 struct net_device *netdev = adapter->netdev;
567 free_irq(adapter->msix_entries[0].vector, netdev);
571 * i40evf_configure_tx - Configure Transmit Unit after Reset
572 * @adapter: board private structure
574 * Configure the Tx unit of the MAC after a reset.
576 static void i40evf_configure_tx(struct i40evf_adapter *adapter)
578 struct i40e_hw *hw = &adapter->hw;
580 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
581 adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i);
585 * i40evf_configure_rx - Configure Receive Unit after Reset
586 * @adapter: board private structure
588 * Configure the Rx unit of the MAC after a reset.
590 static void i40evf_configure_rx(struct i40evf_adapter *adapter)
592 struct i40e_hw *hw = &adapter->hw;
593 struct net_device *netdev = adapter->netdev;
594 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
599 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
600 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
602 /* Decide whether to use packet split mode or not */
603 if (netdev->mtu > ETH_DATA_LEN) {
604 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
605 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
607 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
609 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
610 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
612 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
615 /* Set the RX buffer length according to the mode */
616 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
617 rx_buf_len = I40E_RX_HDR_SIZE;
619 if (netdev->mtu <= ETH_DATA_LEN)
620 rx_buf_len = I40EVF_RXBUFFER_2048;
622 rx_buf_len = ALIGN(max_frame, 1024);
625 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
626 adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i);
627 adapter->rx_rings[i]->rx_buf_len = rx_buf_len;
632 * i40evf_find_vlan - Search filter list for specific vlan filter
633 * @adapter: board private structure
636 * Returns ptr to the filter object or NULL
639 i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
641 struct i40evf_vlan_filter *f;
643 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
651 * i40evf_add_vlan - Add a vlan filter to the list
652 * @adapter: board private structure
655 * Returns ptr to the filter object or NULL when no memory available.
658 i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
660 struct i40evf_vlan_filter *f;
662 f = i40evf_find_vlan(adapter, vlan);
664 f = kzalloc(sizeof(*f), GFP_ATOMIC);
666 dev_info(&adapter->pdev->dev,
667 "%s: no memory for new VLAN filter\n",
673 INIT_LIST_HEAD(&f->list);
674 list_add(&f->list, &adapter->vlan_filter_list);
676 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
683 * i40evf_del_vlan - Remove a vlan filter from the list
684 * @adapter: board private structure
687 static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
689 struct i40evf_vlan_filter *f;
691 f = i40evf_find_vlan(adapter, vlan);
694 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
700 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
701 * @netdev: network device struct
704 static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
705 __always_unused __be16 proto, u16 vid)
707 struct i40evf_adapter *adapter = netdev_priv(netdev);
709 if (i40evf_add_vlan(adapter, vid) == NULL)
715 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
716 * @netdev: network device struct
719 static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
720 __always_unused __be16 proto, u16 vid)
722 struct i40evf_adapter *adapter = netdev_priv(netdev);
724 i40evf_del_vlan(adapter, vid);
729 * i40evf_find_filter - Search filter list for specific mac filter
730 * @adapter: board private structure
731 * @macaddr: the MAC address
733 * Returns ptr to the filter object or NULL
736 i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
739 struct i40evf_mac_filter *f;
744 list_for_each_entry(f, &adapter->mac_filter_list, list) {
745 if (ether_addr_equal(macaddr, f->macaddr))
752 * i40e_add_filter - Add a mac filter to the filter list
753 * @adapter: board private structure
754 * @macaddr: the MAC address
756 * Returns ptr to the filter object or NULL when no memory available.
759 i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
762 struct i40evf_mac_filter *f;
767 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
768 &adapter->crit_section))
771 f = i40evf_find_filter(adapter, macaddr);
773 f = kzalloc(sizeof(*f), GFP_ATOMIC);
775 dev_info(&adapter->pdev->dev,
776 "%s: no memory for new filter\n", __func__);
777 clear_bit(__I40EVF_IN_CRITICAL_TASK,
778 &adapter->crit_section);
782 memcpy(f->macaddr, macaddr, ETH_ALEN);
784 list_add(&f->list, &adapter->mac_filter_list);
786 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
789 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
794 * i40evf_set_mac - NDO callback to set port mac address
795 * @netdev: network interface device structure
796 * @p: pointer to an address structure
798 * Returns 0 on success, negative on failure
800 static int i40evf_set_mac(struct net_device *netdev, void *p)
802 struct i40evf_adapter *adapter = netdev_priv(netdev);
803 struct i40e_hw *hw = &adapter->hw;
804 struct i40evf_mac_filter *f;
805 struct sockaddr *addr = p;
807 if (!is_valid_ether_addr(addr->sa_data))
808 return -EADDRNOTAVAIL;
810 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
813 f = i40evf_add_filter(adapter, addr->sa_data);
815 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
816 memcpy(netdev->dev_addr, adapter->hw.mac.addr,
820 return (f == NULL) ? -ENOMEM : 0;
824 * i40evf_set_rx_mode - NDO callback to set the netdev filters
825 * @netdev: network interface device structure
827 static void i40evf_set_rx_mode(struct net_device *netdev)
829 struct i40evf_adapter *adapter = netdev_priv(netdev);
830 struct i40evf_mac_filter *f, *ftmp;
831 struct netdev_hw_addr *uca;
832 struct netdev_hw_addr *mca;
834 /* add addr if not already in the filter list */
835 netdev_for_each_uc_addr(uca, netdev) {
836 i40evf_add_filter(adapter, uca->addr);
838 netdev_for_each_mc_addr(mca, netdev) {
839 i40evf_add_filter(adapter, mca->addr);
842 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
843 &adapter->crit_section))
845 /* remove filter if not in netdev list */
846 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
849 if (f->macaddr[0] & 0x01) {
850 netdev_for_each_mc_addr(mca, netdev) {
851 if (ether_addr_equal(mca->addr, f->macaddr)) {
857 netdev_for_each_uc_addr(uca, netdev) {
858 if (ether_addr_equal(uca->addr, f->macaddr)) {
866 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
869 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
873 * i40evf_napi_enable_all - enable NAPI on all queue vectors
874 * @adapter: board private structure
876 static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
879 struct i40e_q_vector *q_vector;
880 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
882 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
883 struct napi_struct *napi;
884 q_vector = adapter->q_vector[q_idx];
885 napi = &q_vector->napi;
891 * i40evf_napi_disable_all - disable NAPI on all queue vectors
892 * @adapter: board private structure
894 static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
897 struct i40e_q_vector *q_vector;
898 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
900 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
901 q_vector = adapter->q_vector[q_idx];
902 napi_disable(&q_vector->napi);
907 * i40evf_configure - set up transmit and receive data structures
908 * @adapter: board private structure
910 static void i40evf_configure(struct i40evf_adapter *adapter)
912 struct net_device *netdev = adapter->netdev;
915 i40evf_set_rx_mode(netdev);
917 i40evf_configure_tx(adapter);
918 i40evf_configure_rx(adapter);
919 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
921 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
922 struct i40e_ring *ring = adapter->rx_rings[i];
923 i40evf_alloc_rx_buffers(ring, ring->count);
924 ring->next_to_use = ring->count - 1;
925 writel(ring->next_to_use, ring->tail);
930 * i40evf_up_complete - Finish the last steps of bringing up a connection
931 * @adapter: board private structure
933 static int i40evf_up_complete(struct i40evf_adapter *adapter)
935 adapter->state = __I40EVF_RUNNING;
936 clear_bit(__I40E_DOWN, &adapter->vsi.state);
938 i40evf_napi_enable_all(adapter);
940 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
941 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
946 * i40evf_clean_all_rx_rings - Free Rx Buffers for all queues
947 * @adapter: board private structure
949 static void i40evf_clean_all_rx_rings(struct i40evf_adapter *adapter)
953 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
954 i40evf_clean_rx_ring(adapter->rx_rings[i]);
958 * i40evf_clean_all_tx_rings - Free Tx Buffers for all queues
959 * @adapter: board private structure
961 static void i40evf_clean_all_tx_rings(struct i40evf_adapter *adapter)
965 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
966 i40evf_clean_tx_ring(adapter->tx_rings[i]);
970 * i40e_down - Shutdown the connection processing
971 * @adapter: board private structure
973 void i40evf_down(struct i40evf_adapter *adapter)
975 struct net_device *netdev = adapter->netdev;
976 struct i40evf_mac_filter *f;
978 /* remove all MAC filters */
979 list_for_each_entry(f, &adapter->mac_filter_list, list) {
982 /* remove all VLAN filters */
983 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
986 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
987 adapter->state != __I40EVF_RESETTING) {
988 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
989 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
990 /* disable receives */
991 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
992 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
995 netif_tx_disable(netdev);
997 netif_tx_stop_all_queues(netdev);
999 i40evf_irq_disable(adapter);
1001 i40evf_napi_disable_all(adapter);
1003 netif_carrier_off(netdev);
1005 i40evf_clean_all_tx_rings(adapter);
1006 i40evf_clean_all_rx_rings(adapter);
1010 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1011 * @adapter: board private structure
1012 * @vectors: number of vectors to request
1014 * Work with the OS to set up the MSIX vectors needed.
1016 * Returns 0 on success, negative on failure
1019 i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1021 int err, vector_threshold;
1023 /* We'll want at least 3 (vector_threshold):
1024 * 0) Other (Admin Queue and link, mostly)
1028 vector_threshold = MIN_MSIX_COUNT;
1030 /* The more we get, the more we will assign to Tx/Rx Cleanup
1031 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1032 * Right now, we simply care about how many we'll get; we'll
1033 * set them up later while requesting irq's.
1035 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1036 vector_threshold, vectors);
1038 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts.\n");
1039 kfree(adapter->msix_entries);
1040 adapter->msix_entries = NULL;
1044 /* Adjust for only the vectors we'll use, which is minimum
1045 * of max_msix_q_vectors + NONQ_VECS, or the number of
1046 * vectors we were allocated.
1048 adapter->num_msix_vectors = err;
1053 * i40evf_free_queues - Free memory for all rings
1054 * @adapter: board private structure to initialize
1056 * Free all of the memory associated with queue pairs.
1058 static void i40evf_free_queues(struct i40evf_adapter *adapter)
1062 if (!adapter->vsi_res)
1064 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1065 if (adapter->tx_rings[i])
1066 kfree_rcu(adapter->tx_rings[i], rcu);
1067 adapter->tx_rings[i] = NULL;
1068 adapter->rx_rings[i] = NULL;
1073 * i40evf_alloc_queues - Allocate memory for all rings
1074 * @adapter: board private structure to initialize
1076 * We allocate one ring per queue at run-time since we don't know the
1077 * number of queues at compile-time. The polling_netdev array is
1078 * intended for Multiqueue, but should work fine with a single queue.
1080 static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1084 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1085 struct i40e_ring *tx_ring;
1086 struct i40e_ring *rx_ring;
1088 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
1092 tx_ring->queue_index = i;
1093 tx_ring->netdev = adapter->netdev;
1094 tx_ring->dev = &adapter->pdev->dev;
1095 tx_ring->count = I40EVF_DEFAULT_TXD;
1096 adapter->tx_rings[i] = tx_ring;
1098 rx_ring = &tx_ring[1];
1099 rx_ring->queue_index = i;
1100 rx_ring->netdev = adapter->netdev;
1101 rx_ring->dev = &adapter->pdev->dev;
1102 rx_ring->count = I40EVF_DEFAULT_RXD;
1103 adapter->rx_rings[i] = rx_ring;
1109 i40evf_free_queues(adapter);
1114 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1115 * @adapter: board private structure to initialize
1117 * Attempt to configure the interrupts using the best available
1118 * capabilities of the hardware and the kernel.
1120 static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1122 int vector, v_budget;
1126 if (!adapter->vsi_res) {
1130 pairs = adapter->vsi_res->num_queue_pairs;
1132 /* It's easy to be greedy for MSI-X vectors, but it really
1133 * doesn't do us much good if we have a lot more vectors
1134 * than CPU's. So let's be conservative and only ask for
1135 * (roughly) twice the number of vectors as there are CPU's.
1137 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1138 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
1140 /* A failure in MSI-X entry allocation isn't fatal, but it does
1141 * mean we disable MSI-X capabilities of the adapter.
1143 adapter->msix_entries = kcalloc(v_budget,
1144 sizeof(struct msix_entry), GFP_KERNEL);
1145 if (!adapter->msix_entries) {
1150 for (vector = 0; vector < v_budget; vector++)
1151 adapter->msix_entries[vector].entry = vector;
1153 i40evf_acquire_msix_vectors(adapter, v_budget);
1156 adapter->netdev->real_num_tx_queues = pairs;
1161 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1162 * @adapter: board private structure to initialize
1164 * We allocate one q_vector per queue interrupt. If allocation fails we
1167 static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1169 int q_idx, num_q_vectors;
1170 struct i40e_q_vector *q_vector;
1172 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1174 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1175 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
1178 q_vector->adapter = adapter;
1179 q_vector->vsi = &adapter->vsi;
1180 q_vector->v_idx = q_idx;
1181 netif_napi_add(adapter->netdev, &q_vector->napi,
1182 i40evf_napi_poll, 64);
1183 adapter->q_vector[q_idx] = q_vector;
1191 q_vector = adapter->q_vector[q_idx];
1192 netif_napi_del(&q_vector->napi);
1194 adapter->q_vector[q_idx] = NULL;
1200 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1201 * @adapter: board private structure to initialize
1203 * This function frees the memory allocated to the q_vectors. In addition if
1204 * NAPI is enabled it will delete any references to the NAPI struct prior
1205 * to freeing the q_vector.
1207 static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1209 int q_idx, num_q_vectors;
1212 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1213 napi_vectors = adapter->vsi_res->num_queue_pairs;
1215 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
1216 struct i40e_q_vector *q_vector = adapter->q_vector[q_idx];
1218 adapter->q_vector[q_idx] = NULL;
1219 if (q_idx < napi_vectors)
1220 netif_napi_del(&q_vector->napi);
1226 * i40evf_reset_interrupt_capability - Reset MSIX setup
1227 * @adapter: board private structure
1230 void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1232 pci_disable_msix(adapter->pdev);
1233 kfree(adapter->msix_entries);
1234 adapter->msix_entries = NULL;
1240 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1241 * @adapter: board private structure to initialize
1244 int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1248 err = i40evf_set_interrupt_capability(adapter);
1250 dev_err(&adapter->pdev->dev,
1251 "Unable to setup interrupt capabilities\n");
1252 goto err_set_interrupt;
1255 err = i40evf_alloc_q_vectors(adapter);
1257 dev_err(&adapter->pdev->dev,
1258 "Unable to allocate memory for queue vectors\n");
1259 goto err_alloc_q_vectors;
1262 err = i40evf_alloc_queues(adapter);
1264 dev_err(&adapter->pdev->dev,
1265 "Unable to allocate memory for queues\n");
1266 goto err_alloc_queues;
1269 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
1270 (adapter->vsi_res->num_queue_pairs > 1) ? "Enabled" :
1271 "Disabled", adapter->vsi_res->num_queue_pairs);
1275 i40evf_free_q_vectors(adapter);
1276 err_alloc_q_vectors:
1277 i40evf_reset_interrupt_capability(adapter);
1283 * i40evf_watchdog_timer - Periodic call-back timer
1284 * @data: pointer to adapter disguised as unsigned long
1286 static void i40evf_watchdog_timer(unsigned long data)
1288 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
1289 schedule_work(&adapter->watchdog_task);
1290 /* timer will be rescheduled in watchdog task */
1294 * i40evf_watchdog_task - Periodic call-back task
1295 * @work: pointer to work_struct
1297 static void i40evf_watchdog_task(struct work_struct *work)
1299 struct i40evf_adapter *adapter = container_of(work,
1300 struct i40evf_adapter,
1302 struct i40e_hw *hw = &adapter->hw;
1304 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
1305 goto restart_watchdog;
1307 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1308 if ((rd32(hw, I40E_VFGEN_RSTAT) & 0x3) == I40E_VFR_VFACTIVE) {
1309 /* A chance for redemption! */
1310 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1311 adapter->state = __I40EVF_STARTUP;
1312 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1313 schedule_delayed_work(&adapter->init_task, 10);
1314 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1315 &adapter->crit_section);
1316 /* Don't reschedule the watchdog, since we've restarted
1317 * the init task. When init_task contacts the PF and
1318 * gets everything set up again, it'll restart the
1319 * watchdog for us. Down, boy. Sit. Stay. Woof.
1323 adapter->aq_pending = 0;
1324 adapter->aq_required = 0;
1325 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1329 if ((adapter->state < __I40EVF_DOWN) ||
1330 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
1333 /* check for reset */
1334 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) &&
1335 (rd32(hw, I40E_VFGEN_RSTAT) & 0x3) != I40E_VFR_VFACTIVE) {
1336 adapter->state = __I40EVF_RESETTING;
1337 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1338 dev_err(&adapter->pdev->dev, "Hardware reset detected.\n");
1339 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1340 schedule_work(&adapter->reset_task);
1341 adapter->aq_pending = 0;
1342 adapter->aq_required = 0;
1343 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1347 /* Process admin queue tasks. After init, everything gets done
1348 * here so we don't race on the admin queue.
1350 if (adapter->aq_pending)
1353 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1354 i40evf_map_queues(adapter);
1358 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1359 i40evf_add_ether_addrs(adapter);
1363 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1364 i40evf_add_vlans(adapter);
1368 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1369 i40evf_del_ether_addrs(adapter);
1373 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1374 i40evf_del_vlans(adapter);
1378 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1379 i40evf_disable_queues(adapter);
1383 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1384 i40evf_configure_queues(adapter);
1388 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1389 i40evf_enable_queues(adapter);
1393 if (adapter->state == __I40EVF_RUNNING)
1394 i40evf_request_stats(adapter);
1396 i40evf_irq_enable(adapter, true);
1397 i40evf_fire_sw_int(adapter, 0xFF);
1400 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1402 if (adapter->aq_required)
1403 mod_timer(&adapter->watchdog_timer,
1404 jiffies + msecs_to_jiffies(20));
1406 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
1407 schedule_work(&adapter->adminq_task);
1411 * i40evf_configure_rss - increment to next available tx queue
1412 * @adapter: board private structure
1415 * Helper function for RSS programming to increment through available
1416 * queus. Returns the next queue value.
1418 static int next_queue(struct i40evf_adapter *adapter, int j)
1422 return j >= adapter->vsi_res->num_queue_pairs ? 0 : j;
1426 * i40evf_configure_rss - Prepare for RSS if used
1427 * @adapter: board private structure
1429 static void i40evf_configure_rss(struct i40evf_adapter *adapter)
1431 struct i40e_hw *hw = &adapter->hw;
1436 /* Set of random keys generated using kernel random number generator */
1437 static const u32 seed[I40E_VFQF_HKEY_MAX_INDEX + 1] = {
1438 0x794221b4, 0xbca0c5ab, 0x6cd5ebd9, 0x1ada6127,
1439 0x983b3aa1, 0x1c4e71eb, 0x7f6328b2, 0xfcdc0da0,
1440 0xc135cafa, 0x7a6f7e2d, 0xe7102d28, 0x163cd12e,
1443 /* Hash type is configured by the PF - we just supply the key */
1445 /* Fill out hash function seed */
1446 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1447 wr32(hw, I40E_VFQF_HKEY(i), seed[i]);
1449 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1450 hena = I40E_DEFAULT_RSS_HENA;
1451 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1452 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1454 /* Populate the LUT with max no. of queues in round robin fashion */
1455 j = adapter->vsi_res->num_queue_pairs;
1456 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) {
1457 j = next_queue(adapter, j);
1459 j = next_queue(adapter, j);
1461 j = next_queue(adapter, j);
1463 j = next_queue(adapter, j);
1465 wr32(hw, I40E_VFQF_HLUT(i), lut);
1470 #define I40EVF_RESET_WAIT_MS 100
1471 #define I40EVF_RESET_WAIT_COUNT 200
1473 * i40evf_reset_task - Call-back task to handle hardware reset
1474 * @work: pointer to work_struct
1476 * During reset we need to shut down and reinitialize the admin queue
1477 * before we can use it to communicate with the PF again. We also clear
1478 * and reinit the rings because that context is lost as well.
1480 static void i40evf_reset_task(struct work_struct *work)
1482 struct i40evf_adapter *adapter = container_of(work,
1483 struct i40evf_adapter,
1485 struct i40e_hw *hw = &adapter->hw;
1489 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1490 &adapter->crit_section))
1493 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
1494 dev_info(&adapter->pdev->dev, "Requesting reset from PF\n");
1495 i40evf_request_reset(adapter);
1498 /* poll until we see the reset actually happen */
1499 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1500 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1501 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1502 if (rstat_val != I40E_VFR_VFACTIVE) {
1503 dev_info(&adapter->pdev->dev, "Reset now occurring\n");
1506 msleep(I40EVF_RESET_WAIT_MS);
1509 if (i == I40EVF_RESET_WAIT_COUNT) {
1510 dev_err(&adapter->pdev->dev, "Reset was not detected\n");
1511 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1512 goto continue_reset; /* act like the reset happened */
1515 /* wait until the reset is complete and the PF is responding to us */
1516 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
1517 rstat_val = rd32(hw, I40E_VFGEN_RSTAT) &
1518 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1519 if (rstat_val == I40E_VFR_VFACTIVE) {
1520 dev_info(&adapter->pdev->dev, "Reset is complete. Reinitializing.\n");
1523 msleep(I40EVF_RESET_WAIT_MS);
1526 if (i == I40EVF_RESET_WAIT_COUNT) {
1527 /* reset never finished */
1528 dev_err(&adapter->pdev->dev, "Reset never finished (%x). PF driver is dead, and so am I.\n",
1530 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1532 if (netif_running(adapter->netdev)) {
1533 set_bit(__I40E_DOWN, &adapter->vsi.state);
1534 i40evf_down(adapter);
1535 i40evf_free_traffic_irqs(adapter);
1536 i40evf_free_all_tx_resources(adapter);
1537 i40evf_free_all_rx_resources(adapter);
1539 i40evf_free_misc_irq(adapter);
1540 i40evf_reset_interrupt_capability(adapter);
1541 i40evf_free_queues(adapter);
1542 kfree(adapter->vf_res);
1543 i40evf_shutdown_adminq(hw);
1544 adapter->netdev->flags &= ~IFF_UP;
1545 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1546 return; /* Do not attempt to reinit. It's dead, Jim. */
1550 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1552 i40evf_down(adapter);
1553 adapter->state = __I40EVF_RESETTING;
1555 /* kill and reinit the admin queue */
1556 if (i40evf_shutdown_adminq(hw))
1557 dev_warn(&adapter->pdev->dev,
1558 "%s: Failed to destroy the Admin Queue resources\n",
1560 err = i40evf_init_adminq(hw);
1562 dev_info(&adapter->pdev->dev, "%s: init_adminq failed: %d\n",
1565 adapter->aq_pending = 0;
1566 adapter->aq_required = 0;
1567 i40evf_map_queues(adapter);
1568 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1570 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1572 if (netif_running(adapter->netdev)) {
1573 /* allocate transmit descriptors */
1574 err = i40evf_setup_all_tx_resources(adapter);
1578 /* allocate receive descriptors */
1579 err = i40evf_setup_all_rx_resources(adapter);
1583 i40evf_configure(adapter);
1585 err = i40evf_up_complete(adapter);
1589 i40evf_irq_enable(adapter, true);
1593 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit.\n");
1594 i40evf_close(adapter->netdev);
1598 * i40evf_adminq_task - worker thread to clean the admin queue
1599 * @work: pointer to work_struct containing our data
1601 static void i40evf_adminq_task(struct work_struct *work)
1603 struct i40evf_adapter *adapter =
1604 container_of(work, struct i40evf_adapter, adminq_task);
1605 struct i40e_hw *hw = &adapter->hw;
1606 struct i40e_arq_event_info event;
1607 struct i40e_virtchnl_msg *v_msg;
1611 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
1614 event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
1615 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
1616 if (!event.msg_buf) {
1617 dev_info(&adapter->pdev->dev, "%s: no memory for ARQ clean\n",
1621 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1623 ret = i40evf_clean_arq_element(hw, &event, &pending);
1625 break; /* No event to process or error cleaning ARQ */
1627 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1628 v_msg->v_retval, event.msg_buf,
1631 dev_info(&adapter->pdev->dev,
1632 "%s: ARQ: Pending events %d\n",
1634 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
1638 /* re-enable Admin queue interrupt cause */
1639 i40evf_misc_irq_enable(adapter);
1641 kfree(event.msg_buf);
1645 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1646 * @adapter: board private structure
1648 * Free all transmit software resources
1650 static void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
1654 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
1655 if (adapter->tx_rings[i]->desc)
1656 i40evf_free_tx_resources(adapter->tx_rings[i]);
1661 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1662 * @adapter: board private structure
1664 * If this function returns with an error, then it's possible one or
1665 * more of the rings is populated (while the rest are not). It is the
1666 * callers duty to clean those orphaned rings.
1668 * Return 0 on success, negative on failure
1670 static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
1674 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1675 err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]);
1678 dev_err(&adapter->pdev->dev,
1679 "%s: Allocation for Tx Queue %u failed\n",
1688 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1689 * @adapter: board private structure
1691 * If this function returns with an error, then it's possible one or
1692 * more of the rings is populated (while the rest are not). It is the
1693 * callers duty to clean those orphaned rings.
1695 * Return 0 on success, negative on failure
1697 static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
1701 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
1702 err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]);
1705 dev_err(&adapter->pdev->dev,
1706 "%s: Allocation for Rx Queue %u failed\n",
1714 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1715 * @adapter: board private structure
1717 * Free all receive software resources
1719 static void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
1723 for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++)
1724 if (adapter->rx_rings[i]->desc)
1725 i40evf_free_rx_resources(adapter->rx_rings[i]);
1729 * i40evf_open - Called when a network interface is made active
1730 * @netdev: network interface device structure
1732 * Returns 0 on success, negative value on failure
1734 * The open entry point is called when a network interface is made
1735 * active by the system (IFF_UP). At this point all resources needed
1736 * for transmit and receive operations are allocated, the interrupt
1737 * handler is registered with the OS, the watchdog timer is started,
1738 * and the stack is notified that the interface is ready.
1740 static int i40evf_open(struct net_device *netdev)
1742 struct i40evf_adapter *adapter = netdev_priv(netdev);
1745 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
1746 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
1749 if (adapter->state != __I40EVF_DOWN)
1752 /* allocate transmit descriptors */
1753 err = i40evf_setup_all_tx_resources(adapter);
1757 /* allocate receive descriptors */
1758 err = i40evf_setup_all_rx_resources(adapter);
1762 /* clear any pending interrupts, may auto mask */
1763 err = i40evf_request_traffic_irqs(adapter, netdev->name);
1767 i40evf_configure(adapter);
1769 err = i40evf_up_complete(adapter);
1773 i40evf_irq_enable(adapter, true);
1778 i40evf_down(adapter);
1779 i40evf_free_traffic_irqs(adapter);
1781 i40evf_free_all_rx_resources(adapter);
1783 i40evf_free_all_tx_resources(adapter);
1789 * i40evf_close - Disables a network interface
1790 * @netdev: network interface device structure
1792 * Returns 0, this is not allowed to fail
1794 * The close entry point is called when an interface is de-activated
1795 * by the OS. The hardware is still under the drivers control, but
1796 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
1797 * are freed, along with all transmit and receive resources.
1799 static int i40evf_close(struct net_device *netdev)
1801 struct i40evf_adapter *adapter = netdev_priv(netdev);
1803 if (adapter->state <= __I40EVF_DOWN)
1806 /* signal that we are down to the interrupt handler */
1807 adapter->state = __I40EVF_DOWN;
1809 set_bit(__I40E_DOWN, &adapter->vsi.state);
1811 i40evf_down(adapter);
1812 i40evf_free_traffic_irqs(adapter);
1814 i40evf_free_all_tx_resources(adapter);
1815 i40evf_free_all_rx_resources(adapter);
1821 * i40evf_get_stats - Get System Network Statistics
1822 * @netdev: network interface device structure
1824 * Returns the address of the device statistics structure.
1825 * The statistics are actually updated from the timer callback.
1827 static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
1829 struct i40evf_adapter *adapter = netdev_priv(netdev);
1831 /* only return the current stats */
1832 return &adapter->net_stats;
1836 * i40evf_reinit_locked - Software reinit
1837 * @adapter: board private structure
1839 * Reinititalizes the ring structures in response to a software configuration
1840 * change. Roughly the same as close followed by open, but skips releasing
1841 * and reallocating the interrupts.
1843 void i40evf_reinit_locked(struct i40evf_adapter *adapter)
1845 struct net_device *netdev = adapter->netdev;
1848 WARN_ON(in_interrupt());
1850 adapter->state = __I40EVF_RESETTING;
1852 i40evf_down(adapter);
1854 /* allocate transmit descriptors */
1855 err = i40evf_setup_all_tx_resources(adapter);
1859 /* allocate receive descriptors */
1860 err = i40evf_setup_all_rx_resources(adapter);
1864 i40evf_configure(adapter);
1866 err = i40evf_up_complete(adapter);
1870 i40evf_irq_enable(adapter, true);
1874 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit.\n");
1875 i40evf_close(netdev);
1879 * i40evf_change_mtu - Change the Maximum Transfer Unit
1880 * @netdev: network interface device structure
1881 * @new_mtu: new value for maximum frame size
1883 * Returns 0 on success, negative on failure
1885 static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
1887 struct i40evf_adapter *adapter = netdev_priv(netdev);
1888 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
1890 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1893 /* must set new MTU before calling down or up */
1894 netdev->mtu = new_mtu;
1895 i40evf_reinit_locked(adapter);
1899 static const struct net_device_ops i40evf_netdev_ops = {
1900 .ndo_open = i40evf_open,
1901 .ndo_stop = i40evf_close,
1902 .ndo_start_xmit = i40evf_xmit_frame,
1903 .ndo_get_stats = i40evf_get_stats,
1904 .ndo_set_rx_mode = i40evf_set_rx_mode,
1905 .ndo_validate_addr = eth_validate_addr,
1906 .ndo_set_mac_address = i40evf_set_mac,
1907 .ndo_change_mtu = i40evf_change_mtu,
1908 .ndo_tx_timeout = i40evf_tx_timeout,
1909 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
1910 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
1914 * i40evf_check_reset_complete - check that VF reset is complete
1915 * @hw: pointer to hw struct
1917 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
1919 static int i40evf_check_reset_complete(struct i40e_hw *hw)
1924 for (i = 0; i < 100; i++) {
1925 rstat = rd32(hw, I40E_VFGEN_RSTAT);
1926 if (rstat == I40E_VFR_VFACTIVE)
1934 * i40evf_init_task - worker thread to perform delayed initialization
1935 * @work: pointer to work_struct containing our data
1937 * This task completes the work that was begun in probe. Due to the nature
1938 * of VF-PF communications, we may need to wait tens of milliseconds to get
1939 * reponses back from the PF. Rather than busy-wait in probe and bog down the
1940 * whole system, we'll do it in a task so we can sleep.
1941 * This task only runs during driver init. Once we've established
1942 * communications with the PF driver and set up our netdev, the watchdog
1945 static void i40evf_init_task(struct work_struct *work)
1947 struct i40evf_adapter *adapter = container_of(work,
1948 struct i40evf_adapter,
1950 struct net_device *netdev = adapter->netdev;
1951 struct i40evf_mac_filter *f;
1952 struct i40e_hw *hw = &adapter->hw;
1953 struct pci_dev *pdev = adapter->pdev;
1956 switch (adapter->state) {
1957 case __I40EVF_STARTUP:
1958 /* driver loaded, probe complete */
1959 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1960 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1961 err = i40e_set_mac_type(hw);
1963 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
1967 err = i40evf_check_reset_complete(hw);
1969 dev_err(&pdev->dev, "Device is still in reset (%d)\n",
1973 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
1974 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
1975 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
1976 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
1978 err = i40evf_init_adminq(hw);
1980 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
1984 err = i40evf_send_api_ver(adapter);
1986 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
1987 i40evf_shutdown_adminq(hw);
1990 adapter->state = __I40EVF_INIT_VERSION_CHECK;
1993 case __I40EVF_INIT_VERSION_CHECK:
1994 if (!i40evf_asq_done(hw)) {
1995 dev_err(&pdev->dev, "Admin queue command never completed.\n");
1999 /* aq msg sent, awaiting reply */
2000 err = i40evf_verify_api_ver(adapter);
2002 dev_err(&pdev->dev, "Unable to verify API version (%d)\n",
2006 err = i40evf_send_vf_config_msg(adapter);
2008 dev_err(&pdev->dev, "Unable send config request (%d)\n",
2012 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2015 case __I40EVF_INIT_GET_RESOURCES:
2016 /* aq msg sent, awaiting reply */
2017 if (!adapter->vf_res) {
2018 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2020 sizeof(struct i40e_virtchnl_vsi_resource));
2021 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
2022 if (!adapter->vf_res)
2025 err = i40evf_get_vf_config(adapter);
2026 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
2029 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2033 adapter->state = __I40EVF_INIT_SW;
2038 /* got VF config message back from PF, now we can parse it */
2039 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2040 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2041 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2043 if (!adapter->vsi_res) {
2044 dev_err(&pdev->dev, "No LAN VSI found\n");
2048 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2050 netdev->netdev_ops = &i40evf_netdev_ops;
2051 i40evf_set_ethtool_ops(netdev);
2052 netdev->watchdog_timeo = 5 * HZ;
2053 netdev->features |= NETIF_F_HIGHDMA |
2063 if (adapter->vf_res->vf_offload_flags
2064 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
2065 netdev->vlan_features = netdev->features;
2066 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2067 NETIF_F_HW_VLAN_CTAG_RX |
2068 NETIF_F_HW_VLAN_CTAG_FILTER;
2071 /* copy netdev features into list of user selectable features */
2072 netdev->hw_features |= netdev->features;
2073 netdev->hw_features &= ~NETIF_F_RXCSUM;
2075 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
2076 dev_info(&pdev->dev, "Invalid MAC address %pMAC, using random\n",
2077 adapter->hw.mac.addr);
2078 random_ether_addr(adapter->hw.mac.addr);
2080 memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
2081 memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len);
2083 INIT_LIST_HEAD(&adapter->mac_filter_list);
2084 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2085 f = kzalloc(sizeof(*f), GFP_ATOMIC);
2089 memcpy(f->macaddr, adapter->hw.mac.addr, ETH_ALEN);
2091 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
2093 list_add(&f->list, &adapter->mac_filter_list);
2095 init_timer(&adapter->watchdog_timer);
2096 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2097 adapter->watchdog_timer.data = (unsigned long)adapter;
2098 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2100 err = i40evf_init_interrupt_scheme(adapter);
2103 i40evf_map_rings_to_vectors(adapter);
2104 i40evf_configure_rss(adapter);
2105 err = i40evf_request_misc_irq(adapter);
2109 netif_carrier_off(netdev);
2111 adapter->vsi.id = adapter->vsi_res->vsi_id;
2112 adapter->vsi.seid = adapter->vsi_res->vsi_id; /* dummy */
2113 adapter->vsi.back = adapter;
2114 adapter->vsi.base_vector = 1;
2115 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2116 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2117 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2118 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2119 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2120 adapter->vsi.netdev = adapter->netdev;
2122 if (!adapter->netdev_registered) {
2123 err = register_netdev(netdev);
2128 adapter->netdev_registered = true;
2130 netif_tx_stop_all_queues(netdev);
2132 dev_info(&pdev->dev, "MAC address: %pMAC\n", adapter->hw.mac.addr);
2133 if (netdev->features & NETIF_F_GRO)
2134 dev_info(&pdev->dev, "GRO is enabled\n");
2136 dev_info(&pdev->dev, "%s\n", i40evf_driver_string);
2137 adapter->state = __I40EVF_DOWN;
2138 set_bit(__I40E_DOWN, &adapter->vsi.state);
2139 i40evf_misc_irq_enable(adapter);
2142 schedule_delayed_work(&adapter->init_task,
2143 msecs_to_jiffies(50));
2147 i40evf_free_misc_irq(adapter);
2149 i40evf_reset_interrupt_capability(adapter);
2151 kfree(adapter->vf_res);
2152 adapter->vf_res = NULL;
2154 /* Things went into the weeds, so try again later */
2155 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
2156 dev_err(&pdev->dev, "Failed to communicate with PF; giving up.\n");
2157 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
2158 return; /* do not reschedule */
2160 schedule_delayed_work(&adapter->init_task, HZ * 3);
2165 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2166 * @pdev: pci device structure
2168 static void i40evf_shutdown(struct pci_dev *pdev)
2170 struct net_device *netdev = pci_get_drvdata(pdev);
2172 netif_device_detach(netdev);
2174 if (netif_running(netdev))
2175 i40evf_close(netdev);
2178 pci_save_state(pdev);
2181 pci_disable_device(pdev);
2185 * i40evf_probe - Device Initialization Routine
2186 * @pdev: PCI device information struct
2187 * @ent: entry in i40evf_pci_tbl
2189 * Returns 0 on success, negative on failure
2191 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2192 * The OS initialization, configuring of the adapter private structure,
2193 * and a hardware reset occur.
2195 static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2197 struct net_device *netdev;
2198 struct i40evf_adapter *adapter = NULL;
2199 struct i40e_hw *hw = NULL;
2202 err = pci_enable_device(pdev);
2206 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2208 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2211 "DMA configuration failed: 0x%x\n", err);
2216 err = pci_request_regions(pdev, i40evf_driver_name);
2219 "pci_request_regions failed 0x%x\n", err);
2223 pci_enable_pcie_error_reporting(pdev);
2225 pci_set_master(pdev);
2227 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter),
2231 goto err_alloc_etherdev;
2234 SET_NETDEV_DEV(netdev, &pdev->dev);
2236 pci_set_drvdata(pdev, netdev);
2237 adapter = netdev_priv(netdev);
2239 adapter->netdev = netdev;
2240 adapter->pdev = pdev;
2245 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2246 adapter->state = __I40EVF_STARTUP;
2248 /* Call save state here because it relies on the adapter struct. */
2249 pci_save_state(pdev);
2251 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2252 pci_resource_len(pdev, 0));
2257 hw->vendor_id = pdev->vendor;
2258 hw->device_id = pdev->device;
2259 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2260 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2261 hw->subsystem_device_id = pdev->subsystem_device;
2262 hw->bus.device = PCI_SLOT(pdev->devfn);
2263 hw->bus.func = PCI_FUNC(pdev->devfn);
2265 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2266 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2267 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2268 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
2269 schedule_delayed_work(&adapter->init_task, 10);
2274 free_netdev(netdev);
2276 pci_release_regions(pdev);
2279 pci_disable_device(pdev);
2285 * i40evf_suspend - Power management suspend routine
2286 * @pdev: PCI device information struct
2289 * Called when the system (VM) is entering sleep/suspend.
2291 static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2293 struct net_device *netdev = pci_get_drvdata(pdev);
2294 struct i40evf_adapter *adapter = netdev_priv(netdev);
2297 netif_device_detach(netdev);
2299 if (netif_running(netdev)) {
2301 i40evf_down(adapter);
2304 i40evf_free_misc_irq(adapter);
2305 i40evf_reset_interrupt_capability(adapter);
2307 retval = pci_save_state(pdev);
2311 pci_disable_device(pdev);
2317 * i40evf_resume - Power managment resume routine
2318 * @pdev: PCI device information struct
2320 * Called when the system (VM) is resumed from sleep/suspend.
2322 static int i40evf_resume(struct pci_dev *pdev)
2324 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2325 struct net_device *netdev = adapter->netdev;
2328 pci_set_power_state(pdev, PCI_D0);
2329 pci_restore_state(pdev);
2330 /* pci_restore_state clears dev->state_saved so call
2331 * pci_save_state to restore it.
2333 pci_save_state(pdev);
2335 err = pci_enable_device_mem(pdev);
2337 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2340 pci_set_master(pdev);
2343 err = i40evf_set_interrupt_capability(adapter);
2345 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2348 err = i40evf_request_misc_irq(adapter);
2351 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2355 schedule_work(&adapter->reset_task);
2357 netif_device_attach(netdev);
2362 #endif /* CONFIG_PM */
2364 * i40evf_remove - Device Removal Routine
2365 * @pdev: PCI device information struct
2367 * i40evf_remove is called by the PCI subsystem to alert the driver
2368 * that it should release a PCI device. The could be caused by a
2369 * Hot-Plug event, or because the driver is going to be removed from
2372 static void i40evf_remove(struct pci_dev *pdev)
2374 struct net_device *netdev = pci_get_drvdata(pdev);
2375 struct i40evf_adapter *adapter = netdev_priv(netdev);
2376 struct i40e_hw *hw = &adapter->hw;
2378 cancel_delayed_work_sync(&adapter->init_task);
2379 cancel_work_sync(&adapter->reset_task);
2381 if (adapter->netdev_registered) {
2382 unregister_netdev(netdev);
2383 adapter->netdev_registered = false;
2385 adapter->state = __I40EVF_REMOVE;
2387 if (adapter->msix_entries) {
2388 i40evf_misc_irq_disable(adapter);
2389 i40evf_free_misc_irq(adapter);
2390 i40evf_reset_interrupt_capability(adapter);
2393 del_timer_sync(&adapter->watchdog_timer);
2394 flush_scheduled_work();
2396 if (hw->aq.asq.count)
2397 i40evf_shutdown_adminq(hw);
2399 iounmap(hw->hw_addr);
2400 pci_release_regions(pdev);
2402 i40evf_free_queues(adapter);
2403 kfree(adapter->vf_res);
2405 free_netdev(netdev);
2407 pci_disable_pcie_error_reporting(pdev);
2409 pci_disable_device(pdev);
2412 static struct pci_driver i40evf_driver = {
2413 .name = i40evf_driver_name,
2414 .id_table = i40evf_pci_tbl,
2415 .probe = i40evf_probe,
2416 .remove = i40evf_remove,
2418 .suspend = i40evf_suspend,
2419 .resume = i40evf_resume,
2421 .shutdown = i40evf_shutdown,
2425 * i40e_init_module - Driver Registration Routine
2427 * i40e_init_module is the first routine called when the driver is
2428 * loaded. All it does is register with the PCI subsystem.
2430 static int __init i40evf_init_module(void)
2433 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
2434 i40evf_driver_version);
2436 pr_info("%s\n", i40evf_copyright);
2438 ret = pci_register_driver(&i40evf_driver);
2442 module_init(i40evf_init_module);
2445 * i40e_exit_module - Driver Exit Cleanup Routine
2447 * i40e_exit_module is called just before the driver is removed
2450 static void __exit i40evf_exit_module(void)
2452 pci_unregister_driver(&i40evf_driver);
2455 module_exit(i40evf_exit_module);