1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 - 2016 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 int i40evf_close(struct net_device
*netdev
);
33 char i40evf_driver_name
[] = "i40evf";
34 static const char i40evf_driver_string
[] =
35 "Intel(R) 40-10 Gigabit Virtual Function Network Driver";
39 #define DRV_VERSION_MAJOR 1
40 #define DRV_VERSION_MINOR 6
41 #define DRV_VERSION_BUILD 11
42 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
43 __stringify(DRV_VERSION_MINOR) "." \
44 __stringify(DRV_VERSION_BUILD) \
46 const char i40evf_driver_version
[] = DRV_VERSION
;
47 static const char i40evf_copyright
[] =
48 "Copyright (c) 2013 - 2015 Intel Corporation.";
50 /* i40evf_pci_tbl - PCI Device ID Table
52 * Wildcard entries (PCI_ANY_ID) should come last
53 * Last entry must be all 0s
55 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
56 * Class, Class Mask, private data (not used) }
58 static const struct pci_device_id i40evf_pci_tbl
[] = {
59 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_VF
), 0},
60 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_VF_HV
), 0},
61 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_X722_VF
), 0},
62 {PCI_VDEVICE(INTEL
, I40E_DEV_ID_X722_VF_HV
), 0},
63 /* required last entry */
67 MODULE_DEVICE_TABLE(pci
, i40evf_pci_tbl
);
69 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
70 MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
71 MODULE_LICENSE("GPL");
72 MODULE_VERSION(DRV_VERSION
);
74 static struct workqueue_struct
*i40evf_wq
;
77 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
78 * @hw: pointer to the HW structure
79 * @mem: ptr to mem struct to fill out
80 * @size: size of memory requested
81 * @alignment: what to align the allocation to
83 i40e_status
i40evf_allocate_dma_mem_d(struct i40e_hw
*hw
,
84 struct i40e_dma_mem
*mem
,
85 u64 size
, u32 alignment
)
87 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
90 return I40E_ERR_PARAM
;
92 mem
->size
= ALIGN(size
, alignment
);
93 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
,
94 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
98 return I40E_ERR_NO_MEMORY
;
102 * i40evf_free_dma_mem_d - OS specific memory free for shared code
103 * @hw: pointer to the HW structure
104 * @mem: ptr to mem struct to free
106 i40e_status
i40evf_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
108 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
110 if (!mem
|| !mem
->va
)
111 return I40E_ERR_PARAM
;
112 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
,
113 mem
->va
, (dma_addr_t
)mem
->pa
);
118 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
119 * @hw: pointer to the HW structure
120 * @mem: ptr to mem struct to fill out
121 * @size: size of memory requested
123 i40e_status
i40evf_allocate_virt_mem_d(struct i40e_hw
*hw
,
124 struct i40e_virt_mem
*mem
, u32 size
)
127 return I40E_ERR_PARAM
;
130 mem
->va
= kzalloc(size
, GFP_KERNEL
);
135 return I40E_ERR_NO_MEMORY
;
139 * i40evf_free_virt_mem_d - OS specific memory free for shared code
140 * @hw: pointer to the HW structure
141 * @mem: ptr to mem struct to free
143 i40e_status
i40evf_free_virt_mem_d(struct i40e_hw
*hw
,
144 struct i40e_virt_mem
*mem
)
147 return I40E_ERR_PARAM
;
149 /* it's ok to kfree a NULL pointer */
156 * i40evf_debug_d - OS dependent version of debug printing
157 * @hw: pointer to the HW structure
158 * @mask: debug level mask
159 * @fmt_str: printf-type format description
161 void i40evf_debug_d(void *hw
, u32 mask
, char *fmt_str
, ...)
166 if (!(mask
& ((struct i40e_hw
*)hw
)->debug_mask
))
169 va_start(argptr
, fmt_str
);
170 vsnprintf(buf
, sizeof(buf
), fmt_str
, argptr
);
173 /* the debug string is already formatted with a newline */
178 * i40evf_schedule_reset - Set the flags and schedule a reset event
179 * @adapter: board private structure
181 void i40evf_schedule_reset(struct i40evf_adapter
*adapter
)
183 if (!(adapter
->flags
&
184 (I40EVF_FLAG_RESET_PENDING
| I40EVF_FLAG_RESET_NEEDED
))) {
185 adapter
->flags
|= I40EVF_FLAG_RESET_NEEDED
;
186 schedule_work(&adapter
->reset_task
);
191 * i40evf_tx_timeout - Respond to a Tx Hang
192 * @netdev: network interface device structure
194 static void i40evf_tx_timeout(struct net_device
*netdev
)
196 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
198 adapter
->tx_timeout_count
++;
199 i40evf_schedule_reset(adapter
);
203 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
204 * @adapter: board private structure
206 static void i40evf_misc_irq_disable(struct i40evf_adapter
*adapter
)
208 struct i40e_hw
*hw
= &adapter
->hw
;
210 wr32(hw
, I40E_VFINT_DYN_CTL01
, 0);
213 rd32(hw
, I40E_VFGEN_RSTAT
);
215 synchronize_irq(adapter
->msix_entries
[0].vector
);
219 * i40evf_misc_irq_enable - Enable default interrupt generation settings
220 * @adapter: board private structure
222 static void i40evf_misc_irq_enable(struct i40evf_adapter
*adapter
)
224 struct i40e_hw
*hw
= &adapter
->hw
;
226 wr32(hw
, I40E_VFINT_DYN_CTL01
, I40E_VFINT_DYN_CTL01_INTENA_MASK
|
227 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK
);
228 wr32(hw
, I40E_VFINT_ICR0_ENA1
, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK
);
231 rd32(hw
, I40E_VFGEN_RSTAT
);
235 * i40evf_irq_disable - Mask off interrupt generation on the NIC
236 * @adapter: board private structure
238 static void i40evf_irq_disable(struct i40evf_adapter
*adapter
)
241 struct i40e_hw
*hw
= &adapter
->hw
;
243 if (!adapter
->msix_entries
)
246 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
247 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), 0);
248 synchronize_irq(adapter
->msix_entries
[i
].vector
);
251 rd32(hw
, I40E_VFGEN_RSTAT
);
255 * i40evf_irq_enable_queues - Enable interrupt for specified queues
256 * @adapter: board private structure
257 * @mask: bitmap of queues to enable
259 void i40evf_irq_enable_queues(struct i40evf_adapter
*adapter
, u32 mask
)
261 struct i40e_hw
*hw
= &adapter
->hw
;
264 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
265 if (mask
& BIT(i
- 1)) {
266 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1),
267 I40E_VFINT_DYN_CTLN1_INTENA_MASK
|
268 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
269 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
);
275 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
276 * @adapter: board private structure
277 * @mask: bitmap of vectors to trigger
279 static void i40evf_fire_sw_int(struct i40evf_adapter
*adapter
, u32 mask
)
281 struct i40e_hw
*hw
= &adapter
->hw
;
286 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTL01
);
287 dyn_ctl
|= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK
|
288 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
289 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
;
290 wr32(hw
, I40E_VFINT_DYN_CTL01
, dyn_ctl
);
292 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
294 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1));
295 dyn_ctl
|= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK
|
296 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
297 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
;
298 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), dyn_ctl
);
304 * i40evf_irq_enable - Enable default interrupt generation settings
305 * @adapter: board private structure
306 * @flush: boolean value whether to run rd32()
308 void i40evf_irq_enable(struct i40evf_adapter
*adapter
, bool flush
)
310 struct i40e_hw
*hw
= &adapter
->hw
;
312 i40evf_misc_irq_enable(adapter
);
313 i40evf_irq_enable_queues(adapter
, ~0);
316 rd32(hw
, I40E_VFGEN_RSTAT
);
320 * i40evf_msix_aq - Interrupt handler for vector 0
321 * @irq: interrupt number
322 * @data: pointer to netdev
324 static irqreturn_t
i40evf_msix_aq(int irq
, void *data
)
326 struct net_device
*netdev
= data
;
327 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
328 struct i40e_hw
*hw
= &adapter
->hw
;
331 /* handle non-queue interrupts, these reads clear the registers */
332 val
= rd32(hw
, I40E_VFINT_ICR01
);
333 val
= rd32(hw
, I40E_VFINT_ICR0_ENA1
);
335 val
= rd32(hw
, I40E_VFINT_DYN_CTL01
) |
336 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK
;
337 wr32(hw
, I40E_VFINT_DYN_CTL01
, val
);
339 /* schedule work on the private workqueue */
340 schedule_work(&adapter
->adminq_task
);
346 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
347 * @irq: interrupt number
348 * @data: pointer to a q_vector
350 static irqreturn_t
i40evf_msix_clean_rings(int irq
, void *data
)
352 struct i40e_q_vector
*q_vector
= data
;
354 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
357 napi_schedule_irqoff(&q_vector
->napi
);
363 * i40evf_map_vector_to_rxq - associate irqs with rx queues
364 * @adapter: board private structure
365 * @v_idx: interrupt number
366 * @r_idx: queue number
369 i40evf_map_vector_to_rxq(struct i40evf_adapter
*adapter
, int v_idx
, int r_idx
)
371 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
372 struct i40e_ring
*rx_ring
= &adapter
->rx_rings
[r_idx
];
374 rx_ring
->q_vector
= q_vector
;
375 rx_ring
->next
= q_vector
->rx
.ring
;
376 rx_ring
->vsi
= &adapter
->vsi
;
377 q_vector
->rx
.ring
= rx_ring
;
378 q_vector
->rx
.count
++;
379 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
380 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
384 * i40evf_map_vector_to_txq - associate irqs with tx queues
385 * @adapter: board private structure
386 * @v_idx: interrupt number
387 * @t_idx: queue number
390 i40evf_map_vector_to_txq(struct i40evf_adapter
*adapter
, int v_idx
, int t_idx
)
392 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
393 struct i40e_ring
*tx_ring
= &adapter
->tx_rings
[t_idx
];
395 tx_ring
->q_vector
= q_vector
;
396 tx_ring
->next
= q_vector
->tx
.ring
;
397 tx_ring
->vsi
= &adapter
->vsi
;
398 q_vector
->tx
.ring
= tx_ring
;
399 q_vector
->tx
.count
++;
400 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
401 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
402 q_vector
->num_ringpairs
++;
403 q_vector
->ring_mask
|= BIT(t_idx
);
407 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
408 * @adapter: board private structure to initialize
410 * This function maps descriptor rings to the queue-specific vectors
411 * we were allotted through the MSI-X enabling code. Ideally, we'd have
412 * one vector per ring/queue, but on a constrained vector budget, we
413 * group the rings as "efficiently" as possible. You would add new
414 * mapping configurations in here.
416 static int i40evf_map_rings_to_vectors(struct i40evf_adapter
*adapter
)
420 int rxr_idx
= 0, txr_idx
= 0;
421 int rxr_remaining
= adapter
->num_active_queues
;
422 int txr_remaining
= adapter
->num_active_queues
;
427 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
429 /* The ideal configuration...
430 * We have enough vectors to map one per queue.
432 if (q_vectors
>= (rxr_remaining
* 2)) {
433 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
434 i40evf_map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
436 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
437 i40evf_map_vector_to_txq(adapter
, v_start
, txr_idx
);
441 /* If we don't have enough vectors for a 1-to-1
442 * mapping, we'll have to group them so there are
443 * multiple queues per vector.
444 * Re-adjusting *qpv takes care of the remainder.
446 for (i
= v_start
; i
< q_vectors
; i
++) {
447 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
448 for (j
= 0; j
< rqpv
; j
++) {
449 i40evf_map_vector_to_rxq(adapter
, i
, rxr_idx
);
454 for (i
= v_start
; i
< q_vectors
; i
++) {
455 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
456 for (j
= 0; j
< tqpv
; j
++) {
457 i40evf_map_vector_to_txq(adapter
, i
, txr_idx
);
464 adapter
->aq_required
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
469 #ifdef CONFIG_NET_POLL_CONTROLLER
471 * i40evf_netpoll - A Polling 'interrupt' handler
472 * @netdev: network interface device structure
474 * This is used by netconsole to send skbs without having to re-enable
475 * interrupts. It's not called while the normal interrupt routine is executing.
477 static void i40evf_netpoll(struct net_device
*netdev
)
479 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
480 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
483 /* if interface is down do nothing */
484 if (test_bit(__I40E_DOWN
, &adapter
->vsi
.state
))
487 for (i
= 0; i
< q_vectors
; i
++)
488 i40evf_msix_clean_rings(0, &adapter
->q_vectors
[i
]);
493 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
494 * @adapter: board private structure
496 * Allocates MSI-X vectors for tx and rx handling, and requests
497 * interrupts from the kernel.
500 i40evf_request_traffic_irqs(struct i40evf_adapter
*adapter
, char *basename
)
502 int vector
, err
, q_vectors
;
503 int rx_int_idx
= 0, tx_int_idx
= 0;
505 i40evf_irq_disable(adapter
);
506 /* Decrement for Other and TCP Timer vectors */
507 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
509 for (vector
= 0; vector
< q_vectors
; vector
++) {
510 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[vector
];
512 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
513 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
514 "i40evf-%s-%s-%d", basename
,
515 "TxRx", rx_int_idx
++);
517 } else if (q_vector
->rx
.ring
) {
518 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
519 "i40evf-%s-%s-%d", basename
,
521 } else if (q_vector
->tx
.ring
) {
522 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
523 "i40evf-%s-%s-%d", basename
,
526 /* skip this unused q_vector */
530 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
531 i40evf_msix_clean_rings
,
536 dev_info(&adapter
->pdev
->dev
,
537 "Request_irq failed, error: %d\n", err
);
538 goto free_queue_irqs
;
540 /* assign the mask for this irq */
541 irq_set_affinity_hint(
542 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
543 q_vector
->affinity_mask
);
551 irq_set_affinity_hint(
552 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
554 free_irq(adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
555 &adapter
->q_vectors
[vector
]);
561 * i40evf_request_misc_irq - Initialize MSI-X interrupts
562 * @adapter: board private structure
564 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
565 * vector is only for the admin queue, and stays active even when the netdev
568 static int i40evf_request_misc_irq(struct i40evf_adapter
*adapter
)
570 struct net_device
*netdev
= adapter
->netdev
;
573 snprintf(adapter
->misc_vector_name
,
574 sizeof(adapter
->misc_vector_name
) - 1, "i40evf-%s:mbx",
575 dev_name(&adapter
->pdev
->dev
));
576 err
= request_irq(adapter
->msix_entries
[0].vector
,
578 adapter
->misc_vector_name
, netdev
);
580 dev_err(&adapter
->pdev
->dev
,
581 "request_irq for %s failed: %d\n",
582 adapter
->misc_vector_name
, err
);
583 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
589 * i40evf_free_traffic_irqs - Free MSI-X interrupts
590 * @adapter: board private structure
592 * Frees all MSI-X vectors other than 0.
594 static void i40evf_free_traffic_irqs(struct i40evf_adapter
*adapter
)
599 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
601 for (i
= 0; i
< q_vectors
; i
++) {
602 irq_set_affinity_hint(adapter
->msix_entries
[i
+1].vector
,
604 free_irq(adapter
->msix_entries
[i
+1].vector
,
605 &adapter
->q_vectors
[i
]);
610 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
611 * @adapter: board private structure
613 * Frees MSI-X vector 0.
615 static void i40evf_free_misc_irq(struct i40evf_adapter
*adapter
)
617 struct net_device
*netdev
= adapter
->netdev
;
619 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
623 * i40evf_configure_tx - Configure Transmit Unit after Reset
624 * @adapter: board private structure
626 * Configure the Tx unit of the MAC after a reset.
628 static void i40evf_configure_tx(struct i40evf_adapter
*adapter
)
630 struct i40e_hw
*hw
= &adapter
->hw
;
633 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
634 adapter
->tx_rings
[i
].tail
= hw
->hw_addr
+ I40E_QTX_TAIL1(i
);
638 * i40evf_configure_rx - Configure Receive Unit after Reset
639 * @adapter: board private structure
641 * Configure the Rx unit of the MAC after a reset.
643 static void i40evf_configure_rx(struct i40evf_adapter
*adapter
)
645 struct i40e_hw
*hw
= &adapter
->hw
;
648 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
649 adapter
->rx_rings
[i
].tail
= hw
->hw_addr
+ I40E_QRX_TAIL1(i
);
650 adapter
->rx_rings
[i
].rx_buf_len
= I40EVF_RXBUFFER_2048
;
655 * i40evf_find_vlan - Search filter list for specific vlan filter
656 * @adapter: board private structure
659 * Returns ptr to the filter object or NULL
662 i40evf_vlan_filter
*i40evf_find_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
664 struct i40evf_vlan_filter
*f
;
666 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
674 * i40evf_add_vlan - Add a vlan filter to the list
675 * @adapter: board private structure
678 * Returns ptr to the filter object or NULL when no memory available.
681 i40evf_vlan_filter
*i40evf_add_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
683 struct i40evf_vlan_filter
*f
= NULL
;
686 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
687 &adapter
->crit_section
)) {
693 f
= i40evf_find_vlan(adapter
, vlan
);
695 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
701 INIT_LIST_HEAD(&f
->list
);
702 list_add(&f
->list
, &adapter
->vlan_filter_list
);
704 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
708 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
714 * i40evf_del_vlan - Remove a vlan filter from the list
715 * @adapter: board private structure
718 static void i40evf_del_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
720 struct i40evf_vlan_filter
*f
;
723 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
724 &adapter
->crit_section
)) {
730 f
= i40evf_find_vlan(adapter
, vlan
);
733 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
735 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
739 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
740 * @netdev: network device struct
743 static int i40evf_vlan_rx_add_vid(struct net_device
*netdev
,
744 __always_unused __be16 proto
, u16 vid
)
746 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
748 if (!VLAN_ALLOWED(adapter
))
750 if (i40evf_add_vlan(adapter
, vid
) == NULL
)
756 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
757 * @netdev: network device struct
760 static int i40evf_vlan_rx_kill_vid(struct net_device
*netdev
,
761 __always_unused __be16 proto
, u16 vid
)
763 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
765 if (VLAN_ALLOWED(adapter
)) {
766 i40evf_del_vlan(adapter
, vid
);
773 * i40evf_find_filter - Search filter list for specific mac filter
774 * @adapter: board private structure
775 * @macaddr: the MAC address
777 * Returns ptr to the filter object or NULL
780 i40evf_mac_filter
*i40evf_find_filter(struct i40evf_adapter
*adapter
,
783 struct i40evf_mac_filter
*f
;
788 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
789 if (ether_addr_equal(macaddr
, f
->macaddr
))
796 * i40e_add_filter - Add a mac filter to the filter list
797 * @adapter: board private structure
798 * @macaddr: the MAC address
800 * Returns ptr to the filter object or NULL when no memory available.
803 i40evf_mac_filter
*i40evf_add_filter(struct i40evf_adapter
*adapter
,
806 struct i40evf_mac_filter
*f
;
812 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
813 &adapter
->crit_section
)) {
819 f
= i40evf_find_filter(adapter
, macaddr
);
821 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
823 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
824 &adapter
->crit_section
);
828 ether_addr_copy(f
->macaddr
, macaddr
);
830 list_add_tail(&f
->list
, &adapter
->mac_filter_list
);
832 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
835 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
840 * i40evf_set_mac - NDO callback to set port mac address
841 * @netdev: network interface device structure
842 * @p: pointer to an address structure
844 * Returns 0 on success, negative on failure
846 static int i40evf_set_mac(struct net_device
*netdev
, void *p
)
848 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
849 struct i40e_hw
*hw
= &adapter
->hw
;
850 struct i40evf_mac_filter
*f
;
851 struct sockaddr
*addr
= p
;
853 if (!is_valid_ether_addr(addr
->sa_data
))
854 return -EADDRNOTAVAIL
;
856 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
))
859 if (adapter
->flags
& I40EVF_FLAG_ADDR_SET_BY_PF
)
862 f
= i40evf_find_filter(adapter
, hw
->mac
.addr
);
865 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
868 f
= i40evf_add_filter(adapter
, addr
->sa_data
);
870 ether_addr_copy(hw
->mac
.addr
, addr
->sa_data
);
871 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
874 return (f
== NULL
) ? -ENOMEM
: 0;
878 * i40evf_set_rx_mode - NDO callback to set the netdev filters
879 * @netdev: network interface device structure
881 static void i40evf_set_rx_mode(struct net_device
*netdev
)
883 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
884 struct i40evf_mac_filter
*f
, *ftmp
;
885 struct netdev_hw_addr
*uca
;
886 struct netdev_hw_addr
*mca
;
887 struct netdev_hw_addr
*ha
;
890 /* add addr if not already in the filter list */
891 netdev_for_each_uc_addr(uca
, netdev
) {
892 i40evf_add_filter(adapter
, uca
->addr
);
894 netdev_for_each_mc_addr(mca
, netdev
) {
895 i40evf_add_filter(adapter
, mca
->addr
);
898 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
899 &adapter
->crit_section
)) {
902 dev_err(&adapter
->pdev
->dev
,
903 "Failed to get lock in %s\n", __func__
);
907 /* remove filter if not in netdev list */
908 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
909 netdev_for_each_mc_addr(mca
, netdev
)
910 if (ether_addr_equal(mca
->addr
, f
->macaddr
))
911 goto bottom_of_search_loop
;
913 netdev_for_each_uc_addr(uca
, netdev
)
914 if (ether_addr_equal(uca
->addr
, f
->macaddr
))
915 goto bottom_of_search_loop
;
917 for_each_dev_addr(netdev
, ha
)
918 if (ether_addr_equal(ha
->addr
, f
->macaddr
))
919 goto bottom_of_search_loop
;
921 if (ether_addr_equal(f
->macaddr
, adapter
->hw
.mac
.addr
))
922 goto bottom_of_search_loop
;
924 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
926 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
928 bottom_of_search_loop
:
932 if (netdev
->flags
& IFF_PROMISC
&&
933 !(adapter
->flags
& I40EVF_FLAG_PROMISC_ON
))
934 adapter
->aq_required
|= I40EVF_FLAG_AQ_REQUEST_PROMISC
;
935 else if (!(netdev
->flags
& IFF_PROMISC
) &&
936 adapter
->flags
& I40EVF_FLAG_PROMISC_ON
)
937 adapter
->aq_required
|= I40EVF_FLAG_AQ_RELEASE_PROMISC
;
939 if (netdev
->flags
& IFF_ALLMULTI
&&
940 !(adapter
->flags
& I40EVF_FLAG_ALLMULTI_ON
))
941 adapter
->aq_required
|= I40EVF_FLAG_AQ_REQUEST_ALLMULTI
;
942 else if (!(netdev
->flags
& IFF_ALLMULTI
) &&
943 adapter
->flags
& I40EVF_FLAG_ALLMULTI_ON
)
944 adapter
->aq_required
|= I40EVF_FLAG_AQ_RELEASE_ALLMULTI
;
946 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
950 * i40evf_napi_enable_all - enable NAPI on all queue vectors
951 * @adapter: board private structure
953 static void i40evf_napi_enable_all(struct i40evf_adapter
*adapter
)
956 struct i40e_q_vector
*q_vector
;
957 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
959 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
960 struct napi_struct
*napi
;
962 q_vector
= &adapter
->q_vectors
[q_idx
];
963 napi
= &q_vector
->napi
;
969 * i40evf_napi_disable_all - disable NAPI on all queue vectors
970 * @adapter: board private structure
972 static void i40evf_napi_disable_all(struct i40evf_adapter
*adapter
)
975 struct i40e_q_vector
*q_vector
;
976 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
978 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
979 q_vector
= &adapter
->q_vectors
[q_idx
];
980 napi_disable(&q_vector
->napi
);
985 * i40evf_configure - set up transmit and receive data structures
986 * @adapter: board private structure
988 static void i40evf_configure(struct i40evf_adapter
*adapter
)
990 struct net_device
*netdev
= adapter
->netdev
;
993 i40evf_set_rx_mode(netdev
);
995 i40evf_configure_tx(adapter
);
996 i40evf_configure_rx(adapter
);
997 adapter
->aq_required
|= I40EVF_FLAG_AQ_CONFIGURE_QUEUES
;
999 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
1000 struct i40e_ring
*ring
= &adapter
->rx_rings
[i
];
1002 i40evf_alloc_rx_buffers(ring
, I40E_DESC_UNUSED(ring
));
1007 * i40evf_up_complete - Finish the last steps of bringing up a connection
1008 * @adapter: board private structure
1010 static int i40evf_up_complete(struct i40evf_adapter
*adapter
)
1012 adapter
->state
= __I40EVF_RUNNING
;
1013 clear_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1015 i40evf_napi_enable_all(adapter
);
1017 adapter
->aq_required
|= I40EVF_FLAG_AQ_ENABLE_QUEUES
;
1018 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
1023 * i40e_down - Shutdown the connection processing
1024 * @adapter: board private structure
1026 void i40evf_down(struct i40evf_adapter
*adapter
)
1028 struct net_device
*netdev
= adapter
->netdev
;
1029 struct i40evf_mac_filter
*f
;
1031 if (adapter
->state
<= __I40EVF_DOWN_PENDING
)
1034 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
1035 &adapter
->crit_section
))
1036 usleep_range(500, 1000);
1038 netif_carrier_off(netdev
);
1039 netif_tx_disable(netdev
);
1040 i40evf_napi_disable_all(adapter
);
1041 i40evf_irq_disable(adapter
);
1043 /* remove all MAC filters */
1044 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
1047 /* remove all VLAN filters */
1048 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
1051 if (!(adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) &&
1052 adapter
->state
!= __I40EVF_RESETTING
) {
1053 /* cancel any current operation */
1054 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1055 /* Schedule operations to close down the HW. Don't wait
1056 * here for this to complete. The watchdog is still running
1057 * and it will take care of this.
1059 adapter
->aq_required
= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
1060 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
1061 adapter
->aq_required
|= I40EVF_FLAG_AQ_DISABLE_QUEUES
;
1064 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1068 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1069 * @adapter: board private structure
1070 * @vectors: number of vectors to request
1072 * Work with the OS to set up the MSIX vectors needed.
1074 * Returns 0 on success, negative on failure
1077 i40evf_acquire_msix_vectors(struct i40evf_adapter
*adapter
, int vectors
)
1079 int err
, vector_threshold
;
1081 /* We'll want at least 3 (vector_threshold):
1082 * 0) Other (Admin Queue and link, mostly)
1086 vector_threshold
= MIN_MSIX_COUNT
;
1088 /* The more we get, the more we will assign to Tx/Rx Cleanup
1089 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1090 * Right now, we simply care about how many we'll get; we'll
1091 * set them up later while requesting irq's.
1093 err
= pci_enable_msix_range(adapter
->pdev
, adapter
->msix_entries
,
1094 vector_threshold
, vectors
);
1096 dev_err(&adapter
->pdev
->dev
, "Unable to allocate MSI-X interrupts\n");
1097 kfree(adapter
->msix_entries
);
1098 adapter
->msix_entries
= NULL
;
1102 /* Adjust for only the vectors we'll use, which is minimum
1103 * of max_msix_q_vectors + NONQ_VECS, or the number of
1104 * vectors we were allocated.
1106 adapter
->num_msix_vectors
= err
;
1111 * i40evf_free_queues - Free memory for all rings
1112 * @adapter: board private structure to initialize
1114 * Free all of the memory associated with queue pairs.
1116 static void i40evf_free_queues(struct i40evf_adapter
*adapter
)
1118 if (!adapter
->vsi_res
)
1120 kfree(adapter
->tx_rings
);
1121 adapter
->tx_rings
= NULL
;
1122 kfree(adapter
->rx_rings
);
1123 adapter
->rx_rings
= NULL
;
1127 * i40evf_alloc_queues - Allocate memory for all rings
1128 * @adapter: board private structure to initialize
1130 * We allocate one ring per queue at run-time since we don't know the
1131 * number of queues at compile-time. The polling_netdev array is
1132 * intended for Multiqueue, but should work fine with a single queue.
1134 static int i40evf_alloc_queues(struct i40evf_adapter
*adapter
)
1138 adapter
->tx_rings
= kcalloc(adapter
->num_active_queues
,
1139 sizeof(struct i40e_ring
), GFP_KERNEL
);
1140 if (!adapter
->tx_rings
)
1142 adapter
->rx_rings
= kcalloc(adapter
->num_active_queues
,
1143 sizeof(struct i40e_ring
), GFP_KERNEL
);
1144 if (!adapter
->rx_rings
)
1147 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
1148 struct i40e_ring
*tx_ring
;
1149 struct i40e_ring
*rx_ring
;
1151 tx_ring
= &adapter
->tx_rings
[i
];
1153 tx_ring
->queue_index
= i
;
1154 tx_ring
->netdev
= adapter
->netdev
;
1155 tx_ring
->dev
= &adapter
->pdev
->dev
;
1156 tx_ring
->count
= adapter
->tx_desc_count
;
1157 if (adapter
->flags
& I40E_FLAG_WB_ON_ITR_CAPABLE
)
1158 tx_ring
->flags
|= I40E_TXR_FLAGS_WB_ON_ITR
;
1160 rx_ring
= &adapter
->rx_rings
[i
];
1161 rx_ring
->queue_index
= i
;
1162 rx_ring
->netdev
= adapter
->netdev
;
1163 rx_ring
->dev
= &adapter
->pdev
->dev
;
1164 rx_ring
->count
= adapter
->rx_desc_count
;
1170 i40evf_free_queues(adapter
);
1175 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1176 * @adapter: board private structure to initialize
1178 * Attempt to configure the interrupts using the best available
1179 * capabilities of the hardware and the kernel.
1181 static int i40evf_set_interrupt_capability(struct i40evf_adapter
*adapter
)
1183 int vector
, v_budget
;
1187 if (!adapter
->vsi_res
) {
1191 pairs
= adapter
->num_active_queues
;
1193 /* It's easy to be greedy for MSI-X vectors, but it really
1194 * doesn't do us much good if we have a lot more vectors
1195 * than CPU's. So let's be conservative and only ask for
1196 * (roughly) twice the number of vectors as there are CPU's.
1198 v_budget
= min_t(int, pairs
, (int)(num_online_cpus() * 2)) + NONQ_VECS
;
1199 v_budget
= min_t(int, v_budget
, (int)adapter
->vf_res
->max_vectors
);
1201 adapter
->msix_entries
= kcalloc(v_budget
,
1202 sizeof(struct msix_entry
), GFP_KERNEL
);
1203 if (!adapter
->msix_entries
) {
1208 for (vector
= 0; vector
< v_budget
; vector
++)
1209 adapter
->msix_entries
[vector
].entry
= vector
;
1211 err
= i40evf_acquire_msix_vectors(adapter
, v_budget
);
1214 netif_set_real_num_rx_queues(adapter
->netdev
, pairs
);
1215 netif_set_real_num_tx_queues(adapter
->netdev
, pairs
);
1220 * i40e_config_rss_aq - Configure RSS keys and lut by using AQ commands
1221 * @adapter: board private structure
1223 * Return 0 on success, negative on failure
1225 static int i40evf_config_rss_aq(struct i40evf_adapter
*adapter
)
1227 struct i40e_aqc_get_set_rss_key_data
*rss_key
=
1228 (struct i40e_aqc_get_set_rss_key_data
*)adapter
->rss_key
;
1229 struct i40e_hw
*hw
= &adapter
->hw
;
1232 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
1233 /* bail because we already have a command pending */
1234 dev_err(&adapter
->pdev
->dev
, "Cannot configure RSS, command %d pending\n",
1235 adapter
->current_op
);
1239 ret
= i40evf_aq_set_rss_key(hw
, adapter
->vsi
.id
, rss_key
);
1241 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS key, err %s aq_err %s\n",
1242 i40evf_stat_str(hw
, ret
),
1243 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1248 ret
= i40evf_aq_set_rss_lut(hw
, adapter
->vsi
.id
, false,
1249 adapter
->rss_lut
, adapter
->rss_lut_size
);
1251 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS lut, err %s aq_err %s\n",
1252 i40evf_stat_str(hw
, ret
),
1253 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1261 * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
1262 * @adapter: board private structure
1264 * Returns 0 on success, negative on failure
1266 static int i40evf_config_rss_reg(struct i40evf_adapter
*adapter
)
1268 struct i40e_hw
*hw
= &adapter
->hw
;
1272 dw
= (u32
*)adapter
->rss_key
;
1273 for (i
= 0; i
<= adapter
->rss_key_size
/ 4; i
++)
1274 wr32(hw
, I40E_VFQF_HKEY(i
), dw
[i
]);
1276 dw
= (u32
*)adapter
->rss_lut
;
1277 for (i
= 0; i
<= adapter
->rss_lut_size
/ 4; i
++)
1278 wr32(hw
, I40E_VFQF_HLUT(i
), dw
[i
]);
1286 * i40evf_config_rss - Configure RSS keys and lut
1287 * @adapter: board private structure
1289 * Returns 0 on success, negative on failure
1291 int i40evf_config_rss(struct i40evf_adapter
*adapter
)
1294 if (RSS_PF(adapter
)) {
1295 adapter
->aq_required
|= I40EVF_FLAG_AQ_SET_RSS_LUT
|
1296 I40EVF_FLAG_AQ_SET_RSS_KEY
;
1298 } else if (RSS_AQ(adapter
)) {
1299 return i40evf_config_rss_aq(adapter
);
1301 return i40evf_config_rss_reg(adapter
);
1306 * i40evf_fill_rss_lut - Fill the lut with default values
1307 * @adapter: board private structure
1309 static void i40evf_fill_rss_lut(struct i40evf_adapter
*adapter
)
1313 for (i
= 0; i
< adapter
->rss_lut_size
; i
++)
1314 adapter
->rss_lut
[i
] = i
% adapter
->num_active_queues
;
1318 * i40evf_init_rss - Prepare for RSS
1319 * @adapter: board private structure
1321 * Return 0 on success, negative on failure
1323 static int i40evf_init_rss(struct i40evf_adapter
*adapter
)
1325 struct i40e_hw
*hw
= &adapter
->hw
;
1328 if (!RSS_PF(adapter
)) {
1329 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1330 if (adapter
->vf_res
->vf_offload_flags
&
1331 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
)
1332 adapter
->hena
= I40E_DEFAULT_RSS_HENA_EXPANDED
;
1334 adapter
->hena
= I40E_DEFAULT_RSS_HENA
;
1336 wr32(hw
, I40E_VFQF_HENA(0), (u32
)adapter
->hena
);
1337 wr32(hw
, I40E_VFQF_HENA(1), (u32
)(adapter
->hena
>> 32));
1340 i40evf_fill_rss_lut(adapter
);
1342 netdev_rss_key_fill((void *)adapter
->rss_key
, adapter
->rss_key_size
);
1343 ret
= i40evf_config_rss(adapter
);
1349 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1350 * @adapter: board private structure to initialize
1352 * We allocate one q_vector per queue interrupt. If allocation fails we
1355 static int i40evf_alloc_q_vectors(struct i40evf_adapter
*adapter
)
1357 int q_idx
= 0, num_q_vectors
;
1358 struct i40e_q_vector
*q_vector
;
1360 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1361 adapter
->q_vectors
= kcalloc(num_q_vectors
, sizeof(*q_vector
),
1363 if (!adapter
->q_vectors
)
1366 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1367 q_vector
= &adapter
->q_vectors
[q_idx
];
1368 q_vector
->adapter
= adapter
;
1369 q_vector
->vsi
= &adapter
->vsi
;
1370 q_vector
->v_idx
= q_idx
;
1371 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1372 i40evf_napi_poll
, NAPI_POLL_WEIGHT
);
1379 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1380 * @adapter: board private structure to initialize
1382 * This function frees the memory allocated to the q_vectors. In addition if
1383 * NAPI is enabled it will delete any references to the NAPI struct prior
1384 * to freeing the q_vector.
1386 static void i40evf_free_q_vectors(struct i40evf_adapter
*adapter
)
1388 int q_idx
, num_q_vectors
;
1391 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1392 napi_vectors
= adapter
->num_active_queues
;
1394 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1395 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[q_idx
];
1396 if (q_idx
< napi_vectors
)
1397 netif_napi_del(&q_vector
->napi
);
1399 kfree(adapter
->q_vectors
);
1403 * i40evf_reset_interrupt_capability - Reset MSIX setup
1404 * @adapter: board private structure
1407 void i40evf_reset_interrupt_capability(struct i40evf_adapter
*adapter
)
1409 pci_disable_msix(adapter
->pdev
);
1410 kfree(adapter
->msix_entries
);
1411 adapter
->msix_entries
= NULL
;
1415 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1416 * @adapter: board private structure to initialize
1419 int i40evf_init_interrupt_scheme(struct i40evf_adapter
*adapter
)
1423 err
= i40evf_set_interrupt_capability(adapter
);
1425 dev_err(&adapter
->pdev
->dev
,
1426 "Unable to setup interrupt capabilities\n");
1427 goto err_set_interrupt
;
1430 err
= i40evf_alloc_q_vectors(adapter
);
1432 dev_err(&adapter
->pdev
->dev
,
1433 "Unable to allocate memory for queue vectors\n");
1434 goto err_alloc_q_vectors
;
1437 err
= i40evf_alloc_queues(adapter
);
1439 dev_err(&adapter
->pdev
->dev
,
1440 "Unable to allocate memory for queues\n");
1441 goto err_alloc_queues
;
1444 dev_info(&adapter
->pdev
->dev
, "Multiqueue %s: Queue pair count = %u",
1445 (adapter
->num_active_queues
> 1) ? "Enabled" : "Disabled",
1446 adapter
->num_active_queues
);
1450 i40evf_free_q_vectors(adapter
);
1451 err_alloc_q_vectors
:
1452 i40evf_reset_interrupt_capability(adapter
);
1458 * i40evf_free_rss - Free memory used by RSS structs
1459 * @adapter: board private structure
1461 static void i40evf_free_rss(struct i40evf_adapter
*adapter
)
1463 kfree(adapter
->rss_key
);
1464 adapter
->rss_key
= NULL
;
1466 kfree(adapter
->rss_lut
);
1467 adapter
->rss_lut
= NULL
;
1471 * i40evf_watchdog_timer - Periodic call-back timer
1472 * @data: pointer to adapter disguised as unsigned long
1474 static void i40evf_watchdog_timer(unsigned long data
)
1476 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)data
;
1478 schedule_work(&adapter
->watchdog_task
);
1479 /* timer will be rescheduled in watchdog task */
1483 * i40evf_watchdog_task - Periodic call-back task
1484 * @work: pointer to work_struct
1486 static void i40evf_watchdog_task(struct work_struct
*work
)
1488 struct i40evf_adapter
*adapter
= container_of(work
,
1489 struct i40evf_adapter
,
1491 struct i40e_hw
*hw
= &adapter
->hw
;
1494 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
))
1495 goto restart_watchdog
;
1497 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
1498 reg_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1499 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1500 if ((reg_val
== I40E_VFR_VFACTIVE
) ||
1501 (reg_val
== I40E_VFR_COMPLETED
)) {
1502 /* A chance for redemption! */
1503 dev_err(&adapter
->pdev
->dev
, "Hardware came out of reset. Attempting reinit.\n");
1504 adapter
->state
= __I40EVF_STARTUP
;
1505 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
1506 schedule_delayed_work(&adapter
->init_task
, 10);
1507 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
1508 &adapter
->crit_section
);
1509 /* Don't reschedule the watchdog, since we've restarted
1510 * the init task. When init_task contacts the PF and
1511 * gets everything set up again, it'll restart the
1512 * watchdog for us. Down, boy. Sit. Stay. Woof.
1516 adapter
->aq_required
= 0;
1517 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1521 if ((adapter
->state
< __I40EVF_DOWN
) ||
1522 (adapter
->flags
& I40EVF_FLAG_RESET_PENDING
))
1525 /* check for reset */
1526 reg_val
= rd32(hw
, I40E_VF_ARQLEN1
) & I40E_VF_ARQLEN1_ARQENABLE_MASK
;
1527 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
) && !reg_val
) {
1528 adapter
->state
= __I40EVF_RESETTING
;
1529 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
1530 dev_err(&adapter
->pdev
->dev
, "Hardware reset detected\n");
1531 schedule_work(&adapter
->reset_task
);
1532 adapter
->aq_required
= 0;
1533 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1537 /* Process admin queue tasks. After init, everything gets done
1538 * here so we don't race on the admin queue.
1540 if (adapter
->current_op
) {
1541 if (!i40evf_asq_done(hw
)) {
1542 dev_dbg(&adapter
->pdev
->dev
, "Admin queue timeout\n");
1543 i40evf_send_api_ver(adapter
);
1547 if (adapter
->aq_required
& I40EVF_FLAG_AQ_GET_CONFIG
) {
1548 i40evf_send_vf_config_msg(adapter
);
1552 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DISABLE_QUEUES
) {
1553 i40evf_disable_queues(adapter
);
1557 if (adapter
->aq_required
& I40EVF_FLAG_AQ_MAP_VECTORS
) {
1558 i40evf_map_queues(adapter
);
1562 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_MAC_FILTER
) {
1563 i40evf_add_ether_addrs(adapter
);
1567 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_VLAN_FILTER
) {
1568 i40evf_add_vlans(adapter
);
1572 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_MAC_FILTER
) {
1573 i40evf_del_ether_addrs(adapter
);
1577 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_VLAN_FILTER
) {
1578 i40evf_del_vlans(adapter
);
1582 if (adapter
->aq_required
& I40EVF_FLAG_AQ_CONFIGURE_QUEUES
) {
1583 i40evf_configure_queues(adapter
);
1587 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ENABLE_QUEUES
) {
1588 i40evf_enable_queues(adapter
);
1592 if (adapter
->aq_required
& I40EVF_FLAG_AQ_CONFIGURE_RSS
) {
1593 /* This message goes straight to the firmware, not the
1594 * PF, so we don't have to set current_op as we will
1595 * not get a response through the ARQ.
1597 i40evf_init_rss(adapter
);
1598 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_CONFIGURE_RSS
;
1601 if (adapter
->aq_required
& I40EVF_FLAG_AQ_GET_HENA
) {
1602 i40evf_get_hena(adapter
);
1605 if (adapter
->aq_required
& I40EVF_FLAG_AQ_SET_HENA
) {
1606 i40evf_set_hena(adapter
);
1609 if (adapter
->aq_required
& I40EVF_FLAG_AQ_SET_RSS_KEY
) {
1610 i40evf_set_rss_key(adapter
);
1613 if (adapter
->aq_required
& I40EVF_FLAG_AQ_SET_RSS_LUT
) {
1614 i40evf_set_rss_lut(adapter
);
1618 if (adapter
->aq_required
& I40EVF_FLAG_AQ_REQUEST_PROMISC
) {
1619 i40evf_set_promiscuous(adapter
, I40E_FLAG_VF_UNICAST_PROMISC
|
1620 I40E_FLAG_VF_MULTICAST_PROMISC
);
1624 if (adapter
->aq_required
& I40EVF_FLAG_AQ_REQUEST_ALLMULTI
) {
1625 i40evf_set_promiscuous(adapter
, I40E_FLAG_VF_MULTICAST_PROMISC
);
1629 if ((adapter
->aq_required
& I40EVF_FLAG_AQ_RELEASE_PROMISC
) &&
1630 (adapter
->aq_required
& I40EVF_FLAG_AQ_RELEASE_ALLMULTI
)) {
1631 i40evf_set_promiscuous(adapter
, 0);
1635 if (adapter
->state
== __I40EVF_RUNNING
)
1636 i40evf_request_stats(adapter
);
1638 if (adapter
->state
== __I40EVF_RUNNING
) {
1639 i40evf_irq_enable_queues(adapter
, ~0);
1640 i40evf_fire_sw_int(adapter
, 0xFF);
1642 i40evf_fire_sw_int(adapter
, 0x1);
1645 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1647 if (adapter
->state
== __I40EVF_REMOVE
)
1649 if (adapter
->aq_required
)
1650 mod_timer(&adapter
->watchdog_timer
,
1651 jiffies
+ msecs_to_jiffies(20));
1653 mod_timer(&adapter
->watchdog_timer
, jiffies
+ (HZ
* 2));
1654 schedule_work(&adapter
->adminq_task
);
1657 #define I40EVF_RESET_WAIT_MS 10
1658 #define I40EVF_RESET_WAIT_COUNT 500
1660 * i40evf_reset_task - Call-back task to handle hardware reset
1661 * @work: pointer to work_struct
1663 * During reset we need to shut down and reinitialize the admin queue
1664 * before we can use it to communicate with the PF again. We also clear
1665 * and reinit the rings because that context is lost as well.
1667 static void i40evf_reset_task(struct work_struct
*work
)
1669 struct i40evf_adapter
*adapter
= container_of(work
,
1670 struct i40evf_adapter
,
1672 struct net_device
*netdev
= adapter
->netdev
;
1673 struct i40e_hw
*hw
= &adapter
->hw
;
1674 struct i40evf_vlan_filter
*vlf
;
1675 struct i40evf_mac_filter
*f
;
1679 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
1680 &adapter
->crit_section
))
1681 usleep_range(500, 1000);
1683 i40evf_misc_irq_disable(adapter
);
1684 if (adapter
->flags
& I40EVF_FLAG_RESET_NEEDED
) {
1685 adapter
->flags
&= ~I40EVF_FLAG_RESET_NEEDED
;
1686 /* Restart the AQ here. If we have been reset but didn't
1687 * detect it, or if the PF had to reinit, our AQ will be hosed.
1689 i40evf_shutdown_adminq(hw
);
1690 i40evf_init_adminq(hw
);
1691 i40evf_request_reset(adapter
);
1693 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
1695 /* poll until we see the reset actually happen */
1696 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1697 reg_val
= rd32(hw
, I40E_VF_ARQLEN1
) &
1698 I40E_VF_ARQLEN1_ARQENABLE_MASK
;
1701 usleep_range(5000, 10000);
1703 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1704 dev_info(&adapter
->pdev
->dev
, "Never saw reset\n");
1705 goto continue_reset
; /* act like the reset happened */
1708 /* wait until the reset is complete and the PF is responding to us */
1709 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1710 reg_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1711 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1712 if (reg_val
== I40E_VFR_VFACTIVE
)
1714 msleep(I40EVF_RESET_WAIT_MS
);
1716 pci_set_master(adapter
->pdev
);
1717 /* extra wait to make sure minimum wait is met */
1718 msleep(I40EVF_RESET_WAIT_MS
);
1719 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1720 struct i40evf_mac_filter
*ftmp
;
1721 struct i40evf_vlan_filter
*fv
, *fvtmp
;
1723 /* reset never finished */
1724 dev_err(&adapter
->pdev
->dev
, "Reset never finished (%x)\n",
1726 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
1728 if (netif_running(adapter
->netdev
)) {
1729 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1730 netif_carrier_off(netdev
);
1731 netif_tx_disable(netdev
);
1732 i40evf_napi_disable_all(adapter
);
1733 i40evf_irq_disable(adapter
);
1734 i40evf_free_traffic_irqs(adapter
);
1735 i40evf_free_all_tx_resources(adapter
);
1736 i40evf_free_all_rx_resources(adapter
);
1739 /* Delete all of the filters, both MAC and VLAN. */
1740 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
,
1746 list_for_each_entry_safe(fv
, fvtmp
, &adapter
->vlan_filter_list
,
1748 list_del(&fv
->list
);
1752 i40evf_free_misc_irq(adapter
);
1753 i40evf_reset_interrupt_capability(adapter
);
1754 i40evf_free_queues(adapter
);
1755 i40evf_free_q_vectors(adapter
);
1756 kfree(adapter
->vf_res
);
1757 i40evf_shutdown_adminq(hw
);
1758 adapter
->netdev
->flags
&= ~IFF_UP
;
1759 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1760 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1761 adapter
->state
= __I40EVF_DOWN
;
1762 dev_info(&adapter
->pdev
->dev
, "Reset task did not complete, VF disabled\n");
1763 return; /* Do not attempt to reinit. It's dead, Jim. */
1767 if (netif_running(adapter
->netdev
)) {
1768 netif_carrier_off(netdev
);
1769 netif_tx_stop_all_queues(netdev
);
1770 i40evf_napi_disable_all(adapter
);
1772 i40evf_irq_disable(adapter
);
1774 adapter
->state
= __I40EVF_RESETTING
;
1775 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1777 /* free the Tx/Rx rings and descriptors, might be better to just
1778 * re-use them sometime in the future
1780 i40evf_free_all_rx_resources(adapter
);
1781 i40evf_free_all_tx_resources(adapter
);
1783 /* kill and reinit the admin queue */
1784 if (i40evf_shutdown_adminq(hw
))
1785 dev_warn(&adapter
->pdev
->dev
, "Failed to shut down adminq\n");
1786 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1787 err
= i40evf_init_adminq(hw
);
1789 dev_info(&adapter
->pdev
->dev
, "Failed to init adminq: %d\n",
1792 adapter
->aq_required
= I40EVF_FLAG_AQ_GET_CONFIG
;
1793 adapter
->aq_required
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
1795 /* re-add all MAC filters */
1796 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
1799 /* re-add all VLAN filters */
1800 list_for_each_entry(vlf
, &adapter
->vlan_filter_list
, list
) {
1803 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
1804 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
1805 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1806 i40evf_misc_irq_enable(adapter
);
1808 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2);
1810 if (netif_running(adapter
->netdev
)) {
1811 /* allocate transmit descriptors */
1812 err
= i40evf_setup_all_tx_resources(adapter
);
1816 /* allocate receive descriptors */
1817 err
= i40evf_setup_all_rx_resources(adapter
);
1821 i40evf_configure(adapter
);
1823 err
= i40evf_up_complete(adapter
);
1827 i40evf_irq_enable(adapter
, true);
1829 adapter
->state
= __I40EVF_DOWN
;
1834 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit\n");
1835 i40evf_close(adapter
->netdev
);
1839 * i40evf_adminq_task - worker thread to clean the admin queue
1840 * @work: pointer to work_struct containing our data
1842 static void i40evf_adminq_task(struct work_struct
*work
)
1844 struct i40evf_adapter
*adapter
=
1845 container_of(work
, struct i40evf_adapter
, adminq_task
);
1846 struct i40e_hw
*hw
= &adapter
->hw
;
1847 struct i40e_arq_event_info event
;
1848 struct i40e_virtchnl_msg
*v_msg
;
1853 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
)
1856 event
.buf_len
= I40EVF_MAX_AQ_BUF_SIZE
;
1857 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
1861 v_msg
= (struct i40e_virtchnl_msg
*)&event
.desc
;
1863 ret
= i40evf_clean_arq_element(hw
, &event
, &pending
);
1864 if (ret
|| !v_msg
->v_opcode
)
1865 break; /* No event to process or error cleaning ARQ */
1867 i40evf_virtchnl_completion(adapter
, v_msg
->v_opcode
,
1868 v_msg
->v_retval
, event
.msg_buf
,
1871 memset(event
.msg_buf
, 0, I40EVF_MAX_AQ_BUF_SIZE
);
1874 if ((adapter
->flags
&
1875 (I40EVF_FLAG_RESET_PENDING
| I40EVF_FLAG_RESET_NEEDED
)) ||
1876 adapter
->state
== __I40EVF_RESETTING
)
1879 /* check for error indications */
1880 val
= rd32(hw
, hw
->aq
.arq
.len
);
1881 if (val
== 0xdeadbeef) /* indicates device in reset */
1884 if (val
& I40E_VF_ARQLEN1_ARQVFE_MASK
) {
1885 dev_info(&adapter
->pdev
->dev
, "ARQ VF Error detected\n");
1886 val
&= ~I40E_VF_ARQLEN1_ARQVFE_MASK
;
1888 if (val
& I40E_VF_ARQLEN1_ARQOVFL_MASK
) {
1889 dev_info(&adapter
->pdev
->dev
, "ARQ Overflow Error detected\n");
1890 val
&= ~I40E_VF_ARQLEN1_ARQOVFL_MASK
;
1892 if (val
& I40E_VF_ARQLEN1_ARQCRIT_MASK
) {
1893 dev_info(&adapter
->pdev
->dev
, "ARQ Critical Error detected\n");
1894 val
&= ~I40E_VF_ARQLEN1_ARQCRIT_MASK
;
1897 wr32(hw
, hw
->aq
.arq
.len
, val
);
1899 val
= rd32(hw
, hw
->aq
.asq
.len
);
1901 if (val
& I40E_VF_ATQLEN1_ATQVFE_MASK
) {
1902 dev_info(&adapter
->pdev
->dev
, "ASQ VF Error detected\n");
1903 val
&= ~I40E_VF_ATQLEN1_ATQVFE_MASK
;
1905 if (val
& I40E_VF_ATQLEN1_ATQOVFL_MASK
) {
1906 dev_info(&adapter
->pdev
->dev
, "ASQ Overflow Error detected\n");
1907 val
&= ~I40E_VF_ATQLEN1_ATQOVFL_MASK
;
1909 if (val
& I40E_VF_ATQLEN1_ATQCRIT_MASK
) {
1910 dev_info(&adapter
->pdev
->dev
, "ASQ Critical Error detected\n");
1911 val
&= ~I40E_VF_ATQLEN1_ATQCRIT_MASK
;
1914 wr32(hw
, hw
->aq
.asq
.len
, val
);
1917 kfree(event
.msg_buf
);
1919 /* re-enable Admin queue interrupt cause */
1920 i40evf_misc_irq_enable(adapter
);
1924 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
1925 * @adapter: board private structure
1927 * Free all transmit software resources
1929 void i40evf_free_all_tx_resources(struct i40evf_adapter
*adapter
)
1933 if (!adapter
->tx_rings
)
1936 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
1937 if (adapter
->tx_rings
[i
].desc
)
1938 i40evf_free_tx_resources(&adapter
->tx_rings
[i
]);
1942 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
1943 * @adapter: board private structure
1945 * If this function returns with an error, then it's possible one or
1946 * more of the rings is populated (while the rest are not). It is the
1947 * callers duty to clean those orphaned rings.
1949 * Return 0 on success, negative on failure
1951 static int i40evf_setup_all_tx_resources(struct i40evf_adapter
*adapter
)
1955 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
1956 adapter
->tx_rings
[i
].count
= adapter
->tx_desc_count
;
1957 err
= i40evf_setup_tx_descriptors(&adapter
->tx_rings
[i
]);
1960 dev_err(&adapter
->pdev
->dev
,
1961 "Allocation for Tx Queue %u failed\n", i
);
1969 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
1970 * @adapter: board private structure
1972 * If this function returns with an error, then it's possible one or
1973 * more of the rings is populated (while the rest are not). It is the
1974 * callers duty to clean those orphaned rings.
1976 * Return 0 on success, negative on failure
1978 static int i40evf_setup_all_rx_resources(struct i40evf_adapter
*adapter
)
1982 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
1983 adapter
->rx_rings
[i
].count
= adapter
->rx_desc_count
;
1984 err
= i40evf_setup_rx_descriptors(&adapter
->rx_rings
[i
]);
1987 dev_err(&adapter
->pdev
->dev
,
1988 "Allocation for Rx Queue %u failed\n", i
);
1995 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
1996 * @adapter: board private structure
1998 * Free all receive software resources
2000 void i40evf_free_all_rx_resources(struct i40evf_adapter
*adapter
)
2004 if (!adapter
->rx_rings
)
2007 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2008 if (adapter
->rx_rings
[i
].desc
)
2009 i40evf_free_rx_resources(&adapter
->rx_rings
[i
]);
2013 * i40evf_open - Called when a network interface is made active
2014 * @netdev: network interface device structure
2016 * Returns 0 on success, negative value on failure
2018 * The open entry point is called when a network interface is made
2019 * active by the system (IFF_UP). At this point all resources needed
2020 * for transmit and receive operations are allocated, the interrupt
2021 * handler is registered with the OS, the watchdog timer is started,
2022 * and the stack is notified that the interface is ready.
2024 static int i40evf_open(struct net_device
*netdev
)
2026 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2029 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
2030 dev_err(&adapter
->pdev
->dev
, "Unable to open device due to PF driver failure.\n");
2034 if (adapter
->state
!= __I40EVF_DOWN
)
2037 /* allocate transmit descriptors */
2038 err
= i40evf_setup_all_tx_resources(adapter
);
2042 /* allocate receive descriptors */
2043 err
= i40evf_setup_all_rx_resources(adapter
);
2047 /* clear any pending interrupts, may auto mask */
2048 err
= i40evf_request_traffic_irqs(adapter
, netdev
->name
);
2052 i40evf_add_filter(adapter
, adapter
->hw
.mac
.addr
);
2053 i40evf_configure(adapter
);
2055 err
= i40evf_up_complete(adapter
);
2059 i40evf_irq_enable(adapter
, true);
2064 i40evf_down(adapter
);
2065 i40evf_free_traffic_irqs(adapter
);
2067 i40evf_free_all_rx_resources(adapter
);
2069 i40evf_free_all_tx_resources(adapter
);
2075 * i40evf_close - Disables a network interface
2076 * @netdev: network interface device structure
2078 * Returns 0, this is not allowed to fail
2080 * The close entry point is called when an interface is de-activated
2081 * by the OS. The hardware is still under the drivers control, but
2082 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
2083 * are freed, along with all transmit and receive resources.
2085 static int i40evf_close(struct net_device
*netdev
)
2087 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2089 if (adapter
->state
<= __I40EVF_DOWN_PENDING
)
2093 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
2095 i40evf_down(adapter
);
2096 adapter
->state
= __I40EVF_DOWN_PENDING
;
2097 i40evf_free_traffic_irqs(adapter
);
2103 * i40evf_get_stats - Get System Network Statistics
2104 * @netdev: network interface device structure
2106 * Returns the address of the device statistics structure.
2107 * The statistics are actually updated from the timer callback.
2109 static struct net_device_stats
*i40evf_get_stats(struct net_device
*netdev
)
2111 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2113 /* only return the current stats */
2114 return &adapter
->net_stats
;
2118 * i40evf_change_mtu - Change the Maximum Transfer Unit
2119 * @netdev: network interface device structure
2120 * @new_mtu: new value for maximum frame size
2122 * Returns 0 on success, negative on failure
2124 static int i40evf_change_mtu(struct net_device
*netdev
, int new_mtu
)
2126 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2127 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2129 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
2132 netdev
->mtu
= new_mtu
;
2133 adapter
->flags
|= I40EVF_FLAG_RESET_NEEDED
;
2134 schedule_work(&adapter
->reset_task
);
2139 #define I40EVF_VLAN_FEATURES (NETIF_F_HW_VLAN_CTAG_TX |\
2140 NETIF_F_HW_VLAN_CTAG_RX |\
2141 NETIF_F_HW_VLAN_CTAG_FILTER)
2144 * i40evf_fix_features - fix up the netdev feature bits
2145 * @netdev: our net device
2146 * @features: desired feature bits
2148 * Returns fixed-up features bits
2150 static netdev_features_t
i40evf_fix_features(struct net_device
*netdev
,
2151 netdev_features_t features
)
2153 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2155 features
&= ~I40EVF_VLAN_FEATURES
;
2156 if (adapter
->vf_res
->vf_offload_flags
& I40E_VIRTCHNL_VF_OFFLOAD_VLAN
)
2157 features
|= I40EVF_VLAN_FEATURES
;
2161 static const struct net_device_ops i40evf_netdev_ops
= {
2162 .ndo_open
= i40evf_open
,
2163 .ndo_stop
= i40evf_close
,
2164 .ndo_start_xmit
= i40evf_xmit_frame
,
2165 .ndo_get_stats
= i40evf_get_stats
,
2166 .ndo_set_rx_mode
= i40evf_set_rx_mode
,
2167 .ndo_validate_addr
= eth_validate_addr
,
2168 .ndo_set_mac_address
= i40evf_set_mac
,
2169 .ndo_change_mtu
= i40evf_change_mtu
,
2170 .ndo_tx_timeout
= i40evf_tx_timeout
,
2171 .ndo_vlan_rx_add_vid
= i40evf_vlan_rx_add_vid
,
2172 .ndo_vlan_rx_kill_vid
= i40evf_vlan_rx_kill_vid
,
2173 .ndo_fix_features
= i40evf_fix_features
,
2174 #ifdef CONFIG_NET_POLL_CONTROLLER
2175 .ndo_poll_controller
= i40evf_netpoll
,
2180 * i40evf_check_reset_complete - check that VF reset is complete
2181 * @hw: pointer to hw struct
2183 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2185 static int i40evf_check_reset_complete(struct i40e_hw
*hw
)
2190 for (i
= 0; i
< 100; i
++) {
2191 rstat
= rd32(hw
, I40E_VFGEN_RSTAT
) &
2192 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
2193 if ((rstat
== I40E_VFR_VFACTIVE
) ||
2194 (rstat
== I40E_VFR_COMPLETED
))
2196 usleep_range(10, 20);
2202 * i40evf_process_config - Process the config information we got from the PF
2203 * @adapter: board private structure
2205 * Verify that we have a valid config struct, and set up our netdev features
2206 * and our VSI struct.
2208 int i40evf_process_config(struct i40evf_adapter
*adapter
)
2210 struct i40e_virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
2211 struct net_device
*netdev
= adapter
->netdev
;
2212 struct i40e_vsi
*vsi
= &adapter
->vsi
;
2215 /* got VF config message back from PF, now we can parse it */
2216 for (i
= 0; i
< vfres
->num_vsis
; i
++) {
2217 if (vfres
->vsi_res
[i
].vsi_type
== I40E_VSI_SRIOV
)
2218 adapter
->vsi_res
= &vfres
->vsi_res
[i
];
2220 if (!adapter
->vsi_res
) {
2221 dev_err(&adapter
->pdev
->dev
, "No LAN VSI found\n");
2225 netdev
->hw_enc_features
|= NETIF_F_SG
|
2229 NETIF_F_SOFT_FEATURES
|
2234 NETIF_F_GSO_GRE_CSUM
|
2235 NETIF_F_GSO_IPXIP4
|
2236 NETIF_F_GSO_IPXIP6
|
2237 NETIF_F_GSO_UDP_TUNNEL
|
2238 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
2239 NETIF_F_GSO_PARTIAL
|
2245 if (!(adapter
->flags
& I40EVF_FLAG_OUTER_UDP_CSUM_CAPABLE
))
2246 netdev
->gso_partial_features
|= NETIF_F_GSO_UDP_TUNNEL_CSUM
;
2248 netdev
->gso_partial_features
|= NETIF_F_GSO_GRE_CSUM
;
2250 /* record features VLANs can make use of */
2251 netdev
->vlan_features
|= netdev
->hw_enc_features
|
2252 NETIF_F_TSO_MANGLEID
;
2254 /* Write features and hw_features separately to avoid polluting
2255 * with, or dropping, features that are set when we registgered.
2257 netdev
->hw_features
|= netdev
->hw_enc_features
;
2259 netdev
->features
|= netdev
->hw_enc_features
| I40EVF_VLAN_FEATURES
;
2260 netdev
->hw_enc_features
|= NETIF_F_TSO_MANGLEID
;
2262 /* disable VLAN features if not supported */
2263 if (!(vfres
->vf_offload_flags
& I40E_VIRTCHNL_VF_OFFLOAD_VLAN
))
2264 netdev
->features
^= I40EVF_VLAN_FEATURES
;
2266 adapter
->vsi
.id
= adapter
->vsi_res
->vsi_id
;
2268 adapter
->vsi
.back
= adapter
;
2269 adapter
->vsi
.base_vector
= 1;
2270 adapter
->vsi
.work_limit
= I40E_DEFAULT_IRQ_WORK
;
2271 adapter
->vsi
.rx_itr_setting
= (I40E_ITR_DYNAMIC
|
2272 ITR_REG_TO_USEC(I40E_ITR_RX_DEF
));
2273 adapter
->vsi
.tx_itr_setting
= (I40E_ITR_DYNAMIC
|
2274 ITR_REG_TO_USEC(I40E_ITR_TX_DEF
));
2275 vsi
->netdev
= adapter
->netdev
;
2276 vsi
->qs_handle
= adapter
->vsi_res
->qset_handle
;
2277 if (vfres
->vf_offload_flags
& I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF
) {
2278 adapter
->rss_key_size
= vfres
->rss_key_size
;
2279 adapter
->rss_lut_size
= vfres
->rss_lut_size
;
2281 adapter
->rss_key_size
= I40EVF_HKEY_ARRAY_SIZE
;
2282 adapter
->rss_lut_size
= I40EVF_HLUT_ARRAY_SIZE
;
2289 * i40evf_init_task - worker thread to perform delayed initialization
2290 * @work: pointer to work_struct containing our data
2292 * This task completes the work that was begun in probe. Due to the nature
2293 * of VF-PF communications, we may need to wait tens of milliseconds to get
2294 * responses back from the PF. Rather than busy-wait in probe and bog down the
2295 * whole system, we'll do it in a task so we can sleep.
2296 * This task only runs during driver init. Once we've established
2297 * communications with the PF driver and set up our netdev, the watchdog
2300 static void i40evf_init_task(struct work_struct
*work
)
2302 struct i40evf_adapter
*adapter
= container_of(work
,
2303 struct i40evf_adapter
,
2305 struct net_device
*netdev
= adapter
->netdev
;
2306 struct i40e_hw
*hw
= &adapter
->hw
;
2307 struct pci_dev
*pdev
= adapter
->pdev
;
2310 switch (adapter
->state
) {
2311 case __I40EVF_STARTUP
:
2312 /* driver loaded, probe complete */
2313 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
2314 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
2315 err
= i40e_set_mac_type(hw
);
2317 dev_err(&pdev
->dev
, "Failed to set MAC type (%d)\n",
2321 err
= i40evf_check_reset_complete(hw
);
2323 dev_info(&pdev
->dev
, "Device is still in reset (%d), retrying\n",
2327 hw
->aq
.num_arq_entries
= I40EVF_AQ_LEN
;
2328 hw
->aq
.num_asq_entries
= I40EVF_AQ_LEN
;
2329 hw
->aq
.arq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
2330 hw
->aq
.asq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
2332 err
= i40evf_init_adminq(hw
);
2334 dev_err(&pdev
->dev
, "Failed to init Admin Queue (%d)\n",
2338 err
= i40evf_send_api_ver(adapter
);
2340 dev_err(&pdev
->dev
, "Unable to send to PF (%d)\n", err
);
2341 i40evf_shutdown_adminq(hw
);
2344 adapter
->state
= __I40EVF_INIT_VERSION_CHECK
;
2346 case __I40EVF_INIT_VERSION_CHECK
:
2347 if (!i40evf_asq_done(hw
)) {
2348 dev_err(&pdev
->dev
, "Admin queue command never completed\n");
2349 i40evf_shutdown_adminq(hw
);
2350 adapter
->state
= __I40EVF_STARTUP
;
2354 /* aq msg sent, awaiting reply */
2355 err
= i40evf_verify_api_ver(adapter
);
2357 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
2358 err
= i40evf_send_api_ver(adapter
);
2360 dev_err(&pdev
->dev
, "Unsupported PF API version %d.%d, expected %d.%d\n",
2361 adapter
->pf_version
.major
,
2362 adapter
->pf_version
.minor
,
2363 I40E_VIRTCHNL_VERSION_MAJOR
,
2364 I40E_VIRTCHNL_VERSION_MINOR
);
2367 err
= i40evf_send_vf_config_msg(adapter
);
2369 dev_err(&pdev
->dev
, "Unable to send config request (%d)\n",
2373 adapter
->state
= __I40EVF_INIT_GET_RESOURCES
;
2375 case __I40EVF_INIT_GET_RESOURCES
:
2376 /* aq msg sent, awaiting reply */
2377 if (!adapter
->vf_res
) {
2378 bufsz
= sizeof(struct i40e_virtchnl_vf_resource
) +
2380 sizeof(struct i40e_virtchnl_vsi_resource
));
2381 adapter
->vf_res
= kzalloc(bufsz
, GFP_KERNEL
);
2382 if (!adapter
->vf_res
)
2385 err
= i40evf_get_vf_config(adapter
);
2386 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
) {
2387 err
= i40evf_send_vf_config_msg(adapter
);
2389 } else if (err
== I40E_ERR_PARAM
) {
2390 /* We only get ERR_PARAM if the device is in a very bad
2391 * state or if we've been disabled for previous bad
2392 * behavior. Either way, we're done now.
2394 i40evf_shutdown_adminq(hw
);
2395 dev_err(&pdev
->dev
, "Unable to get VF config due to PF error condition, not retrying\n");
2399 dev_err(&pdev
->dev
, "Unable to get VF config (%d)\n",
2403 adapter
->state
= __I40EVF_INIT_SW
;
2409 if (hw
->mac
.type
== I40E_MAC_X722_VF
)
2410 adapter
->flags
|= I40EVF_FLAG_OUTER_UDP_CSUM_CAPABLE
;
2412 if (i40evf_process_config(adapter
))
2414 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
2416 adapter
->flags
|= I40EVF_FLAG_RX_CSUM_ENABLED
;
2418 netdev
->netdev_ops
= &i40evf_netdev_ops
;
2419 i40evf_set_ethtool_ops(netdev
);
2420 netdev
->watchdog_timeo
= 5 * HZ
;
2422 if (!is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
2423 dev_info(&pdev
->dev
, "Invalid MAC address %pM, using random\n",
2424 adapter
->hw
.mac
.addr
);
2425 eth_hw_addr_random(netdev
);
2426 ether_addr_copy(adapter
->hw
.mac
.addr
, netdev
->dev_addr
);
2428 adapter
->flags
|= I40EVF_FLAG_ADDR_SET_BY_PF
;
2429 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
2430 ether_addr_copy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
);
2433 init_timer(&adapter
->watchdog_timer
);
2434 adapter
->watchdog_timer
.function
= &i40evf_watchdog_timer
;
2435 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
2436 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
2438 adapter
->num_active_queues
= min_t(int,
2439 adapter
->vsi_res
->num_queue_pairs
,
2440 (int)(num_online_cpus()));
2441 adapter
->tx_desc_count
= I40EVF_DEFAULT_TXD
;
2442 adapter
->rx_desc_count
= I40EVF_DEFAULT_RXD
;
2443 err
= i40evf_init_interrupt_scheme(adapter
);
2446 i40evf_map_rings_to_vectors(adapter
);
2447 if (adapter
->vf_res
->vf_offload_flags
&
2448 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
)
2449 adapter
->flags
|= I40EVF_FLAG_WB_ON_ITR_CAPABLE
;
2451 err
= i40evf_request_misc_irq(adapter
);
2455 netif_carrier_off(netdev
);
2457 if (!adapter
->netdev_registered
) {
2458 err
= register_netdev(netdev
);
2463 adapter
->netdev_registered
= true;
2465 netif_tx_stop_all_queues(netdev
);
2467 dev_info(&pdev
->dev
, "MAC address: %pM\n", adapter
->hw
.mac
.addr
);
2468 if (netdev
->features
& NETIF_F_GRO
)
2469 dev_info(&pdev
->dev
, "GRO is enabled\n");
2471 adapter
->state
= __I40EVF_DOWN
;
2472 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
2473 i40evf_misc_irq_enable(adapter
);
2475 adapter
->rss_key
= kzalloc(adapter
->rss_key_size
, GFP_KERNEL
);
2476 adapter
->rss_lut
= kzalloc(adapter
->rss_lut_size
, GFP_KERNEL
);
2477 if (!adapter
->rss_key
|| !adapter
->rss_lut
)
2480 if (RSS_AQ(adapter
)) {
2481 adapter
->aq_required
|= I40EVF_FLAG_AQ_CONFIGURE_RSS
;
2482 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
2484 i40evf_init_rss(adapter
);
2488 schedule_delayed_work(&adapter
->init_task
, msecs_to_jiffies(30));
2491 i40evf_free_rss(adapter
);
2493 i40evf_free_misc_irq(adapter
);
2495 i40evf_reset_interrupt_capability(adapter
);
2497 kfree(adapter
->vf_res
);
2498 adapter
->vf_res
= NULL
;
2500 /* Things went into the weeds, so try again later */
2501 if (++adapter
->aq_wait_count
> I40EVF_AQ_MAX_ERR
) {
2502 dev_err(&pdev
->dev
, "Failed to communicate with PF; waiting before retry\n");
2503 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
2504 i40evf_shutdown_adminq(hw
);
2505 adapter
->state
= __I40EVF_STARTUP
;
2506 schedule_delayed_work(&adapter
->init_task
, HZ
* 5);
2509 schedule_delayed_work(&adapter
->init_task
, HZ
);
2513 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2514 * @pdev: pci device structure
2516 static void i40evf_shutdown(struct pci_dev
*pdev
)
2518 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2519 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2521 netif_device_detach(netdev
);
2523 if (netif_running(netdev
))
2524 i40evf_close(netdev
);
2526 /* Prevent the watchdog from running. */
2527 adapter
->state
= __I40EVF_REMOVE
;
2528 adapter
->aq_required
= 0;
2531 pci_save_state(pdev
);
2534 pci_disable_device(pdev
);
2538 * i40evf_probe - Device Initialization Routine
2539 * @pdev: PCI device information struct
2540 * @ent: entry in i40evf_pci_tbl
2542 * Returns 0 on success, negative on failure
2544 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2545 * The OS initialization, configuring of the adapter private structure,
2546 * and a hardware reset occur.
2548 static int i40evf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2550 struct net_device
*netdev
;
2551 struct i40evf_adapter
*adapter
= NULL
;
2552 struct i40e_hw
*hw
= NULL
;
2555 err
= pci_enable_device(pdev
);
2559 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
2561 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
2564 "DMA configuration failed: 0x%x\n", err
);
2569 err
= pci_request_regions(pdev
, i40evf_driver_name
);
2572 "pci_request_regions failed 0x%x\n", err
);
2576 pci_enable_pcie_error_reporting(pdev
);
2578 pci_set_master(pdev
);
2580 netdev
= alloc_etherdev_mq(sizeof(struct i40evf_adapter
), MAX_QUEUES
);
2583 goto err_alloc_etherdev
;
2586 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2588 pci_set_drvdata(pdev
, netdev
);
2589 adapter
= netdev_priv(netdev
);
2591 adapter
->netdev
= netdev
;
2592 adapter
->pdev
= pdev
;
2597 adapter
->msg_enable
= BIT(DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
2598 adapter
->state
= __I40EVF_STARTUP
;
2600 /* Call save state here because it relies on the adapter struct. */
2601 pci_save_state(pdev
);
2603 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
2604 pci_resource_len(pdev
, 0));
2609 hw
->vendor_id
= pdev
->vendor
;
2610 hw
->device_id
= pdev
->device
;
2611 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2612 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2613 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2614 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
2615 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
2617 /* set up the locks for the AQ, do this only once in probe
2618 * and destroy them only once in remove
2620 mutex_init(&hw
->aq
.asq_mutex
);
2621 mutex_init(&hw
->aq
.arq_mutex
);
2623 INIT_LIST_HEAD(&adapter
->mac_filter_list
);
2624 INIT_LIST_HEAD(&adapter
->vlan_filter_list
);
2626 INIT_WORK(&adapter
->reset_task
, i40evf_reset_task
);
2627 INIT_WORK(&adapter
->adminq_task
, i40evf_adminq_task
);
2628 INIT_WORK(&adapter
->watchdog_task
, i40evf_watchdog_task
);
2629 INIT_DELAYED_WORK(&adapter
->init_task
, i40evf_init_task
);
2630 schedule_delayed_work(&adapter
->init_task
,
2631 msecs_to_jiffies(5 * (pdev
->devfn
& 0x07)));
2636 free_netdev(netdev
);
2638 pci_release_regions(pdev
);
2641 pci_disable_device(pdev
);
2647 * i40evf_suspend - Power management suspend routine
2648 * @pdev: PCI device information struct
2651 * Called when the system (VM) is entering sleep/suspend.
2653 static int i40evf_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2655 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2656 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2659 netif_device_detach(netdev
);
2661 if (netif_running(netdev
)) {
2663 i40evf_down(adapter
);
2666 i40evf_free_misc_irq(adapter
);
2667 i40evf_reset_interrupt_capability(adapter
);
2669 retval
= pci_save_state(pdev
);
2673 pci_disable_device(pdev
);
2679 * i40evf_resume - Power management resume routine
2680 * @pdev: PCI device information struct
2682 * Called when the system (VM) is resumed from sleep/suspend.
2684 static int i40evf_resume(struct pci_dev
*pdev
)
2686 struct i40evf_adapter
*adapter
= pci_get_drvdata(pdev
);
2687 struct net_device
*netdev
= adapter
->netdev
;
2690 pci_set_power_state(pdev
, PCI_D0
);
2691 pci_restore_state(pdev
);
2692 /* pci_restore_state clears dev->state_saved so call
2693 * pci_save_state to restore it.
2695 pci_save_state(pdev
);
2697 err
= pci_enable_device_mem(pdev
);
2699 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend.\n");
2702 pci_set_master(pdev
);
2705 err
= i40evf_set_interrupt_capability(adapter
);
2708 dev_err(&pdev
->dev
, "Cannot enable MSI-X interrupts.\n");
2711 err
= i40evf_request_misc_irq(adapter
);
2714 dev_err(&pdev
->dev
, "Cannot get interrupt vector.\n");
2718 schedule_work(&adapter
->reset_task
);
2720 netif_device_attach(netdev
);
2725 #endif /* CONFIG_PM */
2727 * i40evf_remove - Device Removal Routine
2728 * @pdev: PCI device information struct
2730 * i40evf_remove is called by the PCI subsystem to alert the driver
2731 * that it should release a PCI device. The could be caused by a
2732 * Hot-Plug event, or because the driver is going to be removed from
2735 static void i40evf_remove(struct pci_dev
*pdev
)
2737 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2738 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2739 struct i40evf_mac_filter
*f
, *ftmp
;
2740 struct i40e_hw
*hw
= &adapter
->hw
;
2742 cancel_delayed_work_sync(&adapter
->init_task
);
2743 cancel_work_sync(&adapter
->reset_task
);
2745 if (adapter
->netdev_registered
) {
2746 unregister_netdev(netdev
);
2747 adapter
->netdev_registered
= false;
2750 /* Shut down all the garbage mashers on the detention level */
2751 adapter
->state
= __I40EVF_REMOVE
;
2752 adapter
->aq_required
= 0;
2753 i40evf_request_reset(adapter
);
2755 /* If the FW isn't responding, kick it once, but only once. */
2756 if (!i40evf_asq_done(hw
)) {
2757 i40evf_request_reset(adapter
);
2761 if (adapter
->msix_entries
) {
2762 i40evf_misc_irq_disable(adapter
);
2763 i40evf_free_misc_irq(adapter
);
2764 i40evf_reset_interrupt_capability(adapter
);
2765 i40evf_free_q_vectors(adapter
);
2768 if (adapter
->watchdog_timer
.function
)
2769 del_timer_sync(&adapter
->watchdog_timer
);
2771 flush_scheduled_work();
2773 i40evf_free_rss(adapter
);
2775 if (hw
->aq
.asq
.count
)
2776 i40evf_shutdown_adminq(hw
);
2778 /* destroy the locks only once, here */
2779 mutex_destroy(&hw
->aq
.arq_mutex
);
2780 mutex_destroy(&hw
->aq
.asq_mutex
);
2782 iounmap(hw
->hw_addr
);
2783 pci_release_regions(pdev
);
2784 i40evf_free_all_tx_resources(adapter
);
2785 i40evf_free_all_rx_resources(adapter
);
2786 i40evf_free_queues(adapter
);
2787 kfree(adapter
->vf_res
);
2788 /* If we got removed before an up/down sequence, we've got a filter
2789 * hanging out there that we need to get rid of.
2791 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2795 list_for_each_entry_safe(f
, ftmp
, &adapter
->vlan_filter_list
, list
) {
2800 free_netdev(netdev
);
2802 pci_disable_pcie_error_reporting(pdev
);
2804 pci_disable_device(pdev
);
2807 static struct pci_driver i40evf_driver
= {
2808 .name
= i40evf_driver_name
,
2809 .id_table
= i40evf_pci_tbl
,
2810 .probe
= i40evf_probe
,
2811 .remove
= i40evf_remove
,
2813 .suspend
= i40evf_suspend
,
2814 .resume
= i40evf_resume
,
2816 .shutdown
= i40evf_shutdown
,
2820 * i40e_init_module - Driver Registration Routine
2822 * i40e_init_module is the first routine called when the driver is
2823 * loaded. All it does is register with the PCI subsystem.
2825 static int __init
i40evf_init_module(void)
2829 pr_info("i40evf: %s - version %s\n", i40evf_driver_string
,
2830 i40evf_driver_version
);
2832 pr_info("%s\n", i40evf_copyright
);
2834 i40evf_wq
= create_singlethread_workqueue(i40evf_driver_name
);
2836 pr_err("%s: Failed to create workqueue\n", i40evf_driver_name
);
2839 ret
= pci_register_driver(&i40evf_driver
);
2843 module_init(i40evf_init_module
);
2846 * i40e_exit_module - Driver Exit Cleanup Routine
2848 * i40e_exit_module is called just before the driver is removed
2851 static void __exit
i40evf_exit_module(void)
2853 pci_unregister_driver(&i40evf_driver
);
2854 destroy_workqueue(i40evf_wq
);
2857 module_exit(i40evf_exit_module
);