1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
12 #include <rte_byteorder.h>
13 #include <rte_common.h>
15 #include <rte_debug.h>
16 #include <rte_atomic.h>
18 #include <rte_ether.h>
19 #include <rte_ethdev_driver.h>
23 #include "base/iavf_prototype.h"
24 #include "base/iavf_adminq_cmd.h"
25 #include "base/iavf_type.h"
28 #include "iavf_rxtx.h"
30 #define MAX_TRY_TIMES 200
31 #define ASQ_DELAY_MS 10
33 /* Read data in admin queue to get msg from pf driver */
34 static enum iavf_status_code
35 iavf_read_msg_from_pf(struct iavf_adapter
*adapter
, uint16_t buf_len
,
38 struct iavf_hw
*hw
= IAVF_DEV_PRIVATE_TO_HW(adapter
);
39 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
40 struct iavf_arq_event_info event
;
41 enum virtchnl_ops opcode
;
44 event
.buf_len
= buf_len
;
46 ret
= iavf_clean_arq_element(hw
, &event
, NULL
);
47 /* Can't read any msg from adminQ */
49 PMD_DRV_LOG(DEBUG
, "Can't read msg from AQ");
53 opcode
= (enum virtchnl_ops
)rte_le_to_cpu_32(event
.desc
.cookie_high
);
54 vf
->cmd_retval
= (enum virtchnl_status_code
)rte_le_to_cpu_32(
55 event
.desc
.cookie_low
);
57 PMD_DRV_LOG(DEBUG
, "AQ from pf carries opcode %u, retval %d",
58 opcode
, vf
->cmd_retval
);
60 if (opcode
!= vf
->pend_cmd
)
61 PMD_DRV_LOG(WARNING
, "command mismatch, expect %u, get %u",
62 vf
->pend_cmd
, opcode
);
68 iavf_execute_vf_cmd(struct iavf_adapter
*adapter
, struct iavf_cmd_info
*args
)
70 struct iavf_hw
*hw
= IAVF_DEV_PRIVATE_TO_HW(adapter
);
71 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
72 enum iavf_status_code ret
;
76 if (_atomic_set_cmd(vf
, args
->ops
))
79 ret
= iavf_aq_send_msg_to_pf(hw
, args
->ops
, IAVF_SUCCESS
,
80 args
->in_args
, args
->in_args_size
, NULL
);
82 PMD_DRV_LOG(ERR
, "fail to send cmd %d", args
->ops
);
88 case VIRTCHNL_OP_RESET_VF
:
89 /*no need to wait for response */
92 case VIRTCHNL_OP_VERSION
:
93 case VIRTCHNL_OP_GET_VF_RESOURCES
:
94 /* for init virtchnl ops, need to poll the response */
96 ret
= iavf_read_msg_from_pf(adapter
, args
->out_size
,
98 if (ret
== IAVF_SUCCESS
)
100 rte_delay_ms(ASQ_DELAY_MS
);
101 } while (i
++ < MAX_TRY_TIMES
);
102 if (i
>= MAX_TRY_TIMES
||
103 vf
->cmd_retval
!= VIRTCHNL_STATUS_SUCCESS
) {
105 PMD_DRV_LOG(ERR
, "No response or return failure (%d)"
106 " for cmd %d", vf
->cmd_retval
, args
->ops
);
112 /* For other virtchnl ops in running time,
113 * wait for the cmd done flag.
116 if (vf
->pend_cmd
== VIRTCHNL_OP_UNKNOWN
)
118 rte_delay_ms(ASQ_DELAY_MS
);
119 /* If don't read msg or read sys event, continue */
120 } while (i
++ < MAX_TRY_TIMES
);
121 /* If there's no response is received, clear command */
122 if (i
>= MAX_TRY_TIMES
||
123 vf
->cmd_retval
!= VIRTCHNL_STATUS_SUCCESS
) {
125 PMD_DRV_LOG(ERR
, "No response or return failure (%d)"
126 " for cmd %d", vf
->cmd_retval
, args
->ops
);
136 iavf_handle_pf_event_msg(struct rte_eth_dev
*dev
, uint8_t *msg
,
139 struct virtchnl_pf_event
*pf_msg
=
140 (struct virtchnl_pf_event
*)msg
;
141 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(dev
->data
->dev_private
);
143 if (msglen
< sizeof(struct virtchnl_pf_event
)) {
144 PMD_DRV_LOG(DEBUG
, "Error event");
147 switch (pf_msg
->event
) {
148 case VIRTCHNL_EVENT_RESET_IMPENDING
:
149 PMD_DRV_LOG(DEBUG
, "VIRTCHNL_EVENT_RESET_IMPENDING event");
150 _rte_eth_dev_callback_process(dev
, RTE_ETH_EVENT_INTR_RESET
,
153 case VIRTCHNL_EVENT_LINK_CHANGE
:
154 PMD_DRV_LOG(DEBUG
, "VIRTCHNL_EVENT_LINK_CHANGE event");
155 vf
->link_up
= pf_msg
->event_data
.link_event
.link_status
;
156 vf
->link_speed
= pf_msg
->event_data
.link_event_adv
.link_speed
;
157 iavf_dev_link_update(dev
, 0);
158 _rte_eth_dev_callback_process(dev
, RTE_ETH_EVENT_INTR_LSC
,
161 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE
:
162 PMD_DRV_LOG(DEBUG
, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
165 PMD_DRV_LOG(ERR
, " unknown event received %u", pf_msg
->event
);
171 iavf_handle_virtchnl_msg(struct rte_eth_dev
*dev
)
173 struct iavf_hw
*hw
= IAVF_DEV_PRIVATE_TO_HW(dev
->data
->dev_private
);
174 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(dev
->data
->dev_private
);
175 struct iavf_arq_event_info info
;
176 uint16_t pending
, aq_opc
;
177 enum virtchnl_ops msg_opc
;
178 enum iavf_status_code msg_ret
;
181 info
.buf_len
= IAVF_AQ_BUF_SZ
;
183 PMD_DRV_LOG(ERR
, "Buffer for adminq resp should not be NULL");
186 info
.msg_buf
= vf
->aq_resp
;
190 ret
= iavf_clean_arq_element(hw
, &info
, &pending
);
192 if (ret
!= IAVF_SUCCESS
) {
193 PMD_DRV_LOG(INFO
, "Failed to read msg from AdminQ,"
197 aq_opc
= rte_le_to_cpu_16(info
.desc
.opcode
);
198 /* For the message sent from pf to vf, opcode is stored in
199 * cookie_high of struct iavf_aq_desc, while return error code
200 * are stored in cookie_low, Which is done by PF driver.
202 msg_opc
= (enum virtchnl_ops
)rte_le_to_cpu_32(
203 info
.desc
.cookie_high
);
204 msg_ret
= (enum iavf_status_code
)rte_le_to_cpu_32(
205 info
.desc
.cookie_low
);
207 case iavf_aqc_opc_send_msg_to_vf
:
208 if (msg_opc
== VIRTCHNL_OP_EVENT
) {
209 iavf_handle_pf_event_msg(dev
, info
.msg_buf
,
212 /* read message and it's expected one */
213 if (msg_opc
== vf
->pend_cmd
) {
214 vf
->cmd_retval
= msg_ret
;
215 /* prevent compiler reordering */
216 rte_compiler_barrier();
219 PMD_DRV_LOG(ERR
, "command mismatch,"
221 vf
->pend_cmd
, msg_opc
);
223 "adminq response is received,"
224 " opcode = %d", msg_opc
);
228 PMD_DRV_LOG(ERR
, "Request %u is not supported yet",
236 iavf_enable_vlan_strip(struct iavf_adapter
*adapter
)
238 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
239 struct iavf_cmd_info args
;
242 memset(&args
, 0, sizeof(args
));
243 args
.ops
= VIRTCHNL_OP_ENABLE_VLAN_STRIPPING
;
245 args
.in_args_size
= 0;
246 args
.out_buffer
= vf
->aq_resp
;
247 args
.out_size
= IAVF_AQ_BUF_SZ
;
248 ret
= iavf_execute_vf_cmd(adapter
, &args
);
250 PMD_DRV_LOG(ERR
, "Failed to execute command of"
251 " OP_ENABLE_VLAN_STRIPPING");
257 iavf_disable_vlan_strip(struct iavf_adapter
*adapter
)
259 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
260 struct iavf_cmd_info args
;
263 memset(&args
, 0, sizeof(args
));
264 args
.ops
= VIRTCHNL_OP_DISABLE_VLAN_STRIPPING
;
266 args
.in_args_size
= 0;
267 args
.out_buffer
= vf
->aq_resp
;
268 args
.out_size
= IAVF_AQ_BUF_SZ
;
269 ret
= iavf_execute_vf_cmd(adapter
, &args
);
271 PMD_DRV_LOG(ERR
, "Failed to execute command of"
272 " OP_DISABLE_VLAN_STRIPPING");
277 #define VIRTCHNL_VERSION_MAJOR_START 1
278 #define VIRTCHNL_VERSION_MINOR_START 1
280 /* Check API version with sync wait until version read from admin queue */
282 iavf_check_api_version(struct iavf_adapter
*adapter
)
284 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
285 struct virtchnl_version_info version
, *pver
;
286 struct iavf_cmd_info args
;
289 version
.major
= VIRTCHNL_VERSION_MAJOR
;
290 version
.minor
= VIRTCHNL_VERSION_MINOR
;
292 args
.ops
= VIRTCHNL_OP_VERSION
;
293 args
.in_args
= (uint8_t *)&version
;
294 args
.in_args_size
= sizeof(version
);
295 args
.out_buffer
= vf
->aq_resp
;
296 args
.out_size
= IAVF_AQ_BUF_SZ
;
298 err
= iavf_execute_vf_cmd(adapter
, &args
);
300 PMD_INIT_LOG(ERR
, "Fail to execute command of OP_VERSION");
304 pver
= (struct virtchnl_version_info
*)args
.out_buffer
;
305 vf
->virtchnl_version
= *pver
;
307 if (vf
->virtchnl_version
.major
< VIRTCHNL_VERSION_MAJOR_START
||
308 (vf
->virtchnl_version
.major
== VIRTCHNL_VERSION_MAJOR_START
&&
309 vf
->virtchnl_version
.minor
< VIRTCHNL_VERSION_MINOR_START
)) {
310 PMD_INIT_LOG(ERR
, "VIRTCHNL API version should not be lower"
311 " than (%u.%u) to support Adapative VF",
312 VIRTCHNL_VERSION_MAJOR_START
,
313 VIRTCHNL_VERSION_MAJOR_START
);
315 } else if (vf
->virtchnl_version
.major
> VIRTCHNL_VERSION_MAJOR
||
316 (vf
->virtchnl_version
.major
== VIRTCHNL_VERSION_MAJOR
&&
317 vf
->virtchnl_version
.minor
> VIRTCHNL_VERSION_MINOR
)) {
318 PMD_INIT_LOG(ERR
, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
319 vf
->virtchnl_version
.major
,
320 vf
->virtchnl_version
.minor
,
321 VIRTCHNL_VERSION_MAJOR
,
322 VIRTCHNL_VERSION_MINOR
);
326 PMD_DRV_LOG(DEBUG
, "Peer is supported PF host");
331 iavf_get_vf_resource(struct iavf_adapter
*adapter
)
333 struct iavf_hw
*hw
= IAVF_DEV_PRIVATE_TO_HW(adapter
);
334 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
335 struct iavf_cmd_info args
;
339 args
.ops
= VIRTCHNL_OP_GET_VF_RESOURCES
;
340 args
.out_buffer
= vf
->aq_resp
;
341 args
.out_size
= IAVF_AQ_BUF_SZ
;
343 /* TODO: basic offload capabilities, need to
344 * add advanced/optional offload capabilities
347 caps
= IAVF_BASIC_OFFLOAD_CAPS
| VIRTCHNL_VF_CAP_ADV_LINK_SPEED
;
349 args
.in_args
= (uint8_t *)&caps
;
350 args
.in_args_size
= sizeof(caps
);
352 err
= iavf_execute_vf_cmd(adapter
, &args
);
356 "Failed to execute command of OP_GET_VF_RESOURCE");
360 len
= sizeof(struct virtchnl_vf_resource
) +
361 IAVF_MAX_VF_VSI
* sizeof(struct virtchnl_vsi_resource
);
363 rte_memcpy(vf
->vf_res
, args
.out_buffer
,
364 RTE_MIN(args
.out_size
, len
));
365 /* parse VF config message back from PF*/
366 iavf_parse_hw_config(hw
, vf
->vf_res
);
367 for (i
= 0; i
< vf
->vf_res
->num_vsis
; i
++) {
368 if (vf
->vf_res
->vsi_res
[i
].vsi_type
== VIRTCHNL_VSI_SRIOV
)
369 vf
->vsi_res
= &vf
->vf_res
->vsi_res
[i
];
373 PMD_INIT_LOG(ERR
, "no LAN VSI found");
377 vf
->vsi
.vsi_id
= vf
->vsi_res
->vsi_id
;
378 vf
->vsi
.nb_qps
= vf
->vsi_res
->num_queue_pairs
;
379 vf
->vsi
.adapter
= adapter
;
385 iavf_enable_queues(struct iavf_adapter
*adapter
)
387 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
388 struct virtchnl_queue_select queue_select
;
389 struct iavf_cmd_info args
;
392 memset(&queue_select
, 0, sizeof(queue_select
));
393 queue_select
.vsi_id
= vf
->vsi_res
->vsi_id
;
395 queue_select
.rx_queues
= BIT(adapter
->eth_dev
->data
->nb_rx_queues
) - 1;
396 queue_select
.tx_queues
= BIT(adapter
->eth_dev
->data
->nb_tx_queues
) - 1;
398 args
.ops
= VIRTCHNL_OP_ENABLE_QUEUES
;
399 args
.in_args
= (u8
*)&queue_select
;
400 args
.in_args_size
= sizeof(queue_select
);
401 args
.out_buffer
= vf
->aq_resp
;
402 args
.out_size
= IAVF_AQ_BUF_SZ
;
403 err
= iavf_execute_vf_cmd(adapter
, &args
);
406 "Failed to execute command of OP_ENABLE_QUEUES");
413 iavf_disable_queues(struct iavf_adapter
*adapter
)
415 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
416 struct virtchnl_queue_select queue_select
;
417 struct iavf_cmd_info args
;
420 memset(&queue_select
, 0, sizeof(queue_select
));
421 queue_select
.vsi_id
= vf
->vsi_res
->vsi_id
;
423 queue_select
.rx_queues
= BIT(adapter
->eth_dev
->data
->nb_rx_queues
) - 1;
424 queue_select
.tx_queues
= BIT(adapter
->eth_dev
->data
->nb_tx_queues
) - 1;
426 args
.ops
= VIRTCHNL_OP_DISABLE_QUEUES
;
427 args
.in_args
= (u8
*)&queue_select
;
428 args
.in_args_size
= sizeof(queue_select
);
429 args
.out_buffer
= vf
->aq_resp
;
430 args
.out_size
= IAVF_AQ_BUF_SZ
;
431 err
= iavf_execute_vf_cmd(adapter
, &args
);
434 "Failed to execute command of OP_DISABLE_QUEUES");
441 iavf_switch_queue(struct iavf_adapter
*adapter
, uint16_t qid
,
444 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
445 struct virtchnl_queue_select queue_select
;
446 struct iavf_cmd_info args
;
449 memset(&queue_select
, 0, sizeof(queue_select
));
450 queue_select
.vsi_id
= vf
->vsi_res
->vsi_id
;
452 queue_select
.rx_queues
|= 1 << qid
;
454 queue_select
.tx_queues
|= 1 << qid
;
457 args
.ops
= VIRTCHNL_OP_ENABLE_QUEUES
;
459 args
.ops
= VIRTCHNL_OP_DISABLE_QUEUES
;
460 args
.in_args
= (u8
*)&queue_select
;
461 args
.in_args_size
= sizeof(queue_select
);
462 args
.out_buffer
= vf
->aq_resp
;
463 args
.out_size
= IAVF_AQ_BUF_SZ
;
464 err
= iavf_execute_vf_cmd(adapter
, &args
);
466 PMD_DRV_LOG(ERR
, "Failed to execute command of %s",
467 on
? "OP_ENABLE_QUEUES" : "OP_DISABLE_QUEUES");
472 iavf_configure_rss_lut(struct iavf_adapter
*adapter
)
474 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
475 struct virtchnl_rss_lut
*rss_lut
;
476 struct iavf_cmd_info args
;
479 len
= sizeof(*rss_lut
) + vf
->vf_res
->rss_lut_size
- 1;
480 rss_lut
= rte_zmalloc("rss_lut", len
, 0);
484 rss_lut
->vsi_id
= vf
->vsi_res
->vsi_id
;
485 rss_lut
->lut_entries
= vf
->vf_res
->rss_lut_size
;
486 rte_memcpy(rss_lut
->lut
, vf
->rss_lut
, vf
->vf_res
->rss_lut_size
);
488 args
.ops
= VIRTCHNL_OP_CONFIG_RSS_LUT
;
489 args
.in_args
= (u8
*)rss_lut
;
490 args
.in_args_size
= len
;
491 args
.out_buffer
= vf
->aq_resp
;
492 args
.out_size
= IAVF_AQ_BUF_SZ
;
494 err
= iavf_execute_vf_cmd(adapter
, &args
);
497 "Failed to execute command of OP_CONFIG_RSS_LUT");
504 iavf_configure_rss_key(struct iavf_adapter
*adapter
)
506 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
507 struct virtchnl_rss_key
*rss_key
;
508 struct iavf_cmd_info args
;
511 len
= sizeof(*rss_key
) + vf
->vf_res
->rss_key_size
- 1;
512 rss_key
= rte_zmalloc("rss_key", len
, 0);
516 rss_key
->vsi_id
= vf
->vsi_res
->vsi_id
;
517 rss_key
->key_len
= vf
->vf_res
->rss_key_size
;
518 rte_memcpy(rss_key
->key
, vf
->rss_key
, vf
->vf_res
->rss_key_size
);
520 args
.ops
= VIRTCHNL_OP_CONFIG_RSS_KEY
;
521 args
.in_args
= (u8
*)rss_key
;
522 args
.in_args_size
= len
;
523 args
.out_buffer
= vf
->aq_resp
;
524 args
.out_size
= IAVF_AQ_BUF_SZ
;
526 err
= iavf_execute_vf_cmd(adapter
, &args
);
529 "Failed to execute command of OP_CONFIG_RSS_KEY");
536 iavf_configure_queues(struct iavf_adapter
*adapter
)
538 struct iavf_rx_queue
**rxq
=
539 (struct iavf_rx_queue
**)adapter
->eth_dev
->data
->rx_queues
;
540 struct iavf_tx_queue
**txq
=
541 (struct iavf_tx_queue
**)adapter
->eth_dev
->data
->tx_queues
;
542 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
543 struct virtchnl_vsi_queue_config_info
*vc_config
;
544 struct virtchnl_queue_pair_info
*vc_qp
;
545 struct iavf_cmd_info args
;
549 size
= sizeof(*vc_config
) +
550 sizeof(vc_config
->qpair
[0]) * vf
->num_queue_pairs
;
551 vc_config
= rte_zmalloc("cfg_queue", size
, 0);
555 vc_config
->vsi_id
= vf
->vsi_res
->vsi_id
;
556 vc_config
->num_queue_pairs
= vf
->num_queue_pairs
;
558 for (i
= 0, vc_qp
= vc_config
->qpair
;
559 i
< vf
->num_queue_pairs
;
561 vc_qp
->txq
.vsi_id
= vf
->vsi_res
->vsi_id
;
562 vc_qp
->txq
.queue_id
= i
;
563 /* Virtchnnl configure queues by pairs */
564 if (i
< adapter
->eth_dev
->data
->nb_tx_queues
) {
565 vc_qp
->txq
.ring_len
= txq
[i
]->nb_tx_desc
;
566 vc_qp
->txq
.dma_ring_addr
= txq
[i
]->tx_ring_phys_addr
;
568 vc_qp
->rxq
.vsi_id
= vf
->vsi_res
->vsi_id
;
569 vc_qp
->rxq
.queue_id
= i
;
570 vc_qp
->rxq
.max_pkt_size
= vf
->max_pkt_len
;
571 /* Virtchnnl configure queues by pairs */
572 if (i
< adapter
->eth_dev
->data
->nb_rx_queues
) {
573 vc_qp
->rxq
.ring_len
= rxq
[i
]->nb_rx_desc
;
574 vc_qp
->rxq
.dma_ring_addr
= rxq
[i
]->rx_ring_phys_addr
;
575 vc_qp
->rxq
.databuffer_size
= rxq
[i
]->rx_buf_len
;
579 memset(&args
, 0, sizeof(args
));
580 args
.ops
= VIRTCHNL_OP_CONFIG_VSI_QUEUES
;
581 args
.in_args
= (uint8_t *)vc_config
;
582 args
.in_args_size
= size
;
583 args
.out_buffer
= vf
->aq_resp
;
584 args
.out_size
= IAVF_AQ_BUF_SZ
;
586 err
= iavf_execute_vf_cmd(adapter
, &args
);
588 PMD_DRV_LOG(ERR
, "Failed to execute command of"
589 " VIRTCHNL_OP_CONFIG_VSI_QUEUES");
596 iavf_config_irq_map(struct iavf_adapter
*adapter
)
598 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
599 struct virtchnl_irq_map_info
*map_info
;
600 struct virtchnl_vector_map
*vecmap
;
601 struct iavf_cmd_info args
;
604 len
= sizeof(struct virtchnl_irq_map_info
) +
605 sizeof(struct virtchnl_vector_map
) * vf
->nb_msix
;
607 map_info
= rte_zmalloc("map_info", len
, 0);
611 map_info
->num_vectors
= vf
->nb_msix
;
612 for (i
= 0; i
< vf
->nb_msix
; i
++) {
613 vecmap
= &map_info
->vecmap
[i
];
614 vecmap
->vsi_id
= vf
->vsi_res
->vsi_id
;
615 vecmap
->rxitr_idx
= IAVF_ITR_INDEX_DEFAULT
;
616 vecmap
->vector_id
= vf
->msix_base
+ i
;
618 vecmap
->rxq_map
= vf
->rxq_map
[vf
->msix_base
+ i
];
621 args
.ops
= VIRTCHNL_OP_CONFIG_IRQ_MAP
;
622 args
.in_args
= (u8
*)map_info
;
623 args
.in_args_size
= len
;
624 args
.out_buffer
= vf
->aq_resp
;
625 args
.out_size
= IAVF_AQ_BUF_SZ
;
626 err
= iavf_execute_vf_cmd(adapter
, &args
);
628 PMD_DRV_LOG(ERR
, "fail to execute command OP_CONFIG_IRQ_MAP");
635 iavf_add_del_all_mac_addr(struct iavf_adapter
*adapter
, bool add
)
637 struct virtchnl_ether_addr_list
*list
;
638 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
639 struct ether_addr
*addr
;
640 struct iavf_cmd_info args
;
647 len
= sizeof(struct virtchnl_ether_addr_list
);
648 for (i
= begin
; i
< IAVF_NUM_MACADDR_MAX
; i
++, next_begin
++) {
649 addr
= &adapter
->eth_dev
->data
->mac_addrs
[i
];
650 if (is_zero_ether_addr(addr
))
652 len
+= sizeof(struct virtchnl_ether_addr
);
653 if (len
>= IAVF_AQ_BUF_SZ
) {
659 list
= rte_zmalloc("iavf_del_mac_buffer", len
, 0);
661 PMD_DRV_LOG(ERR
, "fail to allocate memory");
665 for (i
= begin
; i
< next_begin
; i
++) {
666 addr
= &adapter
->eth_dev
->data
->mac_addrs
[i
];
667 if (is_zero_ether_addr(addr
))
669 rte_memcpy(list
->list
[j
].addr
, addr
->addr_bytes
,
670 sizeof(addr
->addr_bytes
));
671 PMD_DRV_LOG(DEBUG
, "add/rm mac:%x:%x:%x:%x:%x:%x",
672 addr
->addr_bytes
[0], addr
->addr_bytes
[1],
673 addr
->addr_bytes
[2], addr
->addr_bytes
[3],
674 addr
->addr_bytes
[4], addr
->addr_bytes
[5]);
677 list
->vsi_id
= vf
->vsi_res
->vsi_id
;
678 list
->num_elements
= j
;
679 args
.ops
= add
? VIRTCHNL_OP_ADD_ETH_ADDR
:
680 VIRTCHNL_OP_DEL_ETH_ADDR
;
681 args
.in_args
= (uint8_t *)list
;
682 args
.in_args_size
= len
;
683 args
.out_buffer
= vf
->aq_resp
;
684 args
.out_size
= IAVF_AQ_BUF_SZ
;
685 err
= iavf_execute_vf_cmd(adapter
, &args
);
687 PMD_DRV_LOG(ERR
, "fail to execute command %s",
688 add
? "OP_ADD_ETHER_ADDRESS" :
689 "OP_DEL_ETHER_ADDRESS");
692 } while (begin
< IAVF_NUM_MACADDR_MAX
);
696 iavf_query_stats(struct iavf_adapter
*adapter
,
697 struct virtchnl_eth_stats
**pstats
)
699 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
700 struct virtchnl_queue_select q_stats
;
701 struct iavf_cmd_info args
;
704 memset(&q_stats
, 0, sizeof(q_stats
));
705 q_stats
.vsi_id
= vf
->vsi_res
->vsi_id
;
706 args
.ops
= VIRTCHNL_OP_GET_STATS
;
707 args
.in_args
= (uint8_t *)&q_stats
;
708 args
.in_args_size
= sizeof(q_stats
);
709 args
.out_buffer
= vf
->aq_resp
;
710 args
.out_size
= IAVF_AQ_BUF_SZ
;
712 err
= iavf_execute_vf_cmd(adapter
, &args
);
714 PMD_DRV_LOG(ERR
, "fail to execute command OP_GET_STATS");
718 *pstats
= (struct virtchnl_eth_stats
*)args
.out_buffer
;
723 iavf_config_promisc(struct iavf_adapter
*adapter
,
725 bool enable_multicast
)
727 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
728 struct virtchnl_promisc_info promisc
;
729 struct iavf_cmd_info args
;
733 promisc
.vsi_id
= vf
->vsi_res
->vsi_id
;
736 promisc
.flags
|= FLAG_VF_UNICAST_PROMISC
;
738 if (enable_multicast
)
739 promisc
.flags
|= FLAG_VF_MULTICAST_PROMISC
;
741 args
.ops
= VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
;
742 args
.in_args
= (uint8_t *)&promisc
;
743 args
.in_args_size
= sizeof(promisc
);
744 args
.out_buffer
= vf
->aq_resp
;
745 args
.out_size
= IAVF_AQ_BUF_SZ
;
747 err
= iavf_execute_vf_cmd(adapter
, &args
);
751 "fail to execute command CONFIG_PROMISCUOUS_MODE");
756 iavf_add_del_eth_addr(struct iavf_adapter
*adapter
, struct ether_addr
*addr
,
759 struct virtchnl_ether_addr_list
*list
;
760 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
761 uint8_t cmd_buffer
[sizeof(struct virtchnl_ether_addr_list
) +
762 sizeof(struct virtchnl_ether_addr
)];
763 struct iavf_cmd_info args
;
766 list
= (struct virtchnl_ether_addr_list
*)cmd_buffer
;
767 list
->vsi_id
= vf
->vsi_res
->vsi_id
;
768 list
->num_elements
= 1;
769 rte_memcpy(list
->list
[0].addr
, addr
->addr_bytes
,
770 sizeof(addr
->addr_bytes
));
772 args
.ops
= add
? VIRTCHNL_OP_ADD_ETH_ADDR
: VIRTCHNL_OP_DEL_ETH_ADDR
;
773 args
.in_args
= cmd_buffer
;
774 args
.in_args_size
= sizeof(cmd_buffer
);
775 args
.out_buffer
= vf
->aq_resp
;
776 args
.out_size
= IAVF_AQ_BUF_SZ
;
777 err
= iavf_execute_vf_cmd(adapter
, &args
);
779 PMD_DRV_LOG(ERR
, "fail to execute command %s",
780 add
? "OP_ADD_ETH_ADDR" : "OP_DEL_ETH_ADDR");
785 iavf_add_del_vlan(struct iavf_adapter
*adapter
, uint16_t vlanid
, bool add
)
787 struct virtchnl_vlan_filter_list
*vlan_list
;
788 struct iavf_info
*vf
= IAVF_DEV_PRIVATE_TO_VF(adapter
);
789 uint8_t cmd_buffer
[sizeof(struct virtchnl_vlan_filter_list
) +
791 struct iavf_cmd_info args
;
794 vlan_list
= (struct virtchnl_vlan_filter_list
*)cmd_buffer
;
795 vlan_list
->vsi_id
= vf
->vsi_res
->vsi_id
;
796 vlan_list
->num_elements
= 1;
797 vlan_list
->vlan_id
[0] = vlanid
;
799 args
.ops
= add
? VIRTCHNL_OP_ADD_VLAN
: VIRTCHNL_OP_DEL_VLAN
;
800 args
.in_args
= cmd_buffer
;
801 args
.in_args_size
= sizeof(cmd_buffer
);
802 args
.out_buffer
= vf
->aq_resp
;
803 args
.out_size
= IAVF_AQ_BUF_SZ
;
804 err
= iavf_execute_vf_cmd(adapter
, &args
);
806 PMD_DRV_LOG(ERR
, "fail to execute command %s",
807 add
? "OP_ADD_VLAN" : "OP_DEL_VLAN");