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 int 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";
26 #define DRV_VERSION_MAJOR 3
27 #define DRV_VERSION_MINOR 2
28 #define DRV_VERSION_BUILD 3
29 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
30 __stringify(DRV_VERSION_MINOR) "." \
31 __stringify(DRV_VERSION_BUILD) \
33 const char iavf_driver_version
[] = DRV_VERSION
;
34 static const char iavf_copyright
[] =
35 "Copyright (c) 2013 - 2018 Intel Corporation.";
37 /* iavf_pci_tbl - PCI Device ID Table
39 * Wildcard entries (PCI_ANY_ID) should come last
40 * Last entry must be all 0s
42 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
43 * Class, Class Mask, private data (not used) }
45 static const struct pci_device_id iavf_pci_tbl
[] = {
46 {PCI_VDEVICE(INTEL
, IAVF_DEV_ID_VF
), 0},
47 {PCI_VDEVICE(INTEL
, IAVF_DEV_ID_VF_HV
), 0},
48 {PCI_VDEVICE(INTEL
, IAVF_DEV_ID_X722_VF
), 0},
49 {PCI_VDEVICE(INTEL
, IAVF_DEV_ID_ADAPTIVE_VF
), 0},
50 /* required last entry */
54 MODULE_DEVICE_TABLE(pci
, iavf_pci_tbl
);
56 MODULE_ALIAS("i40evf");
57 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
58 MODULE_DESCRIPTION("Intel(R) Ethernet Adaptive Virtual Function Network Driver");
59 MODULE_LICENSE("GPL v2");
60 MODULE_VERSION(DRV_VERSION
);
62 static const struct net_device_ops iavf_netdev_ops
;
63 struct workqueue_struct
*iavf_wq
;
66 * iavf_allocate_dma_mem_d - OS specific memory alloc for shared code
67 * @hw: pointer to the HW structure
68 * @mem: ptr to mem struct to fill out
69 * @size: size of memory requested
70 * @alignment: what to align the allocation to
72 enum iavf_status
iavf_allocate_dma_mem_d(struct iavf_hw
*hw
,
73 struct iavf_dma_mem
*mem
,
74 u64 size
, u32 alignment
)
76 struct iavf_adapter
*adapter
= (struct iavf_adapter
*)hw
->back
;
79 return IAVF_ERR_PARAM
;
81 mem
->size
= ALIGN(size
, alignment
);
82 mem
->va
= dma_alloc_coherent(&adapter
->pdev
->dev
, mem
->size
,
83 (dma_addr_t
*)&mem
->pa
, GFP_KERNEL
);
87 return IAVF_ERR_NO_MEMORY
;
91 * iavf_free_dma_mem_d - OS specific memory free for shared code
92 * @hw: pointer to the HW structure
93 * @mem: ptr to mem struct to free
95 enum iavf_status
iavf_free_dma_mem_d(struct iavf_hw
*hw
,
96 struct iavf_dma_mem
*mem
)
98 struct iavf_adapter
*adapter
= (struct iavf_adapter
*)hw
->back
;
100 if (!mem
|| !mem
->va
)
101 return IAVF_ERR_PARAM
;
102 dma_free_coherent(&adapter
->pdev
->dev
, mem
->size
,
103 mem
->va
, (dma_addr_t
)mem
->pa
);
108 * iavf_allocate_virt_mem_d - OS specific memory alloc for shared code
109 * @hw: pointer to the HW structure
110 * @mem: ptr to mem struct to fill out
111 * @size: size of memory requested
113 enum iavf_status
iavf_allocate_virt_mem_d(struct iavf_hw
*hw
,
114 struct iavf_virt_mem
*mem
, u32 size
)
117 return IAVF_ERR_PARAM
;
120 mem
->va
= kzalloc(size
, GFP_KERNEL
);
125 return IAVF_ERR_NO_MEMORY
;
129 * iavf_free_virt_mem_d - OS specific memory free for shared code
130 * @hw: pointer to the HW structure
131 * @mem: ptr to mem struct to free
133 enum iavf_status
iavf_free_virt_mem_d(struct iavf_hw
*hw
,
134 struct iavf_virt_mem
*mem
)
137 return IAVF_ERR_PARAM
;
139 /* it's ok to kfree a NULL pointer */
146 * iavf_schedule_reset - Set the flags and schedule a reset event
147 * @adapter: board private structure
149 void iavf_schedule_reset(struct iavf_adapter
*adapter
)
151 if (!(adapter
->flags
&
152 (IAVF_FLAG_RESET_PENDING
| IAVF_FLAG_RESET_NEEDED
))) {
153 adapter
->flags
|= IAVF_FLAG_RESET_NEEDED
;
154 queue_work(iavf_wq
, &adapter
->reset_task
);
159 * iavf_tx_timeout - Respond to a Tx Hang
160 * @netdev: network interface device structure
162 static void iavf_tx_timeout(struct net_device
*netdev
)
164 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
166 adapter
->tx_timeout_count
++;
167 iavf_schedule_reset(adapter
);
171 * iavf_misc_irq_disable - Mask off interrupt generation on the NIC
172 * @adapter: board private structure
174 static void iavf_misc_irq_disable(struct iavf_adapter
*adapter
)
176 struct iavf_hw
*hw
= &adapter
->hw
;
178 if (!adapter
->msix_entries
)
181 wr32(hw
, IAVF_VFINT_DYN_CTL01
, 0);
185 synchronize_irq(adapter
->msix_entries
[0].vector
);
189 * iavf_misc_irq_enable - Enable default interrupt generation settings
190 * @adapter: board private structure
192 static void iavf_misc_irq_enable(struct iavf_adapter
*adapter
)
194 struct iavf_hw
*hw
= &adapter
->hw
;
196 wr32(hw
, IAVF_VFINT_DYN_CTL01
, IAVF_VFINT_DYN_CTL01_INTENA_MASK
|
197 IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK
);
198 wr32(hw
, IAVF_VFINT_ICR0_ENA1
, IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK
);
204 * iavf_irq_disable - Mask off interrupt generation on the NIC
205 * @adapter: board private structure
207 static void iavf_irq_disable(struct iavf_adapter
*adapter
)
210 struct iavf_hw
*hw
= &adapter
->hw
;
212 if (!adapter
->msix_entries
)
215 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
216 wr32(hw
, IAVF_VFINT_DYN_CTLN1(i
- 1), 0);
217 synchronize_irq(adapter
->msix_entries
[i
].vector
);
223 * iavf_irq_enable_queues - Enable interrupt for specified queues
224 * @adapter: board private structure
225 * @mask: bitmap of queues to enable
227 void iavf_irq_enable_queues(struct iavf_adapter
*adapter
, u32 mask
)
229 struct iavf_hw
*hw
= &adapter
->hw
;
232 for (i
= 1; i
< adapter
->num_msix_vectors
; i
++) {
233 if (mask
& BIT(i
- 1)) {
234 wr32(hw
, IAVF_VFINT_DYN_CTLN1(i
- 1),
235 IAVF_VFINT_DYN_CTLN1_INTENA_MASK
|
236 IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK
);
242 * iavf_irq_enable - Enable default interrupt generation settings
243 * @adapter: board private structure
244 * @flush: boolean value whether to run rd32()
246 void iavf_irq_enable(struct iavf_adapter
*adapter
, bool flush
)
248 struct iavf_hw
*hw
= &adapter
->hw
;
250 iavf_misc_irq_enable(adapter
);
251 iavf_irq_enable_queues(adapter
, ~0);
258 * iavf_msix_aq - Interrupt handler for vector 0
259 * @irq: interrupt number
260 * @data: pointer to netdev
262 static irqreturn_t
iavf_msix_aq(int irq
, void *data
)
264 struct net_device
*netdev
= data
;
265 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
266 struct iavf_hw
*hw
= &adapter
->hw
;
268 /* handle non-queue interrupts, these reads clear the registers */
269 rd32(hw
, IAVF_VFINT_ICR01
);
270 rd32(hw
, IAVF_VFINT_ICR0_ENA1
);
272 /* schedule work on the private workqueue */
273 queue_work(iavf_wq
, &adapter
->adminq_task
);
279 * iavf_msix_clean_rings - MSIX mode Interrupt Handler
280 * @irq: interrupt number
281 * @data: pointer to a q_vector
283 static irqreturn_t
iavf_msix_clean_rings(int irq
, void *data
)
285 struct iavf_q_vector
*q_vector
= data
;
287 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
290 napi_schedule_irqoff(&q_vector
->napi
);
296 * iavf_map_vector_to_rxq - associate irqs with rx queues
297 * @adapter: board private structure
298 * @v_idx: interrupt number
299 * @r_idx: queue number
302 iavf_map_vector_to_rxq(struct iavf_adapter
*adapter
, int v_idx
, int r_idx
)
304 struct iavf_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
305 struct iavf_ring
*rx_ring
= &adapter
->rx_rings
[r_idx
];
306 struct iavf_hw
*hw
= &adapter
->hw
;
308 rx_ring
->q_vector
= q_vector
;
309 rx_ring
->next
= q_vector
->rx
.ring
;
310 rx_ring
->vsi
= &adapter
->vsi
;
311 q_vector
->rx
.ring
= rx_ring
;
312 q_vector
->rx
.count
++;
313 q_vector
->rx
.next_update
= jiffies
+ 1;
314 q_vector
->rx
.target_itr
= ITR_TO_REG(rx_ring
->itr_setting
);
315 q_vector
->ring_mask
|= BIT(r_idx
);
316 wr32(hw
, IAVF_VFINT_ITRN1(IAVF_RX_ITR
, q_vector
->reg_idx
),
317 q_vector
->rx
.current_itr
>> 1);
318 q_vector
->rx
.current_itr
= q_vector
->rx
.target_itr
;
322 * iavf_map_vector_to_txq - associate irqs with tx queues
323 * @adapter: board private structure
324 * @v_idx: interrupt number
325 * @t_idx: queue number
328 iavf_map_vector_to_txq(struct iavf_adapter
*adapter
, int v_idx
, int t_idx
)
330 struct iavf_q_vector
*q_vector
= &adapter
->q_vectors
[v_idx
];
331 struct iavf_ring
*tx_ring
= &adapter
->tx_rings
[t_idx
];
332 struct iavf_hw
*hw
= &adapter
->hw
;
334 tx_ring
->q_vector
= q_vector
;
335 tx_ring
->next
= q_vector
->tx
.ring
;
336 tx_ring
->vsi
= &adapter
->vsi
;
337 q_vector
->tx
.ring
= tx_ring
;
338 q_vector
->tx
.count
++;
339 q_vector
->tx
.next_update
= jiffies
+ 1;
340 q_vector
->tx
.target_itr
= ITR_TO_REG(tx_ring
->itr_setting
);
341 q_vector
->num_ringpairs
++;
342 wr32(hw
, IAVF_VFINT_ITRN1(IAVF_TX_ITR
, q_vector
->reg_idx
),
343 q_vector
->tx
.target_itr
>> 1);
344 q_vector
->tx
.current_itr
= q_vector
->tx
.target_itr
;
348 * iavf_map_rings_to_vectors - Maps descriptor rings to vectors
349 * @adapter: board private structure to initialize
351 * This function maps descriptor rings to the queue-specific vectors
352 * we were allotted through the MSI-X enabling code. Ideally, we'd have
353 * one vector per ring/queue, but on a constrained vector budget, we
354 * group the rings as "efficiently" as possible. You would add new
355 * mapping configurations in here.
357 static void iavf_map_rings_to_vectors(struct iavf_adapter
*adapter
)
359 int rings_remaining
= adapter
->num_active_queues
;
360 int ridx
= 0, vidx
= 0;
363 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
365 for (; ridx
< rings_remaining
; ridx
++) {
366 iavf_map_vector_to_rxq(adapter
, vidx
, ridx
);
367 iavf_map_vector_to_txq(adapter
, vidx
, ridx
);
369 /* In the case where we have more queues than vectors, continue
370 * round-robin on vectors until all queues are mapped.
372 if (++vidx
>= q_vectors
)
376 adapter
->aq_required
|= IAVF_FLAG_AQ_MAP_VECTORS
;
380 * iavf_irq_affinity_notify - Callback for affinity changes
381 * @notify: context as to what irq was changed
382 * @mask: the new affinity mask
384 * This is a callback function used by the irq_set_affinity_notifier function
385 * so that we may register to receive changes to the irq affinity masks.
387 static void iavf_irq_affinity_notify(struct irq_affinity_notify
*notify
,
388 const cpumask_t
*mask
)
390 struct iavf_q_vector
*q_vector
=
391 container_of(notify
, struct iavf_q_vector
, affinity_notify
);
393 cpumask_copy(&q_vector
->affinity_mask
, mask
);
397 * iavf_irq_affinity_release - Callback for affinity notifier release
398 * @ref: internal core kernel usage
400 * This is a callback function used by the irq_set_affinity_notifier function
401 * to inform the current notification subscriber that they will no longer
402 * receive notifications.
404 static void iavf_irq_affinity_release(struct kref
*ref
) {}
407 * iavf_request_traffic_irqs - Initialize MSI-X interrupts
408 * @adapter: board private structure
409 * @basename: device basename
411 * Allocates MSI-X vectors for tx and rx handling, and requests
412 * interrupts from the kernel.
415 iavf_request_traffic_irqs(struct iavf_adapter
*adapter
, char *basename
)
417 unsigned int vector
, q_vectors
;
418 unsigned int rx_int_idx
= 0, tx_int_idx
= 0;
422 iavf_irq_disable(adapter
);
423 /* Decrement for Other and TCP Timer vectors */
424 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
426 for (vector
= 0; vector
< q_vectors
; vector
++) {
427 struct iavf_q_vector
*q_vector
= &adapter
->q_vectors
[vector
];
429 irq_num
= adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
;
431 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
432 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
433 "iavf-%s-TxRx-%d", basename
, rx_int_idx
++);
435 } else if (q_vector
->rx
.ring
) {
436 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
437 "iavf-%s-rx-%d", basename
, rx_int_idx
++);
438 } else if (q_vector
->tx
.ring
) {
439 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
440 "iavf-%s-tx-%d", basename
, tx_int_idx
++);
442 /* skip this unused q_vector */
445 err
= request_irq(irq_num
,
446 iavf_msix_clean_rings
,
451 dev_info(&adapter
->pdev
->dev
,
452 "Request_irq failed, error: %d\n", err
);
453 goto free_queue_irqs
;
455 /* register for affinity change notifications */
456 q_vector
->affinity_notify
.notify
= iavf_irq_affinity_notify
;
457 q_vector
->affinity_notify
.release
=
458 iavf_irq_affinity_release
;
459 irq_set_affinity_notifier(irq_num
, &q_vector
->affinity_notify
);
460 /* Spread the IRQ affinity hints across online CPUs. Note that
461 * get_cpu_mask returns a mask with a permanent lifetime so
462 * it's safe to use as a hint for irq_set_affinity_hint.
464 cpu
= cpumask_local_spread(q_vector
->v_idx
, -1);
465 irq_set_affinity_hint(irq_num
, get_cpu_mask(cpu
));
473 irq_num
= adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
;
474 irq_set_affinity_notifier(irq_num
, NULL
);
475 irq_set_affinity_hint(irq_num
, NULL
);
476 free_irq(irq_num
, &adapter
->q_vectors
[vector
]);
482 * iavf_request_misc_irq - Initialize MSI-X interrupts
483 * @adapter: board private structure
485 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
486 * vector is only for the admin queue, and stays active even when the netdev
489 static int iavf_request_misc_irq(struct iavf_adapter
*adapter
)
491 struct net_device
*netdev
= adapter
->netdev
;
494 snprintf(adapter
->misc_vector_name
,
495 sizeof(adapter
->misc_vector_name
) - 1, "iavf-%s:mbx",
496 dev_name(&adapter
->pdev
->dev
));
497 err
= request_irq(adapter
->msix_entries
[0].vector
,
499 adapter
->misc_vector_name
, netdev
);
501 dev_err(&adapter
->pdev
->dev
,
502 "request_irq for %s failed: %d\n",
503 adapter
->misc_vector_name
, err
);
504 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
510 * iavf_free_traffic_irqs - Free MSI-X interrupts
511 * @adapter: board private structure
513 * Frees all MSI-X vectors other than 0.
515 static void iavf_free_traffic_irqs(struct iavf_adapter
*adapter
)
517 int vector
, irq_num
, q_vectors
;
519 if (!adapter
->msix_entries
)
522 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
524 for (vector
= 0; vector
< q_vectors
; vector
++) {
525 irq_num
= adapter
->msix_entries
[vector
+ NONQ_VECS
].vector
;
526 irq_set_affinity_notifier(irq_num
, NULL
);
527 irq_set_affinity_hint(irq_num
, NULL
);
528 free_irq(irq_num
, &adapter
->q_vectors
[vector
]);
533 * iavf_free_misc_irq - Free MSI-X miscellaneous vector
534 * @adapter: board private structure
536 * Frees MSI-X vector 0.
538 static void iavf_free_misc_irq(struct iavf_adapter
*adapter
)
540 struct net_device
*netdev
= adapter
->netdev
;
542 if (!adapter
->msix_entries
)
545 free_irq(adapter
->msix_entries
[0].vector
, netdev
);
549 * iavf_configure_tx - Configure Transmit Unit after Reset
550 * @adapter: board private structure
552 * Configure the Tx unit of the MAC after a reset.
554 static void iavf_configure_tx(struct iavf_adapter
*adapter
)
556 struct iavf_hw
*hw
= &adapter
->hw
;
559 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
560 adapter
->tx_rings
[i
].tail
= hw
->hw_addr
+ IAVF_QTX_TAIL1(i
);
564 * iavf_configure_rx - Configure Receive Unit after Reset
565 * @adapter: board private structure
567 * Configure the Rx unit of the MAC after a reset.
569 static void iavf_configure_rx(struct iavf_adapter
*adapter
)
571 unsigned int rx_buf_len
= IAVF_RXBUFFER_2048
;
572 struct iavf_hw
*hw
= &adapter
->hw
;
575 /* Legacy Rx will always default to a 2048 buffer size. */
576 #if (PAGE_SIZE < 8192)
577 if (!(adapter
->flags
& IAVF_FLAG_LEGACY_RX
)) {
578 struct net_device
*netdev
= adapter
->netdev
;
580 /* For jumbo frames on systems with 4K pages we have to use
581 * an order 1 page, so we might as well increase the size
582 * of our Rx buffer to make better use of the available space
584 rx_buf_len
= IAVF_RXBUFFER_3072
;
586 /* We use a 1536 buffer size for configurations with
587 * standard Ethernet mtu. On x86 this gives us enough room
588 * for shared info and 192 bytes of padding.
590 if (!IAVF_2K_TOO_SMALL_WITH_PADDING
&&
591 (netdev
->mtu
<= ETH_DATA_LEN
))
592 rx_buf_len
= IAVF_RXBUFFER_1536
- NET_IP_ALIGN
;
596 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
597 adapter
->rx_rings
[i
].tail
= hw
->hw_addr
+ IAVF_QRX_TAIL1(i
);
598 adapter
->rx_rings
[i
].rx_buf_len
= rx_buf_len
;
600 if (adapter
->flags
& IAVF_FLAG_LEGACY_RX
)
601 clear_ring_build_skb_enabled(&adapter
->rx_rings
[i
]);
603 set_ring_build_skb_enabled(&adapter
->rx_rings
[i
]);
608 * iavf_find_vlan - Search filter list for specific vlan filter
609 * @adapter: board private structure
612 * Returns ptr to the filter object or NULL. Must be called while holding the
613 * mac_vlan_list_lock.
616 iavf_vlan_filter
*iavf_find_vlan(struct iavf_adapter
*adapter
, u16 vlan
)
618 struct iavf_vlan_filter
*f
;
620 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
628 * iavf_add_vlan - Add a vlan filter to the list
629 * @adapter: board private structure
632 * Returns ptr to the filter object or NULL when no memory available.
635 iavf_vlan_filter
*iavf_add_vlan(struct iavf_adapter
*adapter
, u16 vlan
)
637 struct iavf_vlan_filter
*f
= NULL
;
639 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
641 f
= iavf_find_vlan(adapter
, vlan
);
643 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
649 list_add_tail(&f
->list
, &adapter
->vlan_filter_list
);
651 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_VLAN_FILTER
;
655 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
660 * iavf_del_vlan - Remove a vlan filter from the list
661 * @adapter: board private structure
664 static void iavf_del_vlan(struct iavf_adapter
*adapter
, u16 vlan
)
666 struct iavf_vlan_filter
*f
;
668 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
670 f
= iavf_find_vlan(adapter
, vlan
);
673 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_VLAN_FILTER
;
676 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
680 * iavf_vlan_rx_add_vid - Add a VLAN filter to a device
681 * @netdev: network device struct
682 * @proto: unused protocol data
685 static int iavf_vlan_rx_add_vid(struct net_device
*netdev
,
686 __always_unused __be16 proto
, u16 vid
)
688 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
690 if (!VLAN_ALLOWED(adapter
))
692 if (iavf_add_vlan(adapter
, vid
) == NULL
)
698 * iavf_vlan_rx_kill_vid - Remove a VLAN filter from a device
699 * @netdev: network device struct
700 * @proto: unused protocol data
703 static int iavf_vlan_rx_kill_vid(struct net_device
*netdev
,
704 __always_unused __be16 proto
, u16 vid
)
706 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
708 if (VLAN_ALLOWED(adapter
)) {
709 iavf_del_vlan(adapter
, vid
);
716 * iavf_find_filter - Search filter list for specific mac filter
717 * @adapter: board private structure
718 * @macaddr: the MAC address
720 * Returns ptr to the filter object or NULL. Must be called while holding the
721 * mac_vlan_list_lock.
724 iavf_mac_filter
*iavf_find_filter(struct iavf_adapter
*adapter
,
727 struct iavf_mac_filter
*f
;
732 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
733 if (ether_addr_equal(macaddr
, f
->macaddr
))
740 * iavf_add_filter - Add a mac filter to the filter list
741 * @adapter: board private structure
742 * @macaddr: the MAC address
744 * Returns ptr to the filter object or NULL when no memory available.
747 iavf_mac_filter
*iavf_add_filter(struct iavf_adapter
*adapter
,
750 struct iavf_mac_filter
*f
;
755 f
= iavf_find_filter(adapter
, macaddr
);
757 f
= kzalloc(sizeof(*f
), GFP_ATOMIC
);
761 ether_addr_copy(f
->macaddr
, macaddr
);
763 list_add_tail(&f
->list
, &adapter
->mac_filter_list
);
765 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_MAC_FILTER
;
774 * iavf_set_mac - NDO callback to set port mac address
775 * @netdev: network interface device structure
776 * @p: pointer to an address structure
778 * Returns 0 on success, negative on failure
780 static int iavf_set_mac(struct net_device
*netdev
, void *p
)
782 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
783 struct iavf_hw
*hw
= &adapter
->hw
;
784 struct iavf_mac_filter
*f
;
785 struct sockaddr
*addr
= p
;
787 if (!is_valid_ether_addr(addr
->sa_data
))
788 return -EADDRNOTAVAIL
;
790 if (ether_addr_equal(netdev
->dev_addr
, addr
->sa_data
))
793 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
795 f
= iavf_find_filter(adapter
, hw
->mac
.addr
);
798 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_MAC_FILTER
;
801 f
= iavf_add_filter(adapter
, addr
->sa_data
);
803 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
806 ether_addr_copy(hw
->mac
.addr
, addr
->sa_data
);
809 return (f
== NULL
) ? -ENOMEM
: 0;
813 * iavf_addr_sync - Callback for dev_(mc|uc)_sync to add address
814 * @netdev: the netdevice
815 * @addr: address to add
817 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
818 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
820 static int iavf_addr_sync(struct net_device
*netdev
, const u8
*addr
)
822 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
824 if (iavf_add_filter(adapter
, addr
))
831 * iavf_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
832 * @netdev: the netdevice
833 * @addr: address to add
835 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
836 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
838 static int iavf_addr_unsync(struct net_device
*netdev
, const u8
*addr
)
840 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
841 struct iavf_mac_filter
*f
;
843 /* Under some circumstances, we might receive a request to delete
844 * our own device address from our uc list. Because we store the
845 * device address in the VSI's MAC/VLAN filter list, we need to ignore
846 * such requests and not delete our device address from this list.
848 if (ether_addr_equal(addr
, netdev
->dev_addr
))
851 f
= iavf_find_filter(adapter
, addr
);
854 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_MAC_FILTER
;
860 * iavf_set_rx_mode - NDO callback to set the netdev filters
861 * @netdev: network interface device structure
863 static void iavf_set_rx_mode(struct net_device
*netdev
)
865 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
867 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
868 __dev_uc_sync(netdev
, iavf_addr_sync
, iavf_addr_unsync
);
869 __dev_mc_sync(netdev
, iavf_addr_sync
, iavf_addr_unsync
);
870 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
872 if (netdev
->flags
& IFF_PROMISC
&&
873 !(adapter
->flags
& IAVF_FLAG_PROMISC_ON
))
874 adapter
->aq_required
|= IAVF_FLAG_AQ_REQUEST_PROMISC
;
875 else if (!(netdev
->flags
& IFF_PROMISC
) &&
876 adapter
->flags
& IAVF_FLAG_PROMISC_ON
)
877 adapter
->aq_required
|= IAVF_FLAG_AQ_RELEASE_PROMISC
;
879 if (netdev
->flags
& IFF_ALLMULTI
&&
880 !(adapter
->flags
& IAVF_FLAG_ALLMULTI_ON
))
881 adapter
->aq_required
|= IAVF_FLAG_AQ_REQUEST_ALLMULTI
;
882 else if (!(netdev
->flags
& IFF_ALLMULTI
) &&
883 adapter
->flags
& IAVF_FLAG_ALLMULTI_ON
)
884 adapter
->aq_required
|= IAVF_FLAG_AQ_RELEASE_ALLMULTI
;
888 * iavf_napi_enable_all - enable NAPI on all queue vectors
889 * @adapter: board private structure
891 static void iavf_napi_enable_all(struct iavf_adapter
*adapter
)
894 struct iavf_q_vector
*q_vector
;
895 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
897 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
898 struct napi_struct
*napi
;
900 q_vector
= &adapter
->q_vectors
[q_idx
];
901 napi
= &q_vector
->napi
;
907 * iavf_napi_disable_all - disable NAPI on all queue vectors
908 * @adapter: board private structure
910 static void iavf_napi_disable_all(struct iavf_adapter
*adapter
)
913 struct iavf_q_vector
*q_vector
;
914 int q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
916 for (q_idx
= 0; q_idx
< q_vectors
; q_idx
++) {
917 q_vector
= &adapter
->q_vectors
[q_idx
];
918 napi_disable(&q_vector
->napi
);
923 * iavf_configure - set up transmit and receive data structures
924 * @adapter: board private structure
926 static void iavf_configure(struct iavf_adapter
*adapter
)
928 struct net_device
*netdev
= adapter
->netdev
;
931 iavf_set_rx_mode(netdev
);
933 iavf_configure_tx(adapter
);
934 iavf_configure_rx(adapter
);
935 adapter
->aq_required
|= IAVF_FLAG_AQ_CONFIGURE_QUEUES
;
937 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
938 struct iavf_ring
*ring
= &adapter
->rx_rings
[i
];
940 iavf_alloc_rx_buffers(ring
, IAVF_DESC_UNUSED(ring
));
945 * iavf_up_complete - Finish the last steps of bringing up a connection
946 * @adapter: board private structure
948 * Expects to be called while holding the __IAVF_IN_CRITICAL_TASK bit lock.
950 static void iavf_up_complete(struct iavf_adapter
*adapter
)
952 adapter
->state
= __IAVF_RUNNING
;
953 clear_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
955 iavf_napi_enable_all(adapter
);
957 adapter
->aq_required
|= IAVF_FLAG_AQ_ENABLE_QUEUES
;
958 if (CLIENT_ENABLED(adapter
))
959 adapter
->flags
|= IAVF_FLAG_CLIENT_NEEDS_OPEN
;
960 mod_delayed_work(iavf_wq
, &adapter
->watchdog_task
, 0);
964 * iavf_down - Shutdown the connection processing
965 * @adapter: board private structure
967 * Expects to be called while holding the __IAVF_IN_CRITICAL_TASK bit lock.
969 void iavf_down(struct iavf_adapter
*adapter
)
971 struct net_device
*netdev
= adapter
->netdev
;
972 struct iavf_vlan_filter
*vlf
;
973 struct iavf_mac_filter
*f
;
974 struct iavf_cloud_filter
*cf
;
976 if (adapter
->state
<= __IAVF_DOWN_PENDING
)
979 netif_carrier_off(netdev
);
980 netif_tx_disable(netdev
);
981 adapter
->link_up
= false;
982 iavf_napi_disable_all(adapter
);
983 iavf_irq_disable(adapter
);
985 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
987 /* clear the sync flag on all filters */
988 __dev_uc_unsync(adapter
->netdev
, NULL
);
989 __dev_mc_unsync(adapter
->netdev
, NULL
);
991 /* remove all MAC filters */
992 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
996 /* remove all VLAN filters */
997 list_for_each_entry(vlf
, &adapter
->vlan_filter_list
, list
) {
1001 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
1003 /* remove all cloud filters */
1004 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
1005 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
1008 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
1010 if (!(adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
) &&
1011 adapter
->state
!= __IAVF_RESETTING
) {
1012 /* cancel any current operation */
1013 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
1014 /* Schedule operations to close down the HW. Don't wait
1015 * here for this to complete. The watchdog is still running
1016 * and it will take care of this.
1018 adapter
->aq_required
= IAVF_FLAG_AQ_DEL_MAC_FILTER
;
1019 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_VLAN_FILTER
;
1020 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_CLOUD_FILTER
;
1021 adapter
->aq_required
|= IAVF_FLAG_AQ_DISABLE_QUEUES
;
1024 mod_delayed_work(iavf_wq
, &adapter
->watchdog_task
, 0);
1028 * iavf_acquire_msix_vectors - Setup the MSIX capability
1029 * @adapter: board private structure
1030 * @vectors: number of vectors to request
1032 * Work with the OS to set up the MSIX vectors needed.
1034 * Returns 0 on success, negative on failure
1037 iavf_acquire_msix_vectors(struct iavf_adapter
*adapter
, int vectors
)
1039 int err
, vector_threshold
;
1041 /* We'll want at least 3 (vector_threshold):
1042 * 0) Other (Admin Queue and link, mostly)
1046 vector_threshold
= MIN_MSIX_COUNT
;
1048 /* The more we get, the more we will assign to Tx/Rx Cleanup
1049 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1050 * Right now, we simply care about how many we'll get; we'll
1051 * set them up later while requesting irq's.
1053 err
= pci_enable_msix_range(adapter
->pdev
, adapter
->msix_entries
,
1054 vector_threshold
, vectors
);
1056 dev_err(&adapter
->pdev
->dev
, "Unable to allocate MSI-X interrupts\n");
1057 kfree(adapter
->msix_entries
);
1058 adapter
->msix_entries
= NULL
;
1062 /* Adjust for only the vectors we'll use, which is minimum
1063 * of max_msix_q_vectors + NONQ_VECS, or the number of
1064 * vectors we were allocated.
1066 adapter
->num_msix_vectors
= err
;
1071 * iavf_free_queues - Free memory for all rings
1072 * @adapter: board private structure to initialize
1074 * Free all of the memory associated with queue pairs.
1076 static void iavf_free_queues(struct iavf_adapter
*adapter
)
1078 if (!adapter
->vsi_res
)
1080 adapter
->num_active_queues
= 0;
1081 kfree(adapter
->tx_rings
);
1082 adapter
->tx_rings
= NULL
;
1083 kfree(adapter
->rx_rings
);
1084 adapter
->rx_rings
= NULL
;
1088 * iavf_alloc_queues - Allocate memory for all rings
1089 * @adapter: board private structure to initialize
1091 * We allocate one ring per queue at run-time since we don't know the
1092 * number of queues at compile-time. The polling_netdev array is
1093 * intended for Multiqueue, but should work fine with a single queue.
1095 static int iavf_alloc_queues(struct iavf_adapter
*adapter
)
1097 int i
, num_active_queues
;
1099 /* If we're in reset reallocating queues we don't actually know yet for
1100 * certain the PF gave us the number of queues we asked for but we'll
1101 * assume it did. Once basic reset is finished we'll confirm once we
1102 * start negotiating config with PF.
1104 if (adapter
->num_req_queues
)
1105 num_active_queues
= adapter
->num_req_queues
;
1106 else if ((adapter
->vf_res
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
) &&
1108 num_active_queues
= adapter
->ch_config
.total_qps
;
1110 num_active_queues
= min_t(int,
1111 adapter
->vsi_res
->num_queue_pairs
,
1112 (int)(num_online_cpus()));
1115 adapter
->tx_rings
= kcalloc(num_active_queues
,
1116 sizeof(struct iavf_ring
), GFP_KERNEL
);
1117 if (!adapter
->tx_rings
)
1119 adapter
->rx_rings
= kcalloc(num_active_queues
,
1120 sizeof(struct iavf_ring
), GFP_KERNEL
);
1121 if (!adapter
->rx_rings
)
1124 for (i
= 0; i
< num_active_queues
; i
++) {
1125 struct iavf_ring
*tx_ring
;
1126 struct iavf_ring
*rx_ring
;
1128 tx_ring
= &adapter
->tx_rings
[i
];
1130 tx_ring
->queue_index
= i
;
1131 tx_ring
->netdev
= adapter
->netdev
;
1132 tx_ring
->dev
= &adapter
->pdev
->dev
;
1133 tx_ring
->count
= adapter
->tx_desc_count
;
1134 tx_ring
->itr_setting
= IAVF_ITR_TX_DEF
;
1135 if (adapter
->flags
& IAVF_FLAG_WB_ON_ITR_CAPABLE
)
1136 tx_ring
->flags
|= IAVF_TXR_FLAGS_WB_ON_ITR
;
1138 rx_ring
= &adapter
->rx_rings
[i
];
1139 rx_ring
->queue_index
= i
;
1140 rx_ring
->netdev
= adapter
->netdev
;
1141 rx_ring
->dev
= &adapter
->pdev
->dev
;
1142 rx_ring
->count
= adapter
->rx_desc_count
;
1143 rx_ring
->itr_setting
= IAVF_ITR_RX_DEF
;
1146 adapter
->num_active_queues
= num_active_queues
;
1151 iavf_free_queues(adapter
);
1156 * iavf_set_interrupt_capability - set MSI-X or FAIL if not supported
1157 * @adapter: board private structure to initialize
1159 * Attempt to configure the interrupts using the best available
1160 * capabilities of the hardware and the kernel.
1162 static int iavf_set_interrupt_capability(struct iavf_adapter
*adapter
)
1164 int vector
, v_budget
;
1168 if (!adapter
->vsi_res
) {
1172 pairs
= adapter
->num_active_queues
;
1174 /* It's easy to be greedy for MSI-X vectors, but it really doesn't do
1175 * us much good if we have more vectors than CPUs. However, we already
1176 * limit the total number of queues by the number of CPUs so we do not
1177 * need any further limiting here.
1179 v_budget
= min_t(int, pairs
+ NONQ_VECS
,
1180 (int)adapter
->vf_res
->max_vectors
);
1182 adapter
->msix_entries
= kcalloc(v_budget
,
1183 sizeof(struct msix_entry
), GFP_KERNEL
);
1184 if (!adapter
->msix_entries
) {
1189 for (vector
= 0; vector
< v_budget
; vector
++)
1190 adapter
->msix_entries
[vector
].entry
= vector
;
1192 err
= iavf_acquire_msix_vectors(adapter
, v_budget
);
1195 netif_set_real_num_rx_queues(adapter
->netdev
, pairs
);
1196 netif_set_real_num_tx_queues(adapter
->netdev
, pairs
);
1201 * iavf_config_rss_aq - Configure RSS keys and lut by using AQ commands
1202 * @adapter: board private structure
1204 * Return 0 on success, negative on failure
1206 static int iavf_config_rss_aq(struct iavf_adapter
*adapter
)
1208 struct iavf_aqc_get_set_rss_key_data
*rss_key
=
1209 (struct iavf_aqc_get_set_rss_key_data
*)adapter
->rss_key
;
1210 struct iavf_hw
*hw
= &adapter
->hw
;
1213 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
1214 /* bail because we already have a command pending */
1215 dev_err(&adapter
->pdev
->dev
, "Cannot configure RSS, command %d pending\n",
1216 adapter
->current_op
);
1220 ret
= iavf_aq_set_rss_key(hw
, adapter
->vsi
.id
, rss_key
);
1222 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS key, err %s aq_err %s\n",
1223 iavf_stat_str(hw
, ret
),
1224 iavf_aq_str(hw
, hw
->aq
.asq_last_status
));
1229 ret
= iavf_aq_set_rss_lut(hw
, adapter
->vsi
.id
, false,
1230 adapter
->rss_lut
, adapter
->rss_lut_size
);
1232 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS lut, err %s aq_err %s\n",
1233 iavf_stat_str(hw
, ret
),
1234 iavf_aq_str(hw
, hw
->aq
.asq_last_status
));
1242 * iavf_config_rss_reg - Configure RSS keys and lut by writing registers
1243 * @adapter: board private structure
1245 * Returns 0 on success, negative on failure
1247 static int iavf_config_rss_reg(struct iavf_adapter
*adapter
)
1249 struct iavf_hw
*hw
= &adapter
->hw
;
1253 dw
= (u32
*)adapter
->rss_key
;
1254 for (i
= 0; i
<= adapter
->rss_key_size
/ 4; i
++)
1255 wr32(hw
, IAVF_VFQF_HKEY(i
), dw
[i
]);
1257 dw
= (u32
*)adapter
->rss_lut
;
1258 for (i
= 0; i
<= adapter
->rss_lut_size
/ 4; i
++)
1259 wr32(hw
, IAVF_VFQF_HLUT(i
), dw
[i
]);
1267 * iavf_config_rss - Configure RSS keys and lut
1268 * @adapter: board private structure
1270 * Returns 0 on success, negative on failure
1272 int iavf_config_rss(struct iavf_adapter
*adapter
)
1275 if (RSS_PF(adapter
)) {
1276 adapter
->aq_required
|= IAVF_FLAG_AQ_SET_RSS_LUT
|
1277 IAVF_FLAG_AQ_SET_RSS_KEY
;
1279 } else if (RSS_AQ(adapter
)) {
1280 return iavf_config_rss_aq(adapter
);
1282 return iavf_config_rss_reg(adapter
);
1287 * iavf_fill_rss_lut - Fill the lut with default values
1288 * @adapter: board private structure
1290 static void iavf_fill_rss_lut(struct iavf_adapter
*adapter
)
1294 for (i
= 0; i
< adapter
->rss_lut_size
; i
++)
1295 adapter
->rss_lut
[i
] = i
% adapter
->num_active_queues
;
1299 * iavf_init_rss - Prepare for RSS
1300 * @adapter: board private structure
1302 * Return 0 on success, negative on failure
1304 static int iavf_init_rss(struct iavf_adapter
*adapter
)
1306 struct iavf_hw
*hw
= &adapter
->hw
;
1309 if (!RSS_PF(adapter
)) {
1310 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1311 if (adapter
->vf_res
->vf_cap_flags
&
1312 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
)
1313 adapter
->hena
= IAVF_DEFAULT_RSS_HENA_EXPANDED
;
1315 adapter
->hena
= IAVF_DEFAULT_RSS_HENA
;
1317 wr32(hw
, IAVF_VFQF_HENA(0), (u32
)adapter
->hena
);
1318 wr32(hw
, IAVF_VFQF_HENA(1), (u32
)(adapter
->hena
>> 32));
1321 iavf_fill_rss_lut(adapter
);
1322 netdev_rss_key_fill((void *)adapter
->rss_key
, adapter
->rss_key_size
);
1323 ret
= iavf_config_rss(adapter
);
1329 * iavf_alloc_q_vectors - Allocate memory for interrupt vectors
1330 * @adapter: board private structure to initialize
1332 * We allocate one q_vector per queue interrupt. If allocation fails we
1335 static int iavf_alloc_q_vectors(struct iavf_adapter
*adapter
)
1337 int q_idx
= 0, num_q_vectors
;
1338 struct iavf_q_vector
*q_vector
;
1340 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1341 adapter
->q_vectors
= kcalloc(num_q_vectors
, sizeof(*q_vector
),
1343 if (!adapter
->q_vectors
)
1346 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1347 q_vector
= &adapter
->q_vectors
[q_idx
];
1348 q_vector
->adapter
= adapter
;
1349 q_vector
->vsi
= &adapter
->vsi
;
1350 q_vector
->v_idx
= q_idx
;
1351 q_vector
->reg_idx
= q_idx
;
1352 cpumask_copy(&q_vector
->affinity_mask
, cpu_possible_mask
);
1353 netif_napi_add(adapter
->netdev
, &q_vector
->napi
,
1354 iavf_napi_poll
, NAPI_POLL_WEIGHT
);
1361 * iavf_free_q_vectors - Free memory allocated for interrupt vectors
1362 * @adapter: board private structure to initialize
1364 * This function frees the memory allocated to the q_vectors. In addition if
1365 * NAPI is enabled it will delete any references to the NAPI struct prior
1366 * to freeing the q_vector.
1368 static void iavf_free_q_vectors(struct iavf_adapter
*adapter
)
1370 int q_idx
, num_q_vectors
;
1373 if (!adapter
->q_vectors
)
1376 num_q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
1377 napi_vectors
= adapter
->num_active_queues
;
1379 for (q_idx
= 0; q_idx
< num_q_vectors
; q_idx
++) {
1380 struct iavf_q_vector
*q_vector
= &adapter
->q_vectors
[q_idx
];
1382 if (q_idx
< napi_vectors
)
1383 netif_napi_del(&q_vector
->napi
);
1385 kfree(adapter
->q_vectors
);
1386 adapter
->q_vectors
= NULL
;
1390 * iavf_reset_interrupt_capability - Reset MSIX setup
1391 * @adapter: board private structure
1394 void iavf_reset_interrupt_capability(struct iavf_adapter
*adapter
)
1396 if (!adapter
->msix_entries
)
1399 pci_disable_msix(adapter
->pdev
);
1400 kfree(adapter
->msix_entries
);
1401 adapter
->msix_entries
= NULL
;
1405 * iavf_init_interrupt_scheme - Determine if MSIX is supported and init
1406 * @adapter: board private structure to initialize
1409 int iavf_init_interrupt_scheme(struct iavf_adapter
*adapter
)
1413 err
= iavf_alloc_queues(adapter
);
1415 dev_err(&adapter
->pdev
->dev
,
1416 "Unable to allocate memory for queues\n");
1417 goto err_alloc_queues
;
1421 err
= iavf_set_interrupt_capability(adapter
);
1424 dev_err(&adapter
->pdev
->dev
,
1425 "Unable to setup interrupt capabilities\n");
1426 goto err_set_interrupt
;
1429 err
= iavf_alloc_q_vectors(adapter
);
1431 dev_err(&adapter
->pdev
->dev
,
1432 "Unable to allocate memory for queue vectors\n");
1433 goto err_alloc_q_vectors
;
1436 /* If we've made it so far while ADq flag being ON, then we haven't
1437 * bailed out anywhere in middle. And ADq isn't just enabled but actual
1438 * resources have been allocated in the reset path.
1439 * Now we can truly claim that ADq is enabled.
1441 if ((adapter
->vf_res
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
) &&
1443 dev_info(&adapter
->pdev
->dev
, "ADq Enabled, %u TCs created",
1446 dev_info(&adapter
->pdev
->dev
, "Multiqueue %s: Queue pair count = %u",
1447 (adapter
->num_active_queues
> 1) ? "Enabled" : "Disabled",
1448 adapter
->num_active_queues
);
1451 err_alloc_q_vectors
:
1452 iavf_reset_interrupt_capability(adapter
);
1454 iavf_free_queues(adapter
);
1460 * iavf_free_rss - Free memory used by RSS structs
1461 * @adapter: board private structure
1463 static void iavf_free_rss(struct iavf_adapter
*adapter
)
1465 kfree(adapter
->rss_key
);
1466 adapter
->rss_key
= NULL
;
1468 kfree(adapter
->rss_lut
);
1469 adapter
->rss_lut
= NULL
;
1473 * iavf_reinit_interrupt_scheme - Reallocate queues and vectors
1474 * @adapter: board private structure
1476 * Returns 0 on success, negative on failure
1478 static int iavf_reinit_interrupt_scheme(struct iavf_adapter
*adapter
)
1480 struct net_device
*netdev
= adapter
->netdev
;
1483 if (netif_running(netdev
))
1484 iavf_free_traffic_irqs(adapter
);
1485 iavf_free_misc_irq(adapter
);
1486 iavf_reset_interrupt_capability(adapter
);
1487 iavf_free_q_vectors(adapter
);
1488 iavf_free_queues(adapter
);
1490 err
= iavf_init_interrupt_scheme(adapter
);
1494 netif_tx_stop_all_queues(netdev
);
1496 err
= iavf_request_misc_irq(adapter
);
1500 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
1502 iavf_map_rings_to_vectors(adapter
);
1504 if (RSS_AQ(adapter
))
1505 adapter
->aq_required
|= IAVF_FLAG_AQ_CONFIGURE_RSS
;
1507 err
= iavf_init_rss(adapter
);
1513 * iavf_process_aq_command - process aq_required flags
1514 * and sends aq command
1515 * @adapter: pointer to iavf adapter structure
1517 * Returns 0 on success
1518 * Returns error code if no command was sent
1519 * or error code if the command failed.
1521 static int iavf_process_aq_command(struct iavf_adapter
*adapter
)
1523 if (adapter
->aq_required
& IAVF_FLAG_AQ_GET_CONFIG
)
1524 return iavf_send_vf_config_msg(adapter
);
1525 if (adapter
->aq_required
& IAVF_FLAG_AQ_DISABLE_QUEUES
) {
1526 iavf_disable_queues(adapter
);
1530 if (adapter
->aq_required
& IAVF_FLAG_AQ_MAP_VECTORS
) {
1531 iavf_map_queues(adapter
);
1535 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_MAC_FILTER
) {
1536 iavf_add_ether_addrs(adapter
);
1540 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_VLAN_FILTER
) {
1541 iavf_add_vlans(adapter
);
1545 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_MAC_FILTER
) {
1546 iavf_del_ether_addrs(adapter
);
1550 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_VLAN_FILTER
) {
1551 iavf_del_vlans(adapter
);
1555 if (adapter
->aq_required
& IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING
) {
1556 iavf_enable_vlan_stripping(adapter
);
1560 if (adapter
->aq_required
& IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING
) {
1561 iavf_disable_vlan_stripping(adapter
);
1565 if (adapter
->aq_required
& IAVF_FLAG_AQ_CONFIGURE_QUEUES
) {
1566 iavf_configure_queues(adapter
);
1570 if (adapter
->aq_required
& IAVF_FLAG_AQ_ENABLE_QUEUES
) {
1571 iavf_enable_queues(adapter
);
1575 if (adapter
->aq_required
& IAVF_FLAG_AQ_CONFIGURE_RSS
) {
1576 /* This message goes straight to the firmware, not the
1577 * PF, so we don't have to set current_op as we will
1578 * not get a response through the ARQ.
1580 adapter
->aq_required
&= ~IAVF_FLAG_AQ_CONFIGURE_RSS
;
1583 if (adapter
->aq_required
& IAVF_FLAG_AQ_GET_HENA
) {
1584 iavf_get_hena(adapter
);
1587 if (adapter
->aq_required
& IAVF_FLAG_AQ_SET_HENA
) {
1588 iavf_set_hena(adapter
);
1591 if (adapter
->aq_required
& IAVF_FLAG_AQ_SET_RSS_KEY
) {
1592 iavf_set_rss_key(adapter
);
1595 if (adapter
->aq_required
& IAVF_FLAG_AQ_SET_RSS_LUT
) {
1596 iavf_set_rss_lut(adapter
);
1600 if (adapter
->aq_required
& IAVF_FLAG_AQ_REQUEST_PROMISC
) {
1601 iavf_set_promiscuous(adapter
, FLAG_VF_UNICAST_PROMISC
|
1602 FLAG_VF_MULTICAST_PROMISC
);
1606 if (adapter
->aq_required
& IAVF_FLAG_AQ_REQUEST_ALLMULTI
) {
1607 iavf_set_promiscuous(adapter
, FLAG_VF_MULTICAST_PROMISC
);
1611 if ((adapter
->aq_required
& IAVF_FLAG_AQ_RELEASE_PROMISC
) &&
1612 (adapter
->aq_required
& IAVF_FLAG_AQ_RELEASE_ALLMULTI
)) {
1613 iavf_set_promiscuous(adapter
, 0);
1617 if (adapter
->aq_required
& IAVF_FLAG_AQ_ENABLE_CHANNELS
) {
1618 iavf_enable_channels(adapter
);
1622 if (adapter
->aq_required
& IAVF_FLAG_AQ_DISABLE_CHANNELS
) {
1623 iavf_disable_channels(adapter
);
1626 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_CLOUD_FILTER
) {
1627 iavf_add_cloud_filter(adapter
);
1631 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_CLOUD_FILTER
) {
1632 iavf_del_cloud_filter(adapter
);
1635 if (adapter
->aq_required
& IAVF_FLAG_AQ_DEL_CLOUD_FILTER
) {
1636 iavf_del_cloud_filter(adapter
);
1639 if (adapter
->aq_required
& IAVF_FLAG_AQ_ADD_CLOUD_FILTER
) {
1640 iavf_add_cloud_filter(adapter
);
1647 * iavf_startup - first step of driver startup
1648 * @adapter: board private structure
1650 * Function process __IAVF_STARTUP driver state.
1651 * When success the state is changed to __IAVF_INIT_VERSION_CHECK
1652 * when fails it returns -EAGAIN
1654 static int iavf_startup(struct iavf_adapter
*adapter
)
1656 struct pci_dev
*pdev
= adapter
->pdev
;
1657 struct iavf_hw
*hw
= &adapter
->hw
;
1660 WARN_ON(adapter
->state
!= __IAVF_STARTUP
);
1662 /* driver loaded, probe complete */
1663 adapter
->flags
&= ~IAVF_FLAG_PF_COMMS_FAILED
;
1664 adapter
->flags
&= ~IAVF_FLAG_RESET_PENDING
;
1665 err
= iavf_set_mac_type(hw
);
1667 dev_err(&pdev
->dev
, "Failed to set MAC type (%d)\n", err
);
1671 err
= iavf_check_reset_complete(hw
);
1673 dev_info(&pdev
->dev
, "Device is still in reset (%d), retrying\n",
1677 hw
->aq
.num_arq_entries
= IAVF_AQ_LEN
;
1678 hw
->aq
.num_asq_entries
= IAVF_AQ_LEN
;
1679 hw
->aq
.arq_buf_size
= IAVF_MAX_AQ_BUF_SIZE
;
1680 hw
->aq
.asq_buf_size
= IAVF_MAX_AQ_BUF_SIZE
;
1682 err
= iavf_init_adminq(hw
);
1684 dev_err(&pdev
->dev
, "Failed to init Admin Queue (%d)\n", err
);
1687 err
= iavf_send_api_ver(adapter
);
1689 dev_err(&pdev
->dev
, "Unable to send to PF (%d)\n", err
);
1690 iavf_shutdown_adminq(hw
);
1693 adapter
->state
= __IAVF_INIT_VERSION_CHECK
;
1699 * iavf_init_version_check - second step of driver startup
1700 * @adapter: board private structure
1702 * Function process __IAVF_INIT_VERSION_CHECK driver state.
1703 * When success the state is changed to __IAVF_INIT_GET_RESOURCES
1704 * when fails it returns -EAGAIN
1706 static int iavf_init_version_check(struct iavf_adapter
*adapter
)
1708 struct pci_dev
*pdev
= adapter
->pdev
;
1709 struct iavf_hw
*hw
= &adapter
->hw
;
1712 WARN_ON(adapter
->state
!= __IAVF_INIT_VERSION_CHECK
);
1714 if (!iavf_asq_done(hw
)) {
1715 dev_err(&pdev
->dev
, "Admin queue command never completed\n");
1716 iavf_shutdown_adminq(hw
);
1717 adapter
->state
= __IAVF_STARTUP
;
1721 /* aq msg sent, awaiting reply */
1722 err
= iavf_verify_api_ver(adapter
);
1724 if (err
== IAVF_ERR_ADMIN_QUEUE_NO_WORK
)
1725 err
= iavf_send_api_ver(adapter
);
1727 dev_err(&pdev
->dev
, "Unsupported PF API version %d.%d, expected %d.%d\n",
1728 adapter
->pf_version
.major
,
1729 adapter
->pf_version
.minor
,
1730 VIRTCHNL_VERSION_MAJOR
,
1731 VIRTCHNL_VERSION_MINOR
);
1734 err
= iavf_send_vf_config_msg(adapter
);
1736 dev_err(&pdev
->dev
, "Unable to send config request (%d)\n",
1740 adapter
->state
= __IAVF_INIT_GET_RESOURCES
;
1747 * iavf_init_get_resources - third step of driver startup
1748 * @adapter: board private structure
1750 * Function process __IAVF_INIT_GET_RESOURCES driver state and
1751 * finishes driver initialization procedure.
1752 * When success the state is changed to __IAVF_DOWN
1753 * when fails it returns -EAGAIN
1755 static int iavf_init_get_resources(struct iavf_adapter
*adapter
)
1757 struct net_device
*netdev
= adapter
->netdev
;
1758 struct pci_dev
*pdev
= adapter
->pdev
;
1759 struct iavf_hw
*hw
= &adapter
->hw
;
1762 WARN_ON(adapter
->state
!= __IAVF_INIT_GET_RESOURCES
);
1763 /* aq msg sent, awaiting reply */
1764 if (!adapter
->vf_res
) {
1765 bufsz
= sizeof(struct virtchnl_vf_resource
) +
1767 sizeof(struct virtchnl_vsi_resource
));
1768 adapter
->vf_res
= kzalloc(bufsz
, GFP_KERNEL
);
1769 if (!adapter
->vf_res
)
1772 err
= iavf_get_vf_config(adapter
);
1773 if (err
== IAVF_ERR_ADMIN_QUEUE_NO_WORK
) {
1774 err
= iavf_send_vf_config_msg(adapter
);
1776 } else if (err
== IAVF_ERR_PARAM
) {
1777 /* We only get ERR_PARAM if the device is in a very bad
1778 * state or if we've been disabled for previous bad
1779 * behavior. Either way, we're done now.
1781 iavf_shutdown_adminq(hw
);
1782 dev_err(&pdev
->dev
, "Unable to get VF config due to PF error condition, not retrying\n");
1786 dev_err(&pdev
->dev
, "Unable to get VF config (%d)\n", err
);
1790 if (iavf_process_config(adapter
))
1792 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
1794 adapter
->flags
|= IAVF_FLAG_RX_CSUM_ENABLED
;
1796 netdev
->netdev_ops
= &iavf_netdev_ops
;
1797 iavf_set_ethtool_ops(netdev
);
1798 netdev
->watchdog_timeo
= 5 * HZ
;
1800 /* MTU range: 68 - 9710 */
1801 netdev
->min_mtu
= ETH_MIN_MTU
;
1802 netdev
->max_mtu
= IAVF_MAX_RXBUFFER
- IAVF_PACKET_HDR_PAD
;
1804 if (!is_valid_ether_addr(adapter
->hw
.mac
.addr
)) {
1805 dev_info(&pdev
->dev
, "Invalid MAC address %pM, using random\n",
1806 adapter
->hw
.mac
.addr
);
1807 eth_hw_addr_random(netdev
);
1808 ether_addr_copy(adapter
->hw
.mac
.addr
, netdev
->dev_addr
);
1810 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
1811 ether_addr_copy(netdev
->perm_addr
, adapter
->hw
.mac
.addr
);
1814 adapter
->tx_desc_count
= IAVF_DEFAULT_TXD
;
1815 adapter
->rx_desc_count
= IAVF_DEFAULT_RXD
;
1816 err
= iavf_init_interrupt_scheme(adapter
);
1819 iavf_map_rings_to_vectors(adapter
);
1820 if (adapter
->vf_res
->vf_cap_flags
&
1821 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
)
1822 adapter
->flags
|= IAVF_FLAG_WB_ON_ITR_CAPABLE
;
1824 err
= iavf_request_misc_irq(adapter
);
1828 netif_carrier_off(netdev
);
1829 adapter
->link_up
= false;
1831 /* set the semaphore to prevent any callbacks after device registration
1832 * up to time when state of driver will be set to __IAVF_DOWN
1835 if (!adapter
->netdev_registered
) {
1836 err
= register_netdevice(netdev
);
1843 adapter
->netdev_registered
= true;
1845 netif_tx_stop_all_queues(netdev
);
1846 if (CLIENT_ALLOWED(adapter
)) {
1847 err
= iavf_lan_add_device(adapter
);
1850 dev_info(&pdev
->dev
, "Failed to add VF to client API service list: %d\n",
1854 dev_info(&pdev
->dev
, "MAC address: %pM\n", adapter
->hw
.mac
.addr
);
1855 if (netdev
->features
& NETIF_F_GRO
)
1856 dev_info(&pdev
->dev
, "GRO is enabled\n");
1858 adapter
->state
= __IAVF_DOWN
;
1859 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
1862 iavf_misc_irq_enable(adapter
);
1863 wake_up(&adapter
->down_waitqueue
);
1865 adapter
->rss_key
= kzalloc(adapter
->rss_key_size
, GFP_KERNEL
);
1866 adapter
->rss_lut
= kzalloc(adapter
->rss_lut_size
, GFP_KERNEL
);
1867 if (!adapter
->rss_key
|| !adapter
->rss_lut
)
1869 if (RSS_AQ(adapter
))
1870 adapter
->aq_required
|= IAVF_FLAG_AQ_CONFIGURE_RSS
;
1872 iavf_init_rss(adapter
);
1876 iavf_free_rss(adapter
);
1878 iavf_free_misc_irq(adapter
);
1880 iavf_reset_interrupt_capability(adapter
);
1882 kfree(adapter
->vf_res
);
1883 adapter
->vf_res
= NULL
;
1889 * iavf_watchdog_task - Periodic call-back task
1890 * @work: pointer to work_struct
1892 static void iavf_watchdog_task(struct work_struct
*work
)
1894 struct iavf_adapter
*adapter
= container_of(work
,
1895 struct iavf_adapter
,
1896 watchdog_task
.work
);
1897 struct iavf_hw
*hw
= &adapter
->hw
;
1900 if (test_and_set_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
))
1901 goto restart_watchdog
;
1903 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
)
1904 adapter
->state
= __IAVF_COMM_FAILED
;
1906 switch (adapter
->state
) {
1907 case __IAVF_COMM_FAILED
:
1908 reg_val
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
1909 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
1910 if (reg_val
== VIRTCHNL_VFR_VFACTIVE
||
1911 reg_val
== VIRTCHNL_VFR_COMPLETED
) {
1912 /* A chance for redemption! */
1913 dev_err(&adapter
->pdev
->dev
,
1914 "Hardware came out of reset. Attempting reinit.\n");
1915 adapter
->state
= __IAVF_STARTUP
;
1916 adapter
->flags
&= ~IAVF_FLAG_PF_COMMS_FAILED
;
1917 queue_delayed_work(iavf_wq
, &adapter
->init_task
, 10);
1918 clear_bit(__IAVF_IN_CRITICAL_TASK
,
1919 &adapter
->crit_section
);
1920 /* Don't reschedule the watchdog, since we've restarted
1921 * the init task. When init_task contacts the PF and
1922 * gets everything set up again, it'll restart the
1923 * watchdog for us. Down, boy. Sit. Stay. Woof.
1927 adapter
->aq_required
= 0;
1928 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
1929 clear_bit(__IAVF_IN_CRITICAL_TASK
,
1930 &adapter
->crit_section
);
1931 queue_delayed_work(iavf_wq
,
1932 &adapter
->watchdog_task
,
1933 msecs_to_jiffies(10));
1935 case __IAVF_RESETTING
:
1936 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1937 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
, HZ
* 2);
1940 case __IAVF_DOWN_PENDING
:
1941 case __IAVF_TESTING
:
1942 case __IAVF_RUNNING
:
1943 if (adapter
->current_op
) {
1944 if (!iavf_asq_done(hw
)) {
1945 dev_dbg(&adapter
->pdev
->dev
,
1946 "Admin queue timeout\n");
1947 iavf_send_api_ver(adapter
);
1950 if (!iavf_process_aq_command(adapter
) &&
1951 adapter
->state
== __IAVF_RUNNING
)
1952 iavf_request_stats(adapter
);
1956 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1959 goto restart_watchdog
;
1962 /* check for hw reset */
1963 reg_val
= rd32(hw
, IAVF_VF_ARQLEN1
) & IAVF_VF_ARQLEN1_ARQENABLE_MASK
;
1965 adapter
->state
= __IAVF_RESETTING
;
1966 adapter
->flags
|= IAVF_FLAG_RESET_PENDING
;
1967 adapter
->aq_required
= 0;
1968 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
1969 dev_err(&adapter
->pdev
->dev
, "Hardware reset detected\n");
1970 queue_work(iavf_wq
, &adapter
->reset_task
);
1974 schedule_delayed_work(&adapter
->client_task
, msecs_to_jiffies(5));
1976 if (adapter
->state
== __IAVF_RUNNING
||
1977 adapter
->state
== __IAVF_COMM_FAILED
)
1978 iavf_detect_recover_hung(&adapter
->vsi
);
1979 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
1981 if (adapter
->aq_required
)
1982 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
,
1983 msecs_to_jiffies(20));
1985 queue_delayed_work(iavf_wq
, &adapter
->watchdog_task
, HZ
* 2);
1986 queue_work(iavf_wq
, &adapter
->adminq_task
);
1989 static void iavf_disable_vf(struct iavf_adapter
*adapter
)
1991 struct iavf_mac_filter
*f
, *ftmp
;
1992 struct iavf_vlan_filter
*fv
, *fvtmp
;
1993 struct iavf_cloud_filter
*cf
, *cftmp
;
1995 adapter
->flags
|= IAVF_FLAG_PF_COMMS_FAILED
;
1997 /* We don't use netif_running() because it may be true prior to
1998 * ndo_open() returning, so we can't assume it means all our open
1999 * tasks have finished, since we're not holding the rtnl_lock here.
2001 if (adapter
->state
== __IAVF_RUNNING
) {
2002 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
2003 netif_carrier_off(adapter
->netdev
);
2004 netif_tx_disable(adapter
->netdev
);
2005 adapter
->link_up
= false;
2006 iavf_napi_disable_all(adapter
);
2007 iavf_irq_disable(adapter
);
2008 iavf_free_traffic_irqs(adapter
);
2009 iavf_free_all_tx_resources(adapter
);
2010 iavf_free_all_rx_resources(adapter
);
2013 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
2015 /* Delete all of the filters */
2016 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
2021 list_for_each_entry_safe(fv
, fvtmp
, &adapter
->vlan_filter_list
, list
) {
2022 list_del(&fv
->list
);
2026 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
2028 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2029 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
, list
) {
2030 list_del(&cf
->list
);
2032 adapter
->num_cloud_filters
--;
2034 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2036 iavf_free_misc_irq(adapter
);
2037 iavf_reset_interrupt_capability(adapter
);
2038 iavf_free_queues(adapter
);
2039 iavf_free_q_vectors(adapter
);
2040 kfree(adapter
->vf_res
);
2041 iavf_shutdown_adminq(&adapter
->hw
);
2042 adapter
->netdev
->flags
&= ~IFF_UP
;
2043 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
2044 adapter
->flags
&= ~IAVF_FLAG_RESET_PENDING
;
2045 adapter
->state
= __IAVF_DOWN
;
2046 wake_up(&adapter
->down_waitqueue
);
2047 dev_info(&adapter
->pdev
->dev
, "Reset task did not complete, VF disabled\n");
2050 #define IAVF_RESET_WAIT_MS 10
2051 #define IAVF_RESET_WAIT_COUNT 500
2053 * iavf_reset_task - Call-back task to handle hardware reset
2054 * @work: pointer to work_struct
2056 * During reset we need to shut down and reinitialize the admin queue
2057 * before we can use it to communicate with the PF again. We also clear
2058 * and reinit the rings because that context is lost as well.
2060 static void iavf_reset_task(struct work_struct
*work
)
2062 struct iavf_adapter
*adapter
= container_of(work
,
2063 struct iavf_adapter
,
2065 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
2066 struct net_device
*netdev
= adapter
->netdev
;
2067 struct iavf_hw
*hw
= &adapter
->hw
;
2068 struct iavf_vlan_filter
*vlf
;
2069 struct iavf_cloud_filter
*cf
;
2070 struct iavf_mac_filter
*f
;
2075 /* When device is being removed it doesn't make sense to run the reset
2076 * task, just return in such a case.
2078 if (test_bit(__IAVF_IN_REMOVE_TASK
, &adapter
->crit_section
))
2081 while (test_and_set_bit(__IAVF_IN_CLIENT_TASK
,
2082 &adapter
->crit_section
))
2083 usleep_range(500, 1000);
2084 if (CLIENT_ENABLED(adapter
)) {
2085 adapter
->flags
&= ~(IAVF_FLAG_CLIENT_NEEDS_OPEN
|
2086 IAVF_FLAG_CLIENT_NEEDS_CLOSE
|
2087 IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
|
2088 IAVF_FLAG_SERVICE_CLIENT_REQUESTED
);
2089 cancel_delayed_work_sync(&adapter
->client_task
);
2090 iavf_notify_client_close(&adapter
->vsi
, true);
2092 iavf_misc_irq_disable(adapter
);
2093 if (adapter
->flags
& IAVF_FLAG_RESET_NEEDED
) {
2094 adapter
->flags
&= ~IAVF_FLAG_RESET_NEEDED
;
2095 /* Restart the AQ here. If we have been reset but didn't
2096 * detect it, or if the PF had to reinit, our AQ will be hosed.
2098 iavf_shutdown_adminq(hw
);
2099 iavf_init_adminq(hw
);
2100 iavf_request_reset(adapter
);
2102 adapter
->flags
|= IAVF_FLAG_RESET_PENDING
;
2104 /* poll until we see the reset actually happen */
2105 for (i
= 0; i
< IAVF_RESET_WAIT_COUNT
; i
++) {
2106 reg_val
= rd32(hw
, IAVF_VF_ARQLEN1
) &
2107 IAVF_VF_ARQLEN1_ARQENABLE_MASK
;
2110 usleep_range(5000, 10000);
2112 if (i
== IAVF_RESET_WAIT_COUNT
) {
2113 dev_info(&adapter
->pdev
->dev
, "Never saw reset\n");
2114 goto continue_reset
; /* act like the reset happened */
2117 /* wait until the reset is complete and the PF is responding to us */
2118 for (i
= 0; i
< IAVF_RESET_WAIT_COUNT
; i
++) {
2119 /* sleep first to make sure a minimum wait time is met */
2120 msleep(IAVF_RESET_WAIT_MS
);
2122 reg_val
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
2123 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
2124 if (reg_val
== VIRTCHNL_VFR_VFACTIVE
)
2128 pci_set_master(adapter
->pdev
);
2130 if (i
== IAVF_RESET_WAIT_COUNT
) {
2131 dev_err(&adapter
->pdev
->dev
, "Reset never finished (%x)\n",
2133 iavf_disable_vf(adapter
);
2134 clear_bit(__IAVF_IN_CLIENT_TASK
, &adapter
->crit_section
);
2135 return; /* Do not attempt to reinit. It's dead, Jim. */
2139 /* We don't use netif_running() because it may be true prior to
2140 * ndo_open() returning, so we can't assume it means all our open
2141 * tasks have finished, since we're not holding the rtnl_lock here.
2143 running
= ((adapter
->state
== __IAVF_RUNNING
) ||
2144 (adapter
->state
== __IAVF_RESETTING
));
2147 netif_carrier_off(netdev
);
2148 netif_tx_stop_all_queues(netdev
);
2149 adapter
->link_up
= false;
2150 iavf_napi_disable_all(adapter
);
2152 iavf_irq_disable(adapter
);
2154 adapter
->state
= __IAVF_RESETTING
;
2155 adapter
->flags
&= ~IAVF_FLAG_RESET_PENDING
;
2157 /* free the Tx/Rx rings and descriptors, might be better to just
2158 * re-use them sometime in the future
2160 iavf_free_all_rx_resources(adapter
);
2161 iavf_free_all_tx_resources(adapter
);
2163 adapter
->flags
|= IAVF_FLAG_QUEUES_DISABLED
;
2164 /* kill and reinit the admin queue */
2165 iavf_shutdown_adminq(hw
);
2166 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
2167 err
= iavf_init_adminq(hw
);
2169 dev_info(&adapter
->pdev
->dev
, "Failed to init adminq: %d\n",
2171 adapter
->aq_required
= 0;
2173 if (adapter
->flags
& IAVF_FLAG_REINIT_ITR_NEEDED
) {
2174 err
= iavf_reinit_interrupt_scheme(adapter
);
2179 adapter
->aq_required
|= IAVF_FLAG_AQ_GET_CONFIG
;
2180 adapter
->aq_required
|= IAVF_FLAG_AQ_MAP_VECTORS
;
2182 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
2184 /* re-add all MAC filters */
2185 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
2188 /* re-add all VLAN filters */
2189 list_for_each_entry(vlf
, &adapter
->vlan_filter_list
, list
) {
2193 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
2195 /* check if TCs are running and re-add all cloud filters */
2196 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2197 if ((vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
) &&
2199 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
2203 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2205 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_MAC_FILTER
;
2206 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_VLAN_FILTER
;
2207 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_CLOUD_FILTER
;
2208 iavf_misc_irq_enable(adapter
);
2210 mod_delayed_work(iavf_wq
, &adapter
->watchdog_task
, 2);
2212 /* We were running when the reset started, so we need to restore some
2216 /* allocate transmit descriptors */
2217 err
= iavf_setup_all_tx_resources(adapter
);
2221 /* allocate receive descriptors */
2222 err
= iavf_setup_all_rx_resources(adapter
);
2226 if (adapter
->flags
& IAVF_FLAG_REINIT_ITR_NEEDED
) {
2227 err
= iavf_request_traffic_irqs(adapter
, netdev
->name
);
2231 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
2234 iavf_configure(adapter
);
2236 iavf_up_complete(adapter
);
2238 iavf_irq_enable(adapter
, true);
2240 adapter
->state
= __IAVF_DOWN
;
2241 wake_up(&adapter
->down_waitqueue
);
2243 clear_bit(__IAVF_IN_CLIENT_TASK
, &adapter
->crit_section
);
2244 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
2248 clear_bit(__IAVF_IN_CLIENT_TASK
, &adapter
->crit_section
);
2249 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
2250 dev_err(&adapter
->pdev
->dev
, "failed to allocate resources during reinit\n");
2255 * iavf_adminq_task - worker thread to clean the admin queue
2256 * @work: pointer to work_struct containing our data
2258 static void iavf_adminq_task(struct work_struct
*work
)
2260 struct iavf_adapter
*adapter
=
2261 container_of(work
, struct iavf_adapter
, adminq_task
);
2262 struct iavf_hw
*hw
= &adapter
->hw
;
2263 struct iavf_arq_event_info event
;
2264 enum virtchnl_ops v_op
;
2265 enum iavf_status ret
, v_ret
;
2269 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
)
2272 event
.buf_len
= IAVF_MAX_AQ_BUF_SIZE
;
2273 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
2278 ret
= iavf_clean_arq_element(hw
, &event
, &pending
);
2279 v_op
= (enum virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
2280 v_ret
= (enum iavf_status
)le32_to_cpu(event
.desc
.cookie_low
);
2283 break; /* No event to process or error cleaning ARQ */
2285 iavf_virtchnl_completion(adapter
, v_op
, v_ret
, event
.msg_buf
,
2288 memset(event
.msg_buf
, 0, IAVF_MAX_AQ_BUF_SIZE
);
2291 if ((adapter
->flags
&
2292 (IAVF_FLAG_RESET_PENDING
| IAVF_FLAG_RESET_NEEDED
)) ||
2293 adapter
->state
== __IAVF_RESETTING
)
2296 /* check for error indications */
2297 val
= rd32(hw
, hw
->aq
.arq
.len
);
2298 if (val
== 0xdeadbeef) /* indicates device in reset */
2301 if (val
& IAVF_VF_ARQLEN1_ARQVFE_MASK
) {
2302 dev_info(&adapter
->pdev
->dev
, "ARQ VF Error detected\n");
2303 val
&= ~IAVF_VF_ARQLEN1_ARQVFE_MASK
;
2305 if (val
& IAVF_VF_ARQLEN1_ARQOVFL_MASK
) {
2306 dev_info(&adapter
->pdev
->dev
, "ARQ Overflow Error detected\n");
2307 val
&= ~IAVF_VF_ARQLEN1_ARQOVFL_MASK
;
2309 if (val
& IAVF_VF_ARQLEN1_ARQCRIT_MASK
) {
2310 dev_info(&adapter
->pdev
->dev
, "ARQ Critical Error detected\n");
2311 val
&= ~IAVF_VF_ARQLEN1_ARQCRIT_MASK
;
2314 wr32(hw
, hw
->aq
.arq
.len
, val
);
2316 val
= rd32(hw
, hw
->aq
.asq
.len
);
2318 if (val
& IAVF_VF_ATQLEN1_ATQVFE_MASK
) {
2319 dev_info(&adapter
->pdev
->dev
, "ASQ VF Error detected\n");
2320 val
&= ~IAVF_VF_ATQLEN1_ATQVFE_MASK
;
2322 if (val
& IAVF_VF_ATQLEN1_ATQOVFL_MASK
) {
2323 dev_info(&adapter
->pdev
->dev
, "ASQ Overflow Error detected\n");
2324 val
&= ~IAVF_VF_ATQLEN1_ATQOVFL_MASK
;
2326 if (val
& IAVF_VF_ATQLEN1_ATQCRIT_MASK
) {
2327 dev_info(&adapter
->pdev
->dev
, "ASQ Critical Error detected\n");
2328 val
&= ~IAVF_VF_ATQLEN1_ATQCRIT_MASK
;
2331 wr32(hw
, hw
->aq
.asq
.len
, val
);
2334 kfree(event
.msg_buf
);
2336 /* re-enable Admin queue interrupt cause */
2337 iavf_misc_irq_enable(adapter
);
2341 * iavf_client_task - worker thread to perform client work
2342 * @work: pointer to work_struct containing our data
2344 * This task handles client interactions. Because client calls can be
2345 * reentrant, we can't handle them in the watchdog.
2347 static void iavf_client_task(struct work_struct
*work
)
2349 struct iavf_adapter
*adapter
=
2350 container_of(work
, struct iavf_adapter
, client_task
.work
);
2352 /* If we can't get the client bit, just give up. We'll be rescheduled
2356 if (test_and_set_bit(__IAVF_IN_CLIENT_TASK
, &adapter
->crit_section
))
2359 if (adapter
->flags
& IAVF_FLAG_SERVICE_CLIENT_REQUESTED
) {
2360 iavf_client_subtask(adapter
);
2361 adapter
->flags
&= ~IAVF_FLAG_SERVICE_CLIENT_REQUESTED
;
2364 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
) {
2365 iavf_notify_client_l2_params(&adapter
->vsi
);
2366 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS
;
2369 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_CLOSE
) {
2370 iavf_notify_client_close(&adapter
->vsi
, false);
2371 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_CLOSE
;
2374 if (adapter
->flags
& IAVF_FLAG_CLIENT_NEEDS_OPEN
) {
2375 iavf_notify_client_open(&adapter
->vsi
);
2376 adapter
->flags
&= ~IAVF_FLAG_CLIENT_NEEDS_OPEN
;
2379 clear_bit(__IAVF_IN_CLIENT_TASK
, &adapter
->crit_section
);
2383 * iavf_free_all_tx_resources - Free Tx Resources for All Queues
2384 * @adapter: board private structure
2386 * Free all transmit software resources
2388 void iavf_free_all_tx_resources(struct iavf_adapter
*adapter
)
2392 if (!adapter
->tx_rings
)
2395 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2396 if (adapter
->tx_rings
[i
].desc
)
2397 iavf_free_tx_resources(&adapter
->tx_rings
[i
]);
2401 * iavf_setup_all_tx_resources - allocate all queues Tx resources
2402 * @adapter: board private structure
2404 * If this function returns with an error, then it's possible one or
2405 * more of the rings is populated (while the rest are not). It is the
2406 * callers duty to clean those orphaned rings.
2408 * Return 0 on success, negative on failure
2410 static int iavf_setup_all_tx_resources(struct iavf_adapter
*adapter
)
2414 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2415 adapter
->tx_rings
[i
].count
= adapter
->tx_desc_count
;
2416 err
= iavf_setup_tx_descriptors(&adapter
->tx_rings
[i
]);
2419 dev_err(&adapter
->pdev
->dev
,
2420 "Allocation for Tx Queue %u failed\n", i
);
2428 * iavf_setup_all_rx_resources - allocate all queues Rx resources
2429 * @adapter: board private structure
2431 * If this function returns with an error, then it's possible one or
2432 * more of the rings is populated (while the rest are not). It is the
2433 * callers duty to clean those orphaned rings.
2435 * Return 0 on success, negative on failure
2437 static int iavf_setup_all_rx_resources(struct iavf_adapter
*adapter
)
2441 for (i
= 0; i
< adapter
->num_active_queues
; i
++) {
2442 adapter
->rx_rings
[i
].count
= adapter
->rx_desc_count
;
2443 err
= iavf_setup_rx_descriptors(&adapter
->rx_rings
[i
]);
2446 dev_err(&adapter
->pdev
->dev
,
2447 "Allocation for Rx Queue %u failed\n", i
);
2454 * iavf_free_all_rx_resources - Free Rx Resources for All Queues
2455 * @adapter: board private structure
2457 * Free all receive software resources
2459 void iavf_free_all_rx_resources(struct iavf_adapter
*adapter
)
2463 if (!adapter
->rx_rings
)
2466 for (i
= 0; i
< adapter
->num_active_queues
; i
++)
2467 if (adapter
->rx_rings
[i
].desc
)
2468 iavf_free_rx_resources(&adapter
->rx_rings
[i
]);
2472 * iavf_validate_tx_bandwidth - validate the max Tx bandwidth
2473 * @adapter: board private structure
2474 * @max_tx_rate: max Tx bw for a tc
2476 static int iavf_validate_tx_bandwidth(struct iavf_adapter
*adapter
,
2479 int speed
= 0, ret
= 0;
2481 switch (adapter
->link_speed
) {
2482 case IAVF_LINK_SPEED_40GB
:
2485 case IAVF_LINK_SPEED_25GB
:
2488 case IAVF_LINK_SPEED_20GB
:
2491 case IAVF_LINK_SPEED_10GB
:
2494 case IAVF_LINK_SPEED_1GB
:
2497 case IAVF_LINK_SPEED_100MB
:
2504 if (max_tx_rate
> speed
) {
2505 dev_err(&adapter
->pdev
->dev
,
2506 "Invalid tx rate specified\n");
2514 * iavf_validate_channel_config - validate queue mapping info
2515 * @adapter: board private structure
2516 * @mqprio_qopt: queue parameters
2518 * This function validates if the config provided by the user to
2519 * configure queue channels is valid or not. Returns 0 on a valid
2522 static int iavf_validate_ch_config(struct iavf_adapter
*adapter
,
2523 struct tc_mqprio_qopt_offload
*mqprio_qopt
)
2525 u64 total_max_rate
= 0;
2530 if (mqprio_qopt
->qopt
.num_tc
> IAVF_MAX_TRAFFIC_CLASS
||
2531 mqprio_qopt
->qopt
.num_tc
< 1)
2534 for (i
= 0; i
<= mqprio_qopt
->qopt
.num_tc
- 1; i
++) {
2535 if (!mqprio_qopt
->qopt
.count
[i
] ||
2536 mqprio_qopt
->qopt
.offset
[i
] != num_qps
)
2538 if (mqprio_qopt
->min_rate
[i
]) {
2539 dev_err(&adapter
->pdev
->dev
,
2540 "Invalid min tx rate (greater than 0) specified\n");
2543 /*convert to Mbps */
2544 tx_rate
= div_u64(mqprio_qopt
->max_rate
[i
],
2546 total_max_rate
+= tx_rate
;
2547 num_qps
+= mqprio_qopt
->qopt
.count
[i
];
2549 if (num_qps
> IAVF_MAX_REQ_QUEUES
)
2552 ret
= iavf_validate_tx_bandwidth(adapter
, total_max_rate
);
2557 * iavf_del_all_cloud_filters - delete all cloud filters
2558 * on the traffic classes
2560 static void iavf_del_all_cloud_filters(struct iavf_adapter
*adapter
)
2562 struct iavf_cloud_filter
*cf
, *cftmp
;
2564 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2565 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
,
2567 list_del(&cf
->list
);
2569 adapter
->num_cloud_filters
--;
2571 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2575 * __iavf_setup_tc - configure multiple traffic classes
2576 * @netdev: network interface device structure
2577 * @type_date: tc offload data
2579 * This function processes the config information provided by the
2580 * user to configure traffic classes/queue channels and packages the
2581 * information to request the PF to setup traffic classes.
2583 * Returns 0 on success.
2585 static int __iavf_setup_tc(struct net_device
*netdev
, void *type_data
)
2587 struct tc_mqprio_qopt_offload
*mqprio_qopt
= type_data
;
2588 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
2589 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
2590 u8 num_tc
= 0, total_qps
= 0;
2591 int ret
= 0, netdev_tc
= 0;
2596 num_tc
= mqprio_qopt
->qopt
.num_tc
;
2597 mode
= mqprio_qopt
->mode
;
2599 /* delete queue_channel */
2600 if (!mqprio_qopt
->qopt
.hw
) {
2601 if (adapter
->ch_config
.state
== __IAVF_TC_RUNNING
) {
2602 /* reset the tc configuration */
2603 netdev_reset_tc(netdev
);
2604 adapter
->num_tc
= 0;
2605 netif_tx_stop_all_queues(netdev
);
2606 netif_tx_disable(netdev
);
2607 iavf_del_all_cloud_filters(adapter
);
2608 adapter
->aq_required
= IAVF_FLAG_AQ_DISABLE_CHANNELS
;
2615 /* add queue channel */
2616 if (mode
== TC_MQPRIO_MODE_CHANNEL
) {
2617 if (!(vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
)) {
2618 dev_err(&adapter
->pdev
->dev
, "ADq not supported\n");
2621 if (adapter
->ch_config
.state
!= __IAVF_TC_INVALID
) {
2622 dev_err(&adapter
->pdev
->dev
, "TC configuration already exists\n");
2626 ret
= iavf_validate_ch_config(adapter
, mqprio_qopt
);
2629 /* Return if same TC config is requested */
2630 if (adapter
->num_tc
== num_tc
)
2632 adapter
->num_tc
= num_tc
;
2634 for (i
= 0; i
< IAVF_MAX_TRAFFIC_CLASS
; i
++) {
2636 adapter
->ch_config
.ch_info
[i
].count
=
2637 mqprio_qopt
->qopt
.count
[i
];
2638 adapter
->ch_config
.ch_info
[i
].offset
=
2639 mqprio_qopt
->qopt
.offset
[i
];
2640 total_qps
+= mqprio_qopt
->qopt
.count
[i
];
2641 max_tx_rate
= mqprio_qopt
->max_rate
[i
];
2642 /* convert to Mbps */
2643 max_tx_rate
= div_u64(max_tx_rate
,
2645 adapter
->ch_config
.ch_info
[i
].max_tx_rate
=
2648 adapter
->ch_config
.ch_info
[i
].count
= 1;
2649 adapter
->ch_config
.ch_info
[i
].offset
= 0;
2652 adapter
->ch_config
.total_qps
= total_qps
;
2653 netif_tx_stop_all_queues(netdev
);
2654 netif_tx_disable(netdev
);
2655 adapter
->aq_required
|= IAVF_FLAG_AQ_ENABLE_CHANNELS
;
2656 netdev_reset_tc(netdev
);
2657 /* Report the tc mapping up the stack */
2658 netdev_set_num_tc(adapter
->netdev
, num_tc
);
2659 for (i
= 0; i
< IAVF_MAX_TRAFFIC_CLASS
; i
++) {
2660 u16 qcount
= mqprio_qopt
->qopt
.count
[i
];
2661 u16 qoffset
= mqprio_qopt
->qopt
.offset
[i
];
2664 netdev_set_tc_queue(netdev
, netdev_tc
++, qcount
,
2673 * iavf_parse_cls_flower - Parse tc flower filters provided by kernel
2674 * @adapter: board private structure
2675 * @cls_flower: pointer to struct flow_cls_offload
2676 * @filter: pointer to cloud filter structure
2678 static int iavf_parse_cls_flower(struct iavf_adapter
*adapter
,
2679 struct flow_cls_offload
*f
,
2680 struct iavf_cloud_filter
*filter
)
2682 struct flow_rule
*rule
= flow_cls_offload_flow_rule(f
);
2683 struct flow_dissector
*dissector
= rule
->match
.dissector
;
2684 u16 n_proto_mask
= 0;
2685 u16 n_proto_key
= 0;
2690 struct virtchnl_filter
*vf
= &filter
->f
;
2692 if (dissector
->used_keys
&
2693 ~(BIT(FLOW_DISSECTOR_KEY_CONTROL
) |
2694 BIT(FLOW_DISSECTOR_KEY_BASIC
) |
2695 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS
) |
2696 BIT(FLOW_DISSECTOR_KEY_VLAN
) |
2697 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS
) |
2698 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS
) |
2699 BIT(FLOW_DISSECTOR_KEY_PORTS
) |
2700 BIT(FLOW_DISSECTOR_KEY_ENC_KEYID
))) {
2701 dev_err(&adapter
->pdev
->dev
, "Unsupported key used: 0x%x\n",
2702 dissector
->used_keys
);
2706 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_ENC_KEYID
)) {
2707 struct flow_match_enc_keyid match
;
2709 flow_rule_match_enc_keyid(rule
, &match
);
2710 if (match
.mask
->keyid
!= 0)
2711 field_flags
|= IAVF_CLOUD_FIELD_TEN_ID
;
2714 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_BASIC
)) {
2715 struct flow_match_basic match
;
2717 flow_rule_match_basic(rule
, &match
);
2718 n_proto_key
= ntohs(match
.key
->n_proto
);
2719 n_proto_mask
= ntohs(match
.mask
->n_proto
);
2721 if (n_proto_key
== ETH_P_ALL
) {
2725 n_proto
= n_proto_key
& n_proto_mask
;
2726 if (n_proto
!= ETH_P_IP
&& n_proto
!= ETH_P_IPV6
)
2728 if (n_proto
== ETH_P_IPV6
) {
2729 /* specify flow type as TCP IPv6 */
2730 vf
->flow_type
= VIRTCHNL_TCP_V6_FLOW
;
2733 if (match
.key
->ip_proto
!= IPPROTO_TCP
) {
2734 dev_info(&adapter
->pdev
->dev
, "Only TCP transport is supported\n");
2739 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_ETH_ADDRS
)) {
2740 struct flow_match_eth_addrs match
;
2742 flow_rule_match_eth_addrs(rule
, &match
);
2744 /* use is_broadcast and is_zero to check for all 0xf or 0 */
2745 if (!is_zero_ether_addr(match
.mask
->dst
)) {
2746 if (is_broadcast_ether_addr(match
.mask
->dst
)) {
2747 field_flags
|= IAVF_CLOUD_FIELD_OMAC
;
2749 dev_err(&adapter
->pdev
->dev
, "Bad ether dest mask %pM\n",
2751 return IAVF_ERR_CONFIG
;
2755 if (!is_zero_ether_addr(match
.mask
->src
)) {
2756 if (is_broadcast_ether_addr(match
.mask
->src
)) {
2757 field_flags
|= IAVF_CLOUD_FIELD_IMAC
;
2759 dev_err(&adapter
->pdev
->dev
, "Bad ether src mask %pM\n",
2761 return IAVF_ERR_CONFIG
;
2765 if (!is_zero_ether_addr(match
.key
->dst
))
2766 if (is_valid_ether_addr(match
.key
->dst
) ||
2767 is_multicast_ether_addr(match
.key
->dst
)) {
2768 /* set the mask if a valid dst_mac address */
2769 for (i
= 0; i
< ETH_ALEN
; i
++)
2770 vf
->mask
.tcp_spec
.dst_mac
[i
] |= 0xff;
2771 ether_addr_copy(vf
->data
.tcp_spec
.dst_mac
,
2775 if (!is_zero_ether_addr(match
.key
->src
))
2776 if (is_valid_ether_addr(match
.key
->src
) ||
2777 is_multicast_ether_addr(match
.key
->src
)) {
2778 /* set the mask if a valid dst_mac address */
2779 for (i
= 0; i
< ETH_ALEN
; i
++)
2780 vf
->mask
.tcp_spec
.src_mac
[i
] |= 0xff;
2781 ether_addr_copy(vf
->data
.tcp_spec
.src_mac
,
2786 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_VLAN
)) {
2787 struct flow_match_vlan match
;
2789 flow_rule_match_vlan(rule
, &match
);
2790 if (match
.mask
->vlan_id
) {
2791 if (match
.mask
->vlan_id
== VLAN_VID_MASK
) {
2792 field_flags
|= IAVF_CLOUD_FIELD_IVLAN
;
2794 dev_err(&adapter
->pdev
->dev
, "Bad vlan mask %u\n",
2795 match
.mask
->vlan_id
);
2796 return IAVF_ERR_CONFIG
;
2799 vf
->mask
.tcp_spec
.vlan_id
|= cpu_to_be16(0xffff);
2800 vf
->data
.tcp_spec
.vlan_id
= cpu_to_be16(match
.key
->vlan_id
);
2803 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_CONTROL
)) {
2804 struct flow_match_control match
;
2806 flow_rule_match_control(rule
, &match
);
2807 addr_type
= match
.key
->addr_type
;
2810 if (addr_type
== FLOW_DISSECTOR_KEY_IPV4_ADDRS
) {
2811 struct flow_match_ipv4_addrs match
;
2813 flow_rule_match_ipv4_addrs(rule
, &match
);
2814 if (match
.mask
->dst
) {
2815 if (match
.mask
->dst
== cpu_to_be32(0xffffffff)) {
2816 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2818 dev_err(&adapter
->pdev
->dev
, "Bad ip dst mask 0x%08x\n",
2819 be32_to_cpu(match
.mask
->dst
));
2820 return IAVF_ERR_CONFIG
;
2824 if (match
.mask
->src
) {
2825 if (match
.mask
->src
== cpu_to_be32(0xffffffff)) {
2826 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2828 dev_err(&adapter
->pdev
->dev
, "Bad ip src mask 0x%08x\n",
2829 be32_to_cpu(match
.mask
->dst
));
2830 return IAVF_ERR_CONFIG
;
2834 if (field_flags
& IAVF_CLOUD_FIELD_TEN_ID
) {
2835 dev_info(&adapter
->pdev
->dev
, "Tenant id not allowed for ip filter\n");
2836 return IAVF_ERR_CONFIG
;
2838 if (match
.key
->dst
) {
2839 vf
->mask
.tcp_spec
.dst_ip
[0] |= cpu_to_be32(0xffffffff);
2840 vf
->data
.tcp_spec
.dst_ip
[0] = match
.key
->dst
;
2842 if (match
.key
->src
) {
2843 vf
->mask
.tcp_spec
.src_ip
[0] |= cpu_to_be32(0xffffffff);
2844 vf
->data
.tcp_spec
.src_ip
[0] = match
.key
->src
;
2848 if (addr_type
== FLOW_DISSECTOR_KEY_IPV6_ADDRS
) {
2849 struct flow_match_ipv6_addrs match
;
2851 flow_rule_match_ipv6_addrs(rule
, &match
);
2853 /* validate mask, make sure it is not IPV6_ADDR_ANY */
2854 if (ipv6_addr_any(&match
.mask
->dst
)) {
2855 dev_err(&adapter
->pdev
->dev
, "Bad ipv6 dst mask 0x%02x\n",
2857 return IAVF_ERR_CONFIG
;
2860 /* src and dest IPv6 address should not be LOOPBACK
2861 * (0:0:0:0:0:0:0:1) which can be represented as ::1
2863 if (ipv6_addr_loopback(&match
.key
->dst
) ||
2864 ipv6_addr_loopback(&match
.key
->src
)) {
2865 dev_err(&adapter
->pdev
->dev
,
2866 "ipv6 addr should not be loopback\n");
2867 return IAVF_ERR_CONFIG
;
2869 if (!ipv6_addr_any(&match
.mask
->dst
) ||
2870 !ipv6_addr_any(&match
.mask
->src
))
2871 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2873 for (i
= 0; i
< 4; i
++)
2874 vf
->mask
.tcp_spec
.dst_ip
[i
] |= cpu_to_be32(0xffffffff);
2875 memcpy(&vf
->data
.tcp_spec
.dst_ip
, &match
.key
->dst
.s6_addr32
,
2876 sizeof(vf
->data
.tcp_spec
.dst_ip
));
2877 for (i
= 0; i
< 4; i
++)
2878 vf
->mask
.tcp_spec
.src_ip
[i
] |= cpu_to_be32(0xffffffff);
2879 memcpy(&vf
->data
.tcp_spec
.src_ip
, &match
.key
->src
.s6_addr32
,
2880 sizeof(vf
->data
.tcp_spec
.src_ip
));
2882 if (flow_rule_match_key(rule
, FLOW_DISSECTOR_KEY_PORTS
)) {
2883 struct flow_match_ports match
;
2885 flow_rule_match_ports(rule
, &match
);
2886 if (match
.mask
->src
) {
2887 if (match
.mask
->src
== cpu_to_be16(0xffff)) {
2888 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2890 dev_err(&adapter
->pdev
->dev
, "Bad src port mask %u\n",
2891 be16_to_cpu(match
.mask
->src
));
2892 return IAVF_ERR_CONFIG
;
2896 if (match
.mask
->dst
) {
2897 if (match
.mask
->dst
== cpu_to_be16(0xffff)) {
2898 field_flags
|= IAVF_CLOUD_FIELD_IIP
;
2900 dev_err(&adapter
->pdev
->dev
, "Bad dst port mask %u\n",
2901 be16_to_cpu(match
.mask
->dst
));
2902 return IAVF_ERR_CONFIG
;
2905 if (match
.key
->dst
) {
2906 vf
->mask
.tcp_spec
.dst_port
|= cpu_to_be16(0xffff);
2907 vf
->data
.tcp_spec
.dst_port
= match
.key
->dst
;
2910 if (match
.key
->src
) {
2911 vf
->mask
.tcp_spec
.src_port
|= cpu_to_be16(0xffff);
2912 vf
->data
.tcp_spec
.src_port
= match
.key
->src
;
2915 vf
->field_flags
= field_flags
;
2921 * iavf_handle_tclass - Forward to a traffic class on the device
2922 * @adapter: board private structure
2923 * @tc: traffic class index on the device
2924 * @filter: pointer to cloud filter structure
2926 static int iavf_handle_tclass(struct iavf_adapter
*adapter
, u32 tc
,
2927 struct iavf_cloud_filter
*filter
)
2931 if (tc
< adapter
->num_tc
) {
2932 if (!filter
->f
.data
.tcp_spec
.dst_port
) {
2933 dev_err(&adapter
->pdev
->dev
,
2934 "Specify destination port to redirect to traffic class other than TC0\n");
2938 /* redirect to a traffic class on the same device */
2939 filter
->f
.action
= VIRTCHNL_ACTION_TC_REDIRECT
;
2940 filter
->f
.action_meta
= tc
;
2945 * iavf_configure_clsflower - Add tc flower filters
2946 * @adapter: board private structure
2947 * @cls_flower: Pointer to struct flow_cls_offload
2949 static int iavf_configure_clsflower(struct iavf_adapter
*adapter
,
2950 struct flow_cls_offload
*cls_flower
)
2952 int tc
= tc_classid_to_hwtc(adapter
->netdev
, cls_flower
->classid
);
2953 struct iavf_cloud_filter
*filter
= NULL
;
2954 int err
= -EINVAL
, count
= 50;
2957 dev_err(&adapter
->pdev
->dev
, "Invalid traffic class\n");
2961 filter
= kzalloc(sizeof(*filter
), GFP_KERNEL
);
2965 while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK
,
2966 &adapter
->crit_section
)) {
2972 filter
->cookie
= cls_flower
->cookie
;
2974 /* set the mask to all zeroes to begin with */
2975 memset(&filter
->f
.mask
.tcp_spec
, 0, sizeof(struct virtchnl_l4_spec
));
2976 /* start out with flow type and eth type IPv4 to begin with */
2977 filter
->f
.flow_type
= VIRTCHNL_TCP_V4_FLOW
;
2978 err
= iavf_parse_cls_flower(adapter
, cls_flower
, filter
);
2982 err
= iavf_handle_tclass(adapter
, tc
, filter
);
2986 /* add filter to the list */
2987 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
2988 list_add_tail(&filter
->list
, &adapter
->cloud_filter_list
);
2989 adapter
->num_cloud_filters
++;
2991 adapter
->aq_required
|= IAVF_FLAG_AQ_ADD_CLOUD_FILTER
;
2992 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
2997 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
3001 /* iavf_find_cf - Find the cloud filter in the list
3002 * @adapter: Board private structure
3003 * @cookie: filter specific cookie
3005 * Returns ptr to the filter object or NULL. Must be called while holding the
3006 * cloud_filter_list_lock.
3008 static struct iavf_cloud_filter
*iavf_find_cf(struct iavf_adapter
*adapter
,
3009 unsigned long *cookie
)
3011 struct iavf_cloud_filter
*filter
= NULL
;
3016 list_for_each_entry(filter
, &adapter
->cloud_filter_list
, list
) {
3017 if (!memcmp(cookie
, &filter
->cookie
, sizeof(filter
->cookie
)))
3024 * iavf_delete_clsflower - Remove tc flower filters
3025 * @adapter: board private structure
3026 * @cls_flower: Pointer to struct flow_cls_offload
3028 static int iavf_delete_clsflower(struct iavf_adapter
*adapter
,
3029 struct flow_cls_offload
*cls_flower
)
3031 struct iavf_cloud_filter
*filter
= NULL
;
3034 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
3035 filter
= iavf_find_cf(adapter
, &cls_flower
->cookie
);
3038 adapter
->aq_required
|= IAVF_FLAG_AQ_DEL_CLOUD_FILTER
;
3042 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
3048 * iavf_setup_tc_cls_flower - flower classifier offloads
3049 * @netdev: net device to configure
3050 * @type_data: offload data
3052 static int iavf_setup_tc_cls_flower(struct iavf_adapter
*adapter
,
3053 struct flow_cls_offload
*cls_flower
)
3055 if (cls_flower
->common
.chain_index
)
3058 switch (cls_flower
->command
) {
3059 case FLOW_CLS_REPLACE
:
3060 return iavf_configure_clsflower(adapter
, cls_flower
);
3061 case FLOW_CLS_DESTROY
:
3062 return iavf_delete_clsflower(adapter
, cls_flower
);
3063 case FLOW_CLS_STATS
:
3071 * iavf_setup_tc_block_cb - block callback for tc
3072 * @type: type of offload
3073 * @type_data: offload data
3076 * This function is the block callback for traffic classes
3078 static int iavf_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
3082 case TC_SETUP_CLSFLOWER
:
3083 return iavf_setup_tc_cls_flower(cb_priv
, type_data
);
3089 static LIST_HEAD(iavf_block_cb_list
);
3092 * iavf_setup_tc - configure multiple traffic classes
3093 * @netdev: network interface device structure
3094 * @type: type of offload
3095 * @type_date: tc offload data
3097 * This function is the callback to ndo_setup_tc in the
3100 * Returns 0 on success
3102 static int iavf_setup_tc(struct net_device
*netdev
, enum tc_setup_type type
,
3105 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3108 case TC_SETUP_QDISC_MQPRIO
:
3109 return __iavf_setup_tc(netdev
, type_data
);
3110 case TC_SETUP_BLOCK
:
3111 return flow_block_cb_setup_simple(type_data
,
3112 &iavf_block_cb_list
,
3113 iavf_setup_tc_block_cb
,
3114 adapter
, adapter
, true);
3121 * iavf_open - Called when a network interface is made active
3122 * @netdev: network interface device structure
3124 * Returns 0 on success, negative value on failure
3126 * The open entry point is called when a network interface is made
3127 * active by the system (IFF_UP). At this point all resources needed
3128 * for transmit and receive operations are allocated, the interrupt
3129 * handler is registered with the OS, the watchdog is started,
3130 * and the stack is notified that the interface is ready.
3132 static int iavf_open(struct net_device
*netdev
)
3134 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3137 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
) {
3138 dev_err(&adapter
->pdev
->dev
, "Unable to open device due to PF driver failure.\n");
3142 while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK
,
3143 &adapter
->crit_section
))
3144 usleep_range(500, 1000);
3146 if (adapter
->state
!= __IAVF_DOWN
) {
3151 /* allocate transmit descriptors */
3152 err
= iavf_setup_all_tx_resources(adapter
);
3156 /* allocate receive descriptors */
3157 err
= iavf_setup_all_rx_resources(adapter
);
3161 /* clear any pending interrupts, may auto mask */
3162 err
= iavf_request_traffic_irqs(adapter
, netdev
->name
);
3166 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
3168 iavf_add_filter(adapter
, adapter
->hw
.mac
.addr
);
3170 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
3172 iavf_configure(adapter
);
3174 iavf_up_complete(adapter
);
3176 iavf_irq_enable(adapter
, true);
3178 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
3184 iavf_free_traffic_irqs(adapter
);
3186 iavf_free_all_rx_resources(adapter
);
3188 iavf_free_all_tx_resources(adapter
);
3190 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
3196 * iavf_close - Disables a network interface
3197 * @netdev: network interface device structure
3199 * Returns 0, this is not allowed to fail
3201 * The close entry point is called when an interface is de-activated
3202 * by the OS. The hardware is still under the drivers control, but
3203 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
3204 * are freed, along with all transmit and receive resources.
3206 static int iavf_close(struct net_device
*netdev
)
3208 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3211 if (adapter
->state
<= __IAVF_DOWN_PENDING
)
3214 while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK
,
3215 &adapter
->crit_section
))
3216 usleep_range(500, 1000);
3218 set_bit(__IAVF_VSI_DOWN
, adapter
->vsi
.state
);
3219 if (CLIENT_ENABLED(adapter
))
3220 adapter
->flags
|= IAVF_FLAG_CLIENT_NEEDS_CLOSE
;
3223 adapter
->state
= __IAVF_DOWN_PENDING
;
3224 iavf_free_traffic_irqs(adapter
);
3226 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
3228 /* We explicitly don't free resources here because the hardware is
3229 * still active and can DMA into memory. Resources are cleared in
3230 * iavf_virtchnl_completion() after we get confirmation from the PF
3231 * driver that the rings have been stopped.
3233 * Also, we wait for state to transition to __IAVF_DOWN before
3234 * returning. State change occurs in iavf_virtchnl_completion() after
3235 * VF resources are released (which occurs after PF driver processes and
3236 * responds to admin queue commands).
3239 status
= wait_event_timeout(adapter
->down_waitqueue
,
3240 adapter
->state
== __IAVF_DOWN
,
3241 msecs_to_jiffies(500));
3243 netdev_warn(netdev
, "Device resources not yet released\n");
3248 * iavf_change_mtu - Change the Maximum Transfer Unit
3249 * @netdev: network interface device structure
3250 * @new_mtu: new value for maximum frame size
3252 * Returns 0 on success, negative on failure
3254 static int iavf_change_mtu(struct net_device
*netdev
, int new_mtu
)
3256 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3258 netdev
->mtu
= new_mtu
;
3259 if (CLIENT_ENABLED(adapter
)) {
3260 iavf_notify_client_l2_params(&adapter
->vsi
);
3261 adapter
->flags
|= IAVF_FLAG_SERVICE_CLIENT_REQUESTED
;
3263 adapter
->flags
|= IAVF_FLAG_RESET_NEEDED
;
3264 queue_work(iavf_wq
, &adapter
->reset_task
);
3270 * iavf_set_features - set the netdev feature flags
3271 * @netdev: ptr to the netdev being adjusted
3272 * @features: the feature set that the stack is suggesting
3273 * Note: expects to be called while under rtnl_lock()
3275 static int iavf_set_features(struct net_device
*netdev
,
3276 netdev_features_t features
)
3278 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3280 /* Don't allow changing VLAN_RX flag when adapter is not capable
3283 if (!VLAN_ALLOWED(adapter
)) {
3284 if ((netdev
->features
^ features
) & NETIF_F_HW_VLAN_CTAG_RX
)
3286 } else if ((netdev
->features
^ features
) & NETIF_F_HW_VLAN_CTAG_RX
) {
3287 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
3288 adapter
->aq_required
|=
3289 IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING
;
3291 adapter
->aq_required
|=
3292 IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING
;
3299 * iavf_features_check - Validate encapsulated packet conforms to limits
3301 * @dev: This physical port's netdev
3302 * @features: Offload features that the stack believes apply
3304 static netdev_features_t
iavf_features_check(struct sk_buff
*skb
,
3305 struct net_device
*dev
,
3306 netdev_features_t features
)
3310 /* No point in doing any of this if neither checksum nor GSO are
3311 * being requested for this frame. We can rule out both by just
3312 * checking for CHECKSUM_PARTIAL
3314 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
3317 /* We cannot support GSO if the MSS is going to be less than
3318 * 64 bytes. If it is then we need to drop support for GSO.
3320 if (skb_is_gso(skb
) && (skb_shinfo(skb
)->gso_size
< 64))
3321 features
&= ~NETIF_F_GSO_MASK
;
3323 /* MACLEN can support at most 63 words */
3324 len
= skb_network_header(skb
) - skb
->data
;
3325 if (len
& ~(63 * 2))
3328 /* IPLEN and EIPLEN can support at most 127 dwords */
3329 len
= skb_transport_header(skb
) - skb_network_header(skb
);
3330 if (len
& ~(127 * 4))
3333 if (skb
->encapsulation
) {
3334 /* L4TUNLEN can support 127 words */
3335 len
= skb_inner_network_header(skb
) - skb_transport_header(skb
);
3336 if (len
& ~(127 * 2))
3339 /* IPLEN can support at most 127 dwords */
3340 len
= skb_inner_transport_header(skb
) -
3341 skb_inner_network_header(skb
);
3342 if (len
& ~(127 * 4))
3346 /* No need to validate L4LEN as TCP is the only protocol with a
3347 * a flexible value and we support all possible values supported
3348 * by TCP, which is at most 15 dwords
3353 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
3357 * iavf_fix_features - fix up the netdev feature bits
3358 * @netdev: our net device
3359 * @features: desired feature bits
3361 * Returns fixed-up features bits
3363 static netdev_features_t
iavf_fix_features(struct net_device
*netdev
,
3364 netdev_features_t features
)
3366 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3368 if (!(adapter
->vf_res
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
))
3369 features
&= ~(NETIF_F_HW_VLAN_CTAG_TX
|
3370 NETIF_F_HW_VLAN_CTAG_RX
|
3371 NETIF_F_HW_VLAN_CTAG_FILTER
);
3376 static const struct net_device_ops iavf_netdev_ops
= {
3377 .ndo_open
= iavf_open
,
3378 .ndo_stop
= iavf_close
,
3379 .ndo_start_xmit
= iavf_xmit_frame
,
3380 .ndo_set_rx_mode
= iavf_set_rx_mode
,
3381 .ndo_validate_addr
= eth_validate_addr
,
3382 .ndo_set_mac_address
= iavf_set_mac
,
3383 .ndo_change_mtu
= iavf_change_mtu
,
3384 .ndo_tx_timeout
= iavf_tx_timeout
,
3385 .ndo_vlan_rx_add_vid
= iavf_vlan_rx_add_vid
,
3386 .ndo_vlan_rx_kill_vid
= iavf_vlan_rx_kill_vid
,
3387 .ndo_features_check
= iavf_features_check
,
3388 .ndo_fix_features
= iavf_fix_features
,
3389 .ndo_set_features
= iavf_set_features
,
3390 .ndo_setup_tc
= iavf_setup_tc
,
3394 * iavf_check_reset_complete - check that VF reset is complete
3395 * @hw: pointer to hw struct
3397 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
3399 static int iavf_check_reset_complete(struct iavf_hw
*hw
)
3404 for (i
= 0; i
< 100; i
++) {
3405 rstat
= rd32(hw
, IAVF_VFGEN_RSTAT
) &
3406 IAVF_VFGEN_RSTAT_VFR_STATE_MASK
;
3407 if ((rstat
== VIRTCHNL_VFR_VFACTIVE
) ||
3408 (rstat
== VIRTCHNL_VFR_COMPLETED
))
3410 usleep_range(10, 20);
3416 * iavf_process_config - Process the config information we got from the PF
3417 * @adapter: board private structure
3419 * Verify that we have a valid config struct, and set up our netdev features
3420 * and our VSI struct.
3422 int iavf_process_config(struct iavf_adapter
*adapter
)
3424 struct virtchnl_vf_resource
*vfres
= adapter
->vf_res
;
3425 int i
, num_req_queues
= adapter
->num_req_queues
;
3426 struct net_device
*netdev
= adapter
->netdev
;
3427 struct iavf_vsi
*vsi
= &adapter
->vsi
;
3428 netdev_features_t hw_enc_features
;
3429 netdev_features_t hw_features
;
3431 /* got VF config message back from PF, now we can parse it */
3432 for (i
= 0; i
< vfres
->num_vsis
; i
++) {
3433 if (vfres
->vsi_res
[i
].vsi_type
== VIRTCHNL_VSI_SRIOV
)
3434 adapter
->vsi_res
= &vfres
->vsi_res
[i
];
3436 if (!adapter
->vsi_res
) {
3437 dev_err(&adapter
->pdev
->dev
, "No LAN VSI found\n");
3441 if (num_req_queues
&&
3442 num_req_queues
!= adapter
->vsi_res
->num_queue_pairs
) {
3443 /* Problem. The PF gave us fewer queues than what we had
3444 * negotiated in our request. Need a reset to see if we can't
3445 * get back to a working state.
3447 dev_err(&adapter
->pdev
->dev
,
3448 "Requested %d queues, but PF only gave us %d.\n",
3450 adapter
->vsi_res
->num_queue_pairs
);
3451 adapter
->flags
|= IAVF_FLAG_REINIT_ITR_NEEDED
;
3452 adapter
->num_req_queues
= adapter
->vsi_res
->num_queue_pairs
;
3453 iavf_schedule_reset(adapter
);
3456 adapter
->num_req_queues
= 0;
3458 hw_enc_features
= NETIF_F_SG
|
3462 NETIF_F_SOFT_FEATURES
|
3471 /* advertise to stack only if offloads for encapsulated packets is
3474 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ENCAP
) {
3475 hw_enc_features
|= NETIF_F_GSO_UDP_TUNNEL
|
3477 NETIF_F_GSO_GRE_CSUM
|
3478 NETIF_F_GSO_IPXIP4
|
3479 NETIF_F_GSO_IPXIP6
|
3480 NETIF_F_GSO_UDP_TUNNEL_CSUM
|
3481 NETIF_F_GSO_PARTIAL
|
3484 if (!(vfres
->vf_cap_flags
&
3485 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
))
3486 netdev
->gso_partial_features
|=
3487 NETIF_F_GSO_UDP_TUNNEL_CSUM
;
3489 netdev
->gso_partial_features
|= NETIF_F_GSO_GRE_CSUM
;
3490 netdev
->hw_enc_features
|= NETIF_F_TSO_MANGLEID
;
3491 netdev
->hw_enc_features
|= hw_enc_features
;
3493 /* record features VLANs can make use of */
3494 netdev
->vlan_features
|= hw_enc_features
| NETIF_F_TSO_MANGLEID
;
3496 /* Write features and hw_features separately to avoid polluting
3497 * with, or dropping, features that are set when we registered.
3499 hw_features
= hw_enc_features
;
3501 /* Enable VLAN features if supported */
3502 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
)
3503 hw_features
|= (NETIF_F_HW_VLAN_CTAG_TX
|
3504 NETIF_F_HW_VLAN_CTAG_RX
);
3505 /* Enable cloud filter if ADQ is supported */
3506 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_ADQ
)
3507 hw_features
|= NETIF_F_HW_TC
;
3509 netdev
->hw_features
|= hw_features
;
3511 netdev
->features
|= hw_features
;
3513 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_VLAN
)
3514 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
3516 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
3518 /* Do not turn on offloads when they are requested to be turned off.
3519 * TSO needs minimum 576 bytes to work correctly.
3521 if (netdev
->wanted_features
) {
3522 if (!(netdev
->wanted_features
& NETIF_F_TSO
) ||
3524 netdev
->features
&= ~NETIF_F_TSO
;
3525 if (!(netdev
->wanted_features
& NETIF_F_TSO6
) ||
3527 netdev
->features
&= ~NETIF_F_TSO6
;
3528 if (!(netdev
->wanted_features
& NETIF_F_TSO_ECN
))
3529 netdev
->features
&= ~NETIF_F_TSO_ECN
;
3530 if (!(netdev
->wanted_features
& NETIF_F_GRO
))
3531 netdev
->features
&= ~NETIF_F_GRO
;
3532 if (!(netdev
->wanted_features
& NETIF_F_GSO
))
3533 netdev
->features
&= ~NETIF_F_GSO
;
3536 adapter
->vsi
.id
= adapter
->vsi_res
->vsi_id
;
3538 adapter
->vsi
.back
= adapter
;
3539 adapter
->vsi
.base_vector
= 1;
3540 adapter
->vsi
.work_limit
= IAVF_DEFAULT_IRQ_WORK
;
3541 vsi
->netdev
= adapter
->netdev
;
3542 vsi
->qs_handle
= adapter
->vsi_res
->qset_handle
;
3543 if (vfres
->vf_cap_flags
& VIRTCHNL_VF_OFFLOAD_RSS_PF
) {
3544 adapter
->rss_key_size
= vfres
->rss_key_size
;
3545 adapter
->rss_lut_size
= vfres
->rss_lut_size
;
3547 adapter
->rss_key_size
= IAVF_HKEY_ARRAY_SIZE
;
3548 adapter
->rss_lut_size
= IAVF_HLUT_ARRAY_SIZE
;
3555 * iavf_init_task - worker thread to perform delayed initialization
3556 * @work: pointer to work_struct containing our data
3558 * This task completes the work that was begun in probe. Due to the nature
3559 * of VF-PF communications, we may need to wait tens of milliseconds to get
3560 * responses back from the PF. Rather than busy-wait in probe and bog down the
3561 * whole system, we'll do it in a task so we can sleep.
3562 * This task only runs during driver init. Once we've established
3563 * communications with the PF driver and set up our netdev, the watchdog
3566 static void iavf_init_task(struct work_struct
*work
)
3568 struct iavf_adapter
*adapter
= container_of(work
,
3569 struct iavf_adapter
,
3571 struct iavf_hw
*hw
= &adapter
->hw
;
3573 switch (adapter
->state
) {
3574 case __IAVF_STARTUP
:
3575 if (iavf_startup(adapter
) < 0)
3578 case __IAVF_INIT_VERSION_CHECK
:
3579 if (iavf_init_version_check(adapter
) < 0)
3582 case __IAVF_INIT_GET_RESOURCES
:
3583 if (iavf_init_get_resources(adapter
) < 0)
3590 queue_delayed_work(iavf_wq
, &adapter
->init_task
,
3591 msecs_to_jiffies(30));
3594 if (++adapter
->aq_wait_count
> IAVF_AQ_MAX_ERR
) {
3595 dev_err(&adapter
->pdev
->dev
,
3596 "Failed to communicate with PF; waiting before retry\n");
3597 adapter
->flags
|= IAVF_FLAG_PF_COMMS_FAILED
;
3598 iavf_shutdown_adminq(hw
);
3599 adapter
->state
= __IAVF_STARTUP
;
3600 queue_delayed_work(iavf_wq
, &adapter
->init_task
, HZ
* 5);
3603 queue_delayed_work(iavf_wq
, &adapter
->init_task
, HZ
);
3607 * iavf_shutdown - Shutdown the device in preparation for a reboot
3608 * @pdev: pci device structure
3610 static void iavf_shutdown(struct pci_dev
*pdev
)
3612 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3613 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3615 netif_device_detach(netdev
);
3617 if (netif_running(netdev
))
3620 /* Prevent the watchdog from running. */
3621 adapter
->state
= __IAVF_REMOVE
;
3622 adapter
->aq_required
= 0;
3625 pci_save_state(pdev
);
3628 pci_disable_device(pdev
);
3632 * iavf_probe - Device Initialization Routine
3633 * @pdev: PCI device information struct
3634 * @ent: entry in iavf_pci_tbl
3636 * Returns 0 on success, negative on failure
3638 * iavf_probe initializes an adapter identified by a pci_dev structure.
3639 * The OS initialization, configuring of the adapter private structure,
3640 * and a hardware reset occur.
3642 static int iavf_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
3644 struct net_device
*netdev
;
3645 struct iavf_adapter
*adapter
= NULL
;
3646 struct iavf_hw
*hw
= NULL
;
3649 err
= pci_enable_device(pdev
);
3653 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
3655 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
3658 "DMA configuration failed: 0x%x\n", err
);
3663 err
= pci_request_regions(pdev
, iavf_driver_name
);
3666 "pci_request_regions failed 0x%x\n", err
);
3670 pci_enable_pcie_error_reporting(pdev
);
3672 pci_set_master(pdev
);
3674 netdev
= alloc_etherdev_mq(sizeof(struct iavf_adapter
),
3675 IAVF_MAX_REQ_QUEUES
);
3678 goto err_alloc_etherdev
;
3681 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3683 pci_set_drvdata(pdev
, netdev
);
3684 adapter
= netdev_priv(netdev
);
3686 adapter
->netdev
= netdev
;
3687 adapter
->pdev
= pdev
;
3692 adapter
->msg_enable
= BIT(DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
3693 adapter
->state
= __IAVF_STARTUP
;
3695 /* Call save state here because it relies on the adapter struct. */
3696 pci_save_state(pdev
);
3698 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
3699 pci_resource_len(pdev
, 0));
3704 hw
->vendor_id
= pdev
->vendor
;
3705 hw
->device_id
= pdev
->device
;
3706 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
3707 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
3708 hw
->subsystem_device_id
= pdev
->subsystem_device
;
3709 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
3710 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
3711 hw
->bus
.bus_id
= pdev
->bus
->number
;
3713 /* set up the locks for the AQ, do this only once in probe
3714 * and destroy them only once in remove
3716 mutex_init(&hw
->aq
.asq_mutex
);
3717 mutex_init(&hw
->aq
.arq_mutex
);
3719 spin_lock_init(&adapter
->mac_vlan_list_lock
);
3720 spin_lock_init(&adapter
->cloud_filter_list_lock
);
3722 INIT_LIST_HEAD(&adapter
->mac_filter_list
);
3723 INIT_LIST_HEAD(&adapter
->vlan_filter_list
);
3724 INIT_LIST_HEAD(&adapter
->cloud_filter_list
);
3726 INIT_WORK(&adapter
->reset_task
, iavf_reset_task
);
3727 INIT_WORK(&adapter
->adminq_task
, iavf_adminq_task
);
3728 INIT_DELAYED_WORK(&adapter
->watchdog_task
, iavf_watchdog_task
);
3729 INIT_DELAYED_WORK(&adapter
->client_task
, iavf_client_task
);
3730 INIT_DELAYED_WORK(&adapter
->init_task
, iavf_init_task
);
3731 queue_delayed_work(iavf_wq
, &adapter
->init_task
,
3732 msecs_to_jiffies(5 * (pdev
->devfn
& 0x07)));
3734 /* Setup the wait queue for indicating transition to down status */
3735 init_waitqueue_head(&adapter
->down_waitqueue
);
3740 free_netdev(netdev
);
3742 pci_release_regions(pdev
);
3745 pci_disable_device(pdev
);
3751 * iavf_suspend - Power management suspend routine
3752 * @pdev: PCI device information struct
3755 * Called when the system (VM) is entering sleep/suspend.
3757 static int iavf_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3759 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3760 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3763 netif_device_detach(netdev
);
3765 while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK
,
3766 &adapter
->crit_section
))
3767 usleep_range(500, 1000);
3769 if (netif_running(netdev
)) {
3774 iavf_free_misc_irq(adapter
);
3775 iavf_reset_interrupt_capability(adapter
);
3777 clear_bit(__IAVF_IN_CRITICAL_TASK
, &adapter
->crit_section
);
3779 retval
= pci_save_state(pdev
);
3783 pci_disable_device(pdev
);
3789 * iavf_resume - Power management resume routine
3790 * @pdev: PCI device information struct
3792 * Called when the system (VM) is resumed from sleep/suspend.
3794 static int iavf_resume(struct pci_dev
*pdev
)
3796 struct iavf_adapter
*adapter
= pci_get_drvdata(pdev
);
3797 struct net_device
*netdev
= adapter
->netdev
;
3800 pci_set_power_state(pdev
, PCI_D0
);
3801 pci_restore_state(pdev
);
3802 /* pci_restore_state clears dev->state_saved so call
3803 * pci_save_state to restore it.
3805 pci_save_state(pdev
);
3807 err
= pci_enable_device_mem(pdev
);
3809 dev_err(&pdev
->dev
, "Cannot enable PCI device from suspend.\n");
3812 pci_set_master(pdev
);
3815 err
= iavf_set_interrupt_capability(adapter
);
3818 dev_err(&pdev
->dev
, "Cannot enable MSI-X interrupts.\n");
3821 err
= iavf_request_misc_irq(adapter
);
3824 dev_err(&pdev
->dev
, "Cannot get interrupt vector.\n");
3828 queue_work(iavf_wq
, &adapter
->reset_task
);
3830 netif_device_attach(netdev
);
3835 #endif /* CONFIG_PM */
3837 * iavf_remove - Device Removal Routine
3838 * @pdev: PCI device information struct
3840 * iavf_remove is called by the PCI subsystem to alert the driver
3841 * that it should release a PCI device. The could be caused by a
3842 * Hot-Plug event, or because the driver is going to be removed from
3845 static void iavf_remove(struct pci_dev
*pdev
)
3847 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3848 struct iavf_adapter
*adapter
= netdev_priv(netdev
);
3849 struct iavf_vlan_filter
*vlf
, *vlftmp
;
3850 struct iavf_mac_filter
*f
, *ftmp
;
3851 struct iavf_cloud_filter
*cf
, *cftmp
;
3852 struct iavf_hw
*hw
= &adapter
->hw
;
3854 /* Indicate we are in remove and not to run reset_task */
3855 set_bit(__IAVF_IN_REMOVE_TASK
, &adapter
->crit_section
);
3856 cancel_delayed_work_sync(&adapter
->init_task
);
3857 cancel_work_sync(&adapter
->reset_task
);
3858 cancel_delayed_work_sync(&adapter
->client_task
);
3859 if (adapter
->netdev_registered
) {
3860 unregister_netdev(netdev
);
3861 adapter
->netdev_registered
= false;
3863 if (CLIENT_ALLOWED(adapter
)) {
3864 err
= iavf_lan_del_device(adapter
);
3866 dev_warn(&pdev
->dev
, "Failed to delete client device: %d\n",
3870 /* Shut down all the garbage mashers on the detention level */
3871 adapter
->state
= __IAVF_REMOVE
;
3872 adapter
->aq_required
= 0;
3873 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
3874 iavf_request_reset(adapter
);
3876 /* If the FW isn't responding, kick it once, but only once. */
3877 if (!iavf_asq_done(hw
)) {
3878 iavf_request_reset(adapter
);
3881 iavf_free_all_tx_resources(adapter
);
3882 iavf_free_all_rx_resources(adapter
);
3883 iavf_misc_irq_disable(adapter
);
3884 iavf_free_misc_irq(adapter
);
3885 iavf_reset_interrupt_capability(adapter
);
3886 iavf_free_q_vectors(adapter
);
3888 cancel_delayed_work_sync(&adapter
->watchdog_task
);
3890 cancel_work_sync(&adapter
->adminq_task
);
3892 iavf_free_rss(adapter
);
3894 if (hw
->aq
.asq
.count
)
3895 iavf_shutdown_adminq(hw
);
3897 /* destroy the locks only once, here */
3898 mutex_destroy(&hw
->aq
.arq_mutex
);
3899 mutex_destroy(&hw
->aq
.asq_mutex
);
3901 iounmap(hw
->hw_addr
);
3902 pci_release_regions(pdev
);
3903 iavf_free_all_tx_resources(adapter
);
3904 iavf_free_all_rx_resources(adapter
);
3905 iavf_free_queues(adapter
);
3906 kfree(adapter
->vf_res
);
3907 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
3908 /* If we got removed before an up/down sequence, we've got a filter
3909 * hanging out there that we need to get rid of.
3911 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
3915 list_for_each_entry_safe(vlf
, vlftmp
, &adapter
->vlan_filter_list
,
3917 list_del(&vlf
->list
);
3921 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
3923 spin_lock_bh(&adapter
->cloud_filter_list_lock
);
3924 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
, list
) {
3925 list_del(&cf
->list
);
3928 spin_unlock_bh(&adapter
->cloud_filter_list_lock
);
3930 free_netdev(netdev
);
3932 pci_disable_pcie_error_reporting(pdev
);
3934 pci_disable_device(pdev
);
3937 static struct pci_driver iavf_driver
= {
3938 .name
= iavf_driver_name
,
3939 .id_table
= iavf_pci_tbl
,
3940 .probe
= iavf_probe
,
3941 .remove
= iavf_remove
,
3943 .suspend
= iavf_suspend
,
3944 .resume
= iavf_resume
,
3946 .shutdown
= iavf_shutdown
,
3950 * iavf_init_module - Driver Registration Routine
3952 * iavf_init_module is the first routine called when the driver is
3953 * loaded. All it does is register with the PCI subsystem.
3955 static int __init
iavf_init_module(void)
3959 pr_info("iavf: %s - version %s\n", iavf_driver_string
,
3960 iavf_driver_version
);
3962 pr_info("%s\n", iavf_copyright
);
3964 iavf_wq
= alloc_workqueue("%s", WQ_UNBOUND
| WQ_MEM_RECLAIM
, 1,
3967 pr_err("%s: Failed to create workqueue\n", iavf_driver_name
);
3970 ret
= pci_register_driver(&iavf_driver
);
3974 module_init(iavf_init_module
);
3977 * iavf_exit_module - Driver Exit Cleanup Routine
3979 * iavf_exit_module is called just before the driver is removed
3982 static void __exit
iavf_exit_module(void)
3984 pci_unregister_driver(&iavf_driver
);
3985 destroy_workqueue(iavf_wq
);
3988 module_exit(iavf_exit_module
);