1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
5 #include "iavf_prototype.h"
6 #include "iavf_client.h"
7 /* All iavf tracepoints are defined by the include below, which must
8 * be included exactly once across the whole kernel with
9 * CREATE_TRACE_POINTS defined
11 #define CREATE_TRACE_POINTS
12 #include "iavf_trace.h"
14 static int iavf_setup_all_tx_resources(struct iavf_adapter
*adapter
);
15 static int iavf_setup_all_rx_resources(struct iavf_adapter
*adapter
);
16 static int iavf_close(struct net_device
*netdev
);
17 static void iavf_init_get_resources(struct iavf_adapter
*adapter
);
18 static int iavf_check_reset_complete(struct iavf_hw
*hw
);
20 char iavf_driver_name
[] = "iavf";
21 static const char iavf_driver_string
[] =
22 "Intel(R) Ethernet Adaptive Virtual Function Network Driver";
24 static const char iavf_copyright
[] =
25 "Copyright (c) 2013 - 2018 Intel Corporation.";
27 /* iavf_pci_tbl - PCI Device ID Table
29 * Wildcard entries (PCI_ANY_ID) should come last
30 * Last entry must be all 0s
32 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
33 * Class, Class Mask, private data (not used) }
35 static const struct pci_device_id iavf_pci_tbl
[] = {
36 {PCI_VDEVICE(INTEL
, IAVF_DEV_ID_VF
), 0},
37 {PCI_VDEVICE(INTEL
, IAVF_DEV_ID_VF_HV
), 0},
38 {PCI_VDEVICE(INTEL
, IAVF_DEV_ID_X722_VF
), 0},
39 {PCI_VDEVICE(INTEL
, IAVF_DEV_ID_ADAPTIVE_VF
), 0},
40 /* required last entry */
44 MODULE_DEVICE_TABLE(pci
, iavf_pci_tbl
);
46 MODULE_ALIAS("i40evf");
47 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
48 MODULE_DESCRIPTION("Intel(R) Ethernet Adaptive Virtual Function Network Driver");
49 MODULE_LICENSE("GPL v2");
51 static const struct net_device_ops iavf_netdev_ops
;
52 struct workqueue_struct
*iavf_wq
;
55 * iavf_allocate_dma_mem_d - OS specific memory alloc for shared code
56 * @hw: pointer to the HW structure
57 * @mem: ptr to mem struct to fill out
58 * @size: size of memory requested
59 * @alignment: what to align the allocation to
61 enum iavf_status
iavf_allocate_dma_mem_d(struct iavf_hw
*hw
,
62 struct iavf_dma_mem
*mem
,
63 u64 size
, u32 alignment
)
65 struct iavf_adapter
*adapter
= (struct iavf_adapter
*)hw
->back
;
68 return IAVF_ERR_PARAM
;
70 mem
->size
= ALIGN(size
, alignment
);
71 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
,
72 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
76 return IAVF_ERR_NO_MEMORY
;
80 * iavf_free_dma_mem_d - OS specific memory free for shared code
81 * @hw: pointer to the HW structure
82 * @mem: ptr to mem struct to free
84 enum iavf_status
iavf_free_dma_mem_d(struct iavf_hw
*hw
,
85 struct iavf_dma_mem
*mem
)
87 struct iavf_adapter
*adapter
= (struct iavf_adapter
*)hw
->back
;
90 return IAVF_ERR_PARAM
;
91 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
,
92 mem
->va
, (dma_addr_t
)mem
->pa
);
97 * iavf_allocate_virt_mem_d - OS specific memory alloc for shared code
98 * @hw: pointer to the HW structure
99 * @mem: ptr to mem struct to fill out
100 * @size: size of memory requested
102 enum iavf_status
iavf_allocate_virt_mem_d(struct iavf_hw
*hw
,
103 struct iavf_virt_mem
*mem
, u32 size
)
106 return IAVF_ERR_PARAM
;
109 mem
->va
= kzalloc(size
, GFP_KERNEL
);
114 return IAVF_ERR_NO_MEMORY
;
118 * iavf_free_virt_mem_d - OS specific memory free for shared code
119 * @hw: pointer to the HW structure
120 * @mem: ptr to mem struct to free
122 enum iavf_status
iavf_free_virt_mem_d(struct iavf_hw
*hw
,
123 struct iavf_virt_mem
*mem
)
126 return IAVF_ERR_PARAM
;
128 /* it's ok to kfree a NULL pointer */
135 * iavf_lock_timeout - try to lock mutex but give up after timeout
136 * @lock: mutex that should be locked
137 * @msecs: timeout in msecs
139 * Returns 0 on success, negative on failure
141 int iavf_lock_timeout(struct mutex
*lock
, unsigned int msecs
)
143 unsigned int wait
, delay
= 10;
145 for (wait
= 0; wait
< msecs
; wait
+= delay
) {
146 if (mutex_trylock(lock
))
156 * iavf_schedule_reset - Set the flags and schedule a reset event
157 * @adapter: board private structure
159 void iavf_schedule_reset(struct iavf_adapter
*adapter
)
161 if (!(adapter
->flags
&
162 (IAVF_FLAG_RESET_PENDING
| IAVF_FLAG_RESET_NEEDED
))) {
163 adapter
->flags
|= IAVF_FLAG_RESET_NEEDED
;
164 queue_work(iavf_wq
, &adapter
->reset_task
);
169 * iavf_schedule_request_stats - Set the flags and schedule statistics request
170 * @adapter: board private structure
172 * Sets IAVF_FLAG_AQ_REQUEST_STATS flag so iavf_watchdog_task() will explicitly
173 * request and refresh ethtool stats
175 void iavf_schedule_request_stats(struct iavf_adapter
*adapter
)
177 adapter
->aq_required
|= IAVF_FLAG_AQ_REQUEST_STATS
;
178 mod_delayed_work(iavf_wq
, &adapter
->watchdog_task
, 0);
182 * iavf_tx_timeout - Respond to a Tx Hang
183 * @netdev: network interface device structure
184 * @txqueue: queue number that is timing out
186 static void iavf_tx_timeout(struct net_device
*netdev
, unsigned int txqueue
)
188 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
190 adapter
->tx_timeout_count
++;
191 iavf_schedule_reset(adapter
);
195 * iavf_misc_irq_disable - Mask off interrupt generation on the NIC
196 * @adapter: board private structure
198 static void iavf_misc_irq_disable(struct iavf_adapter
*adapter
)
200 struct iavf_hw
*hw
= &adapter
->hw
;
202 if (!adapter
->msix_entries
)
205 wr32(hw
, IAVF_VFINT_DYN_CTL01
, 0);
209 synchronize_irq(adapter
->msix_entries
[0].vector
);
213 * iavf_misc_irq_enable - Enable default interrupt generation settings
214 * @adapter: board private structure
216 static void iavf_misc_irq_enable(struct iavf_adapter
*adapter
)
218 struct iavf_hw
*hw
= &adapter
->hw
;
220 wr32(hw
, IAVF_VFINT_DYN_CTL01
, IAVF_VFINT_DYN_CTL01_INTENA_MASK
|
221 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK
);
222 wr32(hw
, IAVF_VFINT_ICR0_ENA1
, IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK
);
228 * iavf_irq_disable - Mask off interrupt generation on the NIC
229 * @adapter: board private structure
231 static void iavf_irq_disable(struct iavf_adapter
*adapter
)
234 struct iavf_hw
*hw
= &adapter
->hw
;
236 if (!adapter
->msix_entries
)
239 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
240 wr32(hw
, IAVF_VFINT_DYN_CTLN1(i
- 1), 0);
241 synchronize_irq(adapter
->msix_entries
[i
].vector
);
247 * iavf_irq_enable_queues - Enable interrupt for specified queues
248 * @adapter: board private structure
249 * @mask: bitmap of queues to enable
251 void iavf_irq_enable_queues(struct iavf_adapter
*adapter
, u32 mask
)
253 struct iavf_hw
*hw
= &adapter
->hw
;
256 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
257 if (mask
& BIT(i
- 1)) {
258 wr32(hw
, IAVF_VFINT_DYN_CTLN1(i
- 1),
259 IAVF_VFINT_DYN_CTLN1_INTENA_MASK
|
260 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK
);
266 * iavf_irq_enable - Enable default interrupt generation settings
267 * @adapter: board private structure
268 * @flush: boolean value whether to run rd32()
270 void iavf_irq_enable(struct iavf_adapter
*adapter
, bool flush
)
272 struct iavf_hw
*hw
= &adapter
->hw
;
274 iavf_misc_irq_enable(adapter
);
275 iavf_irq_enable_queues(adapter
, ~0);
282 * iavf_msix_aq - Interrupt handler for vector 0
283 * @irq: interrupt number
284 * @data: pointer to netdev
286 static irqreturn_t
iavf_msix_aq(int irq
, void *data
)
288 struct net_device
*netdev
= data
;
289 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
290 struct iavf_hw
*hw
= &adapter
->hw
;
292 /* handle non-queue interrupts, these reads clear the registers */
293 rd32(hw
, IAVF_VFINT_ICR01
);
294 rd32(hw
, IAVF_VFINT_ICR0_ENA1
);
296 /* schedule work on the private workqueue */
297 queue_work(iavf_wq
, &adapter
->adminq_task
);
303 * iavf_msix_clean_rings - MSIX mode Interrupt Handler
304 * @irq: interrupt number
305 * @data: pointer to a q_vector
307 static irqreturn_t
iavf_msix_clean_rings(int irq
, void *data
)
309 struct iavf_q_vector
*q_vector
= data
;
311 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
314 napi_schedule_irqoff(&q_vector
->napi
);
320 * iavf_map_vector_to_rxq - associate irqs with rx queues
321 * @adapter: board private structure
322 * @v_idx: interrupt number
323 * @r_idx: queue number
326 iavf_map_vector_to_rxq(struct iavf_adapter
*adapter
, int v_idx
, int r_idx
)
328 struct iavf_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
329 struct iavf_ring
*rx_ring
= &adapter
->rx_rings
[r_idx
];
330 struct iavf_hw
*hw
= &adapter
->hw
;
332 rx_ring
->q_vector
= q_vector
;
333 rx_ring
->next
= q_vector
->rx
.ring
;
334 rx_ring
->vsi
= &adapter
->vsi
;
335 q_vector
->rx
.ring
= rx_ring
;
336 q_vector
->rx
.count
++;
337 q_vector
->rx
.next_update
= jiffies
+ 1;
338 q_vector
->rx
.target_itr
= ITR_TO_REG(rx_ring
->itr_setting
);
339 q_vector
->ring_mask
|= BIT(r_idx
);
340 wr32(hw
, IAVF_VFINT_ITRN1(IAVF_RX_ITR
, q_vector
->reg_idx
),
341 q_vector
->rx
.current_itr
>> 1);
342 q_vector
->rx
.current_itr
= q_vector
->rx
.target_itr
;
346 * iavf_map_vector_to_txq - associate irqs with tx queues
347 * @adapter: board private structure
348 * @v_idx: interrupt number
349 * @t_idx: queue number
352 iavf_map_vector_to_txq(struct iavf_adapter
*adapter
, int v_idx
, int t_idx
)
354 struct iavf_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
355 struct iavf_ring
*tx_ring
= &adapter
->tx_rings
[t_idx
];
356 struct iavf_hw
*hw
= &adapter
->hw
;
358 tx_ring
->q_vector
= q_vector
;
359 tx_ring
->next
= q_vector
->tx
.ring
;
360 tx_ring
->vsi
= &adapter
->vsi
;
361 q_vector
->tx
.ring
= tx_ring
;
362 q_vector
->tx
.count
++;
363 q_vector
->tx
.next_update
= jiffies
+ 1;
364 q_vector
->tx
.target_itr
= ITR_TO_REG(tx_ring
->itr_setting
);
365 q_vector
->num_ringpairs
++;
366 wr32(hw
, IAVF_VFINT_ITRN1(IAVF_TX_ITR
, q_vector
->reg_idx
),
367 q_vector
->tx
.target_itr
>> 1);
368 q_vector
->tx
.current_itr
= q_vector
->tx
.target_itr
;
372 * iavf_map_rings_to_vectors - Maps descriptor rings to vectors
373 * @adapter: board private structure to initialize
375 * This function maps descriptor rings to the queue-specific vectors
376 * we were allotted through the MSI-X enabling code. Ideally, we'd have
377 * one vector per ring/queue, but on a constrained vector budget, we
378 * group the rings as "efficiently" as possible. You would add new
379 * mapping configurations in here.
381 static void iavf_map_rings_to_vectors(struct iavf_adapter
*adapter
)
383 int rings_remaining
= adapter
->num_active_queues
;
384 int ridx
= 0, vidx
= 0;
387 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
389 for (; ridx
< rings_remaining
; ridx
++) {
390 iavf_map_vector_to_rxq(adapter
, vidx
, ridx
);
391 iavf_map_vector_to_txq(adapter
, vidx
, ridx
);
393 /* In the case where we have more queues than vectors, continue
394 * round-robin on vectors until all queues are mapped.
396 if (++vidx
>= q_vectors
)
400 adapter
->aq_required
|= IAVF_FLAG_AQ_MAP_VECTORS
;
404 * iavf_irq_affinity_notify - Callback for affinity changes
405 * @notify: context as to what irq was changed
406 * @mask: the new affinity mask
408 * This is a callback function used by the irq_set_affinity_notifier function
409 * so that we may register to receive changes to the irq affinity masks.
411 static void iavf_irq_affinity_notify(struct irq_affinity_notify
*notify
,
412 const cpumask_t
*mask
)
414 struct iavf_q_vector
*q_vector
=
415 container_of(notify
, struct iavf_q_vector
, affinity_notify
);
417 cpumask_copy(&q_vector
->affinity_mask
, mask
);
421 * iavf_irq_affinity_release - Callback for affinity notifier release
422 * @ref: internal core kernel usage
424 * This is a callback function used by the irq_set_affinity_notifier function
425 * to inform the current notification subscriber that they will no longer
426 * receive notifications.
428 static void iavf_irq_affinity_release(struct kref
*ref
) {}
431 * iavf_request_traffic_irqs - Initialize MSI-X interrupts
432 * @adapter: board private structure
433 * @basename: device basename
435 * Allocates MSI-X vectors for tx and rx handling, and requests
436 * interrupts from the kernel.
439 iavf_request_traffic_irqs(struct iavf_adapter
*adapter
, char *basename
)
441 unsigned int vector
, q_vectors
;
442 unsigned int rx_int_idx
= 0, tx_int_idx
= 0;
446 iavf_irq_disable(adapter
);
447 /* Decrement for Other and TCP Timer vectors */
448 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
450 for (vector
= 0; vector
< q_vectors
; vector
++) {
451 struct iavf_q_vector
*q_vector
= &adapter
->q_vectors
[vector
];
453 irq_num
= adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
;
455 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
456 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
457 "iavf-%s-TxRx-%d", basename
, rx_int_idx
++);
459 } else if (q_vector
->rx
.ring
) {
460 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
461 "iavf-%s-rx-%d", basename
, rx_int_idx
++);
462 } else if (q_vector
->tx
.ring
) {
463 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
464 "iavf-%s-tx-%d", basename
, tx_int_idx
++);
466 /* skip this unused q_vector */
469 err
= request_irq(irq_num
,
470 iavf_msix_clean_rings
,
475 dev_info(&adapter
->pdev
->dev
,
476 "Request_irq failed, error: %d\n", err
);
477 goto free_queue_irqs
;
479 /* register for affinity change notifications */
480 q_vector
->affinity_notify
.notify
= iavf_irq_affinity_notify
;
481 q_vector
->affinity_notify
.release
=
482 iavf_irq_affinity_release
;
483 irq_set_affinity_notifier(irq_num
, &q_vector
->affinity_notify
);
484 /* Spread the IRQ affinity hints across online CPUs. Note that
485 * get_cpu_mask returns a mask with a permanent lifetime so
486 * it's safe to use as a hint for irq_set_affinity_hint.
488 cpu
= cpumask_local_spread(q_vector
->v_idx
, -1);
489 irq_set_affinity_hint(irq_num
, get_cpu_mask(cpu
));
497 irq_num
= adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
;
498 irq_set_affinity_notifier(irq_num
, NULL
);
499 irq_set_affinity_hint(irq_num
, NULL
);
500 free_irq(irq_num
, &adapter
->q_vectors
[vector
]);
506 * iavf_request_misc_irq - Initialize MSI-X interrupts
507 * @adapter: board private structure
509 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
510 * vector is only for the admin queue, and stays active even when the netdev
513 static int iavf_request_misc_irq(struct iavf_adapter
*adapter
)
515 struct net_device
*netdev
= adapter
->netdev
;
518 snprintf(adapter
->misc_vector_name
,
519 sizeof(adapter
->misc_vector_name
) - 1, "iavf-%s:mbx",
520 dev_name(&adapter
->pdev
->dev
));
521 err
= request_irq(adapter
->msix_entries
[0].vector
,
523 adapter
->misc_vector_name
, netdev
);
525 dev_err(&adapter
->pdev
->dev
,
526 "request_irq for %s failed: %d\n",
527 adapter
->misc_vector_name
, err
);
528 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
534 * iavf_free_traffic_irqs - Free MSI-X interrupts
535 * @adapter: board private structure
537 * Frees all MSI-X vectors other than 0.
539 static void iavf_free_traffic_irqs(struct iavf_adapter
*adapter
)
541 int vector
, irq_num
, q_vectors
;
543 if (!adapter
->msix_entries
)
546 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
548 for (vector
= 0; vector
< q_vectors
; vector
++) {
549 irq_num
= adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
;
550 irq_set_affinity_notifier(irq_num
, NULL
);
551 irq_set_affinity_hint(irq_num
, NULL
);
552 free_irq(irq_num
, &adapter
->q_vectors
[vector
]);
557 * iavf_free_misc_irq - Free MSI-X miscellaneous vector
558 * @adapter: board private structure
560 * Frees MSI-X vector 0.
562 static void iavf_free_misc_irq(struct iavf_adapter
*adapter
)
564 struct net_device
*netdev
= adapter
->netdev
;
566 if (!adapter
->msix_entries
)
569 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
573 * iavf_configure_tx - Configure Transmit Unit after Reset
574 * @adapter: board private structure
576 * Configure the Tx unit of the MAC after a reset.
578 static void iavf_configure_tx(struct iavf_adapter
*adapter
)
580 struct iavf_hw
*hw
= &adapter
->hw
;
583 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
584 adapter
->tx_rings
[i
].tail
= hw
->hw_addr
+ IAVF_QTX_TAIL1(i
);
588 * iavf_configure_rx - Configure Receive Unit after Reset
589 * @adapter: board private structure
591 * Configure the Rx unit of the MAC after a reset.
593 static void iavf_configure_rx(struct iavf_adapter
*adapter
)
595 unsigned int rx_buf_len
= IAVF_RXBUFFER_2048
;
596 struct iavf_hw
*hw
= &adapter
->hw
;
599 /* Legacy Rx will always default to a 2048 buffer size. */
600 #if (PAGE_SIZE < 8192)
601 if (!(adapter
->flags
& IAVF_FLAG_LEGACY_RX
)) {
602 struct net_device
*netdev
= adapter
->netdev
;
604 /* For jumbo frames on systems with 4K pages we have to use
605 * an order 1 page, so we might as well increase the size
606 * of our Rx buffer to make better use of the available space
608 rx_buf_len
= IAVF_RXBUFFER_3072
;
610 /* We use a 1536 buffer size for configurations with
611 * standard Ethernet mtu. On x86 this gives us enough room
612 * for shared info and 192 bytes of padding.
614 if (!IAVF_2K_TOO_SMALL_WITH_PADDING
&&
615 (netdev
->mtu
<= ETH_DATA_LEN
))
616 rx_buf_len
= IAVF_RXBUFFER_1536
- NET_IP_ALIGN
;
620 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
621 adapter
->rx_rings
[i
].tail
= hw
->hw_addr
+ IAVF_QRX_TAIL1(i
);
622 adapter
->rx_rings
[i
].rx_buf_len
= rx_buf_len
;
624 if (adapter
->flags
& IAVF_FLAG_LEGACY_RX
)
625 clear_ring_build_skb_enabled(&adapter
->rx_rings
[i
]);
627 set_ring_build_skb_enabled(&adapter
->rx_rings
[i
]);
632 * iavf_find_vlan - Search filter list for specific vlan filter
633 * @adapter: board private structure
636 * Returns ptr to the filter object or NULL. Must be called while holding the
637 * mac_vlan_list_lock.
640 iavf_vlan_filter
*iavf_find_vlan(struct iavf_adapter
*adapter
, u16 vlan
)
642 struct iavf_vlan_filter
*f
;
644 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
652 * iavf_add_vlan - Add a vlan filter to the list
653 * @adapter: board private structure
656 * Returns ptr to the filter object or NULL when no memory available.
659 iavf_vlan_filter
*iavf_add_vlan(struct iavf_adapter
*adapter
, u16 vlan
)
661 struct iavf_vlan_filter
*f
= NULL
;
663 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
665 f
= iavf_find_vlan(adapter
, vlan
);
667 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
673 list_add_tail(&f
->list
, &adapter
->vlan_filter_list
);
675 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_VLAN_FILTER
;
679 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
684 * iavf_del_vlan - Remove a vlan filter from the list
685 * @adapter: board private structure
688 static void iavf_del_vlan(struct iavf_adapter
*adapter
, u16 vlan
)
690 struct iavf_vlan_filter
*f
;
692 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
694 f
= iavf_find_vlan(adapter
, vlan
);
697 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_VLAN_FILTER
;
700 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
704 * iavf_restore_filters
705 * @adapter: board private structure
707 * Restore existing non MAC filters when VF netdev comes back up
709 static void iavf_restore_filters(struct iavf_adapter
*adapter
)
713 /* re-add all VLAN filters */
714 for_each_set_bit(vid
, adapter
->vsi
.active_vlans
, VLAN_N_VID
)
715 iavf_add_vlan(adapter
, vid
);
719 * iavf_vlan_rx_add_vid - Add a VLAN filter to a device
720 * @netdev: network device struct
721 * @proto: unused protocol data
724 static int iavf_vlan_rx_add_vid(struct net_device
*netdev
,
725 __always_unused __be16 proto
, u16 vid
)
727 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
729 if (!VLAN_ALLOWED(adapter
))
732 if (iavf_add_vlan(adapter
, vid
) == NULL
)
735 set_bit(vid
, adapter
->vsi
.active_vlans
);
740 * iavf_vlan_rx_kill_vid - Remove a VLAN filter from a device
741 * @netdev: network device struct
742 * @proto: unused protocol data
745 static int iavf_vlan_rx_kill_vid(struct net_device
*netdev
,
746 __always_unused __be16 proto
, u16 vid
)
748 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
750 iavf_del_vlan(adapter
, vid
);
751 clear_bit(vid
, adapter
->vsi
.active_vlans
);
757 * iavf_find_filter - Search filter list for specific mac filter
758 * @adapter: board private structure
759 * @macaddr: the MAC address
761 * Returns ptr to the filter object or NULL. Must be called while holding the
762 * mac_vlan_list_lock.
765 iavf_mac_filter
*iavf_find_filter(struct iavf_adapter
*adapter
,
768 struct iavf_mac_filter
*f
;
773 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
774 if (ether_addr_equal(macaddr
, f
->macaddr
))
781 * iavf_add_filter - Add a mac filter to the filter list
782 * @adapter: board private structure
783 * @macaddr: the MAC address
785 * Returns ptr to the filter object or NULL when no memory available.
787 struct iavf_mac_filter
*iavf_add_filter(struct iavf_adapter
*adapter
,
790 struct iavf_mac_filter
*f
;
795 f
= iavf_find_filter(adapter
, macaddr
);
797 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
801 ether_addr_copy(f
->macaddr
, macaddr
);
803 list_add_tail(&f
->list
, &adapter
->mac_filter_list
);
805 f
->is_new_mac
= true;
806 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_MAC_FILTER
;
815 * iavf_set_mac - NDO callback to set port mac address
816 * @netdev: network interface device structure
817 * @p: pointer to an address structure
819 * Returns 0 on success, negative on failure
821 static int iavf_set_mac(struct net_device
*netdev
, void *p
)
823 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
824 struct iavf_hw
*hw
= &adapter
->hw
;
825 struct iavf_mac_filter
*f
;
826 struct sockaddr
*addr
= p
;
828 if (!is_valid_ether_addr(addr
->sa_data
))
829 return -EADDRNOTAVAIL
;
831 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
))
834 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
836 f
= iavf_find_filter(adapter
, hw
->mac
.addr
);
839 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_MAC_FILTER
;
842 f
= iavf_add_filter(adapter
, addr
->sa_data
);
844 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
847 ether_addr_copy(hw
->mac
.addr
, addr
->sa_data
);
850 return (f
== NULL
) ? -ENOMEM
: 0;
854 * iavf_addr_sync - Callback for dev_(mc|uc)_sync to add address
855 * @netdev: the netdevice
856 * @addr: address to add
858 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
859 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
861 static int iavf_addr_sync(struct net_device
*netdev
, const u8
*addr
)
863 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
865 if (iavf_add_filter(adapter
, addr
))
872 * iavf_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
873 * @netdev: the netdevice
874 * @addr: address to add
876 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
877 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
879 static int iavf_addr_unsync(struct net_device
*netdev
, const u8
*addr
)
881 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
882 struct iavf_mac_filter
*f
;
884 /* Under some circumstances, we might receive a request to delete
885 * our own device address from our uc list. Because we store the
886 * device address in the VSI's MAC/VLAN filter list, we need to ignore
887 * such requests and not delete our device address from this list.
889 if (ether_addr_equal(addr
, netdev
->dev_addr
))
892 f
= iavf_find_filter(adapter
, addr
);
895 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_MAC_FILTER
;
901 * iavf_set_rx_mode - NDO callback to set the netdev filters
902 * @netdev: network interface device structure
904 static void iavf_set_rx_mode(struct net_device
*netdev
)
906 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
908 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
909 __dev_uc_sync(netdev
, iavf_addr_sync
, iavf_addr_unsync
);
910 __dev_mc_sync(netdev
, iavf_addr_sync
, iavf_addr_unsync
);
911 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
913 if (netdev
->flags
& IFF_PROMISC
&&
914 !(adapter
->flags
& IAVF_FLAG_PROMISC_ON
))
915 adapter
->aq_required
|= IAVF_FLAG_AQ_REQUEST_PROMISC
;
916 else if (!(netdev
->flags
& IFF_PROMISC
) &&
917 adapter
->flags
& IAVF_FLAG_PROMISC_ON
)
918 adapter
->aq_required
|= IAVF_FLAG_AQ_RELEASE_PROMISC
;
920 if (netdev
->flags
& IFF_ALLMULTI
&&
921 !(adapter
->flags
& IAVF_FLAG_ALLMULTI_ON
))
922 adapter
->aq_required
|= IAVF_FLAG_AQ_REQUEST_ALLMULTI
;
923 else if (!(netdev
->flags
& IFF_ALLMULTI
) &&
924 adapter
->flags
& IAVF_FLAG_ALLMULTI_ON
)
925 adapter
->aq_required
|= IAVF_FLAG_AQ_RELEASE_ALLMULTI
;
929 * iavf_napi_enable_all - enable NAPI on all queue vectors
930 * @adapter: board private structure
932 static void iavf_napi_enable_all(struct iavf_adapter
*adapter
)
935 struct iavf_q_vector
*q_vector
;
936 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
938 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
939 struct napi_struct
*napi
;
941 q_vector
= &adapter
->q_vectors
[q_idx
];
942 napi
= &q_vector
->napi
;
948 * iavf_napi_disable_all - disable NAPI on all queue vectors
949 * @adapter: board private structure
951 static void iavf_napi_disable_all(struct iavf_adapter
*adapter
)
954 struct iavf_q_vector
*q_vector
;
955 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
957 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
958 q_vector
= &adapter
->q_vectors
[q_idx
];
959 napi_disable(&q_vector
->napi
);
964 * iavf_configure - set up transmit and receive data structures
965 * @adapter: board private structure
967 static void iavf_configure(struct iavf_adapter
*adapter
)
969 struct net_device
*netdev
= adapter
->netdev
;
972 iavf_set_rx_mode(netdev
);
974 iavf_configure_tx(adapter
);
975 iavf_configure_rx(adapter
);
976 adapter
->aq_required
|= IAVF_FLAG_AQ_CONFIGURE_QUEUES
;
978 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
979 struct iavf_ring
*ring
= &adapter
->rx_rings
[i
];
981 iavf_alloc_rx_buffers(ring
, IAVF_DESC_UNUSED(ring
));
986 * iavf_up_complete - Finish the last steps of bringing up a connection
987 * @adapter: board private structure
989 * Expects to be called while holding the __IAVF_IN_CRITICAL_TASK bit lock.
991 static void iavf_up_complete(struct iavf_adapter
*adapter
)
993 iavf_change_state(adapter
, __IAVF_RUNNING
);
994 clear_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
996 iavf_napi_enable_all(adapter
);
998 adapter
->aq_required
|= IAVF_FLAG_AQ_ENABLE_QUEUES
;
999 if (CLIENT_ENABLED(adapter
))
1000 adapter
->flags
|= IAVF_FLAG_CLIENT_NEEDS_OPEN
;
1001 mod_delayed_work(iavf_wq
, &adapter
->watchdog_task
, 0);
1005 * iavf_down - Shutdown the connection processing
1006 * @adapter: board private structure
1008 * Expects to be called while holding the __IAVF_IN_CRITICAL_TASK bit lock.
1010 void iavf_down(struct iavf_adapter
*adapter
)
1012 struct net_device
*netdev
= adapter
->netdev
;
1013 struct iavf_vlan_filter
*vlf
;
1014 struct iavf_cloud_filter
*cf
;
1015 struct iavf_fdir_fltr
*fdir
;
1016 struct iavf_mac_filter
*f
;
1017 struct iavf_adv_rss
*rss
;
1019 if (adapter
->state
<= __IAVF_DOWN_PENDING
)
1022 netif_carrier_off(netdev
);
1023 netif_tx_disable(netdev
);
1024 adapter
->link_up
= false;
1025 iavf_napi_disable_all(adapter
);
1026 iavf_irq_disable(adapter
);
1028 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
1030 /* clear the sync flag on all filters */
1031 __dev_uc_unsync(adapter
->netdev
, NULL
);
1032 __dev_mc_unsync(adapter
->netdev
, NULL
);
1034 /* remove all MAC filters */
1035 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
1039 /* remove all VLAN filters */
1040 list_for_each_entry(vlf
, &adapter
->vlan_filter_list
, list
) {
1044 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
1046 /* remove all cloud filters */
1047 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
1048 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
1051 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
1053 /* remove all Flow Director filters */
1054 spin_lock_bh(&adapter
->fdir_fltr_lock
);
1055 list_for_each_entry(fdir
, &adapter
->fdir_list_head
, list
) {
1056 fdir
->state
= IAVF_FDIR_FLTR_DEL_REQUEST
;
1058 spin_unlock_bh(&adapter
->fdir_fltr_lock
);
1060 /* remove all advance RSS configuration */
1061 spin_lock_bh(&adapter
->adv_rss_lock
);
1062 list_for_each_entry(rss
, &adapter
->adv_rss_list_head
, list
)
1063 rss
->state
= IAVF_ADV_RSS_DEL_REQUEST
;
1064 spin_unlock_bh(&adapter
->adv_rss_lock
);
1066 if (!(adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
) &&
1067 adapter
->state
!= __IAVF_RESETTING
) {
1068 /* cancel any current operation */
1069 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
1070 /* Schedule operations to close down the HW. Don't wait
1071 * here for this to complete. The watchdog is still running
1072 * and it will take care of this.
1074 adapter
->aq_required
= IAVF_FLAG_AQ_DEL_MAC_FILTER
;
1075 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_VLAN_FILTER
;
1076 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_CLOUD_FILTER
;
1077 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_FDIR_FILTER
;
1078 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_ADV_RSS_CFG
;
1079 adapter
->aq_required
|= IAVF_FLAG_AQ_DISABLE_QUEUES
;
1082 mod_delayed_work(iavf_wq
, &adapter
->watchdog_task
, 0);
1086 * iavf_acquire_msix_vectors - Setup the MSIX capability
1087 * @adapter: board private structure
1088 * @vectors: number of vectors to request
1090 * Work with the OS to set up the MSIX vectors needed.
1092 * Returns 0 on success, negative on failure
1095 iavf_acquire_msix_vectors(struct iavf_adapter
*adapter
, int vectors
)
1097 int err
, vector_threshold
;
1099 /* We'll want at least 3 (vector_threshold):
1100 * 0) Other (Admin Queue and link, mostly)
1104 vector_threshold
= MIN_MSIX_COUNT
;
1106 /* The more we get, the more we will assign to Tx/Rx Cleanup
1107 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1108 * Right now, we simply care about how many we'll get; we'll
1109 * set them up later while requesting irq's.
1111 err
= pci_enable_msix_range(adapter
->pdev
, adapter
->msix_entries
,
1112 vector_threshold
, vectors
);
1114 dev_err(&adapter
->pdev
->dev
, "Unable to allocate MSI-X interrupts\n");
1115 kfree(adapter
->msix_entries
);
1116 adapter
->msix_entries
= NULL
;
1120 /* Adjust for only the vectors we'll use, which is minimum
1121 * of max_msix_q_vectors + NONQ_VECS, or the number of
1122 * vectors we were allocated.
1124 adapter
->num_msix_vectors
= err
;
1129 * iavf_free_queues - Free memory for all rings
1130 * @adapter: board private structure to initialize
1132 * Free all of the memory associated with queue pairs.
1134 static void iavf_free_queues(struct iavf_adapter
*adapter
)
1136 if (!adapter
->vsi_res
)
1138 adapter
->num_active_queues
= 0;
1139 kfree(adapter
->tx_rings
);
1140 adapter
->tx_rings
= NULL
;
1141 kfree(adapter
->rx_rings
);
1142 adapter
->rx_rings
= NULL
;
1146 * iavf_alloc_queues - Allocate memory for all rings
1147 * @adapter: board private structure to initialize
1149 * We allocate one ring per queue at run-time since we don't know the
1150 * number of queues at compile-time. The polling_netdev array is
1151 * intended for Multiqueue, but should work fine with a single queue.
1153 static int iavf_alloc_queues(struct iavf_adapter
*adapter
)
1155 int i
, num_active_queues
;
1157 /* If we're in reset reallocating queues we don't actually know yet for
1158 * certain the PF gave us the number of queues we asked for but we'll
1159 * assume it did. Once basic reset is finished we'll confirm once we
1160 * start negotiating config with PF.
1162 if (adapter
->num_req_queues
)
1163 num_active_queues
= adapter
->num_req_queues
;
1164 else if ((adapter
->vf_res
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
) &&
1166 num_active_queues
= adapter
->ch_config
.total_qps
;
1168 num_active_queues
= min_t(int,
1169 adapter
->vsi_res
->num_queue_pairs
,
1170 (int)(num_online_cpus()));
1173 adapter
->tx_rings
= kcalloc(num_active_queues
,
1174 sizeof(struct iavf_ring
), GFP_KERNEL
);
1175 if (!adapter
->tx_rings
)
1177 adapter
->rx_rings
= kcalloc(num_active_queues
,
1178 sizeof(struct iavf_ring
), GFP_KERNEL
);
1179 if (!adapter
->rx_rings
)
1182 for (i
= 0; i
< num_active_queues
; i
++) {
1183 struct iavf_ring
*tx_ring
;
1184 struct iavf_ring
*rx_ring
;
1186 tx_ring
= &adapter
->tx_rings
[i
];
1188 tx_ring
->queue_index
= i
;
1189 tx_ring
->netdev
= adapter
->netdev
;
1190 tx_ring
->dev
= &adapter
->pdev
->dev
;
1191 tx_ring
->count
= adapter
->tx_desc_count
;
1192 tx_ring
->itr_setting
= IAVF_ITR_TX_DEF
;
1193 if (adapter
->flags
& IAVF_FLAG_WB_ON_ITR_CAPABLE
)
1194 tx_ring
->flags
|= IAVF_TXR_FLAGS_WB_ON_ITR
;
1196 rx_ring
= &adapter
->rx_rings
[i
];
1197 rx_ring
->queue_index
= i
;
1198 rx_ring
->netdev
= adapter
->netdev
;
1199 rx_ring
->dev
= &adapter
->pdev
->dev
;
1200 rx_ring
->count
= adapter
->rx_desc_count
;
1201 rx_ring
->itr_setting
= IAVF_ITR_RX_DEF
;
1204 adapter
->num_active_queues
= num_active_queues
;
1209 iavf_free_queues(adapter
);
1214 * iavf_set_interrupt_capability - set MSI-X or FAIL if not supported
1215 * @adapter: board private structure to initialize
1217 * Attempt to configure the interrupts using the best available
1218 * capabilities of the hardware and the kernel.
1220 static int iavf_set_interrupt_capability(struct iavf_adapter
*adapter
)
1222 int vector
, v_budget
;
1226 if (!adapter
->vsi_res
) {
1230 pairs
= adapter
->num_active_queues
;
1232 /* It's easy to be greedy for MSI-X vectors, but it really doesn't do
1233 * us much good if we have more vectors than CPUs. However, we already
1234 * limit the total number of queues by the number of CPUs so we do not
1235 * need any further limiting here.
1237 v_budget
= min_t(int, pairs
+ NONQ_VECS
,
1238 (int)adapter
->vf_res
->max_vectors
);
1240 adapter
->msix_entries
= kcalloc(v_budget
,
1241 sizeof(struct msix_entry
), GFP_KERNEL
);
1242 if (!adapter
->msix_entries
) {
1247 for (vector
= 0; vector
< v_budget
; vector
++)
1248 adapter
->msix_entries
[vector
].entry
= vector
;
1250 err
= iavf_acquire_msix_vectors(adapter
, v_budget
);
1253 netif_set_real_num_rx_queues(adapter
->netdev
, pairs
);
1254 netif_set_real_num_tx_queues(adapter
->netdev
, pairs
);
1259 * iavf_config_rss_aq - Configure RSS keys and lut by using AQ commands
1260 * @adapter: board private structure
1262 * Return 0 on success, negative on failure
1264 static int iavf_config_rss_aq(struct iavf_adapter
*adapter
)
1266 struct iavf_aqc_get_set_rss_key_data
*rss_key
=
1267 (struct iavf_aqc_get_set_rss_key_data
*)adapter
->rss_key
;
1268 struct iavf_hw
*hw
= &adapter
->hw
;
1271 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
1272 /* bail because we already have a command pending */
1273 dev_err(&adapter
->pdev
->dev
, "Cannot configure RSS, command %d pending\n",
1274 adapter
->current_op
);
1278 ret
= iavf_aq_set_rss_key(hw
, adapter
->vsi
.id
, rss_key
);
1280 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS key, err %s aq_err %s\n",
1281 iavf_stat_str(hw
, ret
),
1282 iavf_aq_str(hw
, hw
->aq
.asq_last_status
));
1287 ret
= iavf_aq_set_rss_lut(hw
, adapter
->vsi
.id
, false,
1288 adapter
->rss_lut
, adapter
->rss_lut_size
);
1290 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS lut, err %s aq_err %s\n",
1291 iavf_stat_str(hw
, ret
),
1292 iavf_aq_str(hw
, hw
->aq
.asq_last_status
));
1300 * iavf_config_rss_reg - Configure RSS keys and lut by writing registers
1301 * @adapter: board private structure
1303 * Returns 0 on success, negative on failure
1305 static int iavf_config_rss_reg(struct iavf_adapter
*adapter
)
1307 struct iavf_hw
*hw
= &adapter
->hw
;
1311 dw
= (u32
*)adapter
->rss_key
;
1312 for (i
= 0; i
<= adapter
->rss_key_size
/ 4; i
++)
1313 wr32(hw
, IAVF_VFQF_HKEY(i
), dw
[i
]);
1315 dw
= (u32
*)adapter
->rss_lut
;
1316 for (i
= 0; i
<= adapter
->rss_lut_size
/ 4; i
++)
1317 wr32(hw
, IAVF_VFQF_HLUT(i
), dw
[i
]);
1325 * iavf_config_rss - Configure RSS keys and lut
1326 * @adapter: board private structure
1328 * Returns 0 on success, negative on failure
1330 int iavf_config_rss(struct iavf_adapter
*adapter
)
1333 if (RSS_PF(adapter
)) {
1334 adapter
->aq_required
|= IAVF_FLAG_AQ_SET_RSS_LUT
|
1335 IAVF_FLAG_AQ_SET_RSS_KEY
;
1337 } else if (RSS_AQ(adapter
)) {
1338 return iavf_config_rss_aq(adapter
);
1340 return iavf_config_rss_reg(adapter
);
1345 * iavf_fill_rss_lut - Fill the lut with default values
1346 * @adapter: board private structure
1348 static void iavf_fill_rss_lut(struct iavf_adapter
*adapter
)
1352 for (i
= 0; i
< adapter
->rss_lut_size
; i
++)
1353 adapter
->rss_lut
[i
] = i
% adapter
->num_active_queues
;
1357 * iavf_init_rss - Prepare for RSS
1358 * @adapter: board private structure
1360 * Return 0 on success, negative on failure
1362 static int iavf_init_rss(struct iavf_adapter
*adapter
)
1364 struct iavf_hw
*hw
= &adapter
->hw
;
1367 if (!RSS_PF(adapter
)) {
1368 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1369 if (adapter
->vf_res
->vf_cap_flags
&
1370 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
)
1371 adapter
->hena
= IAVF_DEFAULT_RSS_HENA_EXPANDED
;
1373 adapter
->hena
= IAVF_DEFAULT_RSS_HENA
;
1375 wr32(hw
, IAVF_VFQF_HENA(0), (u32
)adapter
->hena
);
1376 wr32(hw
, IAVF_VFQF_HENA(1), (u32
)(adapter
->hena
>> 32));
1379 iavf_fill_rss_lut(adapter
);
1380 netdev_rss_key_fill((void *)adapter
->rss_key
, adapter
->rss_key_size
);
1381 ret
= iavf_config_rss(adapter
);
1387 * iavf_alloc_q_vectors - Allocate memory for interrupt vectors
1388 * @adapter: board private structure to initialize
1390 * We allocate one q_vector per queue interrupt. If allocation fails we
1393 static int iavf_alloc_q_vectors(struct iavf_adapter
*adapter
)
1395 int q_idx
= 0, num_q_vectors
;
1396 struct iavf_q_vector
*q_vector
;
1398 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1399 adapter
->q_vectors
= kcalloc(num_q_vectors
, sizeof(*q_vector
),
1401 if (!adapter
->q_vectors
)
1404 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1405 q_vector
= &adapter
->q_vectors
[q_idx
];
1406 q_vector
->adapter
= adapter
;
1407 q_vector
->vsi
= &adapter
->vsi
;
1408 q_vector
->v_idx
= q_idx
;
1409 q_vector
->reg_idx
= q_idx
;
1410 cpumask_copy(&q_vector
->affinity_mask
, cpu_possible_mask
);
1411 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1412 iavf_napi_poll
, NAPI_POLL_WEIGHT
);
1419 * iavf_free_q_vectors - Free memory allocated for interrupt vectors
1420 * @adapter: board private structure to initialize
1422 * This function frees the memory allocated to the q_vectors. In addition if
1423 * NAPI is enabled it will delete any references to the NAPI struct prior
1424 * to freeing the q_vector.
1426 static void iavf_free_q_vectors(struct iavf_adapter
*adapter
)
1428 int q_idx
, num_q_vectors
;
1431 if (!adapter
->q_vectors
)
1434 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1435 napi_vectors
= adapter
->num_active_queues
;
1437 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1438 struct iavf_q_vector
*q_vector
= &adapter
->q_vectors
[q_idx
];
1440 if (q_idx
< napi_vectors
)
1441 netif_napi_del(&q_vector
->napi
);
1443 kfree(adapter
->q_vectors
);
1444 adapter
->q_vectors
= NULL
;
1448 * iavf_reset_interrupt_capability - Reset MSIX setup
1449 * @adapter: board private structure
1452 void iavf_reset_interrupt_capability(struct iavf_adapter
*adapter
)
1454 if (!adapter
->msix_entries
)
1457 pci_disable_msix(adapter
->pdev
);
1458 kfree(adapter
->msix_entries
);
1459 adapter
->msix_entries
= NULL
;
1463 * iavf_init_interrupt_scheme - Determine if MSIX is supported and init
1464 * @adapter: board private structure to initialize
1467 int iavf_init_interrupt_scheme(struct iavf_adapter
*adapter
)
1471 err
= iavf_alloc_queues(adapter
);
1473 dev_err(&adapter
->pdev
->dev
,
1474 "Unable to allocate memory for queues\n");
1475 goto err_alloc_queues
;
1479 err
= iavf_set_interrupt_capability(adapter
);
1482 dev_err(&adapter
->pdev
->dev
,
1483 "Unable to setup interrupt capabilities\n");
1484 goto err_set_interrupt
;
1487 err
= iavf_alloc_q_vectors(adapter
);
1489 dev_err(&adapter
->pdev
->dev
,
1490 "Unable to allocate memory for queue vectors\n");
1491 goto err_alloc_q_vectors
;
1494 /* If we've made it so far while ADq flag being ON, then we haven't
1495 * bailed out anywhere in middle. And ADq isn't just enabled but actual
1496 * resources have been allocated in the reset path.
1497 * Now we can truly claim that ADq is enabled.
1499 if ((adapter
->vf_res
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
) &&
1501 dev_info(&adapter
->pdev
->dev
, "ADq Enabled, %u TCs created",
1504 dev_info(&adapter
->pdev
->dev
, "Multiqueue %s: Queue pair count = %u",
1505 (adapter
->num_active_queues
> 1) ? "Enabled" : "Disabled",
1506 adapter
->num_active_queues
);
1509 err_alloc_q_vectors
:
1510 iavf_reset_interrupt_capability(adapter
);
1512 iavf_free_queues(adapter
);
1518 * iavf_free_rss - Free memory used by RSS structs
1519 * @adapter: board private structure
1521 static void iavf_free_rss(struct iavf_adapter
*adapter
)
1523 kfree(adapter
->rss_key
);
1524 adapter
->rss_key
= NULL
;
1526 kfree(adapter
->rss_lut
);
1527 adapter
->rss_lut
= NULL
;
1531 * iavf_reinit_interrupt_scheme - Reallocate queues and vectors
1532 * @adapter: board private structure
1534 * Returns 0 on success, negative on failure
1536 static int iavf_reinit_interrupt_scheme(struct iavf_adapter
*adapter
)
1538 struct net_device
*netdev
= adapter
->netdev
;
1541 if (netif_running(netdev
))
1542 iavf_free_traffic_irqs(adapter
);
1543 iavf_free_misc_irq(adapter
);
1544 iavf_reset_interrupt_capability(adapter
);
1545 iavf_free_q_vectors(adapter
);
1546 iavf_free_queues(adapter
);
1548 err
= iavf_init_interrupt_scheme(adapter
);
1552 netif_tx_stop_all_queues(netdev
);
1554 err
= iavf_request_misc_irq(adapter
);
1558 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
1560 iavf_map_rings_to_vectors(adapter
);
1566 * iavf_process_aq_command - process aq_required flags
1567 * and sends aq command
1568 * @adapter: pointer to iavf adapter structure
1570 * Returns 0 on success
1571 * Returns error code if no command was sent
1572 * or error code if the command failed.
1574 static int iavf_process_aq_command(struct iavf_adapter
*adapter
)
1576 if (adapter
->aq_required
& IAVF_FLAG_AQ_GET_CONFIG
)
1577 return iavf_send_vf_config_msg(adapter
);
1578 if (adapter
->aq_required
& IAVF_FLAG_AQ_DISABLE_QUEUES
) {
1579 iavf_disable_queues(adapter
);
1583 if (adapter
->aq_required
& IAVF_FLAG_AQ_MAP_VECTORS
) {
1584 iavf_map_queues(adapter
);
1588 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_MAC_FILTER
) {
1589 iavf_add_ether_addrs(adapter
);
1593 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_VLAN_FILTER
) {
1594 iavf_add_vlans(adapter
);
1598 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_MAC_FILTER
) {
1599 iavf_del_ether_addrs(adapter
);
1603 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_VLAN_FILTER
) {
1604 iavf_del_vlans(adapter
);
1608 if (adapter
->aq_required
& IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING
) {
1609 iavf_enable_vlan_stripping(adapter
);
1613 if (adapter
->aq_required
& IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING
) {
1614 iavf_disable_vlan_stripping(adapter
);
1618 if (adapter
->aq_required
& IAVF_FLAG_AQ_CONFIGURE_QUEUES
) {
1619 iavf_configure_queues(adapter
);
1623 if (adapter
->aq_required
& IAVF_FLAG_AQ_ENABLE_QUEUES
) {
1624 iavf_enable_queues(adapter
);
1628 if (adapter
->aq_required
& IAVF_FLAG_AQ_CONFIGURE_RSS
) {
1629 /* This message goes straight to the firmware, not the
1630 * PF, so we don't have to set current_op as we will
1631 * not get a response through the ARQ.
1633 adapter
->aq_required
&= ~IAVF_FLAG_AQ_CONFIGURE_RSS
;
1636 if (adapter
->aq_required
& IAVF_FLAG_AQ_GET_HENA
) {
1637 iavf_get_hena(adapter
);
1640 if (adapter
->aq_required
& IAVF_FLAG_AQ_SET_HENA
) {
1641 iavf_set_hena(adapter
);
1644 if (adapter
->aq_required
& IAVF_FLAG_AQ_SET_RSS_KEY
) {
1645 iavf_set_rss_key(adapter
);
1648 if (adapter
->aq_required
& IAVF_FLAG_AQ_SET_RSS_LUT
) {
1649 iavf_set_rss_lut(adapter
);
1653 if (adapter
->aq_required
& IAVF_FLAG_AQ_REQUEST_PROMISC
) {
1654 iavf_set_promiscuous(adapter
, FLAG_VF_UNICAST_PROMISC
|
1655 FLAG_VF_MULTICAST_PROMISC
);
1659 if (adapter
->aq_required
& IAVF_FLAG_AQ_REQUEST_ALLMULTI
) {
1660 iavf_set_promiscuous(adapter
, FLAG_VF_MULTICAST_PROMISC
);
1663 if ((adapter
->aq_required
& IAVF_FLAG_AQ_RELEASE_PROMISC
) ||
1664 (adapter
->aq_required
& IAVF_FLAG_AQ_RELEASE_ALLMULTI
)) {
1665 iavf_set_promiscuous(adapter
, 0);
1669 if (adapter
->aq_required
& IAVF_FLAG_AQ_ENABLE_CHANNELS
) {
1670 iavf_enable_channels(adapter
);
1674 if (adapter
->aq_required
& IAVF_FLAG_AQ_DISABLE_CHANNELS
) {
1675 iavf_disable_channels(adapter
);
1678 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_CLOUD_FILTER
) {
1679 iavf_add_cloud_filter(adapter
);
1683 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_CLOUD_FILTER
) {
1684 iavf_del_cloud_filter(adapter
);
1687 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_CLOUD_FILTER
) {
1688 iavf_del_cloud_filter(adapter
);
1691 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_CLOUD_FILTER
) {
1692 iavf_add_cloud_filter(adapter
);
1695 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_FDIR_FILTER
) {
1696 iavf_add_fdir_filter(adapter
);
1697 return IAVF_SUCCESS
;
1699 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_FDIR_FILTER
) {
1700 iavf_del_fdir_filter(adapter
);
1701 return IAVF_SUCCESS
;
1703 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_ADV_RSS_CFG
) {
1704 iavf_add_adv_rss_cfg(adapter
);
1707 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_ADV_RSS_CFG
) {
1708 iavf_del_adv_rss_cfg(adapter
);
1711 if (adapter
->aq_required
& IAVF_FLAG_AQ_REQUEST_STATS
) {
1712 iavf_request_stats(adapter
);
1720 * iavf_startup - first step of driver startup
1721 * @adapter: board private structure
1723 * Function process __IAVF_STARTUP driver state.
1724 * When success the state is changed to __IAVF_INIT_VERSION_CHECK
1725 * when fails the state is changed to __IAVF_INIT_FAILED
1727 static void iavf_startup(struct iavf_adapter
*adapter
)
1729 struct pci_dev
*pdev
= adapter
->pdev
;
1730 struct iavf_hw
*hw
= &adapter
->hw
;
1733 WARN_ON(adapter
->state
!= __IAVF_STARTUP
);
1735 /* driver loaded, probe complete */
1736 adapter
->flags
&= ~IAVF_FLAG_PF_COMMS_FAILED
;
1737 adapter
->flags
&= ~IAVF_FLAG_RESET_PENDING
;
1738 err
= iavf_set_mac_type(hw
);
1740 dev_err(&pdev
->dev
, "Failed to set MAC type (%d)\n", err
);
1744 err
= iavf_check_reset_complete(hw
);
1746 dev_info(&pdev
->dev
, "Device is still in reset (%d), retrying\n",
1750 hw
->aq
.num_arq_entries
= IAVF_AQ_LEN
;
1751 hw
->aq
.num_asq_entries
= IAVF_AQ_LEN
;
1752 hw
->aq
.arq_buf_size
= IAVF_MAX_AQ_BUF_SIZE
;
1753 hw
->aq
.asq_buf_size
= IAVF_MAX_AQ_BUF_SIZE
;
1755 err
= iavf_init_adminq(hw
);
1757 dev_err(&pdev
->dev
, "Failed to init Admin Queue (%d)\n", err
);
1760 err
= iavf_send_api_ver(adapter
);
1762 dev_err(&pdev
->dev
, "Unable to send to PF (%d)\n", err
);
1763 iavf_shutdown_adminq(hw
);
1766 iavf_change_state(adapter
, __IAVF_INIT_VERSION_CHECK
);
1769 iavf_change_state(adapter
, __IAVF_INIT_FAILED
);
1773 * iavf_init_version_check - second step of driver startup
1774 * @adapter: board private structure
1776 * Function process __IAVF_INIT_VERSION_CHECK driver state.
1777 * When success the state is changed to __IAVF_INIT_GET_RESOURCES
1778 * when fails the state is changed to __IAVF_INIT_FAILED
1780 static void iavf_init_version_check(struct iavf_adapter
*adapter
)
1782 struct pci_dev
*pdev
= adapter
->pdev
;
1783 struct iavf_hw
*hw
= &adapter
->hw
;
1786 WARN_ON(adapter
->state
!= __IAVF_INIT_VERSION_CHECK
);
1788 if (!iavf_asq_done(hw
)) {
1789 dev_err(&pdev
->dev
, "Admin queue command never completed\n");
1790 iavf_shutdown_adminq(hw
);
1791 iavf_change_state(adapter
, __IAVF_STARTUP
);
1795 /* aq msg sent, awaiting reply */
1796 err
= iavf_verify_api_ver(adapter
);
1798 if (err
== IAVF_ERR_ADMIN_QUEUE_NO_WORK
)
1799 err
= iavf_send_api_ver(adapter
);
1801 dev_err(&pdev
->dev
, "Unsupported PF API version %d.%d, expected %d.%d\n",
1802 adapter
->pf_version
.major
,
1803 adapter
->pf_version
.minor
,
1804 VIRTCHNL_VERSION_MAJOR
,
1805 VIRTCHNL_VERSION_MINOR
);
1808 err
= iavf_send_vf_config_msg(adapter
);
1810 dev_err(&pdev
->dev
, "Unable to send config request (%d)\n",
1814 iavf_change_state(adapter
, __IAVF_INIT_GET_RESOURCES
);
1817 iavf_change_state(adapter
, __IAVF_INIT_FAILED
);
1821 * iavf_init_get_resources - third step of driver startup
1822 * @adapter: board private structure
1824 * Function process __IAVF_INIT_GET_RESOURCES driver state and
1825 * finishes driver initialization procedure.
1826 * When success the state is changed to __IAVF_DOWN
1827 * when fails the state is changed to __IAVF_INIT_FAILED
1829 static void iavf_init_get_resources(struct iavf_adapter
*adapter
)
1831 struct net_device
*netdev
= adapter
->netdev
;
1832 struct pci_dev
*pdev
= adapter
->pdev
;
1833 struct iavf_hw
*hw
= &adapter
->hw
;
1836 WARN_ON(adapter
->state
!= __IAVF_INIT_GET_RESOURCES
);
1837 /* aq msg sent, awaiting reply */
1838 if (!adapter
->vf_res
) {
1839 adapter
->vf_res
= kzalloc(IAVF_VIRTCHNL_VF_RESOURCE_SIZE
,
1841 if (!adapter
->vf_res
) {
1846 err
= iavf_get_vf_config(adapter
);
1847 if (err
== IAVF_ERR_ADMIN_QUEUE_NO_WORK
) {
1848 err
= iavf_send_vf_config_msg(adapter
);
1850 } else if (err
== IAVF_ERR_PARAM
) {
1851 /* We only get ERR_PARAM if the device is in a very bad
1852 * state or if we've been disabled for previous bad
1853 * behavior. Either way, we're done now.
1855 iavf_shutdown_adminq(hw
);
1856 dev_err(&pdev
->dev
, "Unable to get VF config due to PF error condition, not retrying\n");
1860 dev_err(&pdev
->dev
, "Unable to get VF config (%d)\n", err
);
1864 err
= iavf_process_config(adapter
);
1867 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
1869 adapter
->flags
|= IAVF_FLAG_RX_CSUM_ENABLED
;
1871 netdev
->netdev_ops
= &iavf_netdev_ops
;
1872 iavf_set_ethtool_ops(netdev
);
1873 netdev
->watchdog_timeo
= 5 * HZ
;
1875 /* MTU range: 68 - 9710 */
1876 netdev
->min_mtu
= ETH_MIN_MTU
;
1877 netdev
->max_mtu
= IAVF_MAX_RXBUFFER
- IAVF_PACKET_HDR_PAD
;
1879 if (!is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
1880 dev_info(&pdev
->dev
, "Invalid MAC address %pM, using random\n",
1881 adapter
->hw
.mac
.addr
);
1882 eth_hw_addr_random(netdev
);
1883 ether_addr_copy(adapter
->hw
.mac
.addr
, netdev
->dev_addr
);
1885 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
1886 ether_addr_copy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
);
1889 adapter
->tx_desc_count
= IAVF_DEFAULT_TXD
;
1890 adapter
->rx_desc_count
= IAVF_DEFAULT_RXD
;
1891 err
= iavf_init_interrupt_scheme(adapter
);
1894 iavf_map_rings_to_vectors(adapter
);
1895 if (adapter
->vf_res
->vf_cap_flags
&
1896 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
)
1897 adapter
->flags
|= IAVF_FLAG_WB_ON_ITR_CAPABLE
;
1899 err
= iavf_request_misc_irq(adapter
);
1903 netif_carrier_off(netdev
);
1904 adapter
->link_up
= false;
1906 /* set the semaphore to prevent any callbacks after device registration
1907 * up to time when state of driver will be set to __IAVF_DOWN
1910 if (!adapter
->netdev_registered
) {
1911 err
= register_netdevice(netdev
);
1918 adapter
->netdev_registered
= true;
1920 netif_tx_stop_all_queues(netdev
);
1921 if (CLIENT_ALLOWED(adapter
)) {
1922 err
= iavf_lan_add_device(adapter
);
1924 dev_info(&pdev
->dev
, "Failed to add VF to client API service list: %d\n",
1927 dev_info(&pdev
->dev
, "MAC address: %pM\n", adapter
->hw
.mac
.addr
);
1928 if (netdev
->features
& NETIF_F_GRO
)
1929 dev_info(&pdev
->dev
, "GRO is enabled\n");
1931 iavf_change_state(adapter
, __IAVF_DOWN
);
1932 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
1935 iavf_misc_irq_enable(adapter
);
1936 wake_up(&adapter
->down_waitqueue
);
1938 adapter
->rss_key
= kzalloc(adapter
->rss_key_size
, GFP_KERNEL
);
1939 adapter
->rss_lut
= kzalloc(adapter
->rss_lut_size
, GFP_KERNEL
);
1940 if (!adapter
->rss_key
|| !adapter
->rss_lut
) {
1944 if (RSS_AQ(adapter
))
1945 adapter
->aq_required
|= IAVF_FLAG_AQ_CONFIGURE_RSS
;
1947 iavf_init_rss(adapter
);
1951 iavf_free_rss(adapter
);
1953 iavf_free_misc_irq(adapter
);
1955 iavf_reset_interrupt_capability(adapter
);
1957 kfree(adapter
->vf_res
);
1958 adapter
->vf_res
= NULL
;
1960 iavf_change_state(adapter
, __IAVF_INIT_FAILED
);
1964 * iavf_watchdog_task - Periodic call-back task
1965 * @work: pointer to work_struct
1967 static void iavf_watchdog_task(struct work_struct
*work
)
1969 struct iavf_adapter
*adapter
= container_of(work
,
1970 struct iavf_adapter
,
1971 watchdog_task
.work
);
1972 struct iavf_hw
*hw
= &adapter
->hw
;
1975 if (!mutex_trylock(&adapter
->crit_lock
))
1976 goto restart_watchdog
;
1978 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
)
1979 iavf_change_state(adapter
, __IAVF_COMM_FAILED
);
1981 switch (adapter
->state
) {
1982 case __IAVF_COMM_FAILED
:
1983 reg_val
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
1984 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
1985 if (reg_val
== VIRTCHNL_VFR_VFACTIVE
||
1986 reg_val
== VIRTCHNL_VFR_COMPLETED
) {
1987 /* A chance for redemption! */
1988 dev_err(&adapter
->pdev
->dev
,
1989 "Hardware came out of reset. Attempting reinit.\n");
1990 iavf_change_state(adapter
, __IAVF_STARTUP
);
1991 adapter
->flags
&= ~IAVF_FLAG_PF_COMMS_FAILED
;
1992 queue_delayed_work(iavf_wq
, &adapter
->init_task
, 10);
1993 mutex_unlock(&adapter
->crit_lock
);
1994 /* Don't reschedule the watchdog, since we've restarted
1995 * the init task. When init_task contacts the PF and
1996 * gets everything set up again, it'll restart the
1997 * watchdog for us. Down, boy. Sit. Stay. Woof.
2001 adapter
->aq_required
= 0;
2002 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
2003 queue_delayed_work(iavf_wq
,
2004 &adapter
->watchdog_task
,
2005 msecs_to_jiffies(10));
2007 case __IAVF_RESETTING
:
2008 mutex_unlock(&adapter
->crit_lock
);
2009 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
, HZ
* 2);
2012 case __IAVF_DOWN_PENDING
:
2013 case __IAVF_TESTING
:
2014 case __IAVF_RUNNING
:
2015 if (adapter
->current_op
) {
2016 if (!iavf_asq_done(hw
)) {
2017 dev_dbg(&adapter
->pdev
->dev
,
2018 "Admin queue timeout\n");
2019 iavf_send_api_ver(adapter
);
2022 /* An error will be returned if no commands were
2023 * processed; use this opportunity to update stats
2025 if (iavf_process_aq_command(adapter
) &&
2026 adapter
->state
== __IAVF_RUNNING
)
2027 iavf_request_stats(adapter
);
2031 mutex_unlock(&adapter
->crit_lock
);
2034 goto restart_watchdog
;
2037 /* check for hw reset */
2038 reg_val
= rd32(hw
, IAVF_VF_ARQLEN1
) & IAVF_VF_ARQLEN1_ARQENABLE_MASK
;
2040 iavf_change_state(adapter
, __IAVF_RESETTING
);
2041 adapter
->flags
|= IAVF_FLAG_RESET_PENDING
;
2042 adapter
->aq_required
= 0;
2043 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
2044 dev_err(&adapter
->pdev
->dev
, "Hardware reset detected\n");
2045 queue_work(iavf_wq
, &adapter
->reset_task
);
2049 schedule_delayed_work(&adapter
->client_task
, msecs_to_jiffies(5));
2051 if (adapter
->state
== __IAVF_RUNNING
||
2052 adapter
->state
== __IAVF_COMM_FAILED
)
2053 iavf_detect_recover_hung(&adapter
->vsi
);
2054 mutex_unlock(&adapter
->crit_lock
);
2056 if (adapter
->aq_required
)
2057 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
,
2058 msecs_to_jiffies(20));
2060 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
, HZ
* 2);
2061 queue_work(iavf_wq
, &adapter
->adminq_task
);
2064 static void iavf_disable_vf(struct iavf_adapter
*adapter
)
2066 struct iavf_mac_filter
*f
, *ftmp
;
2067 struct iavf_vlan_filter
*fv
, *fvtmp
;
2068 struct iavf_cloud_filter
*cf
, *cftmp
;
2070 adapter
->flags
|= IAVF_FLAG_PF_COMMS_FAILED
;
2072 /* We don't use netif_running() because it may be true prior to
2073 * ndo_open() returning, so we can't assume it means all our open
2074 * tasks have finished, since we're not holding the rtnl_lock here.
2076 if (adapter
->state
== __IAVF_RUNNING
) {
2077 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
2078 netif_carrier_off(adapter
->netdev
);
2079 netif_tx_disable(adapter
->netdev
);
2080 adapter
->link_up
= false;
2081 iavf_napi_disable_all(adapter
);
2082 iavf_irq_disable(adapter
);
2083 iavf_free_traffic_irqs(adapter
);
2084 iavf_free_all_tx_resources(adapter
);
2085 iavf_free_all_rx_resources(adapter
);
2088 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
2090 /* Delete all of the filters */
2091 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2096 list_for_each_entry_safe(fv
, fvtmp
, &adapter
->vlan_filter_list
, list
) {
2097 list_del(&fv
->list
);
2101 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
2103 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2104 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
, list
) {
2105 list_del(&cf
->list
);
2107 adapter
->num_cloud_filters
--;
2109 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2111 iavf_free_misc_irq(adapter
);
2112 iavf_reset_interrupt_capability(adapter
);
2113 iavf_free_q_vectors(adapter
);
2114 iavf_free_queues(adapter
);
2115 memset(adapter
->vf_res
, 0, IAVF_VIRTCHNL_VF_RESOURCE_SIZE
);
2116 iavf_shutdown_adminq(&adapter
->hw
);
2117 adapter
->netdev
->flags
&= ~IFF_UP
;
2118 mutex_unlock(&adapter
->crit_lock
);
2119 adapter
->flags
&= ~IAVF_FLAG_RESET_PENDING
;
2120 iavf_change_state(adapter
, __IAVF_DOWN
);
2121 wake_up(&adapter
->down_waitqueue
);
2122 dev_info(&adapter
->pdev
->dev
, "Reset task did not complete, VF disabled\n");
2126 * iavf_reset_task - Call-back task to handle hardware reset
2127 * @work: pointer to work_struct
2129 * During reset we need to shut down and reinitialize the admin queue
2130 * before we can use it to communicate with the PF again. We also clear
2131 * and reinit the rings because that context is lost as well.
2133 static void iavf_reset_task(struct work_struct
*work
)
2135 struct iavf_adapter
*adapter
= container_of(work
,
2136 struct iavf_adapter
,
2138 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
2139 struct net_device
*netdev
= adapter
->netdev
;
2140 struct iavf_hw
*hw
= &adapter
->hw
;
2141 struct iavf_mac_filter
*f
, *ftmp
;
2142 struct iavf_cloud_filter
*cf
;
2147 /* When device is being removed it doesn't make sense to run the reset
2148 * task, just return in such a case.
2150 if (mutex_is_locked(&adapter
->remove_lock
))
2153 if (iavf_lock_timeout(&adapter
->crit_lock
, 200)) {
2154 schedule_work(&adapter
->reset_task
);
2157 while (!mutex_trylock(&adapter
->client_lock
))
2158 usleep_range(500, 1000);
2159 if (CLIENT_ENABLED(adapter
)) {
2160 adapter
->flags
&= ~(IAVF_FLAG_CLIENT_NEEDS_OPEN
|
2161 IAVF_FLAG_CLIENT_NEEDS_CLOSE
|
2162 IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
|
2163 IAVF_FLAG_SERVICE_CLIENT_REQUESTED
);
2164 cancel_delayed_work_sync(&adapter
->client_task
);
2165 iavf_notify_client_close(&adapter
->vsi
, true);
2167 iavf_misc_irq_disable(adapter
);
2168 if (adapter
->flags
& IAVF_FLAG_RESET_NEEDED
) {
2169 adapter
->flags
&= ~IAVF_FLAG_RESET_NEEDED
;
2170 /* Restart the AQ here. If we have been reset but didn't
2171 * detect it, or if the PF had to reinit, our AQ will be hosed.
2173 iavf_shutdown_adminq(hw
);
2174 iavf_init_adminq(hw
);
2175 iavf_request_reset(adapter
);
2177 adapter
->flags
|= IAVF_FLAG_RESET_PENDING
;
2179 /* poll until we see the reset actually happen */
2180 for (i
= 0; i
< IAVF_RESET_WAIT_DETECTED_COUNT
; i
++) {
2181 reg_val
= rd32(hw
, IAVF_VF_ARQLEN1
) &
2182 IAVF_VF_ARQLEN1_ARQENABLE_MASK
;
2185 usleep_range(5000, 10000);
2187 if (i
== IAVF_RESET_WAIT_DETECTED_COUNT
) {
2188 dev_info(&adapter
->pdev
->dev
, "Never saw reset\n");
2189 goto continue_reset
; /* act like the reset happened */
2192 /* wait until the reset is complete and the PF is responding to us */
2193 for (i
= 0; i
< IAVF_RESET_WAIT_COMPLETE_COUNT
; i
++) {
2194 /* sleep first to make sure a minimum wait time is met */
2195 msleep(IAVF_RESET_WAIT_MS
);
2197 reg_val
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
2198 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
2199 if (reg_val
== VIRTCHNL_VFR_VFACTIVE
)
2203 pci_set_master(adapter
->pdev
);
2204 pci_restore_msi_state(adapter
->pdev
);
2206 if (i
== IAVF_RESET_WAIT_COMPLETE_COUNT
) {
2207 dev_err(&adapter
->pdev
->dev
, "Reset never finished (%x)\n",
2209 iavf_disable_vf(adapter
);
2210 mutex_unlock(&adapter
->client_lock
);
2211 mutex_unlock(&adapter
->crit_lock
);
2212 return; /* Do not attempt to reinit. It's dead, Jim. */
2216 /* We don't use netif_running() because it may be true prior to
2217 * ndo_open() returning, so we can't assume it means all our open
2218 * tasks have finished, since we're not holding the rtnl_lock here.
2220 running
= ((adapter
->state
== __IAVF_RUNNING
) ||
2221 (adapter
->state
== __IAVF_RESETTING
));
2224 netif_carrier_off(netdev
);
2225 netif_tx_stop_all_queues(netdev
);
2226 adapter
->link_up
= false;
2227 iavf_napi_disable_all(adapter
);
2229 iavf_irq_disable(adapter
);
2231 iavf_change_state(adapter
, __IAVF_RESETTING
);
2232 adapter
->flags
&= ~IAVF_FLAG_RESET_PENDING
;
2234 /* free the Tx/Rx rings and descriptors, might be better to just
2235 * re-use them sometime in the future
2237 iavf_free_all_rx_resources(adapter
);
2238 iavf_free_all_tx_resources(adapter
);
2240 adapter
->flags
|= IAVF_FLAG_QUEUES_DISABLED
;
2241 /* kill and reinit the admin queue */
2242 iavf_shutdown_adminq(hw
);
2243 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
2244 err
= iavf_init_adminq(hw
);
2246 dev_info(&adapter
->pdev
->dev
, "Failed to init adminq: %d\n",
2248 adapter
->aq_required
= 0;
2250 if (adapter
->flags
& IAVF_FLAG_REINIT_ITR_NEEDED
) {
2251 err
= iavf_reinit_interrupt_scheme(adapter
);
2256 if (RSS_AQ(adapter
)) {
2257 adapter
->aq_required
|= IAVF_FLAG_AQ_CONFIGURE_RSS
;
2259 err
= iavf_init_rss(adapter
);
2264 adapter
->aq_required
|= IAVF_FLAG_AQ_GET_CONFIG
;
2265 adapter
->aq_required
|= IAVF_FLAG_AQ_MAP_VECTORS
;
2267 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
2269 /* Delete filter for the current MAC address, it could have
2270 * been changed by the PF via administratively set MAC.
2271 * Will be re-added via VIRTCHNL_OP_GET_VF_RESOURCES.
2273 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2274 if (ether_addr_equal(f
->macaddr
, adapter
->hw
.mac
.addr
)) {
2279 /* re-add all MAC filters */
2280 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
2283 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
2285 /* check if TCs are running and re-add all cloud filters */
2286 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2287 if ((vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
) &&
2289 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
2293 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2295 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_MAC_FILTER
;
2296 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_CLOUD_FILTER
;
2297 iavf_misc_irq_enable(adapter
);
2299 mod_delayed_work(iavf_wq
, &adapter
->watchdog_task
, 2);
2301 /* We were running when the reset started, so we need to restore some
2305 /* allocate transmit descriptors */
2306 err
= iavf_setup_all_tx_resources(adapter
);
2310 /* allocate receive descriptors */
2311 err
= iavf_setup_all_rx_resources(adapter
);
2315 if (adapter
->flags
& IAVF_FLAG_REINIT_ITR_NEEDED
) {
2316 err
= iavf_request_traffic_irqs(adapter
, netdev
->name
);
2320 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
2323 iavf_configure(adapter
);
2325 /* iavf_up_complete() will switch device back
2328 iavf_up_complete(adapter
);
2330 iavf_irq_enable(adapter
, true);
2332 iavf_change_state(adapter
, __IAVF_DOWN
);
2333 wake_up(&adapter
->down_waitqueue
);
2335 mutex_unlock(&adapter
->client_lock
);
2336 mutex_unlock(&adapter
->crit_lock
);
2340 mutex_unlock(&adapter
->client_lock
);
2341 mutex_unlock(&adapter
->crit_lock
);
2342 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit\n");
2347 * iavf_adminq_task - worker thread to clean the admin queue
2348 * @work: pointer to work_struct containing our data
2350 static void iavf_adminq_task(struct work_struct
*work
)
2352 struct iavf_adapter
*adapter
=
2353 container_of(work
, struct iavf_adapter
, adminq_task
);
2354 struct iavf_hw
*hw
= &adapter
->hw
;
2355 struct iavf_arq_event_info event
;
2356 enum virtchnl_ops v_op
;
2357 enum iavf_status ret
, v_ret
;
2361 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
)
2364 event
.buf_len
= IAVF_MAX_AQ_BUF_SIZE
;
2365 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
2369 if (iavf_lock_timeout(&adapter
->crit_lock
, 200))
2372 ret
= iavf_clean_arq_element(hw
, &event
, &pending
);
2373 v_op
= (enum virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
2374 v_ret
= (enum iavf_status
)le32_to_cpu(event
.desc
.cookie_low
);
2377 break; /* No event to process or error cleaning ARQ */
2379 iavf_virtchnl_completion(adapter
, v_op
, v_ret
, event
.msg_buf
,
2382 memset(event
.msg_buf
, 0, IAVF_MAX_AQ_BUF_SIZE
);
2384 mutex_unlock(&adapter
->crit_lock
);
2386 if ((adapter
->flags
&
2387 (IAVF_FLAG_RESET_PENDING
| IAVF_FLAG_RESET_NEEDED
)) ||
2388 adapter
->state
== __IAVF_RESETTING
)
2391 /* check for error indications */
2392 val
= rd32(hw
, hw
->aq
.arq
.len
);
2393 if (val
== 0xdeadbeef || val
== 0xffffffff) /* device in reset */
2396 if (val
& IAVF_VF_ARQLEN1_ARQVFE_MASK
) {
2397 dev_info(&adapter
->pdev
->dev
, "ARQ VF Error detected\n");
2398 val
&= ~IAVF_VF_ARQLEN1_ARQVFE_MASK
;
2400 if (val
& IAVF_VF_ARQLEN1_ARQOVFL_MASK
) {
2401 dev_info(&adapter
->pdev
->dev
, "ARQ Overflow Error detected\n");
2402 val
&= ~IAVF_VF_ARQLEN1_ARQOVFL_MASK
;
2404 if (val
& IAVF_VF_ARQLEN1_ARQCRIT_MASK
) {
2405 dev_info(&adapter
->pdev
->dev
, "ARQ Critical Error detected\n");
2406 val
&= ~IAVF_VF_ARQLEN1_ARQCRIT_MASK
;
2409 wr32(hw
, hw
->aq
.arq
.len
, val
);
2411 val
= rd32(hw
, hw
->aq
.asq
.len
);
2413 if (val
& IAVF_VF_ATQLEN1_ATQVFE_MASK
) {
2414 dev_info(&adapter
->pdev
->dev
, "ASQ VF Error detected\n");
2415 val
&= ~IAVF_VF_ATQLEN1_ATQVFE_MASK
;
2417 if (val
& IAVF_VF_ATQLEN1_ATQOVFL_MASK
) {
2418 dev_info(&adapter
->pdev
->dev
, "ASQ Overflow Error detected\n");
2419 val
&= ~IAVF_VF_ATQLEN1_ATQOVFL_MASK
;
2421 if (val
& IAVF_VF_ATQLEN1_ATQCRIT_MASK
) {
2422 dev_info(&adapter
->pdev
->dev
, "ASQ Critical Error detected\n");
2423 val
&= ~IAVF_VF_ATQLEN1_ATQCRIT_MASK
;
2426 wr32(hw
, hw
->aq
.asq
.len
, val
);
2429 kfree(event
.msg_buf
);
2431 /* re-enable Admin queue interrupt cause */
2432 iavf_misc_irq_enable(adapter
);
2436 * iavf_client_task - worker thread to perform client work
2437 * @work: pointer to work_struct containing our data
2439 * This task handles client interactions. Because client calls can be
2440 * reentrant, we can't handle them in the watchdog.
2442 static void iavf_client_task(struct work_struct
*work
)
2444 struct iavf_adapter
*adapter
=
2445 container_of(work
, struct iavf_adapter
, client_task
.work
);
2447 /* If we can't get the client bit, just give up. We'll be rescheduled
2451 if (!mutex_trylock(&adapter
->client_lock
))
2454 if (adapter
->flags
& IAVF_FLAG_SERVICE_CLIENT_REQUESTED
) {
2455 iavf_client_subtask(adapter
);
2456 adapter
->flags
&= ~IAVF_FLAG_SERVICE_CLIENT_REQUESTED
;
2459 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
) {
2460 iavf_notify_client_l2_params(&adapter
->vsi
);
2461 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
;
2464 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_CLOSE
) {
2465 iavf_notify_client_close(&adapter
->vsi
, false);
2466 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_CLOSE
;
2469 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_OPEN
) {
2470 iavf_notify_client_open(&adapter
->vsi
);
2471 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_OPEN
;
2474 mutex_unlock(&adapter
->client_lock
);
2478 * iavf_free_all_tx_resources - Free Tx Resources for All Queues
2479 * @adapter: board private structure
2481 * Free all transmit software resources
2483 void iavf_free_all_tx_resources(struct iavf_adapter
*adapter
)
2487 if (!adapter
->tx_rings
)
2490 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2491 if (adapter
->tx_rings
[i
].desc
)
2492 iavf_free_tx_resources(&adapter
->tx_rings
[i
]);
2496 * iavf_setup_all_tx_resources - allocate all queues Tx resources
2497 * @adapter: board private structure
2499 * If this function returns with an error, then it's possible one or
2500 * more of the rings is populated (while the rest are not). It is the
2501 * callers duty to clean those orphaned rings.
2503 * Return 0 on success, negative on failure
2505 static int iavf_setup_all_tx_resources(struct iavf_adapter
*adapter
)
2509 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2510 adapter
->tx_rings
[i
].count
= adapter
->tx_desc_count
;
2511 err
= iavf_setup_tx_descriptors(&adapter
->tx_rings
[i
]);
2514 dev_err(&adapter
->pdev
->dev
,
2515 "Allocation for Tx Queue %u failed\n", i
);
2523 * iavf_setup_all_rx_resources - allocate all queues Rx resources
2524 * @adapter: board private structure
2526 * If this function returns with an error, then it's possible one or
2527 * more of the rings is populated (while the rest are not). It is the
2528 * callers duty to clean those orphaned rings.
2530 * Return 0 on success, negative on failure
2532 static int iavf_setup_all_rx_resources(struct iavf_adapter
*adapter
)
2536 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2537 adapter
->rx_rings
[i
].count
= adapter
->rx_desc_count
;
2538 err
= iavf_setup_rx_descriptors(&adapter
->rx_rings
[i
]);
2541 dev_err(&adapter
->pdev
->dev
,
2542 "Allocation for Rx Queue %u failed\n", i
);
2549 * iavf_free_all_rx_resources - Free Rx Resources for All Queues
2550 * @adapter: board private structure
2552 * Free all receive software resources
2554 void iavf_free_all_rx_resources(struct iavf_adapter
*adapter
)
2558 if (!adapter
->rx_rings
)
2561 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2562 if (adapter
->rx_rings
[i
].desc
)
2563 iavf_free_rx_resources(&adapter
->rx_rings
[i
]);
2567 * iavf_validate_tx_bandwidth - validate the max Tx bandwidth
2568 * @adapter: board private structure
2569 * @max_tx_rate: max Tx bw for a tc
2571 static int iavf_validate_tx_bandwidth(struct iavf_adapter
*adapter
,
2574 int speed
= 0, ret
= 0;
2576 if (ADV_LINK_SUPPORT(adapter
)) {
2577 if (adapter
->link_speed_mbps
< U32_MAX
) {
2578 speed
= adapter
->link_speed_mbps
;
2581 dev_err(&adapter
->pdev
->dev
, "Unknown link speed\n");
2586 switch (adapter
->link_speed
) {
2587 case VIRTCHNL_LINK_SPEED_40GB
:
2588 speed
= SPEED_40000
;
2590 case VIRTCHNL_LINK_SPEED_25GB
:
2591 speed
= SPEED_25000
;
2593 case VIRTCHNL_LINK_SPEED_20GB
:
2594 speed
= SPEED_20000
;
2596 case VIRTCHNL_LINK_SPEED_10GB
:
2597 speed
= SPEED_10000
;
2599 case VIRTCHNL_LINK_SPEED_5GB
:
2602 case VIRTCHNL_LINK_SPEED_2_5GB
:
2605 case VIRTCHNL_LINK_SPEED_1GB
:
2608 case VIRTCHNL_LINK_SPEED_100MB
:
2616 if (max_tx_rate
> speed
) {
2617 dev_err(&adapter
->pdev
->dev
,
2618 "Invalid tx rate specified\n");
2626 * iavf_validate_ch_config - validate queue mapping info
2627 * @adapter: board private structure
2628 * @mqprio_qopt: queue parameters
2630 * This function validates if the config provided by the user to
2631 * configure queue channels is valid or not. Returns 0 on a valid
2634 static int iavf_validate_ch_config(struct iavf_adapter
*adapter
,
2635 struct tc_mqprio_qopt_offload
*mqprio_qopt
)
2637 u64 total_max_rate
= 0;
2642 if (mqprio_qopt
->qopt
.num_tc
> IAVF_MAX_TRAFFIC_CLASS
||
2643 mqprio_qopt
->qopt
.num_tc
< 1)
2646 for (i
= 0; i
<= mqprio_qopt
->qopt
.num_tc
- 1; i
++) {
2647 if (!mqprio_qopt
->qopt
.count
[i
] ||
2648 mqprio_qopt
->qopt
.offset
[i
] != num_qps
)
2650 if (mqprio_qopt
->min_rate
[i
]) {
2651 dev_err(&adapter
->pdev
->dev
,
2652 "Invalid min tx rate (greater than 0) specified\n");
2655 /*convert to Mbps */
2656 tx_rate
= div_u64(mqprio_qopt
->max_rate
[i
],
2658 total_max_rate
+= tx_rate
;
2659 num_qps
+= mqprio_qopt
->qopt
.count
[i
];
2661 if (num_qps
> adapter
->num_active_queues
) {
2662 dev_err(&adapter
->pdev
->dev
,
2663 "Cannot support requested number of queues\n");
2667 ret
= iavf_validate_tx_bandwidth(adapter
, total_max_rate
);
2672 * iavf_del_all_cloud_filters - delete all cloud filters on the traffic classes
2673 * @adapter: board private structure
2675 static void iavf_del_all_cloud_filters(struct iavf_adapter
*adapter
)
2677 struct iavf_cloud_filter
*cf
, *cftmp
;
2679 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2680 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
,
2682 list_del(&cf
->list
);
2684 adapter
->num_cloud_filters
--;
2686 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2690 * __iavf_setup_tc - configure multiple traffic classes
2691 * @netdev: network interface device structure
2692 * @type_data: tc offload data
2694 * This function processes the config information provided by the
2695 * user to configure traffic classes/queue channels and packages the
2696 * information to request the PF to setup traffic classes.
2698 * Returns 0 on success.
2700 static int __iavf_setup_tc(struct net_device
*netdev
, void *type_data
)
2702 struct tc_mqprio_qopt_offload
*mqprio_qopt
= type_data
;
2703 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
2704 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
2705 u8 num_tc
= 0, total_qps
= 0;
2706 int ret
= 0, netdev_tc
= 0;
2711 num_tc
= mqprio_qopt
->qopt
.num_tc
;
2712 mode
= mqprio_qopt
->mode
;
2714 /* delete queue_channel */
2715 if (!mqprio_qopt
->qopt
.hw
) {
2716 if (adapter
->ch_config
.state
== __IAVF_TC_RUNNING
) {
2717 /* reset the tc configuration */
2718 netdev_reset_tc(netdev
);
2719 adapter
->num_tc
= 0;
2720 netif_tx_stop_all_queues(netdev
);
2721 netif_tx_disable(netdev
);
2722 iavf_del_all_cloud_filters(adapter
);
2723 adapter
->aq_required
= IAVF_FLAG_AQ_DISABLE_CHANNELS
;
2730 /* add queue channel */
2731 if (mode
== TC_MQPRIO_MODE_CHANNEL
) {
2732 if (!(vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
)) {
2733 dev_err(&adapter
->pdev
->dev
, "ADq not supported\n");
2736 if (adapter
->ch_config
.state
!= __IAVF_TC_INVALID
) {
2737 dev_err(&adapter
->pdev
->dev
, "TC configuration already exists\n");
2741 ret
= iavf_validate_ch_config(adapter
, mqprio_qopt
);
2744 /* Return if same TC config is requested */
2745 if (adapter
->num_tc
== num_tc
)
2747 adapter
->num_tc
= num_tc
;
2749 for (i
= 0; i
< IAVF_MAX_TRAFFIC_CLASS
; i
++) {
2751 adapter
->ch_config
.ch_info
[i
].count
=
2752 mqprio_qopt
->qopt
.count
[i
];
2753 adapter
->ch_config
.ch_info
[i
].offset
=
2754 mqprio_qopt
->qopt
.offset
[i
];
2755 total_qps
+= mqprio_qopt
->qopt
.count
[i
];
2756 max_tx_rate
= mqprio_qopt
->max_rate
[i
];
2757 /* convert to Mbps */
2758 max_tx_rate
= div_u64(max_tx_rate
,
2760 adapter
->ch_config
.ch_info
[i
].max_tx_rate
=
2763 adapter
->ch_config
.ch_info
[i
].count
= 1;
2764 adapter
->ch_config
.ch_info
[i
].offset
= 0;
2767 adapter
->ch_config
.total_qps
= total_qps
;
2768 netif_tx_stop_all_queues(netdev
);
2769 netif_tx_disable(netdev
);
2770 adapter
->aq_required
|= IAVF_FLAG_AQ_ENABLE_CHANNELS
;
2771 netdev_reset_tc(netdev
);
2772 /* Report the tc mapping up the stack */
2773 netdev_set_num_tc(adapter
->netdev
, num_tc
);
2774 for (i
= 0; i
< IAVF_MAX_TRAFFIC_CLASS
; i
++) {
2775 u16 qcount
= mqprio_qopt
->qopt
.count
[i
];
2776 u16 qoffset
= mqprio_qopt
->qopt
.offset
[i
];
2779 netdev_set_tc_queue(netdev
, netdev_tc
++, qcount
,
2788 * iavf_parse_cls_flower - Parse tc flower filters provided by kernel
2789 * @adapter: board private structure
2790 * @f: pointer to struct flow_cls_offload
2791 * @filter: pointer to cloud filter structure
2793 static int iavf_parse_cls_flower(struct iavf_adapter
*adapter
,
2794 struct flow_cls_offload
*f
,
2795 struct iavf_cloud_filter
*filter
)
2797 struct flow_rule
*rule
= flow_cls_offload_flow_rule(f
);
2798 struct flow_dissector
*dissector
= rule
->match
.dissector
;
2799 u16 n_proto_mask
= 0;
2800 u16 n_proto_key
= 0;
2805 struct virtchnl_filter
*vf
= &filter
->f
;
2807 if (dissector
->used_keys
&
2808 ~(BIT(FLOW_DISSECTOR_KEY_CONTROL
) |
2809 BIT(FLOW_DISSECTOR_KEY_BASIC
) |
2810 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS
) |
2811 BIT(FLOW_DISSECTOR_KEY_VLAN
) |
2812 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS
) |
2813 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS
) |
2814 BIT(FLOW_DISSECTOR_KEY_PORTS
) |
2815 BIT(FLOW_DISSECTOR_KEY_ENC_KEYID
))) {
2816 dev_err(&adapter
->pdev
->dev
, "Unsupported key used: 0x%x\n",
2817 dissector
->used_keys
);
2821 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_ENC_KEYID
)) {
2822 struct flow_match_enc_keyid match
;
2824 flow_rule_match_enc_keyid(rule
, &match
);
2825 if (match
.mask
->keyid
!= 0)
2826 field_flags
|= IAVF_CLOUD_FIELD_TEN_ID
;
2829 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_BASIC
)) {
2830 struct flow_match_basic match
;
2832 flow_rule_match_basic(rule
, &match
);
2833 n_proto_key
= ntohs(match
.key
->n_proto
);
2834 n_proto_mask
= ntohs(match
.mask
->n_proto
);
2836 if (n_proto_key
== ETH_P_ALL
) {
2840 n_proto
= n_proto_key
& n_proto_mask
;
2841 if (n_proto
!= ETH_P_IP
&& n_proto
!= ETH_P_IPV6
)
2843 if (n_proto
== ETH_P_IPV6
) {
2844 /* specify flow type as TCP IPv6 */
2845 vf
->flow_type
= VIRTCHNL_TCP_V6_FLOW
;
2848 if (match
.key
->ip_proto
!= IPPROTO_TCP
) {
2849 dev_info(&adapter
->pdev
->dev
, "Only TCP transport is supported\n");
2854 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_ETH_ADDRS
)) {
2855 struct flow_match_eth_addrs match
;
2857 flow_rule_match_eth_addrs(rule
, &match
);
2859 /* use is_broadcast and is_zero to check for all 0xf or 0 */
2860 if (!is_zero_ether_addr(match
.mask
->dst
)) {
2861 if (is_broadcast_ether_addr(match
.mask
->dst
)) {
2862 field_flags
|= IAVF_CLOUD_FIELD_OMAC
;
2864 dev_err(&adapter
->pdev
->dev
, "Bad ether dest mask %pM\n",
2866 return IAVF_ERR_CONFIG
;
2870 if (!is_zero_ether_addr(match
.mask
->src
)) {
2871 if (is_broadcast_ether_addr(match
.mask
->src
)) {
2872 field_flags
|= IAVF_CLOUD_FIELD_IMAC
;
2874 dev_err(&adapter
->pdev
->dev
, "Bad ether src mask %pM\n",
2876 return IAVF_ERR_CONFIG
;
2880 if (!is_zero_ether_addr(match
.key
->dst
))
2881 if (is_valid_ether_addr(match
.key
->dst
) ||
2882 is_multicast_ether_addr(match
.key
->dst
)) {
2883 /* set the mask if a valid dst_mac address */
2884 for (i
= 0; i
< ETH_ALEN
; i
++)
2885 vf
->mask
.tcp_spec
.dst_mac
[i
] |= 0xff;
2886 ether_addr_copy(vf
->data
.tcp_spec
.dst_mac
,
2890 if (!is_zero_ether_addr(match
.key
->src
))
2891 if (is_valid_ether_addr(match
.key
->src
) ||
2892 is_multicast_ether_addr(match
.key
->src
)) {
2893 /* set the mask if a valid dst_mac address */
2894 for (i
= 0; i
< ETH_ALEN
; i
++)
2895 vf
->mask
.tcp_spec
.src_mac
[i
] |= 0xff;
2896 ether_addr_copy(vf
->data
.tcp_spec
.src_mac
,
2901 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_VLAN
)) {
2902 struct flow_match_vlan match
;
2904 flow_rule_match_vlan(rule
, &match
);
2905 if (match
.mask
->vlan_id
) {
2906 if (match
.mask
->vlan_id
== VLAN_VID_MASK
) {
2907 field_flags
|= IAVF_CLOUD_FIELD_IVLAN
;
2909 dev_err(&adapter
->pdev
->dev
, "Bad vlan mask %u\n",
2910 match
.mask
->vlan_id
);
2911 return IAVF_ERR_CONFIG
;
2914 vf
->mask
.tcp_spec
.vlan_id
|= cpu_to_be16(0xffff);
2915 vf
->data
.tcp_spec
.vlan_id
= cpu_to_be16(match
.key
->vlan_id
);
2918 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_CONTROL
)) {
2919 struct flow_match_control match
;
2921 flow_rule_match_control(rule
, &match
);
2922 addr_type
= match
.key
->addr_type
;
2925 if (addr_type
== FLOW_DISSECTOR_KEY_IPV4_ADDRS
) {
2926 struct flow_match_ipv4_addrs match
;
2928 flow_rule_match_ipv4_addrs(rule
, &match
);
2929 if (match
.mask
->dst
) {
2930 if (match
.mask
->dst
== cpu_to_be32(0xffffffff)) {
2931 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2933 dev_err(&adapter
->pdev
->dev
, "Bad ip dst mask 0x%08x\n",
2934 be32_to_cpu(match
.mask
->dst
));
2935 return IAVF_ERR_CONFIG
;
2939 if (match
.mask
->src
) {
2940 if (match
.mask
->src
== cpu_to_be32(0xffffffff)) {
2941 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2943 dev_err(&adapter
->pdev
->dev
, "Bad ip src mask 0x%08x\n",
2944 be32_to_cpu(match
.mask
->dst
));
2945 return IAVF_ERR_CONFIG
;
2949 if (field_flags
& IAVF_CLOUD_FIELD_TEN_ID
) {
2950 dev_info(&adapter
->pdev
->dev
, "Tenant id not allowed for ip filter\n");
2951 return IAVF_ERR_CONFIG
;
2953 if (match
.key
->dst
) {
2954 vf
->mask
.tcp_spec
.dst_ip
[0] |= cpu_to_be32(0xffffffff);
2955 vf
->data
.tcp_spec
.dst_ip
[0] = match
.key
->dst
;
2957 if (match
.key
->src
) {
2958 vf
->mask
.tcp_spec
.src_ip
[0] |= cpu_to_be32(0xffffffff);
2959 vf
->data
.tcp_spec
.src_ip
[0] = match
.key
->src
;
2963 if (addr_type
== FLOW_DISSECTOR_KEY_IPV6_ADDRS
) {
2964 struct flow_match_ipv6_addrs match
;
2966 flow_rule_match_ipv6_addrs(rule
, &match
);
2968 /* validate mask, make sure it is not IPV6_ADDR_ANY */
2969 if (ipv6_addr_any(&match
.mask
->dst
)) {
2970 dev_err(&adapter
->pdev
->dev
, "Bad ipv6 dst mask 0x%02x\n",
2972 return IAVF_ERR_CONFIG
;
2975 /* src and dest IPv6 address should not be LOOPBACK
2976 * (0:0:0:0:0:0:0:1) which can be represented as ::1
2978 if (ipv6_addr_loopback(&match
.key
->dst
) ||
2979 ipv6_addr_loopback(&match
.key
->src
)) {
2980 dev_err(&adapter
->pdev
->dev
,
2981 "ipv6 addr should not be loopback\n");
2982 return IAVF_ERR_CONFIG
;
2984 if (!ipv6_addr_any(&match
.mask
->dst
) ||
2985 !ipv6_addr_any(&match
.mask
->src
))
2986 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2988 for (i
= 0; i
< 4; i
++)
2989 vf
->mask
.tcp_spec
.dst_ip
[i
] |= cpu_to_be32(0xffffffff);
2990 memcpy(&vf
->data
.tcp_spec
.dst_ip
, &match
.key
->dst
.s6_addr32
,
2991 sizeof(vf
->data
.tcp_spec
.dst_ip
));
2992 for (i
= 0; i
< 4; i
++)
2993 vf
->mask
.tcp_spec
.src_ip
[i
] |= cpu_to_be32(0xffffffff);
2994 memcpy(&vf
->data
.tcp_spec
.src_ip
, &match
.key
->src
.s6_addr32
,
2995 sizeof(vf
->data
.tcp_spec
.src_ip
));
2997 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_PORTS
)) {
2998 struct flow_match_ports match
;
3000 flow_rule_match_ports(rule
, &match
);
3001 if (match
.mask
->src
) {
3002 if (match
.mask
->src
== cpu_to_be16(0xffff)) {
3003 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
3005 dev_err(&adapter
->pdev
->dev
, "Bad src port mask %u\n",
3006 be16_to_cpu(match
.mask
->src
));
3007 return IAVF_ERR_CONFIG
;
3011 if (match
.mask
->dst
) {
3012 if (match
.mask
->dst
== cpu_to_be16(0xffff)) {
3013 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
3015 dev_err(&adapter
->pdev
->dev
, "Bad dst port mask %u\n",
3016 be16_to_cpu(match
.mask
->dst
));
3017 return IAVF_ERR_CONFIG
;
3020 if (match
.key
->dst
) {
3021 vf
->mask
.tcp_spec
.dst_port
|= cpu_to_be16(0xffff);
3022 vf
->data
.tcp_spec
.dst_port
= match
.key
->dst
;
3025 if (match
.key
->src
) {
3026 vf
->mask
.tcp_spec
.src_port
|= cpu_to_be16(0xffff);
3027 vf
->data
.tcp_spec
.src_port
= match
.key
->src
;
3030 vf
->field_flags
= field_flags
;
3036 * iavf_handle_tclass - Forward to a traffic class on the device
3037 * @adapter: board private structure
3038 * @tc: traffic class index on the device
3039 * @filter: pointer to cloud filter structure
3041 static int iavf_handle_tclass(struct iavf_adapter
*adapter
, u32 tc
,
3042 struct iavf_cloud_filter
*filter
)
3046 if (tc
< adapter
->num_tc
) {
3047 if (!filter
->f
.data
.tcp_spec
.dst_port
) {
3048 dev_err(&adapter
->pdev
->dev
,
3049 "Specify destination port to redirect to traffic class other than TC0\n");
3053 /* redirect to a traffic class on the same device */
3054 filter
->f
.action
= VIRTCHNL_ACTION_TC_REDIRECT
;
3055 filter
->f
.action_meta
= tc
;
3060 * iavf_configure_clsflower - Add tc flower filters
3061 * @adapter: board private structure
3062 * @cls_flower: Pointer to struct flow_cls_offload
3064 static int iavf_configure_clsflower(struct iavf_adapter
*adapter
,
3065 struct flow_cls_offload
*cls_flower
)
3067 int tc
= tc_classid_to_hwtc(adapter
->netdev
, cls_flower
->classid
);
3068 struct iavf_cloud_filter
*filter
= NULL
;
3069 int err
= -EINVAL
, count
= 50;
3072 dev_err(&adapter
->pdev
->dev
, "Invalid traffic class\n");
3076 filter
= kzalloc(sizeof(*filter
), GFP_KERNEL
);
3080 while (!mutex_trylock(&adapter
->crit_lock
)) {
3088 filter
->cookie
= cls_flower
->cookie
;
3090 /* set the mask to all zeroes to begin with */
3091 memset(&filter
->f
.mask
.tcp_spec
, 0, sizeof(struct virtchnl_l4_spec
));
3092 /* start out with flow type and eth type IPv4 to begin with */
3093 filter
->f
.flow_type
= VIRTCHNL_TCP_V4_FLOW
;
3094 err
= iavf_parse_cls_flower(adapter
, cls_flower
, filter
);
3098 err
= iavf_handle_tclass(adapter
, tc
, filter
);
3102 /* add filter to the list */
3103 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
3104 list_add_tail(&filter
->list
, &adapter
->cloud_filter_list
);
3105 adapter
->num_cloud_filters
++;
3107 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_CLOUD_FILTER
;
3108 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
3113 mutex_unlock(&adapter
->crit_lock
);
3117 /* iavf_find_cf - Find the cloud filter in the list
3118 * @adapter: Board private structure
3119 * @cookie: filter specific cookie
3121 * Returns ptr to the filter object or NULL. Must be called while holding the
3122 * cloud_filter_list_lock.
3124 static struct iavf_cloud_filter
*iavf_find_cf(struct iavf_adapter
*adapter
,
3125 unsigned long *cookie
)
3127 struct iavf_cloud_filter
*filter
= NULL
;
3132 list_for_each_entry(filter
, &adapter
->cloud_filter_list
, list
) {
3133 if (!memcmp(cookie
, &filter
->cookie
, sizeof(filter
->cookie
)))
3140 * iavf_delete_clsflower - Remove tc flower filters
3141 * @adapter: board private structure
3142 * @cls_flower: Pointer to struct flow_cls_offload
3144 static int iavf_delete_clsflower(struct iavf_adapter
*adapter
,
3145 struct flow_cls_offload
*cls_flower
)
3147 struct iavf_cloud_filter
*filter
= NULL
;
3150 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
3151 filter
= iavf_find_cf(adapter
, &cls_flower
->cookie
);
3154 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_CLOUD_FILTER
;
3158 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
3164 * iavf_setup_tc_cls_flower - flower classifier offloads
3165 * @adapter: board private structure
3166 * @cls_flower: pointer to flow_cls_offload struct with flow info
3168 static int iavf_setup_tc_cls_flower(struct iavf_adapter
*adapter
,
3169 struct flow_cls_offload
*cls_flower
)
3171 switch (cls_flower
->command
) {
3172 case FLOW_CLS_REPLACE
:
3173 return iavf_configure_clsflower(adapter
, cls_flower
);
3174 case FLOW_CLS_DESTROY
:
3175 return iavf_delete_clsflower(adapter
, cls_flower
);
3176 case FLOW_CLS_STATS
:
3184 * iavf_setup_tc_block_cb - block callback for tc
3185 * @type: type of offload
3186 * @type_data: offload data
3189 * This function is the block callback for traffic classes
3191 static int iavf_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
3194 struct iavf_adapter
*adapter
= cb_priv
;
3196 if (!tc_cls_can_offload_and_chain0(adapter
->netdev
, type_data
))
3200 case TC_SETUP_CLSFLOWER
:
3201 return iavf_setup_tc_cls_flower(cb_priv
, type_data
);
3207 static LIST_HEAD(iavf_block_cb_list
);
3210 * iavf_setup_tc - configure multiple traffic classes
3211 * @netdev: network interface device structure
3212 * @type: type of offload
3213 * @type_data: tc offload data
3215 * This function is the callback to ndo_setup_tc in the
3218 * Returns 0 on success
3220 static int iavf_setup_tc(struct net_device
*netdev
, enum tc_setup_type type
,
3223 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3226 case TC_SETUP_QDISC_MQPRIO
:
3227 return __iavf_setup_tc(netdev
, type_data
);
3228 case TC_SETUP_BLOCK
:
3229 return flow_block_cb_setup_simple(type_data
,
3230 &iavf_block_cb_list
,
3231 iavf_setup_tc_block_cb
,
3232 adapter
, adapter
, true);
3239 * iavf_open - Called when a network interface is made active
3240 * @netdev: network interface device structure
3242 * Returns 0 on success, negative value on failure
3244 * The open entry point is called when a network interface is made
3245 * active by the system (IFF_UP). At this point all resources needed
3246 * for transmit and receive operations are allocated, the interrupt
3247 * handler is registered with the OS, the watchdog is started,
3248 * and the stack is notified that the interface is ready.
3250 static int iavf_open(struct net_device
*netdev
)
3252 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3255 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
) {
3256 dev_err(&adapter
->pdev
->dev
, "Unable to open device due to PF driver failure.\n");
3260 while (!mutex_trylock(&adapter
->crit_lock
))
3261 usleep_range(500, 1000);
3263 if (adapter
->state
!= __IAVF_DOWN
) {
3268 /* allocate transmit descriptors */
3269 err
= iavf_setup_all_tx_resources(adapter
);
3273 /* allocate receive descriptors */
3274 err
= iavf_setup_all_rx_resources(adapter
);
3278 /* clear any pending interrupts, may auto mask */
3279 err
= iavf_request_traffic_irqs(adapter
, netdev
->name
);
3283 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
3285 iavf_add_filter(adapter
, adapter
->hw
.mac
.addr
);
3287 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
3289 /* Restore VLAN filters that were removed with IFF_DOWN */
3290 iavf_restore_filters(adapter
);
3292 iavf_configure(adapter
);
3294 iavf_up_complete(adapter
);
3296 iavf_irq_enable(adapter
, true);
3298 mutex_unlock(&adapter
->crit_lock
);
3304 iavf_free_traffic_irqs(adapter
);
3306 iavf_free_all_rx_resources(adapter
);
3308 iavf_free_all_tx_resources(adapter
);
3310 mutex_unlock(&adapter
->crit_lock
);
3316 * iavf_close - Disables a network interface
3317 * @netdev: network interface device structure
3319 * Returns 0, this is not allowed to fail
3321 * The close entry point is called when an interface is de-activated
3322 * by the OS. The hardware is still under the drivers control, but
3323 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
3324 * are freed, along with all transmit and receive resources.
3326 static int iavf_close(struct net_device
*netdev
)
3328 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3331 if (adapter
->state
<= __IAVF_DOWN_PENDING
)
3334 while (!mutex_trylock(&adapter
->crit_lock
))
3335 usleep_range(500, 1000);
3337 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
3338 if (CLIENT_ENABLED(adapter
))
3339 adapter
->flags
|= IAVF_FLAG_CLIENT_NEEDS_CLOSE
;
3342 iavf_change_state(adapter
, __IAVF_DOWN_PENDING
);
3343 iavf_free_traffic_irqs(adapter
);
3345 mutex_unlock(&adapter
->crit_lock
);
3347 /* We explicitly don't free resources here because the hardware is
3348 * still active and can DMA into memory. Resources are cleared in
3349 * iavf_virtchnl_completion() after we get confirmation from the PF
3350 * driver that the rings have been stopped.
3352 * Also, we wait for state to transition to __IAVF_DOWN before
3353 * returning. State change occurs in iavf_virtchnl_completion() after
3354 * VF resources are released (which occurs after PF driver processes and
3355 * responds to admin queue commands).
3358 status
= wait_event_timeout(adapter
->down_waitqueue
,
3359 adapter
->state
== __IAVF_DOWN
,
3360 msecs_to_jiffies(500));
3362 netdev_warn(netdev
, "Device resources not yet released\n");
3367 * iavf_change_mtu - Change the Maximum Transfer Unit
3368 * @netdev: network interface device structure
3369 * @new_mtu: new value for maximum frame size
3371 * Returns 0 on success, negative on failure
3373 static int iavf_change_mtu(struct net_device
*netdev
, int new_mtu
)
3375 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3377 netdev
->mtu
= new_mtu
;
3378 if (CLIENT_ENABLED(adapter
)) {
3379 iavf_notify_client_l2_params(&adapter
->vsi
);
3380 adapter
->flags
|= IAVF_FLAG_SERVICE_CLIENT_REQUESTED
;
3383 if (netif_running(netdev
)) {
3384 adapter
->flags
|= IAVF_FLAG_RESET_NEEDED
;
3385 queue_work(iavf_wq
, &adapter
->reset_task
);
3392 * iavf_set_features - set the netdev feature flags
3393 * @netdev: ptr to the netdev being adjusted
3394 * @features: the feature set that the stack is suggesting
3395 * Note: expects to be called while under rtnl_lock()
3397 static int iavf_set_features(struct net_device
*netdev
,
3398 netdev_features_t features
)
3400 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3402 /* Don't allow enabling VLAN features when adapter is not capable
3403 * of VLAN offload/filtering
3405 if (!VLAN_ALLOWED(adapter
)) {
3406 netdev
->hw_features
&= ~(NETIF_F_HW_VLAN_CTAG_RX
|
3407 NETIF_F_HW_VLAN_CTAG_TX
|
3408 NETIF_F_HW_VLAN_CTAG_FILTER
);
3409 if (features
& (NETIF_F_HW_VLAN_CTAG_RX
|
3410 NETIF_F_HW_VLAN_CTAG_TX
|
3411 NETIF_F_HW_VLAN_CTAG_FILTER
))
3413 } else if ((netdev
->features
^ features
) & NETIF_F_HW_VLAN_CTAG_RX
) {
3414 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
3415 adapter
->aq_required
|=
3416 IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING
;
3418 adapter
->aq_required
|=
3419 IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING
;
3426 * iavf_features_check - Validate encapsulated packet conforms to limits
3428 * @dev: This physical port's netdev
3429 * @features: Offload features that the stack believes apply
3431 static netdev_features_t
iavf_features_check(struct sk_buff
*skb
,
3432 struct net_device
*dev
,
3433 netdev_features_t features
)
3437 /* No point in doing any of this if neither checksum nor GSO are
3438 * being requested for this frame. We can rule out both by just
3439 * checking for CHECKSUM_PARTIAL
3441 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
3444 /* We cannot support GSO if the MSS is going to be less than
3445 * 64 bytes. If it is then we need to drop support for GSO.
3447 if (skb_is_gso(skb
) && (skb_shinfo(skb
)->gso_size
< 64))
3448 features
&= ~NETIF_F_GSO_MASK
;
3450 /* MACLEN can support at most 63 words */
3451 len
= skb_network_header(skb
) - skb
->data
;
3452 if (len
& ~(63 * 2))
3455 /* IPLEN and EIPLEN can support at most 127 dwords */
3456 len
= skb_transport_header(skb
) - skb_network_header(skb
);
3457 if (len
& ~(127 * 4))
3460 if (skb
->encapsulation
) {
3461 /* L4TUNLEN can support 127 words */
3462 len
= skb_inner_network_header(skb
) - skb_transport_header(skb
);
3463 if (len
& ~(127 * 2))
3466 /* IPLEN can support at most 127 dwords */
3467 len
= skb_inner_transport_header(skb
) -
3468 skb_inner_network_header(skb
);
3469 if (len
& ~(127 * 4))
3473 /* No need to validate L4LEN as TCP is the only protocol with a
3474 * a flexible value and we support all possible values supported
3475 * by TCP, which is at most 15 dwords
3480 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
3484 * iavf_fix_features - fix up the netdev feature bits
3485 * @netdev: our net device
3486 * @features: desired feature bits
3488 * Returns fixed-up features bits
3490 static netdev_features_t
iavf_fix_features(struct net_device
*netdev
,
3491 netdev_features_t features
)
3493 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3495 if (adapter
->vf_res
&&
3496 !(adapter
->vf_res
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
))
3497 features
&= ~(NETIF_F_HW_VLAN_CTAG_TX
|
3498 NETIF_F_HW_VLAN_CTAG_RX
|
3499 NETIF_F_HW_VLAN_CTAG_FILTER
);
3504 static const struct net_device_ops iavf_netdev_ops
= {
3505 .ndo_open
= iavf_open
,
3506 .ndo_stop
= iavf_close
,
3507 .ndo_start_xmit
= iavf_xmit_frame
,
3508 .ndo_set_rx_mode
= iavf_set_rx_mode
,
3509 .ndo_validate_addr
= eth_validate_addr
,
3510 .ndo_set_mac_address
= iavf_set_mac
,
3511 .ndo_change_mtu
= iavf_change_mtu
,
3512 .ndo_tx_timeout
= iavf_tx_timeout
,
3513 .ndo_vlan_rx_add_vid
= iavf_vlan_rx_add_vid
,
3514 .ndo_vlan_rx_kill_vid
= iavf_vlan_rx_kill_vid
,
3515 .ndo_features_check
= iavf_features_check
,
3516 .ndo_fix_features
= iavf_fix_features
,
3517 .ndo_set_features
= iavf_set_features
,
3518 .ndo_setup_tc
= iavf_setup_tc
,
3522 * iavf_check_reset_complete - check that VF reset is complete
3523 * @hw: pointer to hw struct
3525 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
3527 static int iavf_check_reset_complete(struct iavf_hw
*hw
)
3532 for (i
= 0; i
< IAVF_RESET_WAIT_COMPLETE_COUNT
; i
++) {
3533 rstat
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
3534 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
3535 if ((rstat
== VIRTCHNL_VFR_VFACTIVE
) ||
3536 (rstat
== VIRTCHNL_VFR_COMPLETED
))
3538 usleep_range(10, 20);
3544 * iavf_process_config - Process the config information we got from the PF
3545 * @adapter: board private structure
3547 * Verify that we have a valid config struct, and set up our netdev features
3548 * and our VSI struct.
3550 int iavf_process_config(struct iavf_adapter
*adapter
)
3552 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
3553 int i
, num_req_queues
= adapter
->num_req_queues
;
3554 struct net_device
*netdev
= adapter
->netdev
;
3555 struct iavf_vsi
*vsi
= &adapter
->vsi
;
3556 netdev_features_t hw_enc_features
;
3557 netdev_features_t hw_features
;
3559 /* got VF config message back from PF, now we can parse it */
3560 for (i
= 0; i
< vfres
->num_vsis
; i
++) {
3561 if (vfres
->vsi_res
[i
].vsi_type
== VIRTCHNL_VSI_SRIOV
)
3562 adapter
->vsi_res
= &vfres
->vsi_res
[i
];
3564 if (!adapter
->vsi_res
) {
3565 dev_err(&adapter
->pdev
->dev
, "No LAN VSI found\n");
3569 if (num_req_queues
&&
3570 num_req_queues
> adapter
->vsi_res
->num_queue_pairs
) {
3571 /* Problem. The PF gave us fewer queues than what we had
3572 * negotiated in our request. Need a reset to see if we can't
3573 * get back to a working state.
3575 dev_err(&adapter
->pdev
->dev
,
3576 "Requested %d queues, but PF only gave us %d.\n",
3578 adapter
->vsi_res
->num_queue_pairs
);
3579 adapter
->flags
|= IAVF_FLAG_REINIT_ITR_NEEDED
;
3580 adapter
->num_req_queues
= adapter
->vsi_res
->num_queue_pairs
;
3581 iavf_schedule_reset(adapter
);
3584 adapter
->num_req_queues
= 0;
3586 hw_enc_features
= NETIF_F_SG
|
3590 NETIF_F_SOFT_FEATURES
|
3599 /* advertise to stack only if offloads for encapsulated packets is
3602 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ENCAP
) {
3603 hw_enc_features
|= NETIF_F_GSO_UDP_TUNNEL
|
3605 NETIF_F_GSO_GRE_CSUM
|
3606 NETIF_F_GSO_IPXIP4
|
3607 NETIF_F_GSO_IPXIP6
|
3608 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
3609 NETIF_F_GSO_PARTIAL
|
3612 if (!(vfres
->vf_cap_flags
&
3613 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
))
3614 netdev
->gso_partial_features
|=
3615 NETIF_F_GSO_UDP_TUNNEL_CSUM
;
3617 netdev
->gso_partial_features
|= NETIF_F_GSO_GRE_CSUM
;
3618 netdev
->hw_enc_features
|= NETIF_F_TSO_MANGLEID
;
3619 netdev
->hw_enc_features
|= hw_enc_features
;
3621 /* record features VLANs can make use of */
3622 netdev
->vlan_features
|= hw_enc_features
| NETIF_F_TSO_MANGLEID
;
3624 /* Write features and hw_features separately to avoid polluting
3625 * with, or dropping, features that are set when we registered.
3627 hw_features
= hw_enc_features
;
3629 /* Enable VLAN features if supported */
3630 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
)
3631 hw_features
|= (NETIF_F_HW_VLAN_CTAG_TX
|
3632 NETIF_F_HW_VLAN_CTAG_RX
);
3633 /* Enable cloud filter if ADQ is supported */
3634 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
)
3635 hw_features
|= NETIF_F_HW_TC
;
3636 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_USO
)
3637 hw_features
|= NETIF_F_GSO_UDP_L4
;
3639 netdev
->hw_features
|= hw_features
;
3641 netdev
->features
|= hw_features
;
3643 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
)
3644 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
3646 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
3648 /* Do not turn on offloads when they are requested to be turned off.
3649 * TSO needs minimum 576 bytes to work correctly.
3651 if (netdev
->wanted_features
) {
3652 if (!(netdev
->wanted_features
& NETIF_F_TSO
) ||
3654 netdev
->features
&= ~NETIF_F_TSO
;
3655 if (!(netdev
->wanted_features
& NETIF_F_TSO6
) ||
3657 netdev
->features
&= ~NETIF_F_TSO6
;
3658 if (!(netdev
->wanted_features
& NETIF_F_TSO_ECN
))
3659 netdev
->features
&= ~NETIF_F_TSO_ECN
;
3660 if (!(netdev
->wanted_features
& NETIF_F_GRO
))
3661 netdev
->features
&= ~NETIF_F_GRO
;
3662 if (!(netdev
->wanted_features
& NETIF_F_GSO
))
3663 netdev
->features
&= ~NETIF_F_GSO
;
3666 adapter
->vsi
.id
= adapter
->vsi_res
->vsi_id
;
3668 adapter
->vsi
.back
= adapter
;
3669 adapter
->vsi
.base_vector
= 1;
3670 adapter
->vsi
.work_limit
= IAVF_DEFAULT_IRQ_WORK
;
3671 vsi
->netdev
= adapter
->netdev
;
3672 vsi
->qs_handle
= adapter
->vsi_res
->qset_handle
;
3673 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_RSS_PF
) {
3674 adapter
->rss_key_size
= vfres
->rss_key_size
;
3675 adapter
->rss_lut_size
= vfres
->rss_lut_size
;
3677 adapter
->rss_key_size
= IAVF_HKEY_ARRAY_SIZE
;
3678 adapter
->rss_lut_size
= IAVF_HLUT_ARRAY_SIZE
;
3685 * iavf_init_task - worker thread to perform delayed initialization
3686 * @work: pointer to work_struct containing our data
3688 * This task completes the work that was begun in probe. Due to the nature
3689 * of VF-PF communications, we may need to wait tens of milliseconds to get
3690 * responses back from the PF. Rather than busy-wait in probe and bog down the
3691 * whole system, we'll do it in a task so we can sleep.
3692 * This task only runs during driver init. Once we've established
3693 * communications with the PF driver and set up our netdev, the watchdog
3696 static void iavf_init_task(struct work_struct
*work
)
3698 struct iavf_adapter
*adapter
= container_of(work
,
3699 struct iavf_adapter
,
3701 struct iavf_hw
*hw
= &adapter
->hw
;
3703 if (iavf_lock_timeout(&adapter
->crit_lock
, 5000)) {
3704 dev_warn(&adapter
->pdev
->dev
, "failed to acquire crit_lock in %s\n", __FUNCTION__
);
3707 switch (adapter
->state
) {
3708 case __IAVF_STARTUP
:
3709 iavf_startup(adapter
);
3710 if (adapter
->state
== __IAVF_INIT_FAILED
)
3713 case __IAVF_INIT_VERSION_CHECK
:
3714 iavf_init_version_check(adapter
);
3715 if (adapter
->state
== __IAVF_INIT_FAILED
)
3718 case __IAVF_INIT_GET_RESOURCES
:
3719 iavf_init_get_resources(adapter
);
3720 if (adapter
->state
== __IAVF_INIT_FAILED
)
3727 queue_delayed_work(iavf_wq
, &adapter
->init_task
,
3728 msecs_to_jiffies(30));
3731 if (++adapter
->aq_wait_count
> IAVF_AQ_MAX_ERR
) {
3732 dev_err(&adapter
->pdev
->dev
,
3733 "Failed to communicate with PF; waiting before retry\n");
3734 adapter
->flags
|= IAVF_FLAG_PF_COMMS_FAILED
;
3735 iavf_shutdown_adminq(hw
);
3736 iavf_change_state(adapter
, __IAVF_STARTUP
);
3737 queue_delayed_work(iavf_wq
, &adapter
->init_task
, HZ
* 5);
3740 queue_delayed_work(iavf_wq
, &adapter
->init_task
, HZ
);
3742 mutex_unlock(&adapter
->crit_lock
);
3746 * iavf_shutdown - Shutdown the device in preparation for a reboot
3747 * @pdev: pci device structure
3749 static void iavf_shutdown(struct pci_dev
*pdev
)
3751 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3752 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3754 netif_device_detach(netdev
);
3756 if (netif_running(netdev
))
3759 if (iavf_lock_timeout(&adapter
->crit_lock
, 5000))
3760 dev_warn(&adapter
->pdev
->dev
, "failed to acquire crit_lock in %s\n", __FUNCTION__
);
3761 /* Prevent the watchdog from running. */
3762 iavf_change_state(adapter
, __IAVF_REMOVE
);
3763 adapter
->aq_required
= 0;
3764 mutex_unlock(&adapter
->crit_lock
);
3767 pci_save_state(pdev
);
3770 pci_disable_device(pdev
);
3774 * iavf_probe - Device Initialization Routine
3775 * @pdev: PCI device information struct
3776 * @ent: entry in iavf_pci_tbl
3778 * Returns 0 on success, negative on failure
3780 * iavf_probe initializes an adapter identified by a pci_dev structure.
3781 * The OS initialization, configuring of the adapter private structure,
3782 * and a hardware reset occur.
3784 static int iavf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
3786 struct net_device
*netdev
;
3787 struct iavf_adapter
*adapter
= NULL
;
3788 struct iavf_hw
*hw
= NULL
;
3791 err
= pci_enable_device(pdev
);
3795 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
3797 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
3800 "DMA configuration failed: 0x%x\n", err
);
3805 err
= pci_request_regions(pdev
, iavf_driver_name
);
3808 "pci_request_regions failed 0x%x\n", err
);
3812 pci_enable_pcie_error_reporting(pdev
);
3814 pci_set_master(pdev
);
3816 netdev
= alloc_etherdev_mq(sizeof(struct iavf_adapter
),
3817 IAVF_MAX_REQ_QUEUES
);
3820 goto err_alloc_etherdev
;
3823 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3825 pci_set_drvdata(pdev
, netdev
);
3826 adapter
= netdev_priv(netdev
);
3828 adapter
->netdev
= netdev
;
3829 adapter
->pdev
= pdev
;
3834 adapter
->msg_enable
= BIT(DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
3835 iavf_change_state(adapter
, __IAVF_STARTUP
);
3837 /* Call save state here because it relies on the adapter struct. */
3838 pci_save_state(pdev
);
3840 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
3841 pci_resource_len(pdev
, 0));
3846 hw
->vendor_id
= pdev
->vendor
;
3847 hw
->device_id
= pdev
->device
;
3848 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
3849 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
3850 hw
->subsystem_device_id
= pdev
->subsystem_device
;
3851 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
3852 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
3853 hw
->bus
.bus_id
= pdev
->bus
->number
;
3855 /* set up the locks for the AQ, do this only once in probe
3856 * and destroy them only once in remove
3858 mutex_init(&adapter
->crit_lock
);
3859 mutex_init(&adapter
->client_lock
);
3860 mutex_init(&adapter
->remove_lock
);
3861 mutex_init(&hw
->aq
.asq_mutex
);
3862 mutex_init(&hw
->aq
.arq_mutex
);
3864 spin_lock_init(&adapter
->mac_vlan_list_lock
);
3865 spin_lock_init(&adapter
->cloud_filter_list_lock
);
3866 spin_lock_init(&adapter
->fdir_fltr_lock
);
3867 spin_lock_init(&adapter
->adv_rss_lock
);
3869 INIT_LIST_HEAD(&adapter
->mac_filter_list
);
3870 INIT_LIST_HEAD(&adapter
->vlan_filter_list
);
3871 INIT_LIST_HEAD(&adapter
->cloud_filter_list
);
3872 INIT_LIST_HEAD(&adapter
->fdir_list_head
);
3873 INIT_LIST_HEAD(&adapter
->adv_rss_list_head
);
3875 INIT_WORK(&adapter
->reset_task
, iavf_reset_task
);
3876 INIT_WORK(&adapter
->adminq_task
, iavf_adminq_task
);
3877 INIT_DELAYED_WORK(&adapter
->watchdog_task
, iavf_watchdog_task
);
3878 INIT_DELAYED_WORK(&adapter
->client_task
, iavf_client_task
);
3879 INIT_DELAYED_WORK(&adapter
->init_task
, iavf_init_task
);
3880 queue_delayed_work(iavf_wq
, &adapter
->init_task
,
3881 msecs_to_jiffies(5 * (pdev
->devfn
& 0x07)));
3883 /* Setup the wait queue for indicating transition to down status */
3884 init_waitqueue_head(&adapter
->down_waitqueue
);
3889 free_netdev(netdev
);
3891 pci_disable_pcie_error_reporting(pdev
);
3892 pci_release_regions(pdev
);
3895 pci_disable_device(pdev
);
3900 * iavf_suspend - Power management suspend routine
3901 * @dev_d: device info pointer
3903 * Called when the system (VM) is entering sleep/suspend.
3905 static int __maybe_unused
iavf_suspend(struct device
*dev_d
)
3907 struct net_device
*netdev
= dev_get_drvdata(dev_d
);
3908 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3910 netif_device_detach(netdev
);
3912 while (!mutex_trylock(&adapter
->crit_lock
))
3913 usleep_range(500, 1000);
3915 if (netif_running(netdev
)) {
3920 iavf_free_misc_irq(adapter
);
3921 iavf_reset_interrupt_capability(adapter
);
3923 mutex_unlock(&adapter
->crit_lock
);
3929 * iavf_resume - Power management resume routine
3930 * @dev_d: device info pointer
3932 * Called when the system (VM) is resumed from sleep/suspend.
3934 static int __maybe_unused
iavf_resume(struct device
*dev_d
)
3936 struct pci_dev
*pdev
= to_pci_dev(dev_d
);
3937 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3938 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3941 pci_set_master(pdev
);
3944 err
= iavf_set_interrupt_capability(adapter
);
3947 dev_err(&pdev
->dev
, "Cannot enable MSI-X interrupts.\n");
3950 err
= iavf_request_misc_irq(adapter
);
3953 dev_err(&pdev
->dev
, "Cannot get interrupt vector.\n");
3957 queue_work(iavf_wq
, &adapter
->reset_task
);
3959 netif_device_attach(netdev
);
3965 * iavf_remove - Device Removal Routine
3966 * @pdev: PCI device information struct
3968 * iavf_remove is called by the PCI subsystem to alert the driver
3969 * that it should release a PCI device. The could be caused by a
3970 * Hot-Plug event, or because the driver is going to be removed from
3973 static void iavf_remove(struct pci_dev
*pdev
)
3975 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3976 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3977 struct iavf_fdir_fltr
*fdir
, *fdirtmp
;
3978 struct iavf_vlan_filter
*vlf
, *vlftmp
;
3979 struct iavf_adv_rss
*rss
, *rsstmp
;
3980 struct iavf_mac_filter
*f
, *ftmp
;
3981 struct iavf_cloud_filter
*cf
, *cftmp
;
3982 struct iavf_hw
*hw
= &adapter
->hw
;
3984 /* Indicate we are in remove and not to run reset_task */
3985 mutex_lock(&adapter
->remove_lock
);
3986 cancel_delayed_work_sync(&adapter
->init_task
);
3987 cancel_work_sync(&adapter
->reset_task
);
3988 cancel_delayed_work_sync(&adapter
->client_task
);
3989 if (adapter
->netdev_registered
) {
3990 unregister_netdev(netdev
);
3991 adapter
->netdev_registered
= false;
3993 if (CLIENT_ALLOWED(adapter
)) {
3994 err
= iavf_lan_del_device(adapter
);
3996 dev_warn(&pdev
->dev
, "Failed to delete client device: %d\n",
4000 iavf_request_reset(adapter
);
4002 /* If the FW isn't responding, kick it once, but only once. */
4003 if (!iavf_asq_done(hw
)) {
4004 iavf_request_reset(adapter
);
4007 if (iavf_lock_timeout(&adapter
->crit_lock
, 5000))
4008 dev_warn(&adapter
->pdev
->dev
, "failed to acquire crit_lock in %s\n", __FUNCTION__
);
4010 /* Shut down all the garbage mashers on the detention level */
4011 iavf_change_state(adapter
, __IAVF_REMOVE
);
4012 adapter
->aq_required
= 0;
4013 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
4014 iavf_free_all_tx_resources(adapter
);
4015 iavf_free_all_rx_resources(adapter
);
4016 iavf_misc_irq_disable(adapter
);
4017 iavf_free_misc_irq(adapter
);
4018 iavf_reset_interrupt_capability(adapter
);
4019 iavf_free_q_vectors(adapter
);
4021 cancel_delayed_work_sync(&adapter
->watchdog_task
);
4023 cancel_work_sync(&adapter
->adminq_task
);
4025 iavf_free_rss(adapter
);
4027 if (hw
->aq
.asq
.count
)
4028 iavf_shutdown_adminq(hw
);
4030 /* destroy the locks only once, here */
4031 mutex_destroy(&hw
->aq
.arq_mutex
);
4032 mutex_destroy(&hw
->aq
.asq_mutex
);
4033 mutex_destroy(&adapter
->client_lock
);
4034 mutex_unlock(&adapter
->crit_lock
);
4035 mutex_destroy(&adapter
->crit_lock
);
4036 mutex_unlock(&adapter
->remove_lock
);
4037 mutex_destroy(&adapter
->remove_lock
);
4039 iounmap(hw
->hw_addr
);
4040 pci_release_regions(pdev
);
4041 iavf_free_queues(adapter
);
4042 kfree(adapter
->vf_res
);
4043 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
4044 /* If we got removed before an up/down sequence, we've got a filter
4045 * hanging out there that we need to get rid of.
4047 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
4051 list_for_each_entry_safe(vlf
, vlftmp
, &adapter
->vlan_filter_list
,
4053 list_del(&vlf
->list
);
4057 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
4059 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
4060 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
, list
) {
4061 list_del(&cf
->list
);
4064 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
4066 spin_lock_bh(&adapter
->fdir_fltr_lock
);
4067 list_for_each_entry_safe(fdir
, fdirtmp
, &adapter
->fdir_list_head
, list
) {
4068 list_del(&fdir
->list
);
4071 spin_unlock_bh(&adapter
->fdir_fltr_lock
);
4073 spin_lock_bh(&adapter
->adv_rss_lock
);
4074 list_for_each_entry_safe(rss
, rsstmp
, &adapter
->adv_rss_list_head
,
4076 list_del(&rss
->list
);
4079 spin_unlock_bh(&adapter
->adv_rss_lock
);
4081 free_netdev(netdev
);
4083 pci_disable_pcie_error_reporting(pdev
);
4085 pci_disable_device(pdev
);
4088 static SIMPLE_DEV_PM_OPS(iavf_pm_ops
, iavf_suspend
, iavf_resume
);
4090 static struct pci_driver iavf_driver
= {
4091 .name
= iavf_driver_name
,
4092 .id_table
= iavf_pci_tbl
,
4093 .probe
= iavf_probe
,
4094 .remove
= iavf_remove
,
4095 .driver
.pm
= &iavf_pm_ops
,
4096 .shutdown
= iavf_shutdown
,
4100 * iavf_init_module - Driver Registration Routine
4102 * iavf_init_module is the first routine called when the driver is
4103 * loaded. All it does is register with the PCI subsystem.
4105 static int __init
iavf_init_module(void)
4109 pr_info("iavf: %s\n", iavf_driver_string
);
4111 pr_info("%s\n", iavf_copyright
);
4113 iavf_wq
= alloc_workqueue("%s", WQ_UNBOUND
| WQ_MEM_RECLAIM
, 1,
4116 pr_err("%s: Failed to create workqueue\n", iavf_driver_name
);
4119 ret
= pci_register_driver(&iavf_driver
);
4123 module_init(iavf_init_module
);
4126 * iavf_exit_module - Driver Exit Cleanup Routine
4128 * iavf_exit_module is called just before the driver is removed
4131 static void __exit
iavf_exit_module(void)
4133 pci_unregister_driver(&iavf_driver
);
4134 destroy_workqueue(iavf_wq
);
4137 module_exit(iavf_exit_module
);