1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
5 #include "iavf_prototype.h"
6 #include "iavf_client.h"
8 /* busy wait delay in msec */
9 #define IAVF_BUSY_WAIT_DELAY 10
10 #define IAVF_BUSY_WAIT_COUNT 50
14 * @adapter: adapter structure
15 * @op: virtual channel opcode
16 * @msg: pointer to message buffer
17 * @len: message length
19 * Send message to PF and print status if failure.
21 static int iavf_send_pf_msg(struct iavf_adapter
*adapter
,
22 enum virtchnl_ops op
, u8
*msg
, u16 len
)
24 struct iavf_hw
*hw
= &adapter
->hw
;
27 if (adapter
->flags
& IAVF_FLAG_PF_COMMS_FAILED
)
28 return 0; /* nothing to see here, move along */
30 err
= iavf_aq_send_msg_to_pf(hw
, op
, 0, msg
, len
, NULL
);
32 dev_dbg(&adapter
->pdev
->dev
, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
33 op
, iavf_stat_str(hw
, err
),
34 iavf_aq_str(hw
, hw
->aq
.asq_last_status
));
40 * @adapter: adapter structure
42 * Send API version admin queue message to the PF. The reply is not checked
43 * in this function. Returns 0 if the message was successfully
44 * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
46 int iavf_send_api_ver(struct iavf_adapter
*adapter
)
48 struct virtchnl_version_info vvi
;
50 vvi
.major
= VIRTCHNL_VERSION_MAJOR
;
51 vvi
.minor
= VIRTCHNL_VERSION_MINOR
;
53 return iavf_send_pf_msg(adapter
, VIRTCHNL_OP_VERSION
, (u8
*)&vvi
,
59 * @adapter: adapter structure
61 * Compare API versions with the PF. Must be called after admin queue is
62 * initialized. Returns 0 if API versions match, -EIO if they do not,
63 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
64 * from the firmware are propagated.
66 int iavf_verify_api_ver(struct iavf_adapter
*adapter
)
68 struct virtchnl_version_info
*pf_vvi
;
69 struct iavf_hw
*hw
= &adapter
->hw
;
70 struct iavf_arq_event_info event
;
74 event
.buf_len
= IAVF_MAX_AQ_BUF_SIZE
;
75 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
82 err
= iavf_clean_arq_element(hw
, &event
, NULL
);
83 /* When the AQ is empty, iavf_clean_arq_element will return
84 * nonzero and this loop will terminate.
89 (enum virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
90 if (op
== VIRTCHNL_OP_VERSION
)
95 err
= (enum iavf_status
)le32_to_cpu(event
.desc
.cookie_low
);
99 if (op
!= VIRTCHNL_OP_VERSION
) {
100 dev_info(&adapter
->pdev
->dev
, "Invalid reply type %d from PF\n",
106 pf_vvi
= (struct virtchnl_version_info
*)event
.msg_buf
;
107 adapter
->pf_version
= *pf_vvi
;
109 if ((pf_vvi
->major
> VIRTCHNL_VERSION_MAJOR
) ||
110 ((pf_vvi
->major
== VIRTCHNL_VERSION_MAJOR
) &&
111 (pf_vvi
->minor
> VIRTCHNL_VERSION_MINOR
)))
115 kfree(event
.msg_buf
);
121 * iavf_send_vf_config_msg
122 * @adapter: adapter structure
124 * Send VF configuration request admin queue message to the PF. The reply
125 * is not checked in this function. Returns 0 if the message was
126 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
128 int iavf_send_vf_config_msg(struct iavf_adapter
*adapter
)
132 caps
= VIRTCHNL_VF_OFFLOAD_L2
|
133 VIRTCHNL_VF_OFFLOAD_RSS_PF
|
134 VIRTCHNL_VF_OFFLOAD_RSS_AQ
|
135 VIRTCHNL_VF_OFFLOAD_RSS_REG
|
136 VIRTCHNL_VF_OFFLOAD_VLAN
|
137 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
|
138 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
|
139 VIRTCHNL_VF_OFFLOAD_ENCAP
|
140 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
|
141 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES
|
142 VIRTCHNL_VF_OFFLOAD_ADQ
;
144 adapter
->current_op
= VIRTCHNL_OP_GET_VF_RESOURCES
;
145 adapter
->aq_required
&= ~IAVF_FLAG_AQ_GET_CONFIG
;
146 if (PF_IS_V11(adapter
))
147 return iavf_send_pf_msg(adapter
, VIRTCHNL_OP_GET_VF_RESOURCES
,
148 (u8
*)&caps
, sizeof(caps
));
150 return iavf_send_pf_msg(adapter
, VIRTCHNL_OP_GET_VF_RESOURCES
,
155 * iavf_validate_num_queues
156 * @adapter: adapter structure
158 * Validate that the number of queues the PF has sent in
159 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
161 static void iavf_validate_num_queues(struct iavf_adapter
*adapter
)
163 if (adapter
->vf_res
->num_queue_pairs
> IAVF_MAX_REQ_QUEUES
) {
164 struct virtchnl_vsi_resource
*vsi_res
;
167 dev_info(&adapter
->pdev
->dev
, "Received %d queues, but can only have a max of %d\n",
168 adapter
->vf_res
->num_queue_pairs
,
169 IAVF_MAX_REQ_QUEUES
);
170 dev_info(&adapter
->pdev
->dev
, "Fixing by reducing queues to %d\n",
171 IAVF_MAX_REQ_QUEUES
);
172 adapter
->vf_res
->num_queue_pairs
= IAVF_MAX_REQ_QUEUES
;
173 for (i
= 0; i
< adapter
->vf_res
->num_vsis
; i
++) {
174 vsi_res
= &adapter
->vf_res
->vsi_res
[i
];
175 vsi_res
->num_queue_pairs
= IAVF_MAX_REQ_QUEUES
;
182 * @adapter: private adapter structure
184 * Get VF configuration from PF and populate hw structure. Must be called after
185 * admin queue is initialized. Busy waits until response is received from PF,
186 * with maximum timeout. Response from PF is returned in the buffer for further
187 * processing by the caller.
189 int iavf_get_vf_config(struct iavf_adapter
*adapter
)
191 struct iavf_hw
*hw
= &adapter
->hw
;
192 struct iavf_arq_event_info event
;
193 enum virtchnl_ops op
;
194 enum iavf_status err
;
197 len
= sizeof(struct virtchnl_vf_resource
) +
198 IAVF_MAX_VF_VSI
* sizeof(struct virtchnl_vsi_resource
);
200 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
201 if (!event
.msg_buf
) {
207 /* When the AQ is empty, iavf_clean_arq_element will return
208 * nonzero and this loop will terminate.
210 err
= iavf_clean_arq_element(hw
, &event
, NULL
);
214 (enum virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
215 if (op
== VIRTCHNL_OP_GET_VF_RESOURCES
)
219 err
= (enum iavf_status
)le32_to_cpu(event
.desc
.cookie_low
);
220 memcpy(adapter
->vf_res
, event
.msg_buf
, min(event
.msg_len
, len
));
222 /* some PFs send more queues than we should have so validate that
223 * we aren't getting too many queues
226 iavf_validate_num_queues(adapter
);
227 iavf_vf_parse_hw_config(hw
, adapter
->vf_res
);
229 kfree(event
.msg_buf
);
235 * iavf_configure_queues
236 * @adapter: adapter structure
238 * Request that the PF set up our (previously allocated) queues.
240 void iavf_configure_queues(struct iavf_adapter
*adapter
)
242 struct virtchnl_vsi_queue_config_info
*vqci
;
243 struct virtchnl_queue_pair_info
*vqpi
;
244 int pairs
= adapter
->num_active_queues
;
245 int i
, max_frame
= IAVF_MAX_RXBUFFER
;
248 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
249 /* bail because we already have a command pending */
250 dev_err(&adapter
->pdev
->dev
, "Cannot configure queues, command %d pending\n",
251 adapter
->current_op
);
254 adapter
->current_op
= VIRTCHNL_OP_CONFIG_VSI_QUEUES
;
255 len
= struct_size(vqci
, qpair
, pairs
);
256 vqci
= kzalloc(len
, GFP_KERNEL
);
260 /* Limit maximum frame size when jumbo frames is not enabled */
261 if (!(adapter
->flags
& IAVF_FLAG_LEGACY_RX
) &&
262 (adapter
->netdev
->mtu
<= ETH_DATA_LEN
))
263 max_frame
= IAVF_RXBUFFER_1536
- NET_IP_ALIGN
;
265 vqci
->vsi_id
= adapter
->vsi_res
->vsi_id
;
266 vqci
->num_queue_pairs
= pairs
;
268 /* Size check is not needed here - HW max is 16 queue pairs, and we
269 * can fit info for 31 of them into the AQ buffer before it overflows.
271 for (i
= 0; i
< pairs
; i
++) {
272 vqpi
->txq
.vsi_id
= vqci
->vsi_id
;
273 vqpi
->txq
.queue_id
= i
;
274 vqpi
->txq
.ring_len
= adapter
->tx_rings
[i
].count
;
275 vqpi
->txq
.dma_ring_addr
= adapter
->tx_rings
[i
].dma
;
276 vqpi
->rxq
.vsi_id
= vqci
->vsi_id
;
277 vqpi
->rxq
.queue_id
= i
;
278 vqpi
->rxq
.ring_len
= adapter
->rx_rings
[i
].count
;
279 vqpi
->rxq
.dma_ring_addr
= adapter
->rx_rings
[i
].dma
;
280 vqpi
->rxq
.max_pkt_size
= max_frame
;
281 vqpi
->rxq
.databuffer_size
=
282 ALIGN(adapter
->rx_rings
[i
].rx_buf_len
,
283 BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT
));
287 adapter
->aq_required
&= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES
;
288 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_CONFIG_VSI_QUEUES
,
295 * @adapter: adapter structure
297 * Request that the PF enable all of our queues.
299 void iavf_enable_queues(struct iavf_adapter
*adapter
)
301 struct virtchnl_queue_select vqs
;
303 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
304 /* bail because we already have a command pending */
305 dev_err(&adapter
->pdev
->dev
, "Cannot enable queues, command %d pending\n",
306 adapter
->current_op
);
309 adapter
->current_op
= VIRTCHNL_OP_ENABLE_QUEUES
;
310 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
311 vqs
.tx_queues
= BIT(adapter
->num_active_queues
) - 1;
312 vqs
.rx_queues
= vqs
.tx_queues
;
313 adapter
->aq_required
&= ~IAVF_FLAG_AQ_ENABLE_QUEUES
;
314 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_ENABLE_QUEUES
,
315 (u8
*)&vqs
, sizeof(vqs
));
319 * iavf_disable_queues
320 * @adapter: adapter structure
322 * Request that the PF disable all of our queues.
324 void iavf_disable_queues(struct iavf_adapter
*adapter
)
326 struct virtchnl_queue_select vqs
;
328 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
329 /* bail because we already have a command pending */
330 dev_err(&adapter
->pdev
->dev
, "Cannot disable queues, command %d pending\n",
331 adapter
->current_op
);
334 adapter
->current_op
= VIRTCHNL_OP_DISABLE_QUEUES
;
335 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
336 vqs
.tx_queues
= BIT(adapter
->num_active_queues
) - 1;
337 vqs
.rx_queues
= vqs
.tx_queues
;
338 adapter
->aq_required
&= ~IAVF_FLAG_AQ_DISABLE_QUEUES
;
339 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_DISABLE_QUEUES
,
340 (u8
*)&vqs
, sizeof(vqs
));
345 * @adapter: adapter structure
347 * Request that the PF map queues to interrupt vectors. Misc causes, including
348 * admin queue, are always mapped to vector 0.
350 void iavf_map_queues(struct iavf_adapter
*adapter
)
352 struct virtchnl_irq_map_info
*vimi
;
353 struct virtchnl_vector_map
*vecmap
;
354 struct iavf_q_vector
*q_vector
;
355 int v_idx
, q_vectors
;
358 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
359 /* bail because we already have a command pending */
360 dev_err(&adapter
->pdev
->dev
, "Cannot map queues to vectors, command %d pending\n",
361 adapter
->current_op
);
364 adapter
->current_op
= VIRTCHNL_OP_CONFIG_IRQ_MAP
;
366 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
368 len
= struct_size(vimi
, vecmap
, adapter
->num_msix_vectors
);
369 vimi
= kzalloc(len
, GFP_KERNEL
);
373 vimi
->num_vectors
= adapter
->num_msix_vectors
;
374 /* Queue vectors first */
375 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
376 q_vector
= &adapter
->q_vectors
[v_idx
];
377 vecmap
= &vimi
->vecmap
[v_idx
];
379 vecmap
->vsi_id
= adapter
->vsi_res
->vsi_id
;
380 vecmap
->vector_id
= v_idx
+ NONQ_VECS
;
381 vecmap
->txq_map
= q_vector
->ring_mask
;
382 vecmap
->rxq_map
= q_vector
->ring_mask
;
383 vecmap
->rxitr_idx
= IAVF_RX_ITR
;
384 vecmap
->txitr_idx
= IAVF_TX_ITR
;
386 /* Misc vector last - this is only for AdminQ messages */
387 vecmap
= &vimi
->vecmap
[v_idx
];
388 vecmap
->vsi_id
= adapter
->vsi_res
->vsi_id
;
389 vecmap
->vector_id
= 0;
393 adapter
->aq_required
&= ~IAVF_FLAG_AQ_MAP_VECTORS
;
394 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_CONFIG_IRQ_MAP
,
400 * iavf_add_ether_addrs
401 * @adapter: adapter structure
403 * Request that the PF add one or more addresses to our filters.
405 void iavf_add_ether_addrs(struct iavf_adapter
*adapter
)
407 struct virtchnl_ether_addr_list
*veal
;
408 struct iavf_mac_filter
*f
;
409 int i
= 0, count
= 0;
413 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
414 /* bail because we already have a command pending */
415 dev_err(&adapter
->pdev
->dev
, "Cannot add filters, command %d pending\n",
416 adapter
->current_op
);
420 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
422 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
427 adapter
->aq_required
&= ~IAVF_FLAG_AQ_ADD_MAC_FILTER
;
428 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
431 adapter
->current_op
= VIRTCHNL_OP_ADD_ETH_ADDR
;
433 len
= struct_size(veal
, list
, count
);
434 if (len
> IAVF_MAX_AQ_BUF_SIZE
) {
435 dev_warn(&adapter
->pdev
->dev
, "Too many add MAC changes in one request\n");
436 count
= (IAVF_MAX_AQ_BUF_SIZE
-
437 sizeof(struct virtchnl_ether_addr_list
)) /
438 sizeof(struct virtchnl_ether_addr
);
439 len
= struct_size(veal
, list
, count
);
443 veal
= kzalloc(len
, GFP_ATOMIC
);
445 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
449 veal
->vsi_id
= adapter
->vsi_res
->vsi_id
;
450 veal
->num_elements
= count
;
451 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
453 ether_addr_copy(veal
->list
[i
].addr
, f
->macaddr
);
461 adapter
->aq_required
&= ~IAVF_FLAG_AQ_ADD_MAC_FILTER
;
463 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
465 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_ADD_ETH_ADDR
, (u8
*)veal
, len
);
470 * iavf_del_ether_addrs
471 * @adapter: adapter structure
473 * Request that the PF remove one or more addresses from our filters.
475 void iavf_del_ether_addrs(struct iavf_adapter
*adapter
)
477 struct virtchnl_ether_addr_list
*veal
;
478 struct iavf_mac_filter
*f
, *ftmp
;
479 int i
= 0, count
= 0;
483 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
484 /* bail because we already have a command pending */
485 dev_err(&adapter
->pdev
->dev
, "Cannot remove filters, command %d pending\n",
486 adapter
->current_op
);
490 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
492 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
497 adapter
->aq_required
&= ~IAVF_FLAG_AQ_DEL_MAC_FILTER
;
498 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
501 adapter
->current_op
= VIRTCHNL_OP_DEL_ETH_ADDR
;
503 len
= struct_size(veal
, list
, count
);
504 if (len
> IAVF_MAX_AQ_BUF_SIZE
) {
505 dev_warn(&adapter
->pdev
->dev
, "Too many delete MAC changes in one request\n");
506 count
= (IAVF_MAX_AQ_BUF_SIZE
-
507 sizeof(struct virtchnl_ether_addr_list
)) /
508 sizeof(struct virtchnl_ether_addr
);
509 len
= struct_size(veal
, list
, count
);
512 veal
= kzalloc(len
, GFP_ATOMIC
);
514 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
518 veal
->vsi_id
= adapter
->vsi_res
->vsi_id
;
519 veal
->num_elements
= count
;
520 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
522 ether_addr_copy(veal
->list
[i
].addr
, f
->macaddr
);
531 adapter
->aq_required
&= ~IAVF_FLAG_AQ_DEL_MAC_FILTER
;
533 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
535 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_DEL_ETH_ADDR
, (u8
*)veal
, len
);
541 * @adapter: adapter structure
543 * Request that the PF add one or more VLAN filters to our VSI.
545 void iavf_add_vlans(struct iavf_adapter
*adapter
)
547 struct virtchnl_vlan_filter_list
*vvfl
;
548 int len
, i
= 0, count
= 0;
549 struct iavf_vlan_filter
*f
;
552 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
553 /* bail because we already have a command pending */
554 dev_err(&adapter
->pdev
->dev
, "Cannot add VLANs, command %d pending\n",
555 adapter
->current_op
);
559 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
561 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
566 adapter
->aq_required
&= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER
;
567 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
570 adapter
->current_op
= VIRTCHNL_OP_ADD_VLAN
;
572 len
= sizeof(struct virtchnl_vlan_filter_list
) +
573 (count
* sizeof(u16
));
574 if (len
> IAVF_MAX_AQ_BUF_SIZE
) {
575 dev_warn(&adapter
->pdev
->dev
, "Too many add VLAN changes in one request\n");
576 count
= (IAVF_MAX_AQ_BUF_SIZE
-
577 sizeof(struct virtchnl_vlan_filter_list
)) /
579 len
= sizeof(struct virtchnl_vlan_filter_list
) +
580 (count
* sizeof(u16
));
583 vvfl
= kzalloc(len
, GFP_ATOMIC
);
585 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
589 vvfl
->vsi_id
= adapter
->vsi_res
->vsi_id
;
590 vvfl
->num_elements
= count
;
591 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
593 vvfl
->vlan_id
[i
] = f
->vlan
;
601 adapter
->aq_required
&= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER
;
603 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
605 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_ADD_VLAN
, (u8
*)vvfl
, len
);
611 * @adapter: adapter structure
613 * Request that the PF remove one or more VLAN filters from our VSI.
615 void iavf_del_vlans(struct iavf_adapter
*adapter
)
617 struct virtchnl_vlan_filter_list
*vvfl
;
618 struct iavf_vlan_filter
*f
, *ftmp
;
619 int len
, i
= 0, count
= 0;
622 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
623 /* bail because we already have a command pending */
624 dev_err(&adapter
->pdev
->dev
, "Cannot remove VLANs, command %d pending\n",
625 adapter
->current_op
);
629 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
631 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
636 adapter
->aq_required
&= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER
;
637 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
640 adapter
->current_op
= VIRTCHNL_OP_DEL_VLAN
;
642 len
= sizeof(struct virtchnl_vlan_filter_list
) +
643 (count
* sizeof(u16
));
644 if (len
> IAVF_MAX_AQ_BUF_SIZE
) {
645 dev_warn(&adapter
->pdev
->dev
, "Too many delete VLAN changes in one request\n");
646 count
= (IAVF_MAX_AQ_BUF_SIZE
-
647 sizeof(struct virtchnl_vlan_filter_list
)) /
649 len
= sizeof(struct virtchnl_vlan_filter_list
) +
650 (count
* sizeof(u16
));
653 vvfl
= kzalloc(len
, GFP_ATOMIC
);
655 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
659 vvfl
->vsi_id
= adapter
->vsi_res
->vsi_id
;
660 vvfl
->num_elements
= count
;
661 list_for_each_entry_safe(f
, ftmp
, &adapter
->vlan_filter_list
, list
) {
663 vvfl
->vlan_id
[i
] = f
->vlan
;
672 adapter
->aq_required
&= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER
;
674 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
676 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_DEL_VLAN
, (u8
*)vvfl
, len
);
681 * iavf_set_promiscuous
682 * @adapter: adapter structure
683 * @flags: bitmask to control unicast/multicast promiscuous.
685 * Request that the PF enable promiscuous mode for our VSI.
687 void iavf_set_promiscuous(struct iavf_adapter
*adapter
, int flags
)
689 struct virtchnl_promisc_info vpi
;
692 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
693 /* bail because we already have a command pending */
694 dev_err(&adapter
->pdev
->dev
, "Cannot set promiscuous mode, command %d pending\n",
695 adapter
->current_op
);
699 promisc_all
= FLAG_VF_UNICAST_PROMISC
|
700 FLAG_VF_MULTICAST_PROMISC
;
701 if ((flags
& promisc_all
) == promisc_all
) {
702 adapter
->flags
|= IAVF_FLAG_PROMISC_ON
;
703 adapter
->aq_required
&= ~IAVF_FLAG_AQ_REQUEST_PROMISC
;
704 dev_info(&adapter
->pdev
->dev
, "Entering promiscuous mode\n");
707 if (flags
& FLAG_VF_MULTICAST_PROMISC
) {
708 adapter
->flags
|= IAVF_FLAG_ALLMULTI_ON
;
709 adapter
->aq_required
&= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI
;
710 dev_info(&adapter
->pdev
->dev
, "Entering multicast promiscuous mode\n");
714 adapter
->flags
&= ~(IAVF_FLAG_PROMISC_ON
|
715 IAVF_FLAG_ALLMULTI_ON
);
716 adapter
->aq_required
&= ~(IAVF_FLAG_AQ_RELEASE_PROMISC
|
717 IAVF_FLAG_AQ_RELEASE_ALLMULTI
);
718 dev_info(&adapter
->pdev
->dev
, "Leaving promiscuous mode\n");
721 adapter
->current_op
= VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
;
722 vpi
.vsi_id
= adapter
->vsi_res
->vsi_id
;
724 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
,
725 (u8
*)&vpi
, sizeof(vpi
));
730 * @adapter: adapter structure
732 * Request VSI statistics from PF.
734 void iavf_request_stats(struct iavf_adapter
*adapter
)
736 struct virtchnl_queue_select vqs
;
738 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
739 /* no error message, this isn't crucial */
742 adapter
->current_op
= VIRTCHNL_OP_GET_STATS
;
743 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
744 /* queue maps are ignored for this message - only the vsi is used */
745 if (iavf_send_pf_msg(adapter
, VIRTCHNL_OP_GET_STATS
, (u8
*)&vqs
,
747 /* if the request failed, don't lock out others */
748 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
753 * @adapter: adapter structure
755 * Request hash enable capabilities from PF
757 void iavf_get_hena(struct iavf_adapter
*adapter
)
759 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
760 /* bail because we already have a command pending */
761 dev_err(&adapter
->pdev
->dev
, "Cannot get RSS hash capabilities, command %d pending\n",
762 adapter
->current_op
);
765 adapter
->current_op
= VIRTCHNL_OP_GET_RSS_HENA_CAPS
;
766 adapter
->aq_required
&= ~IAVF_FLAG_AQ_GET_HENA
;
767 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_GET_RSS_HENA_CAPS
, NULL
, 0);
772 * @adapter: adapter structure
774 * Request the PF to set our RSS hash capabilities
776 void iavf_set_hena(struct iavf_adapter
*adapter
)
778 struct virtchnl_rss_hena vrh
;
780 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
781 /* bail because we already have a command pending */
782 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS hash enable, command %d pending\n",
783 adapter
->current_op
);
786 vrh
.hena
= adapter
->hena
;
787 adapter
->current_op
= VIRTCHNL_OP_SET_RSS_HENA
;
788 adapter
->aq_required
&= ~IAVF_FLAG_AQ_SET_HENA
;
789 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_SET_RSS_HENA
, (u8
*)&vrh
,
795 * @adapter: adapter structure
797 * Request the PF to set our RSS hash key
799 void iavf_set_rss_key(struct iavf_adapter
*adapter
)
801 struct virtchnl_rss_key
*vrk
;
804 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
805 /* bail because we already have a command pending */
806 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS key, command %d pending\n",
807 adapter
->current_op
);
810 len
= sizeof(struct virtchnl_rss_key
) +
811 (adapter
->rss_key_size
* sizeof(u8
)) - 1;
812 vrk
= kzalloc(len
, GFP_KERNEL
);
815 vrk
->vsi_id
= adapter
->vsi
.id
;
816 vrk
->key_len
= adapter
->rss_key_size
;
817 memcpy(vrk
->key
, adapter
->rss_key
, adapter
->rss_key_size
);
819 adapter
->current_op
= VIRTCHNL_OP_CONFIG_RSS_KEY
;
820 adapter
->aq_required
&= ~IAVF_FLAG_AQ_SET_RSS_KEY
;
821 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_CONFIG_RSS_KEY
, (u8
*)vrk
, len
);
827 * @adapter: adapter structure
829 * Request the PF to set our RSS lookup table
831 void iavf_set_rss_lut(struct iavf_adapter
*adapter
)
833 struct virtchnl_rss_lut
*vrl
;
836 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
837 /* bail because we already have a command pending */
838 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS LUT, command %d pending\n",
839 adapter
->current_op
);
842 len
= sizeof(struct virtchnl_rss_lut
) +
843 (adapter
->rss_lut_size
* sizeof(u8
)) - 1;
844 vrl
= kzalloc(len
, GFP_KERNEL
);
847 vrl
->vsi_id
= adapter
->vsi
.id
;
848 vrl
->lut_entries
= adapter
->rss_lut_size
;
849 memcpy(vrl
->lut
, adapter
->rss_lut
, adapter
->rss_lut_size
);
850 adapter
->current_op
= VIRTCHNL_OP_CONFIG_RSS_LUT
;
851 adapter
->aq_required
&= ~IAVF_FLAG_AQ_SET_RSS_LUT
;
852 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_CONFIG_RSS_LUT
, (u8
*)vrl
, len
);
857 * iavf_enable_vlan_stripping
858 * @adapter: adapter structure
860 * Request VLAN header stripping to be enabled
862 void iavf_enable_vlan_stripping(struct iavf_adapter
*adapter
)
864 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
865 /* bail because we already have a command pending */
866 dev_err(&adapter
->pdev
->dev
, "Cannot enable stripping, command %d pending\n",
867 adapter
->current_op
);
870 adapter
->current_op
= VIRTCHNL_OP_ENABLE_VLAN_STRIPPING
;
871 adapter
->aq_required
&= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING
;
872 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING
, NULL
, 0);
876 * iavf_disable_vlan_stripping
877 * @adapter: adapter structure
879 * Request VLAN header stripping to be disabled
881 void iavf_disable_vlan_stripping(struct iavf_adapter
*adapter
)
883 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
884 /* bail because we already have a command pending */
885 dev_err(&adapter
->pdev
->dev
, "Cannot disable stripping, command %d pending\n",
886 adapter
->current_op
);
889 adapter
->current_op
= VIRTCHNL_OP_DISABLE_VLAN_STRIPPING
;
890 adapter
->aq_required
&= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING
;
891 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING
, NULL
, 0);
895 * iavf_print_link_message - print link up or down
896 * @adapter: adapter structure
898 * Log a message telling the world of our wonderous link status
900 static void iavf_print_link_message(struct iavf_adapter
*adapter
)
902 struct net_device
*netdev
= adapter
->netdev
;
903 char *speed
= "Unknown ";
905 if (!adapter
->link_up
) {
906 netdev_info(netdev
, "NIC Link is Down\n");
910 switch (adapter
->link_speed
) {
911 case IAVF_LINK_SPEED_40GB
:
914 case IAVF_LINK_SPEED_25GB
:
917 case IAVF_LINK_SPEED_20GB
:
920 case IAVF_LINK_SPEED_10GB
:
923 case IAVF_LINK_SPEED_1GB
:
926 case IAVF_LINK_SPEED_100MB
:
933 netdev_info(netdev
, "NIC Link is Up %sbps Full Duplex\n", speed
);
937 * iavf_enable_channel
938 * @adapter: adapter structure
940 * Request that the PF enable channels as specified by
941 * the user via tc tool.
943 void iavf_enable_channels(struct iavf_adapter
*adapter
)
945 struct virtchnl_tc_info
*vti
= NULL
;
949 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
950 /* bail because we already have a command pending */
951 dev_err(&adapter
->pdev
->dev
, "Cannot configure mqprio, command %d pending\n",
952 adapter
->current_op
);
956 len
= struct_size(vti
, list
, adapter
->num_tc
- 1);
957 vti
= kzalloc(len
, GFP_KERNEL
);
960 vti
->num_tc
= adapter
->num_tc
;
961 for (i
= 0; i
< vti
->num_tc
; i
++) {
962 vti
->list
[i
].count
= adapter
->ch_config
.ch_info
[i
].count
;
963 vti
->list
[i
].offset
= adapter
->ch_config
.ch_info
[i
].offset
;
964 vti
->list
[i
].pad
= 0;
965 vti
->list
[i
].max_tx_rate
=
966 adapter
->ch_config
.ch_info
[i
].max_tx_rate
;
969 adapter
->ch_config
.state
= __IAVF_TC_RUNNING
;
970 adapter
->flags
|= IAVF_FLAG_REINIT_ITR_NEEDED
;
971 adapter
->current_op
= VIRTCHNL_OP_ENABLE_CHANNELS
;
972 adapter
->aq_required
&= ~IAVF_FLAG_AQ_ENABLE_CHANNELS
;
973 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_ENABLE_CHANNELS
, (u8
*)vti
, len
);
978 * iavf_disable_channel
979 * @adapter: adapter structure
981 * Request that the PF disable channels that are configured
983 void iavf_disable_channels(struct iavf_adapter
*adapter
)
985 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
986 /* bail because we already have a command pending */
987 dev_err(&adapter
->pdev
->dev
, "Cannot configure mqprio, command %d pending\n",
988 adapter
->current_op
);
992 adapter
->ch_config
.state
= __IAVF_TC_INVALID
;
993 adapter
->flags
|= IAVF_FLAG_REINIT_ITR_NEEDED
;
994 adapter
->current_op
= VIRTCHNL_OP_DISABLE_CHANNELS
;
995 adapter
->aq_required
&= ~IAVF_FLAG_AQ_DISABLE_CHANNELS
;
996 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_DISABLE_CHANNELS
, NULL
, 0);
1000 * iavf_print_cloud_filter
1001 * @adapter: adapter structure
1002 * @f: cloud filter to print
1004 * Print the cloud filter
1006 static void iavf_print_cloud_filter(struct iavf_adapter
*adapter
,
1007 struct virtchnl_filter
*f
)
1009 switch (f
->flow_type
) {
1010 case VIRTCHNL_TCP_V4_FLOW
:
1011 dev_info(&adapter
->pdev
->dev
, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
1012 &f
->data
.tcp_spec
.dst_mac
,
1013 &f
->data
.tcp_spec
.src_mac
,
1014 ntohs(f
->data
.tcp_spec
.vlan_id
),
1015 &f
->data
.tcp_spec
.dst_ip
[0],
1016 &f
->data
.tcp_spec
.src_ip
[0],
1017 ntohs(f
->data
.tcp_spec
.dst_port
),
1018 ntohs(f
->data
.tcp_spec
.src_port
));
1020 case VIRTCHNL_TCP_V6_FLOW
:
1021 dev_info(&adapter
->pdev
->dev
, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
1022 &f
->data
.tcp_spec
.dst_mac
,
1023 &f
->data
.tcp_spec
.src_mac
,
1024 ntohs(f
->data
.tcp_spec
.vlan_id
),
1025 &f
->data
.tcp_spec
.dst_ip
,
1026 &f
->data
.tcp_spec
.src_ip
,
1027 ntohs(f
->data
.tcp_spec
.dst_port
),
1028 ntohs(f
->data
.tcp_spec
.src_port
));
1034 * iavf_add_cloud_filter
1035 * @adapter: adapter structure
1037 * Request that the PF add cloud filters as specified
1038 * by the user via tc tool.
1040 void iavf_add_cloud_filter(struct iavf_adapter
*adapter
)
1042 struct iavf_cloud_filter
*cf
;
1043 struct virtchnl_filter
*f
;
1044 int len
= 0, count
= 0;
1046 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
1047 /* bail because we already have a command pending */
1048 dev_err(&adapter
->pdev
->dev
, "Cannot add cloud filter, command %d pending\n",
1049 adapter
->current_op
);
1052 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
1059 adapter
->aq_required
&= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER
;
1062 adapter
->current_op
= VIRTCHNL_OP_ADD_CLOUD_FILTER
;
1064 len
= sizeof(struct virtchnl_filter
);
1065 f
= kzalloc(len
, GFP_KERNEL
);
1069 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
1071 memcpy(f
, &cf
->f
, sizeof(struct virtchnl_filter
));
1073 cf
->state
= __IAVF_CF_ADD_PENDING
;
1074 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_ADD_CLOUD_FILTER
,
1082 * iavf_del_cloud_filter
1083 * @adapter: adapter structure
1085 * Request that the PF delete cloud filters as specified
1086 * by the user via tc tool.
1088 void iavf_del_cloud_filter(struct iavf_adapter
*adapter
)
1090 struct iavf_cloud_filter
*cf
, *cftmp
;
1091 struct virtchnl_filter
*f
;
1092 int len
= 0, count
= 0;
1094 if (adapter
->current_op
!= VIRTCHNL_OP_UNKNOWN
) {
1095 /* bail because we already have a command pending */
1096 dev_err(&adapter
->pdev
->dev
, "Cannot remove cloud filter, command %d pending\n",
1097 adapter
->current_op
);
1100 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
1107 adapter
->aq_required
&= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER
;
1110 adapter
->current_op
= VIRTCHNL_OP_DEL_CLOUD_FILTER
;
1112 len
= sizeof(struct virtchnl_filter
);
1113 f
= kzalloc(len
, GFP_KERNEL
);
1117 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
, list
) {
1119 memcpy(f
, &cf
->f
, sizeof(struct virtchnl_filter
));
1121 cf
->state
= __IAVF_CF_DEL_PENDING
;
1122 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_DEL_CLOUD_FILTER
,
1130 * iavf_request_reset
1131 * @adapter: adapter structure
1133 * Request that the PF reset this VF. No response is expected.
1135 void iavf_request_reset(struct iavf_adapter
*adapter
)
1137 /* Don't check CURRENT_OP - this is always higher priority */
1138 iavf_send_pf_msg(adapter
, VIRTCHNL_OP_RESET_VF
, NULL
, 0);
1139 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;
1143 * iavf_virtchnl_completion
1144 * @adapter: adapter structure
1145 * @v_opcode: opcode sent by PF
1146 * @v_retval: retval sent by PF
1147 * @msg: message sent by PF
1148 * @msglen: message length
1150 * Asynchronous completion function for admin queue messages. Rather than busy
1151 * wait, we fire off our requests and assume that no errors will be returned.
1152 * This function handles the reply messages.
1154 void iavf_virtchnl_completion(struct iavf_adapter
*adapter
,
1155 enum virtchnl_ops v_opcode
,
1156 enum iavf_status v_retval
, u8
*msg
, u16 msglen
)
1158 struct net_device
*netdev
= adapter
->netdev
;
1160 if (v_opcode
== VIRTCHNL_OP_EVENT
) {
1161 struct virtchnl_pf_event
*vpe
=
1162 (struct virtchnl_pf_event
*)msg
;
1163 bool link_up
= vpe
->event_data
.link_event
.link_status
;
1165 switch (vpe
->event
) {
1166 case VIRTCHNL_EVENT_LINK_CHANGE
:
1167 adapter
->link_speed
=
1168 vpe
->event_data
.link_event
.link_speed
;
1170 /* we've already got the right link status, bail */
1171 if (adapter
->link_up
== link_up
)
1175 /* If we get link up message and start queues
1176 * before our queues are configured it will
1177 * trigger a TX hang. In that case, just ignore
1178 * the link status message,we'll get another one
1179 * after we enable queues and actually prepared
1182 if (adapter
->state
!= __IAVF_RUNNING
)
1185 /* For ADq enabled VF, we reconfigure VSIs and
1186 * re-allocate queues. Hence wait till all
1187 * queues are enabled.
1189 if (adapter
->flags
&
1190 IAVF_FLAG_QUEUES_DISABLED
)
1194 adapter
->link_up
= link_up
;
1196 netif_tx_start_all_queues(netdev
);
1197 netif_carrier_on(netdev
);
1199 netif_tx_stop_all_queues(netdev
);
1200 netif_carrier_off(netdev
);
1202 iavf_print_link_message(adapter
);
1204 case VIRTCHNL_EVENT_RESET_IMPENDING
:
1205 dev_info(&adapter
->pdev
->dev
, "Reset warning received from the PF\n");
1206 if (!(adapter
->flags
& IAVF_FLAG_RESET_PENDING
)) {
1207 adapter
->flags
|= IAVF_FLAG_RESET_PENDING
;
1208 dev_info(&adapter
->pdev
->dev
, "Scheduling reset task\n");
1209 queue_work(iavf_wq
, &adapter
->reset_task
);
1213 dev_err(&adapter
->pdev
->dev
, "Unknown event %d from PF\n",
1221 case VIRTCHNL_OP_ADD_VLAN
:
1222 dev_err(&adapter
->pdev
->dev
, "Failed to add VLAN filter, error %s\n",
1223 iavf_stat_str(&adapter
->hw
, v_retval
));
1225 case VIRTCHNL_OP_ADD_ETH_ADDR
:
1226 dev_err(&adapter
->pdev
->dev
, "Failed to add MAC filter, error %s\n",
1227 iavf_stat_str(&adapter
->hw
, v_retval
));
1228 /* restore administratively set MAC address */
1229 ether_addr_copy(adapter
->hw
.mac
.addr
, netdev
->dev_addr
);
1231 case VIRTCHNL_OP_DEL_VLAN
:
1232 dev_err(&adapter
->pdev
->dev
, "Failed to delete VLAN filter, error %s\n",
1233 iavf_stat_str(&adapter
->hw
, v_retval
));
1235 case VIRTCHNL_OP_DEL_ETH_ADDR
:
1236 dev_err(&adapter
->pdev
->dev
, "Failed to delete MAC filter, error %s\n",
1237 iavf_stat_str(&adapter
->hw
, v_retval
));
1239 case VIRTCHNL_OP_ENABLE_CHANNELS
:
1240 dev_err(&adapter
->pdev
->dev
, "Failed to configure queue channels, error %s\n",
1241 iavf_stat_str(&adapter
->hw
, v_retval
));
1242 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
1243 adapter
->ch_config
.state
= __IAVF_TC_INVALID
;
1244 netdev_reset_tc(netdev
);
1245 netif_tx_start_all_queues(netdev
);
1247 case VIRTCHNL_OP_DISABLE_CHANNELS
:
1248 dev_err(&adapter
->pdev
->dev
, "Failed to disable queue channels, error %s\n",
1249 iavf_stat_str(&adapter
->hw
, v_retval
));
1250 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
1251 adapter
->ch_config
.state
= __IAVF_TC_RUNNING
;
1252 netif_tx_start_all_queues(netdev
);
1254 case VIRTCHNL_OP_ADD_CLOUD_FILTER
: {
1255 struct iavf_cloud_filter
*cf
, *cftmp
;
1257 list_for_each_entry_safe(cf
, cftmp
,
1258 &adapter
->cloud_filter_list
,
1260 if (cf
->state
== __IAVF_CF_ADD_PENDING
) {
1261 cf
->state
= __IAVF_CF_INVALID
;
1262 dev_info(&adapter
->pdev
->dev
, "Failed to add cloud filter, error %s\n",
1263 iavf_stat_str(&adapter
->hw
,
1265 iavf_print_cloud_filter(adapter
,
1267 list_del(&cf
->list
);
1269 adapter
->num_cloud_filters
--;
1274 case VIRTCHNL_OP_DEL_CLOUD_FILTER
: {
1275 struct iavf_cloud_filter
*cf
;
1277 list_for_each_entry(cf
, &adapter
->cloud_filter_list
,
1279 if (cf
->state
== __IAVF_CF_DEL_PENDING
) {
1280 cf
->state
= __IAVF_CF_ACTIVE
;
1281 dev_info(&adapter
->pdev
->dev
, "Failed to del cloud filter, error %s\n",
1282 iavf_stat_str(&adapter
->hw
,
1284 iavf_print_cloud_filter(adapter
,
1291 dev_err(&adapter
->pdev
->dev
, "PF returned error %d (%s) to our request %d\n",
1292 v_retval
, iavf_stat_str(&adapter
->hw
, v_retval
),
1297 case VIRTCHNL_OP_ADD_ETH_ADDR
: {
1298 if (!ether_addr_equal(netdev
->dev_addr
, adapter
->hw
.mac
.addr
))
1299 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
1302 case VIRTCHNL_OP_GET_STATS
: {
1303 struct iavf_eth_stats
*stats
=
1304 (struct iavf_eth_stats
*)msg
;
1305 netdev
->stats
.rx_packets
= stats
->rx_unicast
+
1306 stats
->rx_multicast
+
1307 stats
->rx_broadcast
;
1308 netdev
->stats
.tx_packets
= stats
->tx_unicast
+
1309 stats
->tx_multicast
+
1310 stats
->tx_broadcast
;
1311 netdev
->stats
.rx_bytes
= stats
->rx_bytes
;
1312 netdev
->stats
.tx_bytes
= stats
->tx_bytes
;
1313 netdev
->stats
.tx_errors
= stats
->tx_errors
;
1314 netdev
->stats
.rx_dropped
= stats
->rx_discards
;
1315 netdev
->stats
.tx_dropped
= stats
->tx_discards
;
1316 adapter
->current_stats
= *stats
;
1319 case VIRTCHNL_OP_GET_VF_RESOURCES
: {
1320 u16 len
= sizeof(struct virtchnl_vf_resource
) +
1322 sizeof(struct virtchnl_vsi_resource
);
1323 memcpy(adapter
->vf_res
, msg
, min(msglen
, len
));
1324 iavf_validate_num_queues(adapter
);
1325 iavf_vf_parse_hw_config(&adapter
->hw
, adapter
->vf_res
);
1326 if (is_zero_ether_addr(adapter
->hw
.mac
.addr
)) {
1327 /* restore current mac address */
1328 ether_addr_copy(adapter
->hw
.mac
.addr
, netdev
->dev_addr
);
1330 /* refresh current mac address if changed */
1331 ether_addr_copy(netdev
->dev_addr
, adapter
->hw
.mac
.addr
);
1332 ether_addr_copy(netdev
->perm_addr
,
1333 adapter
->hw
.mac
.addr
);
1335 spin_lock_bh(&adapter
->mac_vlan_list_lock
);
1336 iavf_add_filter(adapter
, adapter
->hw
.mac
.addr
);
1337 spin_unlock_bh(&adapter
->mac_vlan_list_lock
);
1338 iavf_process_config(adapter
);
1341 case VIRTCHNL_OP_ENABLE_QUEUES
:
1342 /* enable transmits */
1343 iavf_irq_enable(adapter
, true);
1344 adapter
->flags
&= ~IAVF_FLAG_QUEUES_DISABLED
;
1346 case VIRTCHNL_OP_DISABLE_QUEUES
:
1347 iavf_free_all_tx_resources(adapter
);
1348 iavf_free_all_rx_resources(adapter
);
1349 if (adapter
->state
== __IAVF_DOWN_PENDING
) {
1350 adapter
->state
= __IAVF_DOWN
;
1351 wake_up(&adapter
->down_waitqueue
);
1354 case VIRTCHNL_OP_VERSION
:
1355 case VIRTCHNL_OP_CONFIG_IRQ_MAP
:
1356 /* Don't display an error if we get these out of sequence.
1357 * If the firmware needed to get kicked, we'll get these and
1360 if (v_opcode
!= adapter
->current_op
)
1363 case VIRTCHNL_OP_IWARP
:
1364 /* Gobble zero-length replies from the PF. They indicate that
1365 * a previous message was received OK, and the client doesn't
1368 if (msglen
&& CLIENT_ENABLED(adapter
))
1369 iavf_notify_client_message(&adapter
->vsi
, msg
, msglen
);
1372 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
:
1373 adapter
->client_pending
&=
1374 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
));
1376 case VIRTCHNL_OP_GET_RSS_HENA_CAPS
: {
1377 struct virtchnl_rss_hena
*vrh
= (struct virtchnl_rss_hena
*)msg
;
1379 if (msglen
== sizeof(*vrh
))
1380 adapter
->hena
= vrh
->hena
;
1382 dev_warn(&adapter
->pdev
->dev
,
1383 "Invalid message %d from PF\n", v_opcode
);
1386 case VIRTCHNL_OP_REQUEST_QUEUES
: {
1387 struct virtchnl_vf_res_request
*vfres
=
1388 (struct virtchnl_vf_res_request
*)msg
;
1390 if (vfres
->num_queue_pairs
!= adapter
->num_req_queues
) {
1391 dev_info(&adapter
->pdev
->dev
,
1392 "Requested %d queues, PF can support %d\n",
1393 adapter
->num_req_queues
,
1394 vfres
->num_queue_pairs
);
1395 adapter
->num_req_queues
= 0;
1396 adapter
->flags
&= ~IAVF_FLAG_REINIT_ITR_NEEDED
;
1400 case VIRTCHNL_OP_ADD_CLOUD_FILTER
: {
1401 struct iavf_cloud_filter
*cf
;
1403 list_for_each_entry(cf
, &adapter
->cloud_filter_list
, list
) {
1404 if (cf
->state
== __IAVF_CF_ADD_PENDING
)
1405 cf
->state
= __IAVF_CF_ACTIVE
;
1409 case VIRTCHNL_OP_DEL_CLOUD_FILTER
: {
1410 struct iavf_cloud_filter
*cf
, *cftmp
;
1412 list_for_each_entry_safe(cf
, cftmp
, &adapter
->cloud_filter_list
,
1414 if (cf
->state
== __IAVF_CF_DEL_PENDING
) {
1415 cf
->state
= __IAVF_CF_INVALID
;
1416 list_del(&cf
->list
);
1418 adapter
->num_cloud_filters
--;
1424 if (adapter
->current_op
&& (v_opcode
!= adapter
->current_op
))
1425 dev_warn(&adapter
->pdev
->dev
, "Expected response %d from PF, received %d\n",
1426 adapter
->current_op
, v_opcode
);
1428 } /* switch v_opcode */
1429 adapter
->current_op
= VIRTCHNL_OP_UNKNOWN
;