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 if (adapter
->flags
& IAVF_FLAG_RESET_NEEDED
&&
1982 adapter
->state
!= __IAVF_RESETTING
) {
1983 iavf_change_state(adapter
, __IAVF_RESETTING
);
1984 adapter
->aq_required
= 0;
1985 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
1988 switch (adapter
->state
) {
1989 case __IAVF_STARTUP
:
1990 iavf_startup(adapter
);
1991 mutex_unlock(&adapter
->crit_lock
);
1992 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
,
1993 msecs_to_jiffies(30));
1995 case __IAVF_INIT_VERSION_CHECK
:
1996 iavf_init_version_check(adapter
);
1997 mutex_unlock(&adapter
->crit_lock
);
1998 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
,
1999 msecs_to_jiffies(30));
2001 case __IAVF_INIT_GET_RESOURCES
:
2002 iavf_init_get_resources(adapter
);
2003 mutex_unlock(&adapter
->crit_lock
);
2004 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
,
2005 msecs_to_jiffies(1));
2007 case __IAVF_INIT_FAILED
:
2008 if (++adapter
->aq_wait_count
> IAVF_AQ_MAX_ERR
) {
2009 dev_err(&adapter
->pdev
->dev
,
2010 "Failed to communicate with PF; waiting before retry\n");
2011 adapter
->flags
|= IAVF_FLAG_PF_COMMS_FAILED
;
2012 iavf_shutdown_adminq(hw
);
2013 mutex_unlock(&adapter
->crit_lock
);
2014 queue_delayed_work(iavf_wq
,
2015 &adapter
->watchdog_task
, (5 * HZ
));
2018 /* Try again from failed step*/
2019 iavf_change_state(adapter
, adapter
->last_state
);
2020 mutex_unlock(&adapter
->crit_lock
);
2021 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
, HZ
);
2023 case __IAVF_COMM_FAILED
:
2024 reg_val
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
2025 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
2026 if (reg_val
== VIRTCHNL_VFR_VFACTIVE
||
2027 reg_val
== VIRTCHNL_VFR_COMPLETED
) {
2028 /* A chance for redemption! */
2029 dev_err(&adapter
->pdev
->dev
,
2030 "Hardware came out of reset. Attempting reinit.\n");
2031 /* When init task contacts the PF and
2032 * gets everything set up again, it'll restart the
2033 * watchdog for us. Down, boy. Sit. Stay. Woof.
2035 iavf_change_state(adapter
, __IAVF_STARTUP
);
2036 adapter
->flags
&= ~IAVF_FLAG_PF_COMMS_FAILED
;
2038 adapter
->aq_required
= 0;
2039 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
2040 queue_delayed_work(iavf_wq
,
2041 &adapter
->watchdog_task
,
2042 msecs_to_jiffies(10));
2044 case __IAVF_RESETTING
:
2045 mutex_unlock(&adapter
->crit_lock
);
2046 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
, HZ
* 2);
2049 case __IAVF_DOWN_PENDING
:
2050 case __IAVF_TESTING
:
2051 case __IAVF_RUNNING
:
2052 if (adapter
->current_op
) {
2053 if (!iavf_asq_done(hw
)) {
2054 dev_dbg(&adapter
->pdev
->dev
,
2055 "Admin queue timeout\n");
2056 iavf_send_api_ver(adapter
);
2059 /* An error will be returned if no commands were
2060 * processed; use this opportunity to update stats
2062 if (iavf_process_aq_command(adapter
) &&
2063 adapter
->state
== __IAVF_RUNNING
)
2064 iavf_request_stats(adapter
);
2066 if (adapter
->state
== __IAVF_RUNNING
)
2067 iavf_detect_recover_hung(&adapter
->vsi
);
2070 mutex_unlock(&adapter
->crit_lock
);
2076 /* check for hw reset */
2077 reg_val
= rd32(hw
, IAVF_VF_ARQLEN1
) & IAVF_VF_ARQLEN1_ARQENABLE_MASK
;
2079 iavf_change_state(adapter
, __IAVF_RESETTING
);
2080 adapter
->flags
|= IAVF_FLAG_RESET_PENDING
;
2081 adapter
->aq_required
= 0;
2082 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
2083 dev_err(&adapter
->pdev
->dev
, "Hardware reset detected\n");
2084 queue_work(iavf_wq
, &adapter
->reset_task
);
2085 mutex_unlock(&adapter
->crit_lock
);
2086 queue_delayed_work(iavf_wq
,
2087 &adapter
->watchdog_task
, HZ
* 2);
2091 schedule_delayed_work(&adapter
->client_task
, msecs_to_jiffies(5));
2092 mutex_unlock(&adapter
->crit_lock
);
2094 queue_work(iavf_wq
, &adapter
->adminq_task
);
2095 if (adapter
->aq_required
)
2096 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
,
2097 msecs_to_jiffies(20));
2099 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
, HZ
* 2);
2102 static void iavf_disable_vf(struct iavf_adapter
*adapter
)
2104 struct iavf_mac_filter
*f
, *ftmp
;
2105 struct iavf_vlan_filter
*fv
, *fvtmp
;
2106 struct iavf_cloud_filter
*cf
, *cftmp
;
2108 adapter
->flags
|= IAVF_FLAG_PF_COMMS_FAILED
;
2110 /* We don't use netif_running() because it may be true prior to
2111 * ndo_open() returning, so we can't assume it means all our open
2112 * tasks have finished, since we're not holding the rtnl_lock here.
2114 if (adapter
->state
== __IAVF_RUNNING
) {
2115 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
2116 netif_carrier_off(adapter
->netdev
);
2117 netif_tx_disable(adapter
->netdev
);
2118 adapter
->link_up
= false;
2119 iavf_napi_disable_all(adapter
);
2120 iavf_irq_disable(adapter
);
2121 iavf_free_traffic_irqs(adapter
);
2122 iavf_free_all_tx_resources(adapter
);
2123 iavf_free_all_rx_resources(adapter
);
2126 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
2128 /* Delete all of the filters */
2129 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2134 list_for_each_entry_safe(fv
, fvtmp
, &adapter
->vlan_filter_list
, list
) {
2135 list_del(&fv
->list
);
2139 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
2141 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2142 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
, list
) {
2143 list_del(&cf
->list
);
2145 adapter
->num_cloud_filters
--;
2147 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2149 iavf_free_misc_irq(adapter
);
2150 iavf_reset_interrupt_capability(adapter
);
2151 iavf_free_q_vectors(adapter
);
2152 iavf_free_queues(adapter
);
2153 memset(adapter
->vf_res
, 0, IAVF_VIRTCHNL_VF_RESOURCE_SIZE
);
2154 iavf_shutdown_adminq(&adapter
->hw
);
2155 adapter
->netdev
->flags
&= ~IFF_UP
;
2156 mutex_unlock(&adapter
->crit_lock
);
2157 adapter
->flags
&= ~IAVF_FLAG_RESET_PENDING
;
2158 iavf_change_state(adapter
, __IAVF_DOWN
);
2159 wake_up(&adapter
->down_waitqueue
);
2160 dev_info(&adapter
->pdev
->dev
, "Reset task did not complete, VF disabled\n");
2164 * iavf_reset_task - Call-back task to handle hardware reset
2165 * @work: pointer to work_struct
2167 * During reset we need to shut down and reinitialize the admin queue
2168 * before we can use it to communicate with the PF again. We also clear
2169 * and reinit the rings because that context is lost as well.
2171 static void iavf_reset_task(struct work_struct
*work
)
2173 struct iavf_adapter
*adapter
= container_of(work
,
2174 struct iavf_adapter
,
2176 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
2177 struct net_device
*netdev
= adapter
->netdev
;
2178 struct iavf_hw
*hw
= &adapter
->hw
;
2179 struct iavf_mac_filter
*f
, *ftmp
;
2180 struct iavf_cloud_filter
*cf
;
2185 /* When device is being removed it doesn't make sense to run the reset
2186 * task, just return in such a case.
2188 if (mutex_is_locked(&adapter
->remove_lock
))
2191 if (iavf_lock_timeout(&adapter
->crit_lock
, 200)) {
2192 schedule_work(&adapter
->reset_task
);
2195 while (!mutex_trylock(&adapter
->client_lock
))
2196 usleep_range(500, 1000);
2197 if (CLIENT_ENABLED(adapter
)) {
2198 adapter
->flags
&= ~(IAVF_FLAG_CLIENT_NEEDS_OPEN
|
2199 IAVF_FLAG_CLIENT_NEEDS_CLOSE
|
2200 IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
|
2201 IAVF_FLAG_SERVICE_CLIENT_REQUESTED
);
2202 cancel_delayed_work_sync(&adapter
->client_task
);
2203 iavf_notify_client_close(&adapter
->vsi
, true);
2205 iavf_misc_irq_disable(adapter
);
2206 if (adapter
->flags
& IAVF_FLAG_RESET_NEEDED
) {
2207 adapter
->flags
&= ~IAVF_FLAG_RESET_NEEDED
;
2208 /* Restart the AQ here. If we have been reset but didn't
2209 * detect it, or if the PF had to reinit, our AQ will be hosed.
2211 iavf_shutdown_adminq(hw
);
2212 iavf_init_adminq(hw
);
2213 iavf_request_reset(adapter
);
2215 adapter
->flags
|= IAVF_FLAG_RESET_PENDING
;
2217 /* poll until we see the reset actually happen */
2218 for (i
= 0; i
< IAVF_RESET_WAIT_DETECTED_COUNT
; i
++) {
2219 reg_val
= rd32(hw
, IAVF_VF_ARQLEN1
) &
2220 IAVF_VF_ARQLEN1_ARQENABLE_MASK
;
2223 usleep_range(5000, 10000);
2225 if (i
== IAVF_RESET_WAIT_DETECTED_COUNT
) {
2226 dev_info(&adapter
->pdev
->dev
, "Never saw reset\n");
2227 goto continue_reset
; /* act like the reset happened */
2230 /* wait until the reset is complete and the PF is responding to us */
2231 for (i
= 0; i
< IAVF_RESET_WAIT_COMPLETE_COUNT
; i
++) {
2232 /* sleep first to make sure a minimum wait time is met */
2233 msleep(IAVF_RESET_WAIT_MS
);
2235 reg_val
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
2236 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
2237 if (reg_val
== VIRTCHNL_VFR_VFACTIVE
)
2241 pci_set_master(adapter
->pdev
);
2242 pci_restore_msi_state(adapter
->pdev
);
2244 if (i
== IAVF_RESET_WAIT_COMPLETE_COUNT
) {
2245 dev_err(&adapter
->pdev
->dev
, "Reset never finished (%x)\n",
2247 iavf_disable_vf(adapter
);
2248 mutex_unlock(&adapter
->client_lock
);
2249 mutex_unlock(&adapter
->crit_lock
);
2250 return; /* Do not attempt to reinit. It's dead, Jim. */
2254 /* We don't use netif_running() because it may be true prior to
2255 * ndo_open() returning, so we can't assume it means all our open
2256 * tasks have finished, since we're not holding the rtnl_lock here.
2258 running
= ((adapter
->state
== __IAVF_RUNNING
) ||
2259 (adapter
->state
== __IAVF_RESETTING
));
2262 netif_carrier_off(netdev
);
2263 netif_tx_stop_all_queues(netdev
);
2264 adapter
->link_up
= false;
2265 iavf_napi_disable_all(adapter
);
2267 iavf_irq_disable(adapter
);
2269 iavf_change_state(adapter
, __IAVF_RESETTING
);
2270 adapter
->flags
&= ~IAVF_FLAG_RESET_PENDING
;
2272 /* free the Tx/Rx rings and descriptors, might be better to just
2273 * re-use them sometime in the future
2275 iavf_free_all_rx_resources(adapter
);
2276 iavf_free_all_tx_resources(adapter
);
2278 adapter
->flags
|= IAVF_FLAG_QUEUES_DISABLED
;
2279 /* kill and reinit the admin queue */
2280 iavf_shutdown_adminq(hw
);
2281 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
2282 err
= iavf_init_adminq(hw
);
2284 dev_info(&adapter
->pdev
->dev
, "Failed to init adminq: %d\n",
2286 adapter
->aq_required
= 0;
2288 if (adapter
->flags
& IAVF_FLAG_REINIT_ITR_NEEDED
) {
2289 err
= iavf_reinit_interrupt_scheme(adapter
);
2294 if (RSS_AQ(adapter
)) {
2295 adapter
->aq_required
|= IAVF_FLAG_AQ_CONFIGURE_RSS
;
2297 err
= iavf_init_rss(adapter
);
2302 adapter
->aq_required
|= IAVF_FLAG_AQ_GET_CONFIG
;
2303 adapter
->aq_required
|= IAVF_FLAG_AQ_MAP_VECTORS
;
2305 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
2307 /* Delete filter for the current MAC address, it could have
2308 * been changed by the PF via administratively set MAC.
2309 * Will be re-added via VIRTCHNL_OP_GET_VF_RESOURCES.
2311 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2312 if (ether_addr_equal(f
->macaddr
, adapter
->hw
.mac
.addr
)) {
2317 /* re-add all MAC filters */
2318 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
2321 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
2323 /* check if TCs are running and re-add all cloud filters */
2324 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2325 if ((vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
) &&
2327 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
2331 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2333 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_MAC_FILTER
;
2334 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_CLOUD_FILTER
;
2335 iavf_misc_irq_enable(adapter
);
2337 mod_delayed_work(iavf_wq
, &adapter
->watchdog_task
, 2);
2339 /* We were running when the reset started, so we need to restore some
2343 /* allocate transmit descriptors */
2344 err
= iavf_setup_all_tx_resources(adapter
);
2348 /* allocate receive descriptors */
2349 err
= iavf_setup_all_rx_resources(adapter
);
2353 if (adapter
->flags
& IAVF_FLAG_REINIT_ITR_NEEDED
) {
2354 err
= iavf_request_traffic_irqs(adapter
, netdev
->name
);
2358 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
2361 iavf_configure(adapter
);
2363 /* iavf_up_complete() will switch device back
2366 iavf_up_complete(adapter
);
2368 iavf_irq_enable(adapter
, true);
2370 iavf_change_state(adapter
, __IAVF_DOWN
);
2371 wake_up(&adapter
->down_waitqueue
);
2373 mutex_unlock(&adapter
->client_lock
);
2374 mutex_unlock(&adapter
->crit_lock
);
2378 mutex_unlock(&adapter
->client_lock
);
2379 mutex_unlock(&adapter
->crit_lock
);
2381 iavf_change_state(adapter
, __IAVF_RUNNING
);
2382 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit\n");
2387 * iavf_adminq_task - worker thread to clean the admin queue
2388 * @work: pointer to work_struct containing our data
2390 static void iavf_adminq_task(struct work_struct
*work
)
2392 struct iavf_adapter
*adapter
=
2393 container_of(work
, struct iavf_adapter
, adminq_task
);
2394 struct iavf_hw
*hw
= &adapter
->hw
;
2395 struct iavf_arq_event_info event
;
2396 enum virtchnl_ops v_op
;
2397 enum iavf_status ret
, v_ret
;
2401 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
)
2404 event
.buf_len
= IAVF_MAX_AQ_BUF_SIZE
;
2405 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
2409 if (iavf_lock_timeout(&adapter
->crit_lock
, 200))
2412 ret
= iavf_clean_arq_element(hw
, &event
, &pending
);
2413 v_op
= (enum virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
2414 v_ret
= (enum iavf_status
)le32_to_cpu(event
.desc
.cookie_low
);
2417 break; /* No event to process or error cleaning ARQ */
2419 iavf_virtchnl_completion(adapter
, v_op
, v_ret
, event
.msg_buf
,
2422 memset(event
.msg_buf
, 0, IAVF_MAX_AQ_BUF_SIZE
);
2424 mutex_unlock(&adapter
->crit_lock
);
2426 if ((adapter
->flags
&
2427 (IAVF_FLAG_RESET_PENDING
| IAVF_FLAG_RESET_NEEDED
)) ||
2428 adapter
->state
== __IAVF_RESETTING
)
2431 /* check for error indications */
2432 val
= rd32(hw
, hw
->aq
.arq
.len
);
2433 if (val
== 0xdeadbeef || val
== 0xffffffff) /* device in reset */
2436 if (val
& IAVF_VF_ARQLEN1_ARQVFE_MASK
) {
2437 dev_info(&adapter
->pdev
->dev
, "ARQ VF Error detected\n");
2438 val
&= ~IAVF_VF_ARQLEN1_ARQVFE_MASK
;
2440 if (val
& IAVF_VF_ARQLEN1_ARQOVFL_MASK
) {
2441 dev_info(&adapter
->pdev
->dev
, "ARQ Overflow Error detected\n");
2442 val
&= ~IAVF_VF_ARQLEN1_ARQOVFL_MASK
;
2444 if (val
& IAVF_VF_ARQLEN1_ARQCRIT_MASK
) {
2445 dev_info(&adapter
->pdev
->dev
, "ARQ Critical Error detected\n");
2446 val
&= ~IAVF_VF_ARQLEN1_ARQCRIT_MASK
;
2449 wr32(hw
, hw
->aq
.arq
.len
, val
);
2451 val
= rd32(hw
, hw
->aq
.asq
.len
);
2453 if (val
& IAVF_VF_ATQLEN1_ATQVFE_MASK
) {
2454 dev_info(&adapter
->pdev
->dev
, "ASQ VF Error detected\n");
2455 val
&= ~IAVF_VF_ATQLEN1_ATQVFE_MASK
;
2457 if (val
& IAVF_VF_ATQLEN1_ATQOVFL_MASK
) {
2458 dev_info(&adapter
->pdev
->dev
, "ASQ Overflow Error detected\n");
2459 val
&= ~IAVF_VF_ATQLEN1_ATQOVFL_MASK
;
2461 if (val
& IAVF_VF_ATQLEN1_ATQCRIT_MASK
) {
2462 dev_info(&adapter
->pdev
->dev
, "ASQ Critical Error detected\n");
2463 val
&= ~IAVF_VF_ATQLEN1_ATQCRIT_MASK
;
2466 wr32(hw
, hw
->aq
.asq
.len
, val
);
2469 kfree(event
.msg_buf
);
2471 /* re-enable Admin queue interrupt cause */
2472 iavf_misc_irq_enable(adapter
);
2476 * iavf_client_task - worker thread to perform client work
2477 * @work: pointer to work_struct containing our data
2479 * This task handles client interactions. Because client calls can be
2480 * reentrant, we can't handle them in the watchdog.
2482 static void iavf_client_task(struct work_struct
*work
)
2484 struct iavf_adapter
*adapter
=
2485 container_of(work
, struct iavf_adapter
, client_task
.work
);
2487 /* If we can't get the client bit, just give up. We'll be rescheduled
2491 if (!mutex_trylock(&adapter
->client_lock
))
2494 if (adapter
->flags
& IAVF_FLAG_SERVICE_CLIENT_REQUESTED
) {
2495 iavf_client_subtask(adapter
);
2496 adapter
->flags
&= ~IAVF_FLAG_SERVICE_CLIENT_REQUESTED
;
2499 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
) {
2500 iavf_notify_client_l2_params(&adapter
->vsi
);
2501 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
;
2504 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_CLOSE
) {
2505 iavf_notify_client_close(&adapter
->vsi
, false);
2506 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_CLOSE
;
2509 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_OPEN
) {
2510 iavf_notify_client_open(&adapter
->vsi
);
2511 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_OPEN
;
2514 mutex_unlock(&adapter
->client_lock
);
2518 * iavf_free_all_tx_resources - Free Tx Resources for All Queues
2519 * @adapter: board private structure
2521 * Free all transmit software resources
2523 void iavf_free_all_tx_resources(struct iavf_adapter
*adapter
)
2527 if (!adapter
->tx_rings
)
2530 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2531 if (adapter
->tx_rings
[i
].desc
)
2532 iavf_free_tx_resources(&adapter
->tx_rings
[i
]);
2536 * iavf_setup_all_tx_resources - allocate all queues Tx resources
2537 * @adapter: board private structure
2539 * If this function returns with an error, then it's possible one or
2540 * more of the rings is populated (while the rest are not). It is the
2541 * callers duty to clean those orphaned rings.
2543 * Return 0 on success, negative on failure
2545 static int iavf_setup_all_tx_resources(struct iavf_adapter
*adapter
)
2549 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2550 adapter
->tx_rings
[i
].count
= adapter
->tx_desc_count
;
2551 err
= iavf_setup_tx_descriptors(&adapter
->tx_rings
[i
]);
2554 dev_err(&adapter
->pdev
->dev
,
2555 "Allocation for Tx Queue %u failed\n", i
);
2563 * iavf_setup_all_rx_resources - allocate all queues Rx resources
2564 * @adapter: board private structure
2566 * If this function returns with an error, then it's possible one or
2567 * more of the rings is populated (while the rest are not). It is the
2568 * callers duty to clean those orphaned rings.
2570 * Return 0 on success, negative on failure
2572 static int iavf_setup_all_rx_resources(struct iavf_adapter
*adapter
)
2576 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2577 adapter
->rx_rings
[i
].count
= adapter
->rx_desc_count
;
2578 err
= iavf_setup_rx_descriptors(&adapter
->rx_rings
[i
]);
2581 dev_err(&adapter
->pdev
->dev
,
2582 "Allocation for Rx Queue %u failed\n", i
);
2589 * iavf_free_all_rx_resources - Free Rx Resources for All Queues
2590 * @adapter: board private structure
2592 * Free all receive software resources
2594 void iavf_free_all_rx_resources(struct iavf_adapter
*adapter
)
2598 if (!adapter
->rx_rings
)
2601 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2602 if (adapter
->rx_rings
[i
].desc
)
2603 iavf_free_rx_resources(&adapter
->rx_rings
[i
]);
2607 * iavf_validate_tx_bandwidth - validate the max Tx bandwidth
2608 * @adapter: board private structure
2609 * @max_tx_rate: max Tx bw for a tc
2611 static int iavf_validate_tx_bandwidth(struct iavf_adapter
*adapter
,
2614 int speed
= 0, ret
= 0;
2616 if (ADV_LINK_SUPPORT(adapter
)) {
2617 if (adapter
->link_speed_mbps
< U32_MAX
) {
2618 speed
= adapter
->link_speed_mbps
;
2621 dev_err(&adapter
->pdev
->dev
, "Unknown link speed\n");
2626 switch (adapter
->link_speed
) {
2627 case VIRTCHNL_LINK_SPEED_40GB
:
2628 speed
= SPEED_40000
;
2630 case VIRTCHNL_LINK_SPEED_25GB
:
2631 speed
= SPEED_25000
;
2633 case VIRTCHNL_LINK_SPEED_20GB
:
2634 speed
= SPEED_20000
;
2636 case VIRTCHNL_LINK_SPEED_10GB
:
2637 speed
= SPEED_10000
;
2639 case VIRTCHNL_LINK_SPEED_5GB
:
2642 case VIRTCHNL_LINK_SPEED_2_5GB
:
2645 case VIRTCHNL_LINK_SPEED_1GB
:
2648 case VIRTCHNL_LINK_SPEED_100MB
:
2656 if (max_tx_rate
> speed
) {
2657 dev_err(&adapter
->pdev
->dev
,
2658 "Invalid tx rate specified\n");
2666 * iavf_validate_ch_config - validate queue mapping info
2667 * @adapter: board private structure
2668 * @mqprio_qopt: queue parameters
2670 * This function validates if the config provided by the user to
2671 * configure queue channels is valid or not. Returns 0 on a valid
2674 static int iavf_validate_ch_config(struct iavf_adapter
*adapter
,
2675 struct tc_mqprio_qopt_offload
*mqprio_qopt
)
2677 u64 total_max_rate
= 0;
2682 if (mqprio_qopt
->qopt
.num_tc
> IAVF_MAX_TRAFFIC_CLASS
||
2683 mqprio_qopt
->qopt
.num_tc
< 1)
2686 for (i
= 0; i
<= mqprio_qopt
->qopt
.num_tc
- 1; i
++) {
2687 if (!mqprio_qopt
->qopt
.count
[i
] ||
2688 mqprio_qopt
->qopt
.offset
[i
] != num_qps
)
2690 if (mqprio_qopt
->min_rate
[i
]) {
2691 dev_err(&adapter
->pdev
->dev
,
2692 "Invalid min tx rate (greater than 0) specified\n");
2695 /*convert to Mbps */
2696 tx_rate
= div_u64(mqprio_qopt
->max_rate
[i
],
2698 total_max_rate
+= tx_rate
;
2699 num_qps
+= mqprio_qopt
->qopt
.count
[i
];
2701 if (num_qps
> adapter
->num_active_queues
) {
2702 dev_err(&adapter
->pdev
->dev
,
2703 "Cannot support requested number of queues\n");
2707 ret
= iavf_validate_tx_bandwidth(adapter
, total_max_rate
);
2712 * iavf_del_all_cloud_filters - delete all cloud filters on the traffic classes
2713 * @adapter: board private structure
2715 static void iavf_del_all_cloud_filters(struct iavf_adapter
*adapter
)
2717 struct iavf_cloud_filter
*cf
, *cftmp
;
2719 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2720 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
,
2722 list_del(&cf
->list
);
2724 adapter
->num_cloud_filters
--;
2726 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2730 * __iavf_setup_tc - configure multiple traffic classes
2731 * @netdev: network interface device structure
2732 * @type_data: tc offload data
2734 * This function processes the config information provided by the
2735 * user to configure traffic classes/queue channels and packages the
2736 * information to request the PF to setup traffic classes.
2738 * Returns 0 on success.
2740 static int __iavf_setup_tc(struct net_device
*netdev
, void *type_data
)
2742 struct tc_mqprio_qopt_offload
*mqprio_qopt
= type_data
;
2743 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
2744 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
2745 u8 num_tc
= 0, total_qps
= 0;
2746 int ret
= 0, netdev_tc
= 0;
2751 num_tc
= mqprio_qopt
->qopt
.num_tc
;
2752 mode
= mqprio_qopt
->mode
;
2754 /* delete queue_channel */
2755 if (!mqprio_qopt
->qopt
.hw
) {
2756 if (adapter
->ch_config
.state
== __IAVF_TC_RUNNING
) {
2757 /* reset the tc configuration */
2758 netdev_reset_tc(netdev
);
2759 adapter
->num_tc
= 0;
2760 netif_tx_stop_all_queues(netdev
);
2761 netif_tx_disable(netdev
);
2762 iavf_del_all_cloud_filters(adapter
);
2763 adapter
->aq_required
= IAVF_FLAG_AQ_DISABLE_CHANNELS
;
2770 /* add queue channel */
2771 if (mode
== TC_MQPRIO_MODE_CHANNEL
) {
2772 if (!(vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
)) {
2773 dev_err(&adapter
->pdev
->dev
, "ADq not supported\n");
2776 if (adapter
->ch_config
.state
!= __IAVF_TC_INVALID
) {
2777 dev_err(&adapter
->pdev
->dev
, "TC configuration already exists\n");
2781 ret
= iavf_validate_ch_config(adapter
, mqprio_qopt
);
2784 /* Return if same TC config is requested */
2785 if (adapter
->num_tc
== num_tc
)
2787 adapter
->num_tc
= num_tc
;
2789 for (i
= 0; i
< IAVF_MAX_TRAFFIC_CLASS
; i
++) {
2791 adapter
->ch_config
.ch_info
[i
].count
=
2792 mqprio_qopt
->qopt
.count
[i
];
2793 adapter
->ch_config
.ch_info
[i
].offset
=
2794 mqprio_qopt
->qopt
.offset
[i
];
2795 total_qps
+= mqprio_qopt
->qopt
.count
[i
];
2796 max_tx_rate
= mqprio_qopt
->max_rate
[i
];
2797 /* convert to Mbps */
2798 max_tx_rate
= div_u64(max_tx_rate
,
2800 adapter
->ch_config
.ch_info
[i
].max_tx_rate
=
2803 adapter
->ch_config
.ch_info
[i
].count
= 1;
2804 adapter
->ch_config
.ch_info
[i
].offset
= 0;
2807 adapter
->ch_config
.total_qps
= total_qps
;
2808 netif_tx_stop_all_queues(netdev
);
2809 netif_tx_disable(netdev
);
2810 adapter
->aq_required
|= IAVF_FLAG_AQ_ENABLE_CHANNELS
;
2811 netdev_reset_tc(netdev
);
2812 /* Report the tc mapping up the stack */
2813 netdev_set_num_tc(adapter
->netdev
, num_tc
);
2814 for (i
= 0; i
< IAVF_MAX_TRAFFIC_CLASS
; i
++) {
2815 u16 qcount
= mqprio_qopt
->qopt
.count
[i
];
2816 u16 qoffset
= mqprio_qopt
->qopt
.offset
[i
];
2819 netdev_set_tc_queue(netdev
, netdev_tc
++, qcount
,
2828 * iavf_parse_cls_flower - Parse tc flower filters provided by kernel
2829 * @adapter: board private structure
2830 * @f: pointer to struct flow_cls_offload
2831 * @filter: pointer to cloud filter structure
2833 static int iavf_parse_cls_flower(struct iavf_adapter
*adapter
,
2834 struct flow_cls_offload
*f
,
2835 struct iavf_cloud_filter
*filter
)
2837 struct flow_rule
*rule
= flow_cls_offload_flow_rule(f
);
2838 struct flow_dissector
*dissector
= rule
->match
.dissector
;
2839 u16 n_proto_mask
= 0;
2840 u16 n_proto_key
= 0;
2845 struct virtchnl_filter
*vf
= &filter
->f
;
2847 if (dissector
->used_keys
&
2848 ~(BIT(FLOW_DISSECTOR_KEY_CONTROL
) |
2849 BIT(FLOW_DISSECTOR_KEY_BASIC
) |
2850 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS
) |
2851 BIT(FLOW_DISSECTOR_KEY_VLAN
) |
2852 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS
) |
2853 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS
) |
2854 BIT(FLOW_DISSECTOR_KEY_PORTS
) |
2855 BIT(FLOW_DISSECTOR_KEY_ENC_KEYID
))) {
2856 dev_err(&adapter
->pdev
->dev
, "Unsupported key used: 0x%x\n",
2857 dissector
->used_keys
);
2861 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_ENC_KEYID
)) {
2862 struct flow_match_enc_keyid match
;
2864 flow_rule_match_enc_keyid(rule
, &match
);
2865 if (match
.mask
->keyid
!= 0)
2866 field_flags
|= IAVF_CLOUD_FIELD_TEN_ID
;
2869 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_BASIC
)) {
2870 struct flow_match_basic match
;
2872 flow_rule_match_basic(rule
, &match
);
2873 n_proto_key
= ntohs(match
.key
->n_proto
);
2874 n_proto_mask
= ntohs(match
.mask
->n_proto
);
2876 if (n_proto_key
== ETH_P_ALL
) {
2880 n_proto
= n_proto_key
& n_proto_mask
;
2881 if (n_proto
!= ETH_P_IP
&& n_proto
!= ETH_P_IPV6
)
2883 if (n_proto
== ETH_P_IPV6
) {
2884 /* specify flow type as TCP IPv6 */
2885 vf
->flow_type
= VIRTCHNL_TCP_V6_FLOW
;
2888 if (match
.key
->ip_proto
!= IPPROTO_TCP
) {
2889 dev_info(&adapter
->pdev
->dev
, "Only TCP transport is supported\n");
2894 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_ETH_ADDRS
)) {
2895 struct flow_match_eth_addrs match
;
2897 flow_rule_match_eth_addrs(rule
, &match
);
2899 /* use is_broadcast and is_zero to check for all 0xf or 0 */
2900 if (!is_zero_ether_addr(match
.mask
->dst
)) {
2901 if (is_broadcast_ether_addr(match
.mask
->dst
)) {
2902 field_flags
|= IAVF_CLOUD_FIELD_OMAC
;
2904 dev_err(&adapter
->pdev
->dev
, "Bad ether dest mask %pM\n",
2906 return IAVF_ERR_CONFIG
;
2910 if (!is_zero_ether_addr(match
.mask
->src
)) {
2911 if (is_broadcast_ether_addr(match
.mask
->src
)) {
2912 field_flags
|= IAVF_CLOUD_FIELD_IMAC
;
2914 dev_err(&adapter
->pdev
->dev
, "Bad ether src mask %pM\n",
2916 return IAVF_ERR_CONFIG
;
2920 if (!is_zero_ether_addr(match
.key
->dst
))
2921 if (is_valid_ether_addr(match
.key
->dst
) ||
2922 is_multicast_ether_addr(match
.key
->dst
)) {
2923 /* set the mask if a valid dst_mac address */
2924 for (i
= 0; i
< ETH_ALEN
; i
++)
2925 vf
->mask
.tcp_spec
.dst_mac
[i
] |= 0xff;
2926 ether_addr_copy(vf
->data
.tcp_spec
.dst_mac
,
2930 if (!is_zero_ether_addr(match
.key
->src
))
2931 if (is_valid_ether_addr(match
.key
->src
) ||
2932 is_multicast_ether_addr(match
.key
->src
)) {
2933 /* set the mask if a valid dst_mac address */
2934 for (i
= 0; i
< ETH_ALEN
; i
++)
2935 vf
->mask
.tcp_spec
.src_mac
[i
] |= 0xff;
2936 ether_addr_copy(vf
->data
.tcp_spec
.src_mac
,
2941 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_VLAN
)) {
2942 struct flow_match_vlan match
;
2944 flow_rule_match_vlan(rule
, &match
);
2945 if (match
.mask
->vlan_id
) {
2946 if (match
.mask
->vlan_id
== VLAN_VID_MASK
) {
2947 field_flags
|= IAVF_CLOUD_FIELD_IVLAN
;
2949 dev_err(&adapter
->pdev
->dev
, "Bad vlan mask %u\n",
2950 match
.mask
->vlan_id
);
2951 return IAVF_ERR_CONFIG
;
2954 vf
->mask
.tcp_spec
.vlan_id
|= cpu_to_be16(0xffff);
2955 vf
->data
.tcp_spec
.vlan_id
= cpu_to_be16(match
.key
->vlan_id
);
2958 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_CONTROL
)) {
2959 struct flow_match_control match
;
2961 flow_rule_match_control(rule
, &match
);
2962 addr_type
= match
.key
->addr_type
;
2965 if (addr_type
== FLOW_DISSECTOR_KEY_IPV4_ADDRS
) {
2966 struct flow_match_ipv4_addrs match
;
2968 flow_rule_match_ipv4_addrs(rule
, &match
);
2969 if (match
.mask
->dst
) {
2970 if (match
.mask
->dst
== cpu_to_be32(0xffffffff)) {
2971 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2973 dev_err(&adapter
->pdev
->dev
, "Bad ip dst mask 0x%08x\n",
2974 be32_to_cpu(match
.mask
->dst
));
2975 return IAVF_ERR_CONFIG
;
2979 if (match
.mask
->src
) {
2980 if (match
.mask
->src
== cpu_to_be32(0xffffffff)) {
2981 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2983 dev_err(&adapter
->pdev
->dev
, "Bad ip src mask 0x%08x\n",
2984 be32_to_cpu(match
.mask
->dst
));
2985 return IAVF_ERR_CONFIG
;
2989 if (field_flags
& IAVF_CLOUD_FIELD_TEN_ID
) {
2990 dev_info(&adapter
->pdev
->dev
, "Tenant id not allowed for ip filter\n");
2991 return IAVF_ERR_CONFIG
;
2993 if (match
.key
->dst
) {
2994 vf
->mask
.tcp_spec
.dst_ip
[0] |= cpu_to_be32(0xffffffff);
2995 vf
->data
.tcp_spec
.dst_ip
[0] = match
.key
->dst
;
2997 if (match
.key
->src
) {
2998 vf
->mask
.tcp_spec
.src_ip
[0] |= cpu_to_be32(0xffffffff);
2999 vf
->data
.tcp_spec
.src_ip
[0] = match
.key
->src
;
3003 if (addr_type
== FLOW_DISSECTOR_KEY_IPV6_ADDRS
) {
3004 struct flow_match_ipv6_addrs match
;
3006 flow_rule_match_ipv6_addrs(rule
, &match
);
3008 /* validate mask, make sure it is not IPV6_ADDR_ANY */
3009 if (ipv6_addr_any(&match
.mask
->dst
)) {
3010 dev_err(&adapter
->pdev
->dev
, "Bad ipv6 dst mask 0x%02x\n",
3012 return IAVF_ERR_CONFIG
;
3015 /* src and dest IPv6 address should not be LOOPBACK
3016 * (0:0:0:0:0:0:0:1) which can be represented as ::1
3018 if (ipv6_addr_loopback(&match
.key
->dst
) ||
3019 ipv6_addr_loopback(&match
.key
->src
)) {
3020 dev_err(&adapter
->pdev
->dev
,
3021 "ipv6 addr should not be loopback\n");
3022 return IAVF_ERR_CONFIG
;
3024 if (!ipv6_addr_any(&match
.mask
->dst
) ||
3025 !ipv6_addr_any(&match
.mask
->src
))
3026 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
3028 for (i
= 0; i
< 4; i
++)
3029 vf
->mask
.tcp_spec
.dst_ip
[i
] |= cpu_to_be32(0xffffffff);
3030 memcpy(&vf
->data
.tcp_spec
.dst_ip
, &match
.key
->dst
.s6_addr32
,
3031 sizeof(vf
->data
.tcp_spec
.dst_ip
));
3032 for (i
= 0; i
< 4; i
++)
3033 vf
->mask
.tcp_spec
.src_ip
[i
] |= cpu_to_be32(0xffffffff);
3034 memcpy(&vf
->data
.tcp_spec
.src_ip
, &match
.key
->src
.s6_addr32
,
3035 sizeof(vf
->data
.tcp_spec
.src_ip
));
3037 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_PORTS
)) {
3038 struct flow_match_ports match
;
3040 flow_rule_match_ports(rule
, &match
);
3041 if (match
.mask
->src
) {
3042 if (match
.mask
->src
== cpu_to_be16(0xffff)) {
3043 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
3045 dev_err(&adapter
->pdev
->dev
, "Bad src port mask %u\n",
3046 be16_to_cpu(match
.mask
->src
));
3047 return IAVF_ERR_CONFIG
;
3051 if (match
.mask
->dst
) {
3052 if (match
.mask
->dst
== cpu_to_be16(0xffff)) {
3053 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
3055 dev_err(&adapter
->pdev
->dev
, "Bad dst port mask %u\n",
3056 be16_to_cpu(match
.mask
->dst
));
3057 return IAVF_ERR_CONFIG
;
3060 if (match
.key
->dst
) {
3061 vf
->mask
.tcp_spec
.dst_port
|= cpu_to_be16(0xffff);
3062 vf
->data
.tcp_spec
.dst_port
= match
.key
->dst
;
3065 if (match
.key
->src
) {
3066 vf
->mask
.tcp_spec
.src_port
|= cpu_to_be16(0xffff);
3067 vf
->data
.tcp_spec
.src_port
= match
.key
->src
;
3070 vf
->field_flags
= field_flags
;
3076 * iavf_handle_tclass - Forward to a traffic class on the device
3077 * @adapter: board private structure
3078 * @tc: traffic class index on the device
3079 * @filter: pointer to cloud filter structure
3081 static int iavf_handle_tclass(struct iavf_adapter
*adapter
, u32 tc
,
3082 struct iavf_cloud_filter
*filter
)
3086 if (tc
< adapter
->num_tc
) {
3087 if (!filter
->f
.data
.tcp_spec
.dst_port
) {
3088 dev_err(&adapter
->pdev
->dev
,
3089 "Specify destination port to redirect to traffic class other than TC0\n");
3093 /* redirect to a traffic class on the same device */
3094 filter
->f
.action
= VIRTCHNL_ACTION_TC_REDIRECT
;
3095 filter
->f
.action_meta
= tc
;
3100 * iavf_configure_clsflower - Add tc flower filters
3101 * @adapter: board private structure
3102 * @cls_flower: Pointer to struct flow_cls_offload
3104 static int iavf_configure_clsflower(struct iavf_adapter
*adapter
,
3105 struct flow_cls_offload
*cls_flower
)
3107 int tc
= tc_classid_to_hwtc(adapter
->netdev
, cls_flower
->classid
);
3108 struct iavf_cloud_filter
*filter
= NULL
;
3109 int err
= -EINVAL
, count
= 50;
3112 dev_err(&adapter
->pdev
->dev
, "Invalid traffic class\n");
3116 filter
= kzalloc(sizeof(*filter
), GFP_KERNEL
);
3120 while (!mutex_trylock(&adapter
->crit_lock
)) {
3128 filter
->cookie
= cls_flower
->cookie
;
3130 /* set the mask to all zeroes to begin with */
3131 memset(&filter
->f
.mask
.tcp_spec
, 0, sizeof(struct virtchnl_l4_spec
));
3132 /* start out with flow type and eth type IPv4 to begin with */
3133 filter
->f
.flow_type
= VIRTCHNL_TCP_V4_FLOW
;
3134 err
= iavf_parse_cls_flower(adapter
, cls_flower
, filter
);
3138 err
= iavf_handle_tclass(adapter
, tc
, filter
);
3142 /* add filter to the list */
3143 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
3144 list_add_tail(&filter
->list
, &adapter
->cloud_filter_list
);
3145 adapter
->num_cloud_filters
++;
3147 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_CLOUD_FILTER
;
3148 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
3153 mutex_unlock(&adapter
->crit_lock
);
3157 /* iavf_find_cf - Find the cloud filter in the list
3158 * @adapter: Board private structure
3159 * @cookie: filter specific cookie
3161 * Returns ptr to the filter object or NULL. Must be called while holding the
3162 * cloud_filter_list_lock.
3164 static struct iavf_cloud_filter
*iavf_find_cf(struct iavf_adapter
*adapter
,
3165 unsigned long *cookie
)
3167 struct iavf_cloud_filter
*filter
= NULL
;
3172 list_for_each_entry(filter
, &adapter
->cloud_filter_list
, list
) {
3173 if (!memcmp(cookie
, &filter
->cookie
, sizeof(filter
->cookie
)))
3180 * iavf_delete_clsflower - Remove tc flower filters
3181 * @adapter: board private structure
3182 * @cls_flower: Pointer to struct flow_cls_offload
3184 static int iavf_delete_clsflower(struct iavf_adapter
*adapter
,
3185 struct flow_cls_offload
*cls_flower
)
3187 struct iavf_cloud_filter
*filter
= NULL
;
3190 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
3191 filter
= iavf_find_cf(adapter
, &cls_flower
->cookie
);
3194 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_CLOUD_FILTER
;
3198 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
3204 * iavf_setup_tc_cls_flower - flower classifier offloads
3205 * @adapter: board private structure
3206 * @cls_flower: pointer to flow_cls_offload struct with flow info
3208 static int iavf_setup_tc_cls_flower(struct iavf_adapter
*adapter
,
3209 struct flow_cls_offload
*cls_flower
)
3211 switch (cls_flower
->command
) {
3212 case FLOW_CLS_REPLACE
:
3213 return iavf_configure_clsflower(adapter
, cls_flower
);
3214 case FLOW_CLS_DESTROY
:
3215 return iavf_delete_clsflower(adapter
, cls_flower
);
3216 case FLOW_CLS_STATS
:
3224 * iavf_setup_tc_block_cb - block callback for tc
3225 * @type: type of offload
3226 * @type_data: offload data
3229 * This function is the block callback for traffic classes
3231 static int iavf_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
3234 struct iavf_adapter
*adapter
= cb_priv
;
3236 if (!tc_cls_can_offload_and_chain0(adapter
->netdev
, type_data
))
3240 case TC_SETUP_CLSFLOWER
:
3241 return iavf_setup_tc_cls_flower(cb_priv
, type_data
);
3247 static LIST_HEAD(iavf_block_cb_list
);
3250 * iavf_setup_tc - configure multiple traffic classes
3251 * @netdev: network interface device structure
3252 * @type: type of offload
3253 * @type_data: tc offload data
3255 * This function is the callback to ndo_setup_tc in the
3258 * Returns 0 on success
3260 static int iavf_setup_tc(struct net_device
*netdev
, enum tc_setup_type type
,
3263 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3266 case TC_SETUP_QDISC_MQPRIO
:
3267 return __iavf_setup_tc(netdev
, type_data
);
3268 case TC_SETUP_BLOCK
:
3269 return flow_block_cb_setup_simple(type_data
,
3270 &iavf_block_cb_list
,
3271 iavf_setup_tc_block_cb
,
3272 adapter
, adapter
, true);
3279 * iavf_open - Called when a network interface is made active
3280 * @netdev: network interface device structure
3282 * Returns 0 on success, negative value on failure
3284 * The open entry point is called when a network interface is made
3285 * active by the system (IFF_UP). At this point all resources needed
3286 * for transmit and receive operations are allocated, the interrupt
3287 * handler is registered with the OS, the watchdog is started,
3288 * and the stack is notified that the interface is ready.
3290 static int iavf_open(struct net_device
*netdev
)
3292 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3295 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
) {
3296 dev_err(&adapter
->pdev
->dev
, "Unable to open device due to PF driver failure.\n");
3300 while (!mutex_trylock(&adapter
->crit_lock
))
3301 usleep_range(500, 1000);
3303 if (adapter
->state
!= __IAVF_DOWN
) {
3308 /* allocate transmit descriptors */
3309 err
= iavf_setup_all_tx_resources(adapter
);
3313 /* allocate receive descriptors */
3314 err
= iavf_setup_all_rx_resources(adapter
);
3318 /* clear any pending interrupts, may auto mask */
3319 err
= iavf_request_traffic_irqs(adapter
, netdev
->name
);
3323 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
3325 iavf_add_filter(adapter
, adapter
->hw
.mac
.addr
);
3327 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
3329 /* Restore VLAN filters that were removed with IFF_DOWN */
3330 iavf_restore_filters(adapter
);
3332 iavf_configure(adapter
);
3334 iavf_up_complete(adapter
);
3336 iavf_irq_enable(adapter
, true);
3338 mutex_unlock(&adapter
->crit_lock
);
3344 iavf_free_traffic_irqs(adapter
);
3346 iavf_free_all_rx_resources(adapter
);
3348 iavf_free_all_tx_resources(adapter
);
3350 mutex_unlock(&adapter
->crit_lock
);
3356 * iavf_close - Disables a network interface
3357 * @netdev: network interface device structure
3359 * Returns 0, this is not allowed to fail
3361 * The close entry point is called when an interface is de-activated
3362 * by the OS. The hardware is still under the drivers control, but
3363 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
3364 * are freed, along with all transmit and receive resources.
3366 static int iavf_close(struct net_device
*netdev
)
3368 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3371 if (adapter
->state
<= __IAVF_DOWN_PENDING
)
3374 while (!mutex_trylock(&adapter
->crit_lock
))
3375 usleep_range(500, 1000);
3377 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
3378 if (CLIENT_ENABLED(adapter
))
3379 adapter
->flags
|= IAVF_FLAG_CLIENT_NEEDS_CLOSE
;
3382 iavf_change_state(adapter
, __IAVF_DOWN_PENDING
);
3383 iavf_free_traffic_irqs(adapter
);
3385 mutex_unlock(&adapter
->crit_lock
);
3387 /* We explicitly don't free resources here because the hardware is
3388 * still active and can DMA into memory. Resources are cleared in
3389 * iavf_virtchnl_completion() after we get confirmation from the PF
3390 * driver that the rings have been stopped.
3392 * Also, we wait for state to transition to __IAVF_DOWN before
3393 * returning. State change occurs in iavf_virtchnl_completion() after
3394 * VF resources are released (which occurs after PF driver processes and
3395 * responds to admin queue commands).
3398 status
= wait_event_timeout(adapter
->down_waitqueue
,
3399 adapter
->state
== __IAVF_DOWN
,
3400 msecs_to_jiffies(500));
3402 netdev_warn(netdev
, "Device resources not yet released\n");
3407 * iavf_change_mtu - Change the Maximum Transfer Unit
3408 * @netdev: network interface device structure
3409 * @new_mtu: new value for maximum frame size
3411 * Returns 0 on success, negative on failure
3413 static int iavf_change_mtu(struct net_device
*netdev
, int new_mtu
)
3415 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3417 netdev
->mtu
= new_mtu
;
3418 if (CLIENT_ENABLED(adapter
)) {
3419 iavf_notify_client_l2_params(&adapter
->vsi
);
3420 adapter
->flags
|= IAVF_FLAG_SERVICE_CLIENT_REQUESTED
;
3423 if (netif_running(netdev
)) {
3424 adapter
->flags
|= IAVF_FLAG_RESET_NEEDED
;
3425 queue_work(iavf_wq
, &adapter
->reset_task
);
3432 * iavf_set_features - set the netdev feature flags
3433 * @netdev: ptr to the netdev being adjusted
3434 * @features: the feature set that the stack is suggesting
3435 * Note: expects to be called while under rtnl_lock()
3437 static int iavf_set_features(struct net_device
*netdev
,
3438 netdev_features_t features
)
3440 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3442 /* Don't allow enabling VLAN features when adapter is not capable
3443 * of VLAN offload/filtering
3445 if (!VLAN_ALLOWED(adapter
)) {
3446 netdev
->hw_features
&= ~(NETIF_F_HW_VLAN_CTAG_RX
|
3447 NETIF_F_HW_VLAN_CTAG_TX
|
3448 NETIF_F_HW_VLAN_CTAG_FILTER
);
3449 if (features
& (NETIF_F_HW_VLAN_CTAG_RX
|
3450 NETIF_F_HW_VLAN_CTAG_TX
|
3451 NETIF_F_HW_VLAN_CTAG_FILTER
))
3453 } else if ((netdev
->features
^ features
) & NETIF_F_HW_VLAN_CTAG_RX
) {
3454 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
3455 adapter
->aq_required
|=
3456 IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING
;
3458 adapter
->aq_required
|=
3459 IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING
;
3466 * iavf_features_check - Validate encapsulated packet conforms to limits
3468 * @dev: This physical port's netdev
3469 * @features: Offload features that the stack believes apply
3471 static netdev_features_t
iavf_features_check(struct sk_buff
*skb
,
3472 struct net_device
*dev
,
3473 netdev_features_t features
)
3477 /* No point in doing any of this if neither checksum nor GSO are
3478 * being requested for this frame. We can rule out both by just
3479 * checking for CHECKSUM_PARTIAL
3481 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
3484 /* We cannot support GSO if the MSS is going to be less than
3485 * 64 bytes. If it is then we need to drop support for GSO.
3487 if (skb_is_gso(skb
) && (skb_shinfo(skb
)->gso_size
< 64))
3488 features
&= ~NETIF_F_GSO_MASK
;
3490 /* MACLEN can support at most 63 words */
3491 len
= skb_network_header(skb
) - skb
->data
;
3492 if (len
& ~(63 * 2))
3495 /* IPLEN and EIPLEN can support at most 127 dwords */
3496 len
= skb_transport_header(skb
) - skb_network_header(skb
);
3497 if (len
& ~(127 * 4))
3500 if (skb
->encapsulation
) {
3501 /* L4TUNLEN can support 127 words */
3502 len
= skb_inner_network_header(skb
) - skb_transport_header(skb
);
3503 if (len
& ~(127 * 2))
3506 /* IPLEN can support at most 127 dwords */
3507 len
= skb_inner_transport_header(skb
) -
3508 skb_inner_network_header(skb
);
3509 if (len
& ~(127 * 4))
3513 /* No need to validate L4LEN as TCP is the only protocol with a
3514 * a flexible value and we support all possible values supported
3515 * by TCP, which is at most 15 dwords
3520 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
3524 * iavf_fix_features - fix up the netdev feature bits
3525 * @netdev: our net device
3526 * @features: desired feature bits
3528 * Returns fixed-up features bits
3530 static netdev_features_t
iavf_fix_features(struct net_device
*netdev
,
3531 netdev_features_t features
)
3533 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3535 if (adapter
->vf_res
&&
3536 !(adapter
->vf_res
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
))
3537 features
&= ~(NETIF_F_HW_VLAN_CTAG_TX
|
3538 NETIF_F_HW_VLAN_CTAG_RX
|
3539 NETIF_F_HW_VLAN_CTAG_FILTER
);
3544 static const struct net_device_ops iavf_netdev_ops
= {
3545 .ndo_open
= iavf_open
,
3546 .ndo_stop
= iavf_close
,
3547 .ndo_start_xmit
= iavf_xmit_frame
,
3548 .ndo_set_rx_mode
= iavf_set_rx_mode
,
3549 .ndo_validate_addr
= eth_validate_addr
,
3550 .ndo_set_mac_address
= iavf_set_mac
,
3551 .ndo_change_mtu
= iavf_change_mtu
,
3552 .ndo_tx_timeout
= iavf_tx_timeout
,
3553 .ndo_vlan_rx_add_vid
= iavf_vlan_rx_add_vid
,
3554 .ndo_vlan_rx_kill_vid
= iavf_vlan_rx_kill_vid
,
3555 .ndo_features_check
= iavf_features_check
,
3556 .ndo_fix_features
= iavf_fix_features
,
3557 .ndo_set_features
= iavf_set_features
,
3558 .ndo_setup_tc
= iavf_setup_tc
,
3562 * iavf_check_reset_complete - check that VF reset is complete
3563 * @hw: pointer to hw struct
3565 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
3567 static int iavf_check_reset_complete(struct iavf_hw
*hw
)
3572 for (i
= 0; i
< IAVF_RESET_WAIT_COMPLETE_COUNT
; i
++) {
3573 rstat
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
3574 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
3575 if ((rstat
== VIRTCHNL_VFR_VFACTIVE
) ||
3576 (rstat
== VIRTCHNL_VFR_COMPLETED
))
3578 usleep_range(10, 20);
3584 * iavf_process_config - Process the config information we got from the PF
3585 * @adapter: board private structure
3587 * Verify that we have a valid config struct, and set up our netdev features
3588 * and our VSI struct.
3590 int iavf_process_config(struct iavf_adapter
*adapter
)
3592 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
3593 int i
, num_req_queues
= adapter
->num_req_queues
;
3594 struct net_device
*netdev
= adapter
->netdev
;
3595 struct iavf_vsi
*vsi
= &adapter
->vsi
;
3596 netdev_features_t hw_enc_features
;
3597 netdev_features_t hw_features
;
3599 /* got VF config message back from PF, now we can parse it */
3600 for (i
= 0; i
< vfres
->num_vsis
; i
++) {
3601 if (vfres
->vsi_res
[i
].vsi_type
== VIRTCHNL_VSI_SRIOV
)
3602 adapter
->vsi_res
= &vfres
->vsi_res
[i
];
3604 if (!adapter
->vsi_res
) {
3605 dev_err(&adapter
->pdev
->dev
, "No LAN VSI found\n");
3609 if (num_req_queues
&&
3610 num_req_queues
> adapter
->vsi_res
->num_queue_pairs
) {
3611 /* Problem. The PF gave us fewer queues than what we had
3612 * negotiated in our request. Need a reset to see if we can't
3613 * get back to a working state.
3615 dev_err(&adapter
->pdev
->dev
,
3616 "Requested %d queues, but PF only gave us %d.\n",
3618 adapter
->vsi_res
->num_queue_pairs
);
3619 adapter
->flags
|= IAVF_FLAG_REINIT_ITR_NEEDED
;
3620 adapter
->num_req_queues
= adapter
->vsi_res
->num_queue_pairs
;
3621 iavf_schedule_reset(adapter
);
3624 adapter
->num_req_queues
= 0;
3626 hw_enc_features
= NETIF_F_SG
|
3630 NETIF_F_SOFT_FEATURES
|
3639 /* advertise to stack only if offloads for encapsulated packets is
3642 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ENCAP
) {
3643 hw_enc_features
|= NETIF_F_GSO_UDP_TUNNEL
|
3645 NETIF_F_GSO_GRE_CSUM
|
3646 NETIF_F_GSO_IPXIP4
|
3647 NETIF_F_GSO_IPXIP6
|
3648 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
3649 NETIF_F_GSO_PARTIAL
|
3652 if (!(vfres
->vf_cap_flags
&
3653 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
))
3654 netdev
->gso_partial_features
|=
3655 NETIF_F_GSO_UDP_TUNNEL_CSUM
;
3657 netdev
->gso_partial_features
|= NETIF_F_GSO_GRE_CSUM
;
3658 netdev
->hw_enc_features
|= NETIF_F_TSO_MANGLEID
;
3659 netdev
->hw_enc_features
|= hw_enc_features
;
3661 /* record features VLANs can make use of */
3662 netdev
->vlan_features
|= hw_enc_features
| NETIF_F_TSO_MANGLEID
;
3664 /* Write features and hw_features separately to avoid polluting
3665 * with, or dropping, features that are set when we registered.
3667 hw_features
= hw_enc_features
;
3669 /* Enable VLAN features if supported */
3670 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
)
3671 hw_features
|= (NETIF_F_HW_VLAN_CTAG_TX
|
3672 NETIF_F_HW_VLAN_CTAG_RX
);
3673 /* Enable cloud filter if ADQ is supported */
3674 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
)
3675 hw_features
|= NETIF_F_HW_TC
;
3676 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_USO
)
3677 hw_features
|= NETIF_F_GSO_UDP_L4
;
3679 netdev
->hw_features
|= hw_features
;
3681 netdev
->features
|= hw_features
;
3683 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
)
3684 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
3686 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
3688 /* Do not turn on offloads when they are requested to be turned off.
3689 * TSO needs minimum 576 bytes to work correctly.
3691 if (netdev
->wanted_features
) {
3692 if (!(netdev
->wanted_features
& NETIF_F_TSO
) ||
3694 netdev
->features
&= ~NETIF_F_TSO
;
3695 if (!(netdev
->wanted_features
& NETIF_F_TSO6
) ||
3697 netdev
->features
&= ~NETIF_F_TSO6
;
3698 if (!(netdev
->wanted_features
& NETIF_F_TSO_ECN
))
3699 netdev
->features
&= ~NETIF_F_TSO_ECN
;
3700 if (!(netdev
->wanted_features
& NETIF_F_GRO
))
3701 netdev
->features
&= ~NETIF_F_GRO
;
3702 if (!(netdev
->wanted_features
& NETIF_F_GSO
))
3703 netdev
->features
&= ~NETIF_F_GSO
;
3706 adapter
->vsi
.id
= adapter
->vsi_res
->vsi_id
;
3708 adapter
->vsi
.back
= adapter
;
3709 adapter
->vsi
.base_vector
= 1;
3710 adapter
->vsi
.work_limit
= IAVF_DEFAULT_IRQ_WORK
;
3711 vsi
->netdev
= adapter
->netdev
;
3712 vsi
->qs_handle
= adapter
->vsi_res
->qset_handle
;
3713 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_RSS_PF
) {
3714 adapter
->rss_key_size
= vfres
->rss_key_size
;
3715 adapter
->rss_lut_size
= vfres
->rss_lut_size
;
3717 adapter
->rss_key_size
= IAVF_HKEY_ARRAY_SIZE
;
3718 adapter
->rss_lut_size
= IAVF_HLUT_ARRAY_SIZE
;
3725 * iavf_shutdown - Shutdown the device in preparation for a reboot
3726 * @pdev: pci device structure
3728 static void iavf_shutdown(struct pci_dev
*pdev
)
3730 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3731 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3733 netif_device_detach(netdev
);
3735 if (netif_running(netdev
))
3738 if (iavf_lock_timeout(&adapter
->crit_lock
, 5000))
3739 dev_warn(&adapter
->pdev
->dev
, "failed to acquire crit_lock in %s\n", __FUNCTION__
);
3740 /* Prevent the watchdog from running. */
3741 iavf_change_state(adapter
, __IAVF_REMOVE
);
3742 adapter
->aq_required
= 0;
3743 mutex_unlock(&adapter
->crit_lock
);
3746 pci_save_state(pdev
);
3749 pci_disable_device(pdev
);
3753 * iavf_probe - Device Initialization Routine
3754 * @pdev: PCI device information struct
3755 * @ent: entry in iavf_pci_tbl
3757 * Returns 0 on success, negative on failure
3759 * iavf_probe initializes an adapter identified by a pci_dev structure.
3760 * The OS initialization, configuring of the adapter private structure,
3761 * and a hardware reset occur.
3763 static int iavf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
3765 struct net_device
*netdev
;
3766 struct iavf_adapter
*adapter
= NULL
;
3767 struct iavf_hw
*hw
= NULL
;
3770 err
= pci_enable_device(pdev
);
3774 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
3776 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
3779 "DMA configuration failed: 0x%x\n", err
);
3784 err
= pci_request_regions(pdev
, iavf_driver_name
);
3787 "pci_request_regions failed 0x%x\n", err
);
3791 pci_enable_pcie_error_reporting(pdev
);
3793 pci_set_master(pdev
);
3795 netdev
= alloc_etherdev_mq(sizeof(struct iavf_adapter
),
3796 IAVF_MAX_REQ_QUEUES
);
3799 goto err_alloc_etherdev
;
3802 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3804 pci_set_drvdata(pdev
, netdev
);
3805 adapter
= netdev_priv(netdev
);
3807 adapter
->netdev
= netdev
;
3808 adapter
->pdev
= pdev
;
3813 adapter
->msg_enable
= BIT(DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
3814 iavf_change_state(adapter
, __IAVF_STARTUP
);
3816 /* Call save state here because it relies on the adapter struct. */
3817 pci_save_state(pdev
);
3819 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
3820 pci_resource_len(pdev
, 0));
3825 hw
->vendor_id
= pdev
->vendor
;
3826 hw
->device_id
= pdev
->device
;
3827 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
3828 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
3829 hw
->subsystem_device_id
= pdev
->subsystem_device
;
3830 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
3831 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
3832 hw
->bus
.bus_id
= pdev
->bus
->number
;
3834 /* set up the locks for the AQ, do this only once in probe
3835 * and destroy them only once in remove
3837 mutex_init(&adapter
->crit_lock
);
3838 mutex_init(&adapter
->client_lock
);
3839 mutex_init(&adapter
->remove_lock
);
3840 mutex_init(&hw
->aq
.asq_mutex
);
3841 mutex_init(&hw
->aq
.arq_mutex
);
3843 spin_lock_init(&adapter
->mac_vlan_list_lock
);
3844 spin_lock_init(&adapter
->cloud_filter_list_lock
);
3845 spin_lock_init(&adapter
->fdir_fltr_lock
);
3846 spin_lock_init(&adapter
->adv_rss_lock
);
3848 INIT_LIST_HEAD(&adapter
->mac_filter_list
);
3849 INIT_LIST_HEAD(&adapter
->vlan_filter_list
);
3850 INIT_LIST_HEAD(&adapter
->cloud_filter_list
);
3851 INIT_LIST_HEAD(&adapter
->fdir_list_head
);
3852 INIT_LIST_HEAD(&adapter
->adv_rss_list_head
);
3854 INIT_WORK(&adapter
->reset_task
, iavf_reset_task
);
3855 INIT_WORK(&adapter
->adminq_task
, iavf_adminq_task
);
3856 INIT_DELAYED_WORK(&adapter
->watchdog_task
, iavf_watchdog_task
);
3857 INIT_DELAYED_WORK(&adapter
->client_task
, iavf_client_task
);
3858 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
,
3859 msecs_to_jiffies(5 * (pdev
->devfn
& 0x07)));
3861 /* Setup the wait queue for indicating transition to down status */
3862 init_waitqueue_head(&adapter
->down_waitqueue
);
3867 free_netdev(netdev
);
3869 pci_disable_pcie_error_reporting(pdev
);
3870 pci_release_regions(pdev
);
3873 pci_disable_device(pdev
);
3878 * iavf_suspend - Power management suspend routine
3879 * @dev_d: device info pointer
3881 * Called when the system (VM) is entering sleep/suspend.
3883 static int __maybe_unused
iavf_suspend(struct device
*dev_d
)
3885 struct net_device
*netdev
= dev_get_drvdata(dev_d
);
3886 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3888 netif_device_detach(netdev
);
3890 while (!mutex_trylock(&adapter
->crit_lock
))
3891 usleep_range(500, 1000);
3893 if (netif_running(netdev
)) {
3898 iavf_free_misc_irq(adapter
);
3899 iavf_reset_interrupt_capability(adapter
);
3901 mutex_unlock(&adapter
->crit_lock
);
3907 * iavf_resume - Power management resume routine
3908 * @dev_d: device info pointer
3910 * Called when the system (VM) is resumed from sleep/suspend.
3912 static int __maybe_unused
iavf_resume(struct device
*dev_d
)
3914 struct pci_dev
*pdev
= to_pci_dev(dev_d
);
3915 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3916 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3919 pci_set_master(pdev
);
3922 err
= iavf_set_interrupt_capability(adapter
);
3925 dev_err(&pdev
->dev
, "Cannot enable MSI-X interrupts.\n");
3928 err
= iavf_request_misc_irq(adapter
);
3931 dev_err(&pdev
->dev
, "Cannot get interrupt vector.\n");
3935 queue_work(iavf_wq
, &adapter
->reset_task
);
3937 netif_device_attach(netdev
);
3943 * iavf_remove - Device Removal Routine
3944 * @pdev: PCI device information struct
3946 * iavf_remove is called by the PCI subsystem to alert the driver
3947 * that it should release a PCI device. The could be caused by a
3948 * Hot-Plug event, or because the driver is going to be removed from
3951 static void iavf_remove(struct pci_dev
*pdev
)
3953 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3954 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3955 struct iavf_fdir_fltr
*fdir
, *fdirtmp
;
3956 struct iavf_vlan_filter
*vlf
, *vlftmp
;
3957 struct iavf_adv_rss
*rss
, *rsstmp
;
3958 struct iavf_mac_filter
*f
, *ftmp
;
3959 struct iavf_cloud_filter
*cf
, *cftmp
;
3960 struct iavf_hw
*hw
= &adapter
->hw
;
3962 /* Indicate we are in remove and not to run reset_task */
3963 mutex_lock(&adapter
->remove_lock
);
3964 cancel_work_sync(&adapter
->reset_task
);
3965 cancel_delayed_work_sync(&adapter
->watchdog_task
);
3966 cancel_delayed_work_sync(&adapter
->client_task
);
3967 if (adapter
->netdev_registered
) {
3968 unregister_netdev(netdev
);
3969 adapter
->netdev_registered
= false;
3971 if (CLIENT_ALLOWED(adapter
)) {
3972 err
= iavf_lan_del_device(adapter
);
3974 dev_warn(&pdev
->dev
, "Failed to delete client device: %d\n",
3978 iavf_request_reset(adapter
);
3980 /* If the FW isn't responding, kick it once, but only once. */
3981 if (!iavf_asq_done(hw
)) {
3982 iavf_request_reset(adapter
);
3985 if (iavf_lock_timeout(&adapter
->crit_lock
, 5000))
3986 dev_warn(&adapter
->pdev
->dev
, "failed to acquire crit_lock in %s\n", __FUNCTION__
);
3988 /* Shut down all the garbage mashers on the detention level */
3989 iavf_change_state(adapter
, __IAVF_REMOVE
);
3990 adapter
->aq_required
= 0;
3991 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
3992 iavf_free_all_tx_resources(adapter
);
3993 iavf_free_all_rx_resources(adapter
);
3994 iavf_misc_irq_disable(adapter
);
3995 iavf_free_misc_irq(adapter
);
3996 iavf_reset_interrupt_capability(adapter
);
3997 iavf_free_q_vectors(adapter
);
3999 cancel_delayed_work_sync(&adapter
->watchdog_task
);
4001 cancel_work_sync(&adapter
->adminq_task
);
4003 iavf_free_rss(adapter
);
4005 if (hw
->aq
.asq
.count
)
4006 iavf_shutdown_adminq(hw
);
4008 /* destroy the locks only once, here */
4009 mutex_destroy(&hw
->aq
.arq_mutex
);
4010 mutex_destroy(&hw
->aq
.asq_mutex
);
4011 mutex_destroy(&adapter
->client_lock
);
4012 mutex_unlock(&adapter
->crit_lock
);
4013 mutex_destroy(&adapter
->crit_lock
);
4014 mutex_unlock(&adapter
->remove_lock
);
4015 mutex_destroy(&adapter
->remove_lock
);
4017 iounmap(hw
->hw_addr
);
4018 pci_release_regions(pdev
);
4019 iavf_free_queues(adapter
);
4020 kfree(adapter
->vf_res
);
4021 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
4022 /* If we got removed before an up/down sequence, we've got a filter
4023 * hanging out there that we need to get rid of.
4025 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
4029 list_for_each_entry_safe(vlf
, vlftmp
, &adapter
->vlan_filter_list
,
4031 list_del(&vlf
->list
);
4035 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
4037 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
4038 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
, list
) {
4039 list_del(&cf
->list
);
4042 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
4044 spin_lock_bh(&adapter
->fdir_fltr_lock
);
4045 list_for_each_entry_safe(fdir
, fdirtmp
, &adapter
->fdir_list_head
, list
) {
4046 list_del(&fdir
->list
);
4049 spin_unlock_bh(&adapter
->fdir_fltr_lock
);
4051 spin_lock_bh(&adapter
->adv_rss_lock
);
4052 list_for_each_entry_safe(rss
, rsstmp
, &adapter
->adv_rss_list_head
,
4054 list_del(&rss
->list
);
4057 spin_unlock_bh(&adapter
->adv_rss_lock
);
4059 free_netdev(netdev
);
4061 pci_disable_pcie_error_reporting(pdev
);
4063 pci_disable_device(pdev
);
4066 static SIMPLE_DEV_PM_OPS(iavf_pm_ops
, iavf_suspend
, iavf_resume
);
4068 static struct pci_driver iavf_driver
= {
4069 .name
= iavf_driver_name
,
4070 .id_table
= iavf_pci_tbl
,
4071 .probe
= iavf_probe
,
4072 .remove
= iavf_remove
,
4073 .driver
.pm
= &iavf_pm_ops
,
4074 .shutdown
= iavf_shutdown
,
4078 * iavf_init_module - Driver Registration Routine
4080 * iavf_init_module is the first routine called when the driver is
4081 * loaded. All it does is register with the PCI subsystem.
4083 static int __init
iavf_init_module(void)
4087 pr_info("iavf: %s\n", iavf_driver_string
);
4089 pr_info("%s\n", iavf_copyright
);
4091 iavf_wq
= alloc_workqueue("%s", WQ_UNBOUND
| WQ_MEM_RECLAIM
, 1,
4094 pr_err("%s: Failed to create workqueue\n", iavf_driver_name
);
4097 ret
= pci_register_driver(&iavf_driver
);
4101 module_init(iavf_init_module
);
4104 * iavf_exit_module - Driver Exit Cleanup Routine
4106 * iavf_exit_module is called just before the driver is removed
4109 static void __exit
iavf_exit_module(void)
4111 pci_unregister_driver(&iavf_driver
);
4112 destroy_workqueue(iavf_wq
);
4115 module_exit(iavf_exit_module
);