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 4
41 #define DRV_VERSION_BUILD 15
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_X722_VF
), 0},
61 /* required last entry */
65 MODULE_DEVICE_TABLE(pci
, i40evf_pci_tbl
);
67 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
68 MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
69 MODULE_LICENSE("GPL");
70 MODULE_VERSION(DRV_VERSION
);
72 static struct workqueue_struct
*i40evf_wq
;
75 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
76 * @hw: pointer to the HW structure
77 * @mem: ptr to mem struct to fill out
78 * @size: size of memory requested
79 * @alignment: what to align the allocation to
81 i40e_status
i40evf_allocate_dma_mem_d(struct i40e_hw
*hw
,
82 struct i40e_dma_mem
*mem
,
83 u64 size
, u32 alignment
)
85 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
88 return I40E_ERR_PARAM
;
90 mem
->size
= ALIGN(size
, alignment
);
91 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
,
92 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
96 return I40E_ERR_NO_MEMORY
;
100 * i40evf_free_dma_mem_d - OS specific memory free for shared code
101 * @hw: pointer to the HW structure
102 * @mem: ptr to mem struct to free
104 i40e_status
i40evf_free_dma_mem_d(struct i40e_hw
*hw
, struct i40e_dma_mem
*mem
)
106 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)hw
->back
;
108 if (!mem
|| !mem
->va
)
109 return I40E_ERR_PARAM
;
110 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
,
111 mem
->va
, (dma_addr_t
)mem
->pa
);
116 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
117 * @hw: pointer to the HW structure
118 * @mem: ptr to mem struct to fill out
119 * @size: size of memory requested
121 i40e_status
i40evf_allocate_virt_mem_d(struct i40e_hw
*hw
,
122 struct i40e_virt_mem
*mem
, u32 size
)
125 return I40E_ERR_PARAM
;
128 mem
->va
= kzalloc(size
, GFP_KERNEL
);
133 return I40E_ERR_NO_MEMORY
;
137 * i40evf_free_virt_mem_d - OS specific memory free for shared code
138 * @hw: pointer to the HW structure
139 * @mem: ptr to mem struct to free
141 i40e_status
i40evf_free_virt_mem_d(struct i40e_hw
*hw
,
142 struct i40e_virt_mem
*mem
)
145 return I40E_ERR_PARAM
;
147 /* it's ok to kfree a NULL pointer */
154 * i40evf_debug_d - OS dependent version of debug printing
155 * @hw: pointer to the HW structure
156 * @mask: debug level mask
157 * @fmt_str: printf-type format description
159 void i40evf_debug_d(void *hw
, u32 mask
, char *fmt_str
, ...)
164 if (!(mask
& ((struct i40e_hw
*)hw
)->debug_mask
))
167 va_start(argptr
, fmt_str
);
168 vsnprintf(buf
, sizeof(buf
), fmt_str
, argptr
);
171 /* the debug string is already formatted with a newline */
176 * i40evf_schedule_reset - Set the flags and schedule a reset event
177 * @adapter: board private structure
179 void i40evf_schedule_reset(struct i40evf_adapter
*adapter
)
181 if (!(adapter
->flags
&
182 (I40EVF_FLAG_RESET_PENDING
| I40EVF_FLAG_RESET_NEEDED
))) {
183 adapter
->flags
|= I40EVF_FLAG_RESET_NEEDED
;
184 schedule_work(&adapter
->reset_task
);
189 * i40evf_tx_timeout - Respond to a Tx Hang
190 * @netdev: network interface device structure
192 static void i40evf_tx_timeout(struct net_device
*netdev
)
194 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
196 adapter
->tx_timeout_count
++;
197 i40evf_schedule_reset(adapter
);
201 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
202 * @adapter: board private structure
204 static void i40evf_misc_irq_disable(struct i40evf_adapter
*adapter
)
206 struct i40e_hw
*hw
= &adapter
->hw
;
208 wr32(hw
, I40E_VFINT_DYN_CTL01
, 0);
211 rd32(hw
, I40E_VFGEN_RSTAT
);
213 synchronize_irq(adapter
->msix_entries
[0].vector
);
217 * i40evf_misc_irq_enable - Enable default interrupt generation settings
218 * @adapter: board private structure
220 static void i40evf_misc_irq_enable(struct i40evf_adapter
*adapter
)
222 struct i40e_hw
*hw
= &adapter
->hw
;
224 wr32(hw
, I40E_VFINT_DYN_CTL01
, I40E_VFINT_DYN_CTL01_INTENA_MASK
|
225 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK
);
226 wr32(hw
, I40E_VFINT_ICR0_ENA1
, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK
);
229 rd32(hw
, I40E_VFGEN_RSTAT
);
233 * i40evf_irq_disable - Mask off interrupt generation on the NIC
234 * @adapter: board private structure
236 static void i40evf_irq_disable(struct i40evf_adapter
*adapter
)
239 struct i40e_hw
*hw
= &adapter
->hw
;
241 if (!adapter
->msix_entries
)
244 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
245 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), 0);
246 synchronize_irq(adapter
->msix_entries
[i
].vector
);
249 rd32(hw
, I40E_VFGEN_RSTAT
);
253 * i40evf_irq_enable_queues - Enable interrupt for specified queues
254 * @adapter: board private structure
255 * @mask: bitmap of queues to enable
257 void i40evf_irq_enable_queues(struct i40evf_adapter
*adapter
, u32 mask
)
259 struct i40e_hw
*hw
= &adapter
->hw
;
262 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
263 if (mask
& BIT(i
- 1)) {
264 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1),
265 I40E_VFINT_DYN_CTLN1_INTENA_MASK
|
266 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
267 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
);
273 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
274 * @adapter: board private structure
275 * @mask: bitmap of vectors to trigger
277 static void i40evf_fire_sw_int(struct i40evf_adapter
*adapter
, u32 mask
)
279 struct i40e_hw
*hw
= &adapter
->hw
;
284 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTL01
);
285 dyn_ctl
|= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK
|
286 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
287 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
;
288 wr32(hw
, I40E_VFINT_DYN_CTL01
, dyn_ctl
);
290 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
292 dyn_ctl
= rd32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1));
293 dyn_ctl
|= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK
|
294 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK
|
295 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK
;
296 wr32(hw
, I40E_VFINT_DYN_CTLN1(i
- 1), dyn_ctl
);
302 * i40evf_irq_enable - Enable default interrupt generation settings
303 * @adapter: board private structure
304 * @flush: boolean value whether to run rd32()
306 void i40evf_irq_enable(struct i40evf_adapter
*adapter
, bool flush
)
308 struct i40e_hw
*hw
= &adapter
->hw
;
310 i40evf_misc_irq_enable(adapter
);
311 i40evf_irq_enable_queues(adapter
, ~0);
314 rd32(hw
, I40E_VFGEN_RSTAT
);
318 * i40evf_msix_aq - Interrupt handler for vector 0
319 * @irq: interrupt number
320 * @data: pointer to netdev
322 static irqreturn_t
i40evf_msix_aq(int irq
, void *data
)
324 struct net_device
*netdev
= data
;
325 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
326 struct i40e_hw
*hw
= &adapter
->hw
;
329 /* handle non-queue interrupts, these reads clear the registers */
330 val
= rd32(hw
, I40E_VFINT_ICR01
);
331 val
= rd32(hw
, I40E_VFINT_ICR0_ENA1
);
333 val
= rd32(hw
, I40E_VFINT_DYN_CTL01
) |
334 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK
;
335 wr32(hw
, I40E_VFINT_DYN_CTL01
, val
);
337 /* schedule work on the private workqueue */
338 schedule_work(&adapter
->adminq_task
);
344 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
345 * @irq: interrupt number
346 * @data: pointer to a q_vector
348 static irqreturn_t
i40evf_msix_clean_rings(int irq
, void *data
)
350 struct i40e_q_vector
*q_vector
= data
;
352 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
355 napi_schedule_irqoff(&q_vector
->napi
);
361 * i40evf_map_vector_to_rxq - associate irqs with rx queues
362 * @adapter: board private structure
363 * @v_idx: interrupt number
364 * @r_idx: queue number
367 i40evf_map_vector_to_rxq(struct i40evf_adapter
*adapter
, int v_idx
, int r_idx
)
369 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
370 struct i40e_ring
*rx_ring
= &adapter
->rx_rings
[r_idx
];
372 rx_ring
->q_vector
= q_vector
;
373 rx_ring
->next
= q_vector
->rx
.ring
;
374 rx_ring
->vsi
= &adapter
->vsi
;
375 q_vector
->rx
.ring
= rx_ring
;
376 q_vector
->rx
.count
++;
377 q_vector
->rx
.latency_range
= I40E_LOW_LATENCY
;
378 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
382 * i40evf_map_vector_to_txq - associate irqs with tx queues
383 * @adapter: board private structure
384 * @v_idx: interrupt number
385 * @t_idx: queue number
388 i40evf_map_vector_to_txq(struct i40evf_adapter
*adapter
, int v_idx
, int t_idx
)
390 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
391 struct i40e_ring
*tx_ring
= &adapter
->tx_rings
[t_idx
];
393 tx_ring
->q_vector
= q_vector
;
394 tx_ring
->next
= q_vector
->tx
.ring
;
395 tx_ring
->vsi
= &adapter
->vsi
;
396 q_vector
->tx
.ring
= tx_ring
;
397 q_vector
->tx
.count
++;
398 q_vector
->tx
.latency_range
= I40E_LOW_LATENCY
;
399 q_vector
->itr_countdown
= ITR_COUNTDOWN_START
;
400 q_vector
->num_ringpairs
++;
401 q_vector
->ring_mask
|= BIT(t_idx
);
405 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
406 * @adapter: board private structure to initialize
408 * This function maps descriptor rings to the queue-specific vectors
409 * we were allotted through the MSI-X enabling code. Ideally, we'd have
410 * one vector per ring/queue, but on a constrained vector budget, we
411 * group the rings as "efficiently" as possible. You would add new
412 * mapping configurations in here.
414 static int i40evf_map_rings_to_vectors(struct i40evf_adapter
*adapter
)
418 int rxr_idx
= 0, txr_idx
= 0;
419 int rxr_remaining
= adapter
->num_active_queues
;
420 int txr_remaining
= adapter
->num_active_queues
;
425 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
427 /* The ideal configuration...
428 * We have enough vectors to map one per queue.
430 if (q_vectors
>= (rxr_remaining
* 2)) {
431 for (; rxr_idx
< rxr_remaining
; v_start
++, rxr_idx
++)
432 i40evf_map_vector_to_rxq(adapter
, v_start
, rxr_idx
);
434 for (; txr_idx
< txr_remaining
; v_start
++, txr_idx
++)
435 i40evf_map_vector_to_txq(adapter
, v_start
, txr_idx
);
439 /* If we don't have enough vectors for a 1-to-1
440 * mapping, we'll have to group them so there are
441 * multiple queues per vector.
442 * Re-adjusting *qpv takes care of the remainder.
444 for (i
= v_start
; i
< q_vectors
; i
++) {
445 rqpv
= DIV_ROUND_UP(rxr_remaining
, q_vectors
- i
);
446 for (j
= 0; j
< rqpv
; j
++) {
447 i40evf_map_vector_to_rxq(adapter
, i
, rxr_idx
);
452 for (i
= v_start
; i
< q_vectors
; i
++) {
453 tqpv
= DIV_ROUND_UP(txr_remaining
, q_vectors
- i
);
454 for (j
= 0; j
< tqpv
; j
++) {
455 i40evf_map_vector_to_txq(adapter
, i
, txr_idx
);
462 adapter
->aq_required
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
467 #ifdef CONFIG_NET_POLL_CONTROLLER
469 * i40evf_netpoll - A Polling 'interrupt' handler
470 * @netdev: network interface device structure
472 * This is used by netconsole to send skbs without having to re-enable
473 * interrupts. It's not called while the normal interrupt routine is executing.
475 static void i40evf_netpoll(struct net_device
*netdev
)
477 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
478 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
481 /* if interface is down do nothing */
482 if (test_bit(__I40E_DOWN
, &adapter
->vsi
.state
))
485 for (i
= 0; i
< q_vectors
; i
++)
486 i40evf_msix_clean_rings(0, &adapter
->q_vectors
[i
]);
491 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
492 * @adapter: board private structure
494 * Allocates MSI-X vectors for tx and rx handling, and requests
495 * interrupts from the kernel.
498 i40evf_request_traffic_irqs(struct i40evf_adapter
*adapter
, char *basename
)
500 int vector
, err
, q_vectors
;
501 int rx_int_idx
= 0, tx_int_idx
= 0;
503 i40evf_irq_disable(adapter
);
504 /* Decrement for Other and TCP Timer vectors */
505 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
507 for (vector
= 0; vector
< q_vectors
; vector
++) {
508 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[vector
];
510 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
511 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
512 "i40evf-%s-%s-%d", basename
,
513 "TxRx", rx_int_idx
++);
515 } else if (q_vector
->rx
.ring
) {
516 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
517 "i40evf-%s-%s-%d", basename
,
519 } else if (q_vector
->tx
.ring
) {
520 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
521 "i40evf-%s-%s-%d", basename
,
524 /* skip this unused q_vector */
528 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
529 i40evf_msix_clean_rings
,
534 dev_info(&adapter
->pdev
->dev
,
535 "Request_irq failed, error: %d\n", err
);
536 goto free_queue_irqs
;
538 /* assign the mask for this irq */
539 irq_set_affinity_hint(
540 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
541 q_vector
->affinity_mask
);
549 irq_set_affinity_hint(
550 adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
552 free_irq(adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
,
553 &adapter
->q_vectors
[vector
]);
559 * i40evf_request_misc_irq - Initialize MSI-X interrupts
560 * @adapter: board private structure
562 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
563 * vector is only for the admin queue, and stays active even when the netdev
566 static int i40evf_request_misc_irq(struct i40evf_adapter
*adapter
)
568 struct net_device
*netdev
= adapter
->netdev
;
571 snprintf(adapter
->misc_vector_name
,
572 sizeof(adapter
->misc_vector_name
) - 1, "i40evf-%s:mbx",
573 dev_name(&adapter
->pdev
->dev
));
574 err
= request_irq(adapter
->msix_entries
[0].vector
,
576 adapter
->misc_vector_name
, netdev
);
578 dev_err(&adapter
->pdev
->dev
,
579 "request_irq for %s failed: %d\n",
580 adapter
->misc_vector_name
, err
);
581 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
587 * i40evf_free_traffic_irqs - Free MSI-X interrupts
588 * @adapter: board private structure
590 * Frees all MSI-X vectors other than 0.
592 static void i40evf_free_traffic_irqs(struct i40evf_adapter
*adapter
)
597 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
599 for (i
= 0; i
< q_vectors
; i
++) {
600 irq_set_affinity_hint(adapter
->msix_entries
[i
+1].vector
,
602 free_irq(adapter
->msix_entries
[i
+1].vector
,
603 &adapter
->q_vectors
[i
]);
608 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
609 * @adapter: board private structure
611 * Frees MSI-X vector 0.
613 static void i40evf_free_misc_irq(struct i40evf_adapter
*adapter
)
615 struct net_device
*netdev
= adapter
->netdev
;
617 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
621 * i40evf_configure_tx - Configure Transmit Unit after Reset
622 * @adapter: board private structure
624 * Configure the Tx unit of the MAC after a reset.
626 static void i40evf_configure_tx(struct i40evf_adapter
*adapter
)
628 struct i40e_hw
*hw
= &adapter
->hw
;
631 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
632 adapter
->tx_rings
[i
].tail
= hw
->hw_addr
+ I40E_QTX_TAIL1(i
);
636 * i40evf_configure_rx - Configure Receive Unit after Reset
637 * @adapter: board private structure
639 * Configure the Rx unit of the MAC after a reset.
641 static void i40evf_configure_rx(struct i40evf_adapter
*adapter
)
643 struct i40e_hw
*hw
= &adapter
->hw
;
644 struct net_device
*netdev
= adapter
->netdev
;
645 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
650 /* Set the RX buffer length according to the mode */
651 if (adapter
->flags
& I40EVF_FLAG_RX_PS_ENABLED
||
652 netdev
->mtu
<= ETH_DATA_LEN
)
653 rx_buf_len
= I40EVF_RXBUFFER_2048
;
655 rx_buf_len
= ALIGN(max_frame
, 1024);
657 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
658 adapter
->rx_rings
[i
].tail
= hw
->hw_addr
+ I40E_QRX_TAIL1(i
);
659 adapter
->rx_rings
[i
].rx_buf_len
= rx_buf_len
;
660 if (adapter
->flags
& I40EVF_FLAG_RX_PS_ENABLED
) {
661 set_ring_ps_enabled(&adapter
->rx_rings
[i
]);
662 adapter
->rx_rings
[i
].rx_hdr_len
= I40E_RX_HDR_SIZE
;
664 clear_ring_ps_enabled(&adapter
->rx_rings
[i
]);
670 * i40evf_find_vlan - Search filter list for specific vlan filter
671 * @adapter: board private structure
674 * Returns ptr to the filter object or NULL
677 i40evf_vlan_filter
*i40evf_find_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
679 struct i40evf_vlan_filter
*f
;
681 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
689 * i40evf_add_vlan - Add a vlan filter to the list
690 * @adapter: board private structure
693 * Returns ptr to the filter object or NULL when no memory available.
696 i40evf_vlan_filter
*i40evf_add_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
698 struct i40evf_vlan_filter
*f
= NULL
;
701 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
702 &adapter
->crit_section
)) {
708 f
= i40evf_find_vlan(adapter
, vlan
);
710 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
716 INIT_LIST_HEAD(&f
->list
);
717 list_add(&f
->list
, &adapter
->vlan_filter_list
);
719 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
723 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
729 * i40evf_del_vlan - Remove a vlan filter from the list
730 * @adapter: board private structure
733 static void i40evf_del_vlan(struct i40evf_adapter
*adapter
, u16 vlan
)
735 struct i40evf_vlan_filter
*f
;
738 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
739 &adapter
->crit_section
)) {
745 f
= i40evf_find_vlan(adapter
, vlan
);
748 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
750 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
754 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
755 * @netdev: network device struct
758 static int i40evf_vlan_rx_add_vid(struct net_device
*netdev
,
759 __always_unused __be16 proto
, u16 vid
)
761 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
763 if (!VLAN_ALLOWED(adapter
))
765 if (i40evf_add_vlan(adapter
, vid
) == NULL
)
771 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
772 * @netdev: network device struct
775 static int i40evf_vlan_rx_kill_vid(struct net_device
*netdev
,
776 __always_unused __be16 proto
, u16 vid
)
778 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
780 if (VLAN_ALLOWED(adapter
)) {
781 i40evf_del_vlan(adapter
, vid
);
788 * i40evf_find_filter - Search filter list for specific mac filter
789 * @adapter: board private structure
790 * @macaddr: the MAC address
792 * Returns ptr to the filter object or NULL
795 i40evf_mac_filter
*i40evf_find_filter(struct i40evf_adapter
*adapter
,
798 struct i40evf_mac_filter
*f
;
803 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
804 if (ether_addr_equal(macaddr
, f
->macaddr
))
811 * i40e_add_filter - Add a mac filter to the filter list
812 * @adapter: board private structure
813 * @macaddr: the MAC address
815 * Returns ptr to the filter object or NULL when no memory available.
818 i40evf_mac_filter
*i40evf_add_filter(struct i40evf_adapter
*adapter
,
821 struct i40evf_mac_filter
*f
;
827 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
828 &adapter
->crit_section
)) {
834 f
= i40evf_find_filter(adapter
, macaddr
);
836 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
838 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
839 &adapter
->crit_section
);
843 ether_addr_copy(f
->macaddr
, macaddr
);
845 list_add(&f
->list
, &adapter
->mac_filter_list
);
847 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
850 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
855 * i40evf_set_mac - NDO callback to set port mac address
856 * @netdev: network interface device structure
857 * @p: pointer to an address structure
859 * Returns 0 on success, negative on failure
861 static int i40evf_set_mac(struct net_device
*netdev
, void *p
)
863 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
864 struct i40e_hw
*hw
= &adapter
->hw
;
865 struct i40evf_mac_filter
*f
;
866 struct sockaddr
*addr
= p
;
868 if (!is_valid_ether_addr(addr
->sa_data
))
869 return -EADDRNOTAVAIL
;
871 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
))
874 if (adapter
->flags
& I40EVF_FLAG_ADDR_SET_BY_PF
)
877 f
= i40evf_find_filter(adapter
, hw
->mac
.addr
);
880 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
883 f
= i40evf_add_filter(adapter
, addr
->sa_data
);
885 ether_addr_copy(hw
->mac
.addr
, addr
->sa_data
);
886 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
889 return (f
== NULL
) ? -ENOMEM
: 0;
893 * i40evf_set_rx_mode - NDO callback to set the netdev filters
894 * @netdev: network interface device structure
896 static void i40evf_set_rx_mode(struct net_device
*netdev
)
898 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
899 struct i40evf_mac_filter
*f
, *ftmp
;
900 struct netdev_hw_addr
*uca
;
901 struct netdev_hw_addr
*mca
;
902 struct netdev_hw_addr
*ha
;
905 /* add addr if not already in the filter list */
906 netdev_for_each_uc_addr(uca
, netdev
) {
907 i40evf_add_filter(adapter
, uca
->addr
);
909 netdev_for_each_mc_addr(mca
, netdev
) {
910 i40evf_add_filter(adapter
, mca
->addr
);
913 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
914 &adapter
->crit_section
)) {
917 dev_err(&adapter
->pdev
->dev
,
918 "Failed to get lock in %s\n", __func__
);
922 /* remove filter if not in netdev list */
923 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
924 netdev_for_each_mc_addr(mca
, netdev
)
925 if (ether_addr_equal(mca
->addr
, f
->macaddr
))
926 goto bottom_of_search_loop
;
928 netdev_for_each_uc_addr(uca
, netdev
)
929 if (ether_addr_equal(uca
->addr
, f
->macaddr
))
930 goto bottom_of_search_loop
;
932 for_each_dev_addr(netdev
, ha
)
933 if (ether_addr_equal(ha
->addr
, f
->macaddr
))
934 goto bottom_of_search_loop
;
936 if (ether_addr_equal(f
->macaddr
, adapter
->hw
.mac
.addr
))
937 goto bottom_of_search_loop
;
939 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
941 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
943 bottom_of_search_loop
:
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 if (adapter
->flags
& I40EVF_FLAG_RX_PS_ENABLED
) {
1003 i40evf_alloc_rx_headers(ring
);
1004 i40evf_alloc_rx_buffers_ps(ring
, ring
->count
);
1006 i40evf_alloc_rx_buffers_1buf(ring
, ring
->count
);
1008 ring
->next_to_use
= ring
->count
- 1;
1009 writel(ring
->next_to_use
, ring
->tail
);
1014 * i40evf_up_complete - Finish the last steps of bringing up a connection
1015 * @adapter: board private structure
1017 static int i40evf_up_complete(struct i40evf_adapter
*adapter
)
1019 adapter
->state
= __I40EVF_RUNNING
;
1020 clear_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1022 i40evf_napi_enable_all(adapter
);
1024 adapter
->aq_required
|= I40EVF_FLAG_AQ_ENABLE_QUEUES
;
1025 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
1030 * i40e_down - Shutdown the connection processing
1031 * @adapter: board private structure
1033 void i40evf_down(struct i40evf_adapter
*adapter
)
1035 struct net_device
*netdev
= adapter
->netdev
;
1036 struct i40evf_mac_filter
*f
;
1038 if (adapter
->state
<= __I40EVF_DOWN_PENDING
)
1041 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
1042 &adapter
->crit_section
))
1043 usleep_range(500, 1000);
1045 netif_carrier_off(netdev
);
1046 netif_tx_disable(netdev
);
1047 i40evf_napi_disable_all(adapter
);
1048 i40evf_irq_disable(adapter
);
1050 /* remove all MAC filters */
1051 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
1054 /* remove all VLAN filters */
1055 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
1058 if (!(adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) &&
1059 adapter
->state
!= __I40EVF_RESETTING
) {
1060 /* cancel any current operation */
1061 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1062 /* Schedule operations to close down the HW. Don't wait
1063 * here for this to complete. The watchdog is still running
1064 * and it will take care of this.
1066 adapter
->aq_required
= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
1067 adapter
->aq_required
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
1068 adapter
->aq_required
|= I40EVF_FLAG_AQ_DISABLE_QUEUES
;
1071 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1075 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1076 * @adapter: board private structure
1077 * @vectors: number of vectors to request
1079 * Work with the OS to set up the MSIX vectors needed.
1081 * Returns 0 on success, negative on failure
1084 i40evf_acquire_msix_vectors(struct i40evf_adapter
*adapter
, int vectors
)
1086 int err
, vector_threshold
;
1088 /* We'll want at least 3 (vector_threshold):
1089 * 0) Other (Admin Queue and link, mostly)
1093 vector_threshold
= MIN_MSIX_COUNT
;
1095 /* The more we get, the more we will assign to Tx/Rx Cleanup
1096 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1097 * Right now, we simply care about how many we'll get; we'll
1098 * set them up later while requesting irq's.
1100 err
= pci_enable_msix_range(adapter
->pdev
, adapter
->msix_entries
,
1101 vector_threshold
, vectors
);
1103 dev_err(&adapter
->pdev
->dev
, "Unable to allocate MSI-X interrupts\n");
1104 kfree(adapter
->msix_entries
);
1105 adapter
->msix_entries
= NULL
;
1109 /* Adjust for only the vectors we'll use, which is minimum
1110 * of max_msix_q_vectors + NONQ_VECS, or the number of
1111 * vectors we were allocated.
1113 adapter
->num_msix_vectors
= err
;
1118 * i40evf_free_queues - Free memory for all rings
1119 * @adapter: board private structure to initialize
1121 * Free all of the memory associated with queue pairs.
1123 static void i40evf_free_queues(struct i40evf_adapter
*adapter
)
1125 if (!adapter
->vsi_res
)
1127 kfree(adapter
->tx_rings
);
1128 adapter
->tx_rings
= NULL
;
1129 kfree(adapter
->rx_rings
);
1130 adapter
->rx_rings
= NULL
;
1134 * i40evf_alloc_queues - Allocate memory for all rings
1135 * @adapter: board private structure to initialize
1137 * We allocate one ring per queue at run-time since we don't know the
1138 * number of queues at compile-time. The polling_netdev array is
1139 * intended for Multiqueue, but should work fine with a single queue.
1141 static int i40evf_alloc_queues(struct i40evf_adapter
*adapter
)
1145 adapter
->tx_rings
= kcalloc(adapter
->num_active_queues
,
1146 sizeof(struct i40e_ring
), GFP_KERNEL
);
1147 if (!adapter
->tx_rings
)
1149 adapter
->rx_rings
= kcalloc(adapter
->num_active_queues
,
1150 sizeof(struct i40e_ring
), GFP_KERNEL
);
1151 if (!adapter
->rx_rings
)
1154 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
1155 struct i40e_ring
*tx_ring
;
1156 struct i40e_ring
*rx_ring
;
1158 tx_ring
= &adapter
->tx_rings
[i
];
1160 tx_ring
->queue_index
= i
;
1161 tx_ring
->netdev
= adapter
->netdev
;
1162 tx_ring
->dev
= &adapter
->pdev
->dev
;
1163 tx_ring
->count
= adapter
->tx_desc_count
;
1164 if (adapter
->flags
& I40E_FLAG_WB_ON_ITR_CAPABLE
)
1165 tx_ring
->flags
|= I40E_TXR_FLAGS_WB_ON_ITR
;
1167 rx_ring
= &adapter
->rx_rings
[i
];
1168 rx_ring
->queue_index
= i
;
1169 rx_ring
->netdev
= adapter
->netdev
;
1170 rx_ring
->dev
= &adapter
->pdev
->dev
;
1171 rx_ring
->count
= adapter
->rx_desc_count
;
1177 i40evf_free_queues(adapter
);
1182 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1183 * @adapter: board private structure to initialize
1185 * Attempt to configure the interrupts using the best available
1186 * capabilities of the hardware and the kernel.
1188 static int i40evf_set_interrupt_capability(struct i40evf_adapter
*adapter
)
1190 int vector
, v_budget
;
1194 if (!adapter
->vsi_res
) {
1198 pairs
= adapter
->num_active_queues
;
1200 /* It's easy to be greedy for MSI-X vectors, but it really
1201 * doesn't do us much good if we have a lot more vectors
1202 * than CPU's. So let's be conservative and only ask for
1203 * (roughly) twice the number of vectors as there are CPU's.
1205 v_budget
= min_t(int, pairs
, (int)(num_online_cpus() * 2)) + NONQ_VECS
;
1206 v_budget
= min_t(int, v_budget
, (int)adapter
->vf_res
->max_vectors
);
1208 adapter
->msix_entries
= kcalloc(v_budget
,
1209 sizeof(struct msix_entry
), GFP_KERNEL
);
1210 if (!adapter
->msix_entries
) {
1215 for (vector
= 0; vector
< v_budget
; vector
++)
1216 adapter
->msix_entries
[vector
].entry
= vector
;
1218 err
= i40evf_acquire_msix_vectors(adapter
, v_budget
);
1221 netif_set_real_num_rx_queues(adapter
->netdev
, pairs
);
1222 netif_set_real_num_tx_queues(adapter
->netdev
, pairs
);
1227 * i40e_config_rss_aq - Prepare for RSS using AQ commands
1228 * @vsi: vsi structure
1229 * @seed: RSS hash seed
1230 * @lut: Lookup table
1231 * @lut_size: Lookup table size
1233 * Return 0 on success, negative on failure
1235 static int i40evf_config_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
1236 u8
*lut
, u16 lut_size
)
1238 struct i40evf_adapter
*adapter
= vsi
->back
;
1239 struct i40e_hw
*hw
= &adapter
->hw
;
1245 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
1246 /* bail because we already have a command pending */
1247 dev_err(&adapter
->pdev
->dev
, "Cannot configure RSS, command %d pending\n",
1248 adapter
->current_op
);
1253 struct i40e_aqc_get_set_rss_key_data
*rss_key
=
1254 (struct i40e_aqc_get_set_rss_key_data
*)seed
;
1255 ret
= i40evf_aq_set_rss_key(hw
, vsi
->id
, rss_key
);
1257 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS key, err %s aq_err %s\n",
1258 i40evf_stat_str(hw
, ret
),
1259 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1265 ret
= i40evf_aq_set_rss_lut(hw
, vsi
->id
, false, lut
, lut_size
);
1267 dev_err(&adapter
->pdev
->dev
,
1268 "Cannot set RSS lut, err %s aq_err %s\n",
1269 i40evf_stat_str(hw
, ret
),
1270 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1279 * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
1280 * @vsi: Pointer to vsi structure
1281 * @seed: RSS hash seed
1282 * @lut: Lookup table
1283 * @lut_size: Lookup table size
1285 * Returns 0 on success, negative on failure
1287 static int i40evf_config_rss_reg(struct i40e_vsi
*vsi
, const u8
*seed
,
1288 const u8
*lut
, u16 lut_size
)
1290 struct i40evf_adapter
*adapter
= vsi
->back
;
1291 struct i40e_hw
*hw
= &adapter
->hw
;
1295 u32
*seed_dw
= (u32
*)seed
;
1297 for (i
= 0; i
<= I40E_VFQF_HKEY_MAX_INDEX
; i
++)
1298 wr32(hw
, I40E_VFQF_HKEY(i
), seed_dw
[i
]);
1302 u32
*lut_dw
= (u32
*)lut
;
1304 if (lut_size
!= I40EVF_HLUT_ARRAY_SIZE
)
1307 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
1308 wr32(hw
, I40E_VFQF_HLUT(i
), lut_dw
[i
]);
1316 * * i40evf_get_rss_aq - Get RSS keys and lut by using AQ commands
1317 * @vsi: Pointer to vsi structure
1318 * @seed: RSS hash seed
1319 * @lut: Lookup table
1320 * @lut_size: Lookup table size
1322 * Return 0 on success, negative on failure
1324 static int i40evf_get_rss_aq(struct i40e_vsi
*vsi
, const u8
*seed
,
1325 u8
*lut
, u16 lut_size
)
1327 struct i40evf_adapter
*adapter
= vsi
->back
;
1328 struct i40e_hw
*hw
= &adapter
->hw
;
1332 ret
= i40evf_aq_get_rss_key(hw
, vsi
->id
,
1333 (struct i40e_aqc_get_set_rss_key_data
*)seed
);
1335 dev_err(&adapter
->pdev
->dev
,
1336 "Cannot get RSS key, err %s aq_err %s\n",
1337 i40evf_stat_str(hw
, ret
),
1338 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1344 ret
= i40evf_aq_get_rss_lut(hw
, vsi
->id
, seed
, lut
, lut_size
);
1346 dev_err(&adapter
->pdev
->dev
,
1347 "Cannot get RSS lut, err %s aq_err %s\n",
1348 i40evf_stat_str(hw
, ret
),
1349 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
1358 * * i40evf_get_rss_reg - Get RSS keys and lut by reading registers
1359 * @vsi: Pointer to vsi structure
1360 * @seed: RSS hash seed
1361 * @lut: Lookup table
1362 * @lut_size: Lookup table size
1364 * Returns 0 on success, negative on failure
1366 static int i40evf_get_rss_reg(struct i40e_vsi
*vsi
, const u8
*seed
,
1367 const u8
*lut
, u16 lut_size
)
1369 struct i40evf_adapter
*adapter
= vsi
->back
;
1370 struct i40e_hw
*hw
= &adapter
->hw
;
1374 u32
*seed_dw
= (u32
*)seed
;
1376 for (i
= 0; i
<= I40E_VFQF_HKEY_MAX_INDEX
; i
++)
1377 seed_dw
[i
] = rd32(hw
, I40E_VFQF_HKEY(i
));
1381 u32
*lut_dw
= (u32
*)lut
;
1383 if (lut_size
!= I40EVF_HLUT_ARRAY_SIZE
)
1386 for (i
= 0; i
<= I40E_VFQF_HLUT_MAX_INDEX
; i
++)
1387 lut_dw
[i
] = rd32(hw
, I40E_VFQF_HLUT(i
));
1394 * i40evf_config_rss - Configure RSS keys and lut
1395 * @vsi: Pointer to vsi structure
1396 * @seed: RSS hash seed
1397 * @lut: Lookup table
1398 * @lut_size: Lookup table size
1400 * Returns 0 on success, negative on failure
1402 int i40evf_config_rss(struct i40e_vsi
*vsi
, const u8
*seed
,
1403 u8
*lut
, u16 lut_size
)
1405 struct i40evf_adapter
*adapter
= vsi
->back
;
1407 if (RSS_AQ(adapter
))
1408 return i40evf_config_rss_aq(vsi
, seed
, lut
, lut_size
);
1410 return i40evf_config_rss_reg(vsi
, seed
, lut
, lut_size
);
1414 * i40evf_get_rss - Get RSS keys and lut
1415 * @vsi: Pointer to vsi structure
1416 * @seed: RSS hash seed
1417 * @lut: Lookup table
1418 * @lut_size: Lookup table size
1420 * Returns 0 on success, negative on failure
1422 int i40evf_get_rss(struct i40e_vsi
*vsi
, const u8
*seed
, u8
*lut
, u16 lut_size
)
1424 struct i40evf_adapter
*adapter
= vsi
->back
;
1426 if (RSS_AQ(adapter
))
1427 return i40evf_get_rss_aq(vsi
, seed
, lut
, lut_size
);
1429 return i40evf_get_rss_reg(vsi
, seed
, lut
, lut_size
);
1433 * i40evf_fill_rss_lut - Fill the lut with default values
1434 * @lut: Lookup table to be filled with
1435 * @rss_table_size: Lookup table size
1436 * @rss_size: Range of queue number for hashing
1438 static void i40evf_fill_rss_lut(u8
*lut
, u16 rss_table_size
, u16 rss_size
)
1442 for (i
= 0; i
< rss_table_size
; i
++)
1443 lut
[i
] = i
% rss_size
;
1447 * i40evf_init_rss - Prepare for RSS
1448 * @adapter: board private structure
1450 * Return 0 on success, negative on failure
1452 static int i40evf_init_rss(struct i40evf_adapter
*adapter
)
1454 struct i40e_vsi
*vsi
= &adapter
->vsi
;
1455 struct i40e_hw
*hw
= &adapter
->hw
;
1456 u8 seed
[I40EVF_HKEY_ARRAY_SIZE
];
1461 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1462 if (adapter
->vf_res
->vf_offload_flags
&
1463 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
)
1464 hena
= I40E_DEFAULT_RSS_HENA_EXPANDED
;
1466 hena
= I40E_DEFAULT_RSS_HENA
;
1467 wr32(hw
, I40E_VFQF_HENA(0), (u32
)hena
);
1468 wr32(hw
, I40E_VFQF_HENA(1), (u32
)(hena
>> 32));
1470 lut
= kzalloc(I40EVF_HLUT_ARRAY_SIZE
, GFP_KERNEL
);
1474 /* Use user configured lut if there is one, otherwise use default */
1475 if (vsi
->rss_lut_user
)
1476 memcpy(lut
, vsi
->rss_lut_user
, I40EVF_HLUT_ARRAY_SIZE
);
1478 i40evf_fill_rss_lut(lut
, I40EVF_HLUT_ARRAY_SIZE
,
1479 adapter
->num_active_queues
);
1481 /* Use user configured hash key if there is one, otherwise
1484 if (vsi
->rss_hkey_user
)
1485 memcpy(seed
, vsi
->rss_hkey_user
, I40EVF_HKEY_ARRAY_SIZE
);
1487 netdev_rss_key_fill((void *)seed
, I40EVF_HKEY_ARRAY_SIZE
);
1488 ret
= i40evf_config_rss(vsi
, seed
, lut
, I40EVF_HLUT_ARRAY_SIZE
);
1495 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1496 * @adapter: board private structure to initialize
1498 * We allocate one q_vector per queue interrupt. If allocation fails we
1501 static int i40evf_alloc_q_vectors(struct i40evf_adapter
*adapter
)
1503 int q_idx
= 0, num_q_vectors
;
1504 struct i40e_q_vector
*q_vector
;
1506 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1507 adapter
->q_vectors
= kcalloc(num_q_vectors
, sizeof(*q_vector
),
1509 if (!adapter
->q_vectors
)
1512 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1513 q_vector
= &adapter
->q_vectors
[q_idx
];
1514 q_vector
->adapter
= adapter
;
1515 q_vector
->vsi
= &adapter
->vsi
;
1516 q_vector
->v_idx
= q_idx
;
1517 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1518 i40evf_napi_poll
, NAPI_POLL_WEIGHT
);
1525 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1526 * @adapter: board private structure to initialize
1528 * This function frees the memory allocated to the q_vectors. In addition if
1529 * NAPI is enabled it will delete any references to the NAPI struct prior
1530 * to freeing the q_vector.
1532 static void i40evf_free_q_vectors(struct i40evf_adapter
*adapter
)
1534 int q_idx
, num_q_vectors
;
1537 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1538 napi_vectors
= adapter
->num_active_queues
;
1540 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1541 struct i40e_q_vector
*q_vector
= &adapter
->q_vectors
[q_idx
];
1542 if (q_idx
< napi_vectors
)
1543 netif_napi_del(&q_vector
->napi
);
1545 kfree(adapter
->q_vectors
);
1549 * i40evf_reset_interrupt_capability - Reset MSIX setup
1550 * @adapter: board private structure
1553 void i40evf_reset_interrupt_capability(struct i40evf_adapter
*adapter
)
1555 pci_disable_msix(adapter
->pdev
);
1556 kfree(adapter
->msix_entries
);
1557 adapter
->msix_entries
= NULL
;
1561 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1562 * @adapter: board private structure to initialize
1565 int i40evf_init_interrupt_scheme(struct i40evf_adapter
*adapter
)
1569 err
= i40evf_set_interrupt_capability(adapter
);
1571 dev_err(&adapter
->pdev
->dev
,
1572 "Unable to setup interrupt capabilities\n");
1573 goto err_set_interrupt
;
1576 err
= i40evf_alloc_q_vectors(adapter
);
1578 dev_err(&adapter
->pdev
->dev
,
1579 "Unable to allocate memory for queue vectors\n");
1580 goto err_alloc_q_vectors
;
1583 err
= i40evf_alloc_queues(adapter
);
1585 dev_err(&adapter
->pdev
->dev
,
1586 "Unable to allocate memory for queues\n");
1587 goto err_alloc_queues
;
1590 dev_info(&adapter
->pdev
->dev
, "Multiqueue %s: Queue pair count = %u",
1591 (adapter
->num_active_queues
> 1) ? "Enabled" : "Disabled",
1592 adapter
->num_active_queues
);
1596 i40evf_free_q_vectors(adapter
);
1597 err_alloc_q_vectors
:
1598 i40evf_reset_interrupt_capability(adapter
);
1604 * i40evf_clear_rss_config_user - Clear user configurations of RSS
1605 * @vsi: Pointer to VSI structure
1607 static void i40evf_clear_rss_config_user(struct i40e_vsi
*vsi
)
1612 kfree(vsi
->rss_hkey_user
);
1613 vsi
->rss_hkey_user
= NULL
;
1615 kfree(vsi
->rss_lut_user
);
1616 vsi
->rss_lut_user
= NULL
;
1620 * i40evf_watchdog_timer - Periodic call-back timer
1621 * @data: pointer to adapter disguised as unsigned long
1623 static void i40evf_watchdog_timer(unsigned long data
)
1625 struct i40evf_adapter
*adapter
= (struct i40evf_adapter
*)data
;
1627 schedule_work(&adapter
->watchdog_task
);
1628 /* timer will be rescheduled in watchdog task */
1632 * i40evf_watchdog_task - Periodic call-back task
1633 * @work: pointer to work_struct
1635 static void i40evf_watchdog_task(struct work_struct
*work
)
1637 struct i40evf_adapter
*adapter
= container_of(work
,
1638 struct i40evf_adapter
,
1640 struct i40e_hw
*hw
= &adapter
->hw
;
1643 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
))
1644 goto restart_watchdog
;
1646 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
1647 reg_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1648 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1649 if ((reg_val
== I40E_VFR_VFACTIVE
) ||
1650 (reg_val
== I40E_VFR_COMPLETED
)) {
1651 /* A chance for redemption! */
1652 dev_err(&adapter
->pdev
->dev
, "Hardware came out of reset. Attempting reinit.\n");
1653 adapter
->state
= __I40EVF_STARTUP
;
1654 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
1655 schedule_delayed_work(&adapter
->init_task
, 10);
1656 clear_bit(__I40EVF_IN_CRITICAL_TASK
,
1657 &adapter
->crit_section
);
1658 /* Don't reschedule the watchdog, since we've restarted
1659 * the init task. When init_task contacts the PF and
1660 * gets everything set up again, it'll restart the
1661 * watchdog for us. Down, boy. Sit. Stay. Woof.
1665 adapter
->aq_required
= 0;
1666 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1670 if ((adapter
->state
< __I40EVF_DOWN
) ||
1671 (adapter
->flags
& I40EVF_FLAG_RESET_PENDING
))
1674 /* check for reset */
1675 reg_val
= rd32(hw
, I40E_VF_ARQLEN1
) & I40E_VF_ARQLEN1_ARQENABLE_MASK
;
1676 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
) && !reg_val
) {
1677 adapter
->state
= __I40EVF_RESETTING
;
1678 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
1679 dev_err(&adapter
->pdev
->dev
, "Hardware reset detected\n");
1680 schedule_work(&adapter
->reset_task
);
1681 adapter
->aq_required
= 0;
1682 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1686 /* Process admin queue tasks. After init, everything gets done
1687 * here so we don't race on the admin queue.
1689 if (adapter
->current_op
) {
1690 if (!i40evf_asq_done(hw
)) {
1691 dev_dbg(&adapter
->pdev
->dev
, "Admin queue timeout\n");
1692 i40evf_send_api_ver(adapter
);
1696 if (adapter
->aq_required
& I40EVF_FLAG_AQ_GET_CONFIG
) {
1697 i40evf_send_vf_config_msg(adapter
);
1701 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DISABLE_QUEUES
) {
1702 i40evf_disable_queues(adapter
);
1706 if (adapter
->aq_required
& I40EVF_FLAG_AQ_MAP_VECTORS
) {
1707 i40evf_map_queues(adapter
);
1711 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_MAC_FILTER
) {
1712 i40evf_add_ether_addrs(adapter
);
1716 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ADD_VLAN_FILTER
) {
1717 i40evf_add_vlans(adapter
);
1721 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_MAC_FILTER
) {
1722 i40evf_del_ether_addrs(adapter
);
1726 if (adapter
->aq_required
& I40EVF_FLAG_AQ_DEL_VLAN_FILTER
) {
1727 i40evf_del_vlans(adapter
);
1731 if (adapter
->aq_required
& I40EVF_FLAG_AQ_CONFIGURE_QUEUES
) {
1732 i40evf_configure_queues(adapter
);
1736 if (adapter
->aq_required
& I40EVF_FLAG_AQ_ENABLE_QUEUES
) {
1737 i40evf_enable_queues(adapter
);
1741 if (adapter
->aq_required
& I40EVF_FLAG_AQ_CONFIGURE_RSS
) {
1742 /* This message goes straight to the firmware, not the
1743 * PF, so we don't have to set current_op as we will
1744 * not get a response through the ARQ.
1746 i40evf_init_rss(adapter
);
1747 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_CONFIGURE_RSS
;
1751 if (adapter
->state
== __I40EVF_RUNNING
)
1752 i40evf_request_stats(adapter
);
1754 if (adapter
->state
== __I40EVF_RUNNING
) {
1755 i40evf_irq_enable_queues(adapter
, ~0);
1756 i40evf_fire_sw_int(adapter
, 0xFF);
1758 i40evf_fire_sw_int(adapter
, 0x1);
1761 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1763 if (adapter
->state
== __I40EVF_REMOVE
)
1765 if (adapter
->aq_required
)
1766 mod_timer(&adapter
->watchdog_timer
,
1767 jiffies
+ msecs_to_jiffies(20));
1769 mod_timer(&adapter
->watchdog_timer
, jiffies
+ (HZ
* 2));
1770 schedule_work(&adapter
->adminq_task
);
1773 #define I40EVF_RESET_WAIT_MS 10
1774 #define I40EVF_RESET_WAIT_COUNT 500
1776 * i40evf_reset_task - Call-back task to handle hardware reset
1777 * @work: pointer to work_struct
1779 * During reset we need to shut down and reinitialize the admin queue
1780 * before we can use it to communicate with the PF again. We also clear
1781 * and reinit the rings because that context is lost as well.
1783 static void i40evf_reset_task(struct work_struct
*work
)
1785 struct i40evf_adapter
*adapter
= container_of(work
,
1786 struct i40evf_adapter
,
1788 struct net_device
*netdev
= adapter
->netdev
;
1789 struct i40e_hw
*hw
= &adapter
->hw
;
1790 struct i40evf_vlan_filter
*vlf
;
1791 struct i40evf_mac_filter
*f
;
1795 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK
,
1796 &adapter
->crit_section
))
1797 usleep_range(500, 1000);
1799 i40evf_misc_irq_disable(adapter
);
1800 if (adapter
->flags
& I40EVF_FLAG_RESET_NEEDED
) {
1801 adapter
->flags
&= ~I40EVF_FLAG_RESET_NEEDED
;
1802 /* Restart the AQ here. If we have been reset but didn't
1803 * detect it, or if the PF had to reinit, our AQ will be hosed.
1805 i40evf_shutdown_adminq(hw
);
1806 i40evf_init_adminq(hw
);
1807 i40evf_request_reset(adapter
);
1809 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
1811 /* poll until we see the reset actually happen */
1812 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1813 reg_val
= rd32(hw
, I40E_VF_ARQLEN1
) &
1814 I40E_VF_ARQLEN1_ARQENABLE_MASK
;
1817 usleep_range(5000, 10000);
1819 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1820 dev_info(&adapter
->pdev
->dev
, "Never saw reset\n");
1821 goto continue_reset
; /* act like the reset happened */
1824 /* wait until the reset is complete and the PF is responding to us */
1825 for (i
= 0; i
< I40EVF_RESET_WAIT_COUNT
; i
++) {
1826 reg_val
= rd32(hw
, I40E_VFGEN_RSTAT
) &
1827 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
1828 if (reg_val
== I40E_VFR_VFACTIVE
)
1830 msleep(I40EVF_RESET_WAIT_MS
);
1832 pci_set_master(adapter
->pdev
);
1833 /* extra wait to make sure minimum wait is met */
1834 msleep(I40EVF_RESET_WAIT_MS
);
1835 if (i
== I40EVF_RESET_WAIT_COUNT
) {
1836 struct i40evf_mac_filter
*ftmp
;
1837 struct i40evf_vlan_filter
*fv
, *fvtmp
;
1839 /* reset never finished */
1840 dev_err(&adapter
->pdev
->dev
, "Reset never finished (%x)\n",
1842 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
1844 if (netif_running(adapter
->netdev
)) {
1845 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
1846 netif_carrier_off(netdev
);
1847 netif_tx_disable(netdev
);
1848 i40evf_napi_disable_all(adapter
);
1849 i40evf_irq_disable(adapter
);
1850 i40evf_free_traffic_irqs(adapter
);
1851 i40evf_free_all_tx_resources(adapter
);
1852 i40evf_free_all_rx_resources(adapter
);
1855 /* Delete all of the filters, both MAC and VLAN. */
1856 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
,
1862 list_for_each_entry_safe(fv
, fvtmp
, &adapter
->vlan_filter_list
,
1864 list_del(&fv
->list
);
1868 i40evf_free_misc_irq(adapter
);
1869 i40evf_reset_interrupt_capability(adapter
);
1870 i40evf_free_queues(adapter
);
1871 i40evf_free_q_vectors(adapter
);
1872 kfree(adapter
->vf_res
);
1873 i40evf_shutdown_adminq(hw
);
1874 adapter
->netdev
->flags
&= ~IFF_UP
;
1875 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1876 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1877 adapter
->state
= __I40EVF_DOWN
;
1878 dev_info(&adapter
->pdev
->dev
, "Reset task did not complete, VF disabled\n");
1879 return; /* Do not attempt to reinit. It's dead, Jim. */
1883 if (netif_running(adapter
->netdev
)) {
1884 netif_carrier_off(netdev
);
1885 netif_tx_stop_all_queues(netdev
);
1886 i40evf_napi_disable_all(adapter
);
1888 i40evf_irq_disable(adapter
);
1890 adapter
->state
= __I40EVF_RESETTING
;
1891 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
1893 /* free the Tx/Rx rings and descriptors, might be better to just
1894 * re-use them sometime in the future
1896 i40evf_free_all_rx_resources(adapter
);
1897 i40evf_free_all_tx_resources(adapter
);
1899 /* kill and reinit the admin queue */
1900 if (i40evf_shutdown_adminq(hw
))
1901 dev_warn(&adapter
->pdev
->dev
, "Failed to shut down adminq\n");
1902 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
1903 err
= i40evf_init_adminq(hw
);
1905 dev_info(&adapter
->pdev
->dev
, "Failed to init adminq: %d\n",
1908 adapter
->aq_required
= I40EVF_FLAG_AQ_GET_CONFIG
;
1909 adapter
->aq_required
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
1911 /* re-add all MAC filters */
1912 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
1915 /* re-add all VLAN filters */
1916 list_for_each_entry(vlf
, &adapter
->vlan_filter_list
, list
) {
1919 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
1920 adapter
->aq_required
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
1921 clear_bit(__I40EVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1922 i40evf_misc_irq_enable(adapter
);
1924 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 2);
1926 if (netif_running(adapter
->netdev
)) {
1927 /* allocate transmit descriptors */
1928 err
= i40evf_setup_all_tx_resources(adapter
);
1932 /* allocate receive descriptors */
1933 err
= i40evf_setup_all_rx_resources(adapter
);
1937 i40evf_configure(adapter
);
1939 err
= i40evf_up_complete(adapter
);
1943 i40evf_irq_enable(adapter
, true);
1945 adapter
->state
= __I40EVF_DOWN
;
1950 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit\n");
1951 i40evf_close(adapter
->netdev
);
1955 * i40evf_adminq_task - worker thread to clean the admin queue
1956 * @work: pointer to work_struct containing our data
1958 static void i40evf_adminq_task(struct work_struct
*work
)
1960 struct i40evf_adapter
*adapter
=
1961 container_of(work
, struct i40evf_adapter
, adminq_task
);
1962 struct i40e_hw
*hw
= &adapter
->hw
;
1963 struct i40e_arq_event_info event
;
1964 struct i40e_virtchnl_msg
*v_msg
;
1969 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
)
1972 event
.buf_len
= I40EVF_MAX_AQ_BUF_SIZE
;
1973 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
1977 v_msg
= (struct i40e_virtchnl_msg
*)&event
.desc
;
1979 ret
= i40evf_clean_arq_element(hw
, &event
, &pending
);
1980 if (ret
|| !v_msg
->v_opcode
)
1981 break; /* No event to process or error cleaning ARQ */
1983 i40evf_virtchnl_completion(adapter
, v_msg
->v_opcode
,
1984 v_msg
->v_retval
, event
.msg_buf
,
1987 memset(event
.msg_buf
, 0, I40EVF_MAX_AQ_BUF_SIZE
);
1990 if ((adapter
->flags
&
1991 (I40EVF_FLAG_RESET_PENDING
| I40EVF_FLAG_RESET_NEEDED
)) ||
1992 adapter
->state
== __I40EVF_RESETTING
)
1995 /* check for error indications */
1996 val
= rd32(hw
, hw
->aq
.arq
.len
);
1998 if (val
& I40E_VF_ARQLEN1_ARQVFE_MASK
) {
1999 dev_info(&adapter
->pdev
->dev
, "ARQ VF Error detected\n");
2000 val
&= ~I40E_VF_ARQLEN1_ARQVFE_MASK
;
2002 if (val
& I40E_VF_ARQLEN1_ARQOVFL_MASK
) {
2003 dev_info(&adapter
->pdev
->dev
, "ARQ Overflow Error detected\n");
2004 val
&= ~I40E_VF_ARQLEN1_ARQOVFL_MASK
;
2006 if (val
& I40E_VF_ARQLEN1_ARQCRIT_MASK
) {
2007 dev_info(&adapter
->pdev
->dev
, "ARQ Critical Error detected\n");
2008 val
&= ~I40E_VF_ARQLEN1_ARQCRIT_MASK
;
2011 wr32(hw
, hw
->aq
.arq
.len
, val
);
2013 val
= rd32(hw
, hw
->aq
.asq
.len
);
2015 if (val
& I40E_VF_ATQLEN1_ATQVFE_MASK
) {
2016 dev_info(&adapter
->pdev
->dev
, "ASQ VF Error detected\n");
2017 val
&= ~I40E_VF_ATQLEN1_ATQVFE_MASK
;
2019 if (val
& I40E_VF_ATQLEN1_ATQOVFL_MASK
) {
2020 dev_info(&adapter
->pdev
->dev
, "ASQ Overflow Error detected\n");
2021 val
&= ~I40E_VF_ATQLEN1_ATQOVFL_MASK
;
2023 if (val
& I40E_VF_ATQLEN1_ATQCRIT_MASK
) {
2024 dev_info(&adapter
->pdev
->dev
, "ASQ Critical Error detected\n");
2025 val
&= ~I40E_VF_ATQLEN1_ATQCRIT_MASK
;
2028 wr32(hw
, hw
->aq
.asq
.len
, val
);
2031 kfree(event
.msg_buf
);
2033 /* re-enable Admin queue interrupt cause */
2034 i40evf_misc_irq_enable(adapter
);
2038 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
2039 * @adapter: board private structure
2041 * Free all transmit software resources
2043 void i40evf_free_all_tx_resources(struct i40evf_adapter
*adapter
)
2047 if (!adapter
->tx_rings
)
2050 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2051 if (adapter
->tx_rings
[i
].desc
)
2052 i40evf_free_tx_resources(&adapter
->tx_rings
[i
]);
2056 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
2057 * @adapter: board private structure
2059 * If this function returns with an error, then it's possible one or
2060 * more of the rings is populated (while the rest are not). It is the
2061 * callers duty to clean those orphaned rings.
2063 * Return 0 on success, negative on failure
2065 static int i40evf_setup_all_tx_resources(struct i40evf_adapter
*adapter
)
2069 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2070 adapter
->tx_rings
[i
].count
= adapter
->tx_desc_count
;
2071 err
= i40evf_setup_tx_descriptors(&adapter
->tx_rings
[i
]);
2074 dev_err(&adapter
->pdev
->dev
,
2075 "Allocation for Tx Queue %u failed\n", i
);
2083 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
2084 * @adapter: board private structure
2086 * If this function returns with an error, then it's possible one or
2087 * more of the rings is populated (while the rest are not). It is the
2088 * callers duty to clean those orphaned rings.
2090 * Return 0 on success, negative on failure
2092 static int i40evf_setup_all_rx_resources(struct i40evf_adapter
*adapter
)
2096 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2097 adapter
->rx_rings
[i
].count
= adapter
->rx_desc_count
;
2098 err
= i40evf_setup_rx_descriptors(&adapter
->rx_rings
[i
]);
2101 dev_err(&adapter
->pdev
->dev
,
2102 "Allocation for Rx Queue %u failed\n", i
);
2109 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
2110 * @adapter: board private structure
2112 * Free all receive software resources
2114 void i40evf_free_all_rx_resources(struct i40evf_adapter
*adapter
)
2118 if (!adapter
->rx_rings
)
2121 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2122 if (adapter
->rx_rings
[i
].desc
)
2123 i40evf_free_rx_resources(&adapter
->rx_rings
[i
]);
2127 * i40evf_open - Called when a network interface is made active
2128 * @netdev: network interface device structure
2130 * Returns 0 on success, negative value on failure
2132 * The open entry point is called when a network interface is made
2133 * active by the system (IFF_UP). At this point all resources needed
2134 * for transmit and receive operations are allocated, the interrupt
2135 * handler is registered with the OS, the watchdog timer is started,
2136 * and the stack is notified that the interface is ready.
2138 static int i40evf_open(struct net_device
*netdev
)
2140 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2143 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
) {
2144 dev_err(&adapter
->pdev
->dev
, "Unable to open device due to PF driver failure.\n");
2148 if (adapter
->state
!= __I40EVF_DOWN
)
2151 /* allocate transmit descriptors */
2152 err
= i40evf_setup_all_tx_resources(adapter
);
2156 /* allocate receive descriptors */
2157 err
= i40evf_setup_all_rx_resources(adapter
);
2161 /* clear any pending interrupts, may auto mask */
2162 err
= i40evf_request_traffic_irqs(adapter
, netdev
->name
);
2166 i40evf_add_filter(adapter
, adapter
->hw
.mac
.addr
);
2167 i40evf_configure(adapter
);
2169 err
= i40evf_up_complete(adapter
);
2173 i40evf_irq_enable(adapter
, true);
2178 i40evf_down(adapter
);
2179 i40evf_free_traffic_irqs(adapter
);
2181 i40evf_free_all_rx_resources(adapter
);
2183 i40evf_free_all_tx_resources(adapter
);
2189 * i40evf_close - Disables a network interface
2190 * @netdev: network interface device structure
2192 * Returns 0, this is not allowed to fail
2194 * The close entry point is called when an interface is de-activated
2195 * by the OS. The hardware is still under the drivers control, but
2196 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
2197 * are freed, along with all transmit and receive resources.
2199 static int i40evf_close(struct net_device
*netdev
)
2201 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2203 if (adapter
->state
<= __I40EVF_DOWN_PENDING
)
2207 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
2209 i40evf_down(adapter
);
2210 adapter
->state
= __I40EVF_DOWN_PENDING
;
2211 i40evf_free_traffic_irqs(adapter
);
2217 * i40evf_get_stats - Get System Network Statistics
2218 * @netdev: network interface device structure
2220 * Returns the address of the device statistics structure.
2221 * The statistics are actually updated from the timer callback.
2223 static struct net_device_stats
*i40evf_get_stats(struct net_device
*netdev
)
2225 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2227 /* only return the current stats */
2228 return &adapter
->net_stats
;
2232 * i40evf_change_mtu - Change the Maximum Transfer Unit
2233 * @netdev: network interface device structure
2234 * @new_mtu: new value for maximum frame size
2236 * Returns 0 on success, negative on failure
2238 static int i40evf_change_mtu(struct net_device
*netdev
, int new_mtu
)
2240 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2241 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2243 if ((new_mtu
< 68) || (max_frame
> I40E_MAX_RXBUFFER
))
2246 netdev
->mtu
= new_mtu
;
2247 adapter
->flags
|= I40EVF_FLAG_RESET_NEEDED
;
2248 schedule_work(&adapter
->reset_task
);
2253 static const struct net_device_ops i40evf_netdev_ops
= {
2254 .ndo_open
= i40evf_open
,
2255 .ndo_stop
= i40evf_close
,
2256 .ndo_start_xmit
= i40evf_xmit_frame
,
2257 .ndo_get_stats
= i40evf_get_stats
,
2258 .ndo_set_rx_mode
= i40evf_set_rx_mode
,
2259 .ndo_validate_addr
= eth_validate_addr
,
2260 .ndo_set_mac_address
= i40evf_set_mac
,
2261 .ndo_change_mtu
= i40evf_change_mtu
,
2262 .ndo_tx_timeout
= i40evf_tx_timeout
,
2263 .ndo_vlan_rx_add_vid
= i40evf_vlan_rx_add_vid
,
2264 .ndo_vlan_rx_kill_vid
= i40evf_vlan_rx_kill_vid
,
2265 #ifdef CONFIG_NET_POLL_CONTROLLER
2266 .ndo_poll_controller
= i40evf_netpoll
,
2271 * i40evf_check_reset_complete - check that VF reset is complete
2272 * @hw: pointer to hw struct
2274 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2276 static int i40evf_check_reset_complete(struct i40e_hw
*hw
)
2281 for (i
= 0; i
< 100; i
++) {
2282 rstat
= rd32(hw
, I40E_VFGEN_RSTAT
) &
2283 I40E_VFGEN_RSTAT_VFR_STATE_MASK
;
2284 if ((rstat
== I40E_VFR_VFACTIVE
) ||
2285 (rstat
== I40E_VFR_COMPLETED
))
2287 usleep_range(10, 20);
2293 * i40evf_process_config - Process the config information we got from the PF
2294 * @adapter: board private structure
2296 * Verify that we have a valid config struct, and set up our netdev features
2297 * and our VSI struct.
2299 int i40evf_process_config(struct i40evf_adapter
*adapter
)
2301 struct net_device
*netdev
= adapter
->netdev
;
2304 /* got VF config message back from PF, now we can parse it */
2305 for (i
= 0; i
< adapter
->vf_res
->num_vsis
; i
++) {
2306 if (adapter
->vf_res
->vsi_res
[i
].vsi_type
== I40E_VSI_SRIOV
)
2307 adapter
->vsi_res
= &adapter
->vf_res
->vsi_res
[i
];
2309 if (!adapter
->vsi_res
) {
2310 dev_err(&adapter
->pdev
->dev
, "No LAN VSI found\n");
2314 if (adapter
->vf_res
->vf_offload_flags
2315 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN
) {
2316 netdev
->vlan_features
= netdev
->features
&
2317 ~(NETIF_F_HW_VLAN_CTAG_TX
|
2318 NETIF_F_HW_VLAN_CTAG_RX
|
2319 NETIF_F_HW_VLAN_CTAG_FILTER
);
2320 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
2321 NETIF_F_HW_VLAN_CTAG_RX
|
2322 NETIF_F_HW_VLAN_CTAG_FILTER
;
2324 netdev
->features
|= NETIF_F_HIGHDMA
|
2333 NETIF_F_GSO_UDP_TUNNEL
|
2337 netdev
->hw_enc_features
|= NETIF_F_IP_CSUM
|
2343 NETIF_F_GSO_UDP_TUNNEL
|
2344 NETIF_F_GSO_UDP_TUNNEL_CSUM
;
2346 if (adapter
->flags
& I40EVF_FLAG_OUTER_UDP_CSUM_CAPABLE
)
2347 netdev
->features
|= NETIF_F_GSO_UDP_TUNNEL_CSUM
;
2349 /* copy netdev features into list of user selectable features */
2350 netdev
->hw_features
|= netdev
->features
;
2351 netdev
->hw_features
&= ~NETIF_F_RXCSUM
;
2353 adapter
->vsi
.id
= adapter
->vsi_res
->vsi_id
;
2355 adapter
->vsi
.back
= adapter
;
2356 adapter
->vsi
.base_vector
= 1;
2357 adapter
->vsi
.work_limit
= I40E_DEFAULT_IRQ_WORK
;
2358 adapter
->vsi
.rx_itr_setting
= (I40E_ITR_DYNAMIC
|
2359 ITR_REG_TO_USEC(I40E_ITR_RX_DEF
));
2360 adapter
->vsi
.tx_itr_setting
= (I40E_ITR_DYNAMIC
|
2361 ITR_REG_TO_USEC(I40E_ITR_TX_DEF
));
2362 adapter
->vsi
.netdev
= adapter
->netdev
;
2363 adapter
->vsi
.qs_handle
= adapter
->vsi_res
->qset_handle
;
2368 * i40evf_init_task - worker thread to perform delayed initialization
2369 * @work: pointer to work_struct containing our data
2371 * This task completes the work that was begun in probe. Due to the nature
2372 * of VF-PF communications, we may need to wait tens of milliseconds to get
2373 * responses back from the PF. Rather than busy-wait in probe and bog down the
2374 * whole system, we'll do it in a task so we can sleep.
2375 * This task only runs during driver init. Once we've established
2376 * communications with the PF driver and set up our netdev, the watchdog
2379 static void i40evf_init_task(struct work_struct
*work
)
2381 struct i40evf_adapter
*adapter
= container_of(work
,
2382 struct i40evf_adapter
,
2384 struct net_device
*netdev
= adapter
->netdev
;
2385 struct i40e_hw
*hw
= &adapter
->hw
;
2386 struct pci_dev
*pdev
= adapter
->pdev
;
2389 switch (adapter
->state
) {
2390 case __I40EVF_STARTUP
:
2391 /* driver loaded, probe complete */
2392 adapter
->flags
&= ~I40EVF_FLAG_PF_COMMS_FAILED
;
2393 adapter
->flags
&= ~I40EVF_FLAG_RESET_PENDING
;
2394 err
= i40e_set_mac_type(hw
);
2396 dev_err(&pdev
->dev
, "Failed to set MAC type (%d)\n",
2400 err
= i40evf_check_reset_complete(hw
);
2402 dev_info(&pdev
->dev
, "Device is still in reset (%d), retrying\n",
2406 hw
->aq
.num_arq_entries
= I40EVF_AQ_LEN
;
2407 hw
->aq
.num_asq_entries
= I40EVF_AQ_LEN
;
2408 hw
->aq
.arq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
2409 hw
->aq
.asq_buf_size
= I40EVF_MAX_AQ_BUF_SIZE
;
2411 err
= i40evf_init_adminq(hw
);
2413 dev_err(&pdev
->dev
, "Failed to init Admin Queue (%d)\n",
2417 err
= i40evf_send_api_ver(adapter
);
2419 dev_err(&pdev
->dev
, "Unable to send to PF (%d)\n", err
);
2420 i40evf_shutdown_adminq(hw
);
2423 adapter
->state
= __I40EVF_INIT_VERSION_CHECK
;
2425 case __I40EVF_INIT_VERSION_CHECK
:
2426 if (!i40evf_asq_done(hw
)) {
2427 dev_err(&pdev
->dev
, "Admin queue command never completed\n");
2428 i40evf_shutdown_adminq(hw
);
2429 adapter
->state
= __I40EVF_STARTUP
;
2433 /* aq msg sent, awaiting reply */
2434 err
= i40evf_verify_api_ver(adapter
);
2436 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
)
2437 err
= i40evf_send_api_ver(adapter
);
2439 dev_err(&pdev
->dev
, "Unsupported PF API version %d.%d, expected %d.%d\n",
2440 adapter
->pf_version
.major
,
2441 adapter
->pf_version
.minor
,
2442 I40E_VIRTCHNL_VERSION_MAJOR
,
2443 I40E_VIRTCHNL_VERSION_MINOR
);
2446 err
= i40evf_send_vf_config_msg(adapter
);
2448 dev_err(&pdev
->dev
, "Unable to send config request (%d)\n",
2452 adapter
->state
= __I40EVF_INIT_GET_RESOURCES
;
2454 case __I40EVF_INIT_GET_RESOURCES
:
2455 /* aq msg sent, awaiting reply */
2456 if (!adapter
->vf_res
) {
2457 bufsz
= sizeof(struct i40e_virtchnl_vf_resource
) +
2459 sizeof(struct i40e_virtchnl_vsi_resource
));
2460 adapter
->vf_res
= kzalloc(bufsz
, GFP_KERNEL
);
2461 if (!adapter
->vf_res
)
2464 err
= i40evf_get_vf_config(adapter
);
2465 if (err
== I40E_ERR_ADMIN_QUEUE_NO_WORK
) {
2466 err
= i40evf_send_vf_config_msg(adapter
);
2468 } else if (err
== I40E_ERR_PARAM
) {
2469 /* We only get ERR_PARAM if the device is in a very bad
2470 * state or if we've been disabled for previous bad
2471 * behavior. Either way, we're done now.
2473 i40evf_shutdown_adminq(hw
);
2474 dev_err(&pdev
->dev
, "Unable to get VF config due to PF error condition, not retrying\n");
2478 dev_err(&pdev
->dev
, "Unable to get VF config (%d)\n",
2482 adapter
->state
= __I40EVF_INIT_SW
;
2488 if (hw
->mac
.type
== I40E_MAC_X722_VF
)
2489 adapter
->flags
|= I40EVF_FLAG_OUTER_UDP_CSUM_CAPABLE
;
2491 if (i40evf_process_config(adapter
))
2493 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
2495 adapter
->flags
|= I40EVF_FLAG_RX_CSUM_ENABLED
;
2496 adapter
->flags
|= I40EVF_FLAG_RX_1BUF_CAPABLE
;
2497 adapter
->flags
|= I40EVF_FLAG_RX_PS_CAPABLE
;
2499 /* Default to single buffer rx, can be changed through ethtool. */
2500 adapter
->flags
&= ~I40EVF_FLAG_RX_PS_ENABLED
;
2502 netdev
->netdev_ops
= &i40evf_netdev_ops
;
2503 i40evf_set_ethtool_ops(netdev
);
2504 netdev
->watchdog_timeo
= 5 * HZ
;
2506 if (!is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
2507 dev_info(&pdev
->dev
, "Invalid MAC address %pM, using random\n",
2508 adapter
->hw
.mac
.addr
);
2509 eth_hw_addr_random(netdev
);
2510 ether_addr_copy(adapter
->hw
.mac
.addr
, netdev
->dev_addr
);
2512 adapter
->flags
|= I40EVF_FLAG_ADDR_SET_BY_PF
;
2513 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
2514 ether_addr_copy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
);
2517 init_timer(&adapter
->watchdog_timer
);
2518 adapter
->watchdog_timer
.function
= &i40evf_watchdog_timer
;
2519 adapter
->watchdog_timer
.data
= (unsigned long)adapter
;
2520 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
2522 adapter
->num_active_queues
= min_t(int,
2523 adapter
->vsi_res
->num_queue_pairs
,
2524 (int)(num_online_cpus()));
2525 adapter
->tx_desc_count
= I40EVF_DEFAULT_TXD
;
2526 adapter
->rx_desc_count
= I40EVF_DEFAULT_RXD
;
2527 err
= i40evf_init_interrupt_scheme(adapter
);
2530 i40evf_map_rings_to_vectors(adapter
);
2531 if (adapter
->vf_res
->vf_offload_flags
&
2532 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
)
2533 adapter
->flags
|= I40EVF_FLAG_WB_ON_ITR_CAPABLE
;
2535 err
= i40evf_request_misc_irq(adapter
);
2539 netif_carrier_off(netdev
);
2541 if (!adapter
->netdev_registered
) {
2542 err
= register_netdev(netdev
);
2547 adapter
->netdev_registered
= true;
2549 netif_tx_stop_all_queues(netdev
);
2551 dev_info(&pdev
->dev
, "MAC address: %pM\n", adapter
->hw
.mac
.addr
);
2552 if (netdev
->features
& NETIF_F_GRO
)
2553 dev_info(&pdev
->dev
, "GRO is enabled\n");
2555 adapter
->state
= __I40EVF_DOWN
;
2556 set_bit(__I40E_DOWN
, &adapter
->vsi
.state
);
2557 i40evf_misc_irq_enable(adapter
);
2559 if (RSS_AQ(adapter
)) {
2560 adapter
->aq_required
|= I40EVF_FLAG_AQ_CONFIGURE_RSS
;
2561 mod_timer_pending(&adapter
->watchdog_timer
, jiffies
+ 1);
2563 i40evf_init_rss(adapter
);
2567 schedule_delayed_work(&adapter
->init_task
, msecs_to_jiffies(30));
2571 i40evf_free_misc_irq(adapter
);
2573 i40evf_reset_interrupt_capability(adapter
);
2575 kfree(adapter
->vf_res
);
2576 adapter
->vf_res
= NULL
;
2578 /* Things went into the weeds, so try again later */
2579 if (++adapter
->aq_wait_count
> I40EVF_AQ_MAX_ERR
) {
2580 dev_err(&pdev
->dev
, "Failed to communicate with PF; waiting before retry\n");
2581 adapter
->flags
|= I40EVF_FLAG_PF_COMMS_FAILED
;
2582 i40evf_shutdown_adminq(hw
);
2583 adapter
->state
= __I40EVF_STARTUP
;
2584 schedule_delayed_work(&adapter
->init_task
, HZ
* 5);
2587 schedule_delayed_work(&adapter
->init_task
, HZ
);
2591 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2592 * @pdev: pci device structure
2594 static void i40evf_shutdown(struct pci_dev
*pdev
)
2596 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2597 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2599 netif_device_detach(netdev
);
2601 if (netif_running(netdev
))
2602 i40evf_close(netdev
);
2604 /* Prevent the watchdog from running. */
2605 adapter
->state
= __I40EVF_REMOVE
;
2606 adapter
->aq_required
= 0;
2609 pci_save_state(pdev
);
2612 pci_disable_device(pdev
);
2616 * i40evf_probe - Device Initialization Routine
2617 * @pdev: PCI device information struct
2618 * @ent: entry in i40evf_pci_tbl
2620 * Returns 0 on success, negative on failure
2622 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2623 * The OS initialization, configuring of the adapter private structure,
2624 * and a hardware reset occur.
2626 static int i40evf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2628 struct net_device
*netdev
;
2629 struct i40evf_adapter
*adapter
= NULL
;
2630 struct i40e_hw
*hw
= NULL
;
2633 err
= pci_enable_device(pdev
);
2637 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
2639 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
2642 "DMA configuration failed: 0x%x\n", err
);
2647 err
= pci_request_regions(pdev
, i40evf_driver_name
);
2650 "pci_request_regions failed 0x%x\n", err
);
2654 pci_enable_pcie_error_reporting(pdev
);
2656 pci_set_master(pdev
);
2658 netdev
= alloc_etherdev_mq(sizeof(struct i40evf_adapter
), MAX_QUEUES
);
2661 goto err_alloc_etherdev
;
2664 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2666 pci_set_drvdata(pdev
, netdev
);
2667 adapter
= netdev_priv(netdev
);
2669 adapter
->netdev
= netdev
;
2670 adapter
->pdev
= pdev
;
2675 adapter
->msg_enable
= BIT(DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
2676 adapter
->state
= __I40EVF_STARTUP
;
2678 /* Call save state here because it relies on the adapter struct. */
2679 pci_save_state(pdev
);
2681 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
2682 pci_resource_len(pdev
, 0));
2687 hw
->vendor_id
= pdev
->vendor
;
2688 hw
->device_id
= pdev
->device
;
2689 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2690 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
2691 hw
->subsystem_device_id
= pdev
->subsystem_device
;
2692 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
2693 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
2695 /* set up the locks for the AQ, do this only once in probe
2696 * and destroy them only once in remove
2698 mutex_init(&hw
->aq
.asq_mutex
);
2699 mutex_init(&hw
->aq
.arq_mutex
);
2701 INIT_LIST_HEAD(&adapter
->mac_filter_list
);
2702 INIT_LIST_HEAD(&adapter
->vlan_filter_list
);
2704 INIT_WORK(&adapter
->reset_task
, i40evf_reset_task
);
2705 INIT_WORK(&adapter
->adminq_task
, i40evf_adminq_task
);
2706 INIT_WORK(&adapter
->watchdog_task
, i40evf_watchdog_task
);
2707 INIT_DELAYED_WORK(&adapter
->init_task
, i40evf_init_task
);
2708 schedule_delayed_work(&adapter
->init_task
,
2709 msecs_to_jiffies(5 * (pdev
->devfn
& 0x07)));
2714 free_netdev(netdev
);
2716 pci_release_regions(pdev
);
2719 pci_disable_device(pdev
);
2725 * i40evf_suspend - Power management suspend routine
2726 * @pdev: PCI device information struct
2729 * Called when the system (VM) is entering sleep/suspend.
2731 static int i40evf_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2733 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2734 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2737 netif_device_detach(netdev
);
2739 if (netif_running(netdev
)) {
2741 i40evf_down(adapter
);
2744 i40evf_free_misc_irq(adapter
);
2745 i40evf_reset_interrupt_capability(adapter
);
2747 retval
= pci_save_state(pdev
);
2751 pci_disable_device(pdev
);
2757 * i40evf_resume - Power management resume routine
2758 * @pdev: PCI device information struct
2760 * Called when the system (VM) is resumed from sleep/suspend.
2762 static int i40evf_resume(struct pci_dev
*pdev
)
2764 struct i40evf_adapter
*adapter
= pci_get_drvdata(pdev
);
2765 struct net_device
*netdev
= adapter
->netdev
;
2768 pci_set_power_state(pdev
, PCI_D0
);
2769 pci_restore_state(pdev
);
2770 /* pci_restore_state clears dev->state_saved so call
2771 * pci_save_state to restore it.
2773 pci_save_state(pdev
);
2775 err
= pci_enable_device_mem(pdev
);
2777 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend.\n");
2780 pci_set_master(pdev
);
2783 err
= i40evf_set_interrupt_capability(adapter
);
2786 dev_err(&pdev
->dev
, "Cannot enable MSI-X interrupts.\n");
2789 err
= i40evf_request_misc_irq(adapter
);
2792 dev_err(&pdev
->dev
, "Cannot get interrupt vector.\n");
2796 schedule_work(&adapter
->reset_task
);
2798 netif_device_attach(netdev
);
2803 #endif /* CONFIG_PM */
2805 * i40evf_remove - Device Removal Routine
2806 * @pdev: PCI device information struct
2808 * i40evf_remove is called by the PCI subsystem to alert the driver
2809 * that it should release a PCI device. The could be caused by a
2810 * Hot-Plug event, or because the driver is going to be removed from
2813 static void i40evf_remove(struct pci_dev
*pdev
)
2815 struct net_device
*netdev
= pci_get_drvdata(pdev
);
2816 struct i40evf_adapter
*adapter
= netdev_priv(netdev
);
2817 struct i40evf_mac_filter
*f
, *ftmp
;
2818 struct i40e_hw
*hw
= &adapter
->hw
;
2820 cancel_delayed_work_sync(&adapter
->init_task
);
2821 cancel_work_sync(&adapter
->reset_task
);
2823 if (adapter
->netdev_registered
) {
2824 unregister_netdev(netdev
);
2825 adapter
->netdev_registered
= false;
2828 /* Shut down all the garbage mashers on the detention level */
2829 adapter
->state
= __I40EVF_REMOVE
;
2830 adapter
->aq_required
= 0;
2831 i40evf_request_reset(adapter
);
2833 /* If the FW isn't responding, kick it once, but only once. */
2834 if (!i40evf_asq_done(hw
)) {
2835 i40evf_request_reset(adapter
);
2839 if (adapter
->msix_entries
) {
2840 i40evf_misc_irq_disable(adapter
);
2841 i40evf_free_misc_irq(adapter
);
2842 i40evf_reset_interrupt_capability(adapter
);
2843 i40evf_free_q_vectors(adapter
);
2846 if (adapter
->watchdog_timer
.function
)
2847 del_timer_sync(&adapter
->watchdog_timer
);
2849 flush_scheduled_work();
2851 /* Clear user configurations for RSS */
2852 i40evf_clear_rss_config_user(&adapter
->vsi
);
2854 if (hw
->aq
.asq
.count
)
2855 i40evf_shutdown_adminq(hw
);
2857 /* destroy the locks only once, here */
2858 mutex_destroy(&hw
->aq
.arq_mutex
);
2859 mutex_destroy(&hw
->aq
.asq_mutex
);
2861 iounmap(hw
->hw_addr
);
2862 pci_release_regions(pdev
);
2864 i40evf_free_all_tx_resources(adapter
);
2865 i40evf_free_all_rx_resources(adapter
);
2866 i40evf_free_queues(adapter
);
2867 kfree(adapter
->vf_res
);
2868 /* If we got removed before an up/down sequence, we've got a filter
2869 * hanging out there that we need to get rid of.
2871 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2875 list_for_each_entry_safe(f
, ftmp
, &adapter
->vlan_filter_list
, list
) {
2880 free_netdev(netdev
);
2882 pci_disable_pcie_error_reporting(pdev
);
2884 pci_disable_device(pdev
);
2887 static struct pci_driver i40evf_driver
= {
2888 .name
= i40evf_driver_name
,
2889 .id_table
= i40evf_pci_tbl
,
2890 .probe
= i40evf_probe
,
2891 .remove
= i40evf_remove
,
2893 .suspend
= i40evf_suspend
,
2894 .resume
= i40evf_resume
,
2896 .shutdown
= i40evf_shutdown
,
2900 * i40e_init_module - Driver Registration Routine
2902 * i40e_init_module is the first routine called when the driver is
2903 * loaded. All it does is register with the PCI subsystem.
2905 static int __init
i40evf_init_module(void)
2909 pr_info("i40evf: %s - version %s\n", i40evf_driver_string
,
2910 i40evf_driver_version
);
2912 pr_info("%s\n", i40evf_copyright
);
2914 i40evf_wq
= create_singlethread_workqueue(i40evf_driver_name
);
2916 pr_err("%s: Failed to create workqueue\n", i40evf_driver_name
);
2919 ret
= pci_register_driver(&i40evf_driver
);
2923 module_init(i40evf_init_module
);
2926 * i40e_exit_module - Driver Exit Cleanup Routine
2928 * i40e_exit_module is called just before the driver is removed
2931 static void __exit
i40evf_exit_module(void)
2933 pci_unregister_driver(&i40evf_driver
);
2934 destroy_workqueue(i40evf_wq
);
2937 module_exit(i40evf_exit_module
);