4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
42 #include <rte_byteorder.h>
43 #include <rte_common.h>
44 #include <rte_cycles.h>
46 #include <rte_interrupts.h>
48 #include <rte_debug.h>
50 #include <rte_atomic.h>
51 #include <rte_branch_prediction.h>
52 #include <rte_memory.h>
53 #include <rte_memzone.h>
54 #include <rte_tailq.h>
56 #include <rte_alarm.h>
57 #include <rte_ether.h>
58 #include <rte_ethdev.h>
59 #include <rte_atomic.h>
60 #include <rte_malloc.h>
63 #include "i40e_logs.h"
64 #include "i40e/i40e_prototype.h"
65 #include "i40e/i40e_adminq_cmd.h"
66 #include "i40e/i40e_type.h"
68 #include "i40e_rxtx.h"
69 #include "i40e_ethdev.h"
71 #define I40EVF_VSI_DEFAULT_MSIX_INTR 1
73 /* busy wait delay in msec */
74 #define I40EVF_BUSY_WAIT_DELAY 10
75 #define I40EVF_BUSY_WAIT_COUNT 50
76 #define MAX_RESET_WAIT_CNT 20
78 struct i40evf_arq_msg_info {
79 enum i40e_virtchnl_ops ops;
80 enum i40e_status_code result;
86 enum i40e_virtchnl_ops ops;
88 uint32_t in_args_size;
90 /* Input & output type. pass in buffer size and pass out
91 * actual return result
96 enum i40evf_aq_result {
97 I40EVF_MSG_ERR = -1, /* Meet error when accessing admin queue */
98 I40EVF_MSG_NON, /* Read nothing from admin queue */
99 I40EVF_MSG_SYS, /* Read system msg from admin queue */
100 I40EVF_MSG_CMD, /* Read async command result */
103 /* A share buffer to store the command result from PF driver */
104 static uint8_t cmd_result_buffer[I40E_AQ_BUF_SZ];
106 static int i40evf_dev_configure(struct rte_eth_dev *dev);
107 static int i40evf_dev_start(struct rte_eth_dev *dev);
108 static void i40evf_dev_stop(struct rte_eth_dev *dev);
109 static void i40evf_dev_info_get(struct rte_eth_dev *dev,
110 struct rte_eth_dev_info *dev_info);
111 static int i40evf_dev_link_update(struct rte_eth_dev *dev,
112 __rte_unused int wait_to_complete);
113 static void i40evf_dev_stats_get(struct rte_eth_dev *dev,
114 struct rte_eth_stats *stats);
115 static int i40evf_vlan_filter_set(struct rte_eth_dev *dev,
116 uint16_t vlan_id, int on);
117 static void i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
118 static int i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid,
120 static void i40evf_dev_close(struct rte_eth_dev *dev);
121 static void i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev);
122 static void i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev);
123 static void i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev);
124 static void i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev);
125 static int i40evf_get_link_status(struct rte_eth_dev *dev,
126 struct rte_eth_link *link);
127 static int i40evf_init_vlan(struct rte_eth_dev *dev);
128 static struct eth_dev_ops i40evf_eth_dev_ops = {
129 .dev_configure = i40evf_dev_configure,
130 .dev_start = i40evf_dev_start,
131 .dev_stop = i40evf_dev_stop,
132 .promiscuous_enable = i40evf_dev_promiscuous_enable,
133 .promiscuous_disable = i40evf_dev_promiscuous_disable,
134 .allmulticast_enable = i40evf_dev_allmulticast_enable,
135 .allmulticast_disable = i40evf_dev_allmulticast_disable,
136 .link_update = i40evf_dev_link_update,
137 .stats_get = i40evf_dev_stats_get,
138 .dev_close = i40evf_dev_close,
139 .dev_infos_get = i40evf_dev_info_get,
140 .vlan_filter_set = i40evf_vlan_filter_set,
141 .vlan_offload_set = i40evf_vlan_offload_set,
142 .vlan_pvid_set = i40evf_vlan_pvid_set,
143 .rx_queue_setup = i40e_dev_rx_queue_setup,
144 .rx_queue_release = i40e_dev_rx_queue_release,
145 .tx_queue_setup = i40e_dev_tx_queue_setup,
146 .tx_queue_release = i40e_dev_tx_queue_release,
150 i40evf_set_mac_type(struct i40e_hw *hw)
152 int status = I40E_ERR_DEVICE_NOT_SUPPORTED;
154 if (hw->vendor_id == I40E_INTEL_VENDOR_ID) {
155 switch (hw->device_id) {
157 case I40E_DEV_ID_VF_HV:
158 hw->mac.type = I40E_MAC_VF;
159 status = I40E_SUCCESS;
170 * Parse admin queue message.
175 * > 0: read cmd result
177 static enum i40evf_aq_result
178 i40evf_parse_pfmsg(struct i40e_vf *vf,
179 struct i40e_arq_event_info *event,
180 struct i40evf_arq_msg_info *data)
182 enum i40e_virtchnl_ops opcode = (enum i40e_virtchnl_ops)\
183 rte_le_to_cpu_32(event->desc.cookie_high);
184 enum i40e_status_code retval = (enum i40e_status_code)\
185 rte_le_to_cpu_32(event->desc.cookie_low);
186 enum i40evf_aq_result ret = I40EVF_MSG_CMD;
189 if (opcode == I40E_VIRTCHNL_OP_EVENT) {
190 struct i40e_virtchnl_pf_event *vpe =
191 (struct i40e_virtchnl_pf_event *)event->msg_buf;
193 /* Initialize ret to sys event */
194 ret = I40EVF_MSG_SYS;
195 switch (vpe->event) {
196 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
198 vpe->event_data.link_event.link_status;
199 vf->pend_msg |= PFMSG_LINK_CHANGE;
200 PMD_DRV_LOG(INFO, "Link status update:%s\n",
201 vf->link_up ? "up" : "down");
203 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
205 vf->pend_msg |= PFMSG_RESET_IMPENDING;
206 PMD_DRV_LOG(INFO, "vf is reseting\n");
208 case I40E_VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
209 vf->dev_closed = true;
210 vf->pend_msg |= PFMSG_DRIVER_CLOSE;
211 PMD_DRV_LOG(INFO, "PF driver closed\n");
215 "%s: Unknown event %d from pf\n",
216 __func__, vpe->event);
219 /* async reply msg on command issued by vf previously */
220 ret = I40EVF_MSG_CMD;
221 /* Actual buffer length read from PF */
222 data->msg_len = event->msg_size;
224 /* fill the ops and result to notify VF */
225 data->result = retval;
232 * Read data in admin queue to get msg from pf driver
234 static enum i40evf_aq_result
235 i40evf_read_pfmsg(struct rte_eth_dev *dev, struct i40evf_arq_msg_info *data)
237 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
238 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
239 struct i40e_arq_event_info event;
241 enum i40evf_aq_result result = I40EVF_MSG_NON;
243 event.msg_size = data->msg_len;
244 event.msg_buf = data->msg;
245 ret = i40e_clean_arq_element(hw, &event, NULL);
246 /* Can't read any msg from adminQ */
248 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
249 result = I40EVF_MSG_NON;
251 result = I40EVF_MSG_ERR;
255 /* Parse the event */
256 result = i40evf_parse_pfmsg(vf, &event, data);
262 * Polling read until command result return from pf driver or meet error.
265 i40evf_wait_cmd_done(struct rte_eth_dev *dev,
266 struct i40evf_arq_msg_info *data)
269 enum i40evf_aq_result ret;
271 #define MAX_TRY_TIMES 10
272 #define ASQ_DELAY_MS 50
274 /* Delay some time first */
275 rte_delay_ms(ASQ_DELAY_MS);
276 ret = i40evf_read_pfmsg(dev, data);
278 if (ret == I40EVF_MSG_CMD)
280 else if (ret == I40EVF_MSG_ERR)
283 /* If don't read msg or read sys event, continue */
284 } while(i++ < MAX_TRY_TIMES);
290 * clear current command. Only call in case execute
291 * _atomic_set_cmd successfully.
294 _clear_cmd(struct i40e_vf *vf)
297 vf->pend_cmd = I40E_VIRTCHNL_OP_UNKNOWN;
301 * Check there is pending cmd in execution. If none, set new command.
304 _atomic_set_cmd(struct i40e_vf *vf, enum i40e_virtchnl_ops ops)
306 int ret = rte_atomic32_cmpset(&vf->pend_cmd,
307 I40E_VIRTCHNL_OP_UNKNOWN, ops);
310 PMD_DRV_LOG(ERR, "There is incomplete cmd %d\n", vf->pend_cmd);
316 i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
318 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
319 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
321 struct i40evf_arq_msg_info info;
323 if (_atomic_set_cmd(vf, args->ops))
326 info.msg = args->out_buffer;
327 info.msg_len = args->out_size;
328 info.ops = I40E_VIRTCHNL_OP_UNKNOWN;
329 info.result = I40E_SUCCESS;
331 err = i40e_aq_send_msg_to_pf(hw, args->ops, I40E_SUCCESS,
332 args->in_args, args->in_args_size, NULL);
334 PMD_DRV_LOG(ERR, "fail to send cmd %d\n", args->ops);
338 err = i40evf_wait_cmd_done(dev, &info);
339 /* read message and it's expected one */
340 if (!err && args->ops == info.ops)
343 PMD_DRV_LOG(ERR, "Failed to read message from AdminQ\n");
344 else if (args->ops != info.ops)
345 PMD_DRV_LOG(ERR, "command mismatch, expect %u, get %u\n",
346 args->ops, info.ops);
348 return (err | info.result);
352 * Check API version with sync wait until version read or fail from admin queue
355 i40evf_check_api_version(struct rte_eth_dev *dev)
357 struct i40e_virtchnl_version_info version, *pver;
359 struct vf_cmd_info args;
360 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
362 version.major = I40E_VIRTCHNL_VERSION_MAJOR;
363 version.minor = I40E_VIRTCHNL_VERSION_MINOR;
365 args.ops = I40E_VIRTCHNL_OP_VERSION;
366 args.in_args = (uint8_t *)&version;
367 args.in_args_size = sizeof(version);
368 args.out_buffer = cmd_result_buffer;
369 args.out_size = I40E_AQ_BUF_SZ;
371 err = i40evf_execute_vf_cmd(dev, &args);
373 PMD_INIT_LOG(ERR, "fail to execute command OP_VERSION\n");
377 pver = (struct i40e_virtchnl_version_info *)args.out_buffer;
378 /* We are talking with DPDK host */
379 if (pver->major == I40E_DPDK_VERSION_MAJOR) {
380 vf->host_is_dpdk = TRUE;
381 PMD_DRV_LOG(INFO, "Detect PF host is DPDK app\n");
383 /* It's linux host driver */
384 else if ((pver->major != version.major) ||
385 (pver->minor != version.minor)) {
386 PMD_INIT_LOG(ERR, "pf/vf API version mismatch. "
387 "(%u.%u)-(%u.%u)\n", pver->major, pver->minor,
388 version.major, version.minor);
396 i40evf_get_vf_resource(struct rte_eth_dev *dev)
398 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
399 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
401 struct vf_cmd_info args;
404 args.ops = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
406 args.in_args_size = 0;
407 args.out_buffer = cmd_result_buffer;
408 args.out_size = I40E_AQ_BUF_SZ;
410 err = i40evf_execute_vf_cmd(dev, &args);
413 PMD_DRV_LOG(ERR, "fail to execute command "
414 "OP_GET_VF_RESOURCE\n");
418 len = sizeof(struct i40e_virtchnl_vf_resource) +
419 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
421 (void)rte_memcpy(vf->vf_res, args.out_buffer,
422 RTE_MIN(args.out_size, len));
423 i40e_vf_parse_hw_config(hw, vf->vf_res);
429 i40evf_config_promisc(struct rte_eth_dev *dev,
431 bool enable_multicast)
433 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
435 struct vf_cmd_info args;
436 struct i40e_virtchnl_promisc_info promisc;
439 promisc.vsi_id = vf->vsi_res->vsi_id;
442 promisc.flags |= I40E_FLAG_VF_UNICAST_PROMISC;
444 if (enable_multicast)
445 promisc.flags |= I40E_FLAG_VF_MULTICAST_PROMISC;
447 args.ops = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
448 args.in_args = (uint8_t *)&promisc;
449 args.in_args_size = sizeof(promisc);
450 args.out_buffer = cmd_result_buffer;
451 args.out_size = I40E_AQ_BUF_SZ;
453 err = i40evf_execute_vf_cmd(dev, &args);
456 PMD_DRV_LOG(ERR, "fail to execute command "
457 "CONFIG_PROMISCUOUS_MODE\n");
461 /* Configure vlan and double vlan offload. Use flag to specify which part to configure */
463 i40evf_config_vlan_offload(struct rte_eth_dev *dev,
464 bool enable_vlan_strip)
466 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
468 struct vf_cmd_info args;
469 struct i40e_virtchnl_vlan_offload_info offload;
471 offload.vsi_id = vf->vsi_res->vsi_id;
472 offload.enable_vlan_strip = enable_vlan_strip;
474 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD;
475 args.in_args = (uint8_t *)&offload;
476 args.in_args_size = sizeof(offload);
477 args.out_buffer = cmd_result_buffer;
478 args.out_size = I40E_AQ_BUF_SZ;
480 err = i40evf_execute_vf_cmd(dev, &args);
482 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_OFFLOAD\n");
488 i40evf_config_vlan_pvid(struct rte_eth_dev *dev,
489 struct i40e_vsi_vlan_pvid_info *info)
491 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
493 struct vf_cmd_info args;
494 struct i40e_virtchnl_pvid_info tpid_info;
496 if (dev == NULL || info == NULL) {
497 PMD_DRV_LOG(ERR, "invalid parameters\n");
498 return I40E_ERR_PARAM;
501 memset(&tpid_info, 0, sizeof(tpid_info));
502 tpid_info.vsi_id = vf->vsi_res->vsi_id;
503 (void)rte_memcpy(&tpid_info.info, info, sizeof(*info));
505 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_PVID;
506 args.in_args = (uint8_t *)&tpid_info;
507 args.in_args_size = sizeof(tpid_info);
508 args.out_buffer = cmd_result_buffer;
509 args.out_size = I40E_AQ_BUF_SZ;
511 err = i40evf_execute_vf_cmd(dev, &args);
513 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_PVID\n");
519 i40evf_configure_queues(struct rte_eth_dev *dev)
521 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
522 struct i40e_virtchnl_vsi_queue_config_info *queue_info;
523 struct i40e_virtchnl_queue_pair_info *queue_cfg;
524 struct i40e_rx_queue **rxq =
525 (struct i40e_rx_queue **)dev->data->rx_queues;
526 struct i40e_tx_queue **txq =
527 (struct i40e_tx_queue **)dev->data->tx_queues;
528 int i, len, nb_qpairs, num_rxq, num_txq;
530 struct vf_cmd_info args;
531 struct rte_pktmbuf_pool_private *mbp_priv;
533 nb_qpairs = vf->num_queue_pairs;
534 len = sizeof(*queue_info) + sizeof(*queue_cfg) * nb_qpairs;
535 queue_info = rte_zmalloc("queue_info", len, 0);
536 if (queue_info == NULL) {
537 PMD_INIT_LOG(ERR, "failed alloc memory for queue_info\n");
540 queue_info->vsi_id = vf->vsi_res->vsi_id;
541 queue_info->num_queue_pairs = nb_qpairs;
542 queue_cfg = queue_info->qpair;
544 num_rxq = dev->data->nb_rx_queues;
545 num_txq = dev->data->nb_tx_queues;
547 * PF host driver required to configure queues in pairs, which means
548 * rxq_num should equals to txq_num. The actual usage won't always
549 * work that way. The solution is fills 0 with HW ring option in case
550 * they are not equal.
552 for (i = 0; i < nb_qpairs; i++) {
554 queue_cfg->txq.vsi_id = queue_info->vsi_id;
555 queue_cfg->txq.queue_id = i;
557 queue_cfg->txq.ring_len = txq[i]->nb_tx_desc;
558 queue_cfg->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
560 queue_cfg->txq.ring_len = 0;
561 queue_cfg->txq.dma_ring_addr = 0;
565 queue_cfg->rxq.vsi_id = queue_info->vsi_id;
566 queue_cfg->rxq.queue_id = i;
567 queue_cfg->rxq.max_pkt_size = vf->max_pkt_len;
569 mbp_priv = rte_mempool_get_priv(rxq[i]->mp);
570 queue_cfg->rxq.databuffer_size = mbp_priv->mbuf_data_room_size -
571 RTE_PKTMBUF_HEADROOM;;
572 queue_cfg->rxq.ring_len = rxq[i]->nb_rx_desc;
573 queue_cfg->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;;
575 queue_cfg->rxq.ring_len = 0;
576 queue_cfg->rxq.dma_ring_addr = 0;
577 queue_cfg->rxq.databuffer_size = 0;
582 args.ops = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
583 args.in_args = (u8 *)queue_info;
584 args.in_args_size = len;
585 args.out_buffer = cmd_result_buffer;
586 args.out_size = I40E_AQ_BUF_SZ;
587 err = i40evf_execute_vf_cmd(dev, &args);
589 PMD_DRV_LOG(ERR, "fail to execute command "
590 "OP_CONFIG_VSI_QUEUES\n");
591 rte_free(queue_info);
597 i40evf_config_irq_map(struct rte_eth_dev *dev)
599 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
600 struct vf_cmd_info args;
601 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_irq_map_info) + \
602 sizeof(struct i40e_virtchnl_vector_map)];
603 struct i40e_virtchnl_irq_map_info *map_info;
605 map_info = (struct i40e_virtchnl_irq_map_info *)cmd_buffer;
606 map_info->num_vectors = 1;
607 map_info->vecmap[0].rxitr_idx = RTE_LIBRTE_I40E_ITR_INTERVAL / 2;
608 map_info->vecmap[0].txitr_idx = RTE_LIBRTE_I40E_ITR_INTERVAL / 2;
609 map_info->vecmap[0].vsi_id = vf->vsi_res->vsi_id;
610 /* Alway use default dynamic MSIX interrupt */
611 map_info->vecmap[0].vector_id = I40EVF_VSI_DEFAULT_MSIX_INTR;
612 /* Don't map any tx queue */
613 map_info->vecmap[0].txq_map = 0;
614 map_info->vecmap[0].rxq_map = 0;
615 for (i = 0; i < dev->data->nb_rx_queues; i++)
616 map_info->vecmap[0].rxq_map |= 1 << i;
618 args.ops = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
619 args.in_args = (u8 *)cmd_buffer;
620 args.in_args_size = sizeof(cmd_buffer);
621 args.out_buffer = cmd_result_buffer;
622 args.out_size = I40E_AQ_BUF_SZ;
623 err = i40evf_execute_vf_cmd(dev, &args);
625 PMD_DRV_LOG(ERR, "fail to execute command OP_ENABLE_QUEUES\n");
631 i40evf_enable_queues(struct rte_eth_dev *dev)
633 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
634 struct i40e_virtchnl_queue_select queue_select;
636 struct vf_cmd_info args;
638 queue_select.vsi_id = vf->vsi_res->vsi_id;
640 queue_select.rx_queues = 0;
641 /* Enable configured RX queues */
642 for (i = 0; i < dev->data->nb_rx_queues; i++)
643 queue_select.rx_queues |= 1 << i;
645 /* Enable configured TX queues */
646 queue_select.tx_queues = 0;
647 for (i = 0; i < dev->data->nb_tx_queues; i++)
648 queue_select.tx_queues |= 1 << i;
650 args.ops = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
651 args.in_args = (u8 *)&queue_select;
652 args.in_args_size = sizeof(queue_select);
653 args.out_buffer = cmd_result_buffer;
654 args.out_size = I40E_AQ_BUF_SZ;
655 err = i40evf_execute_vf_cmd(dev, &args);
657 PMD_DRV_LOG(ERR, "fail to execute command OP_ENABLE_QUEUES\n");
663 i40evf_disable_queues(struct rte_eth_dev *dev)
665 struct i40e_virtchnl_queue_select queue_select;
667 struct vf_cmd_info args;
669 /* Enable configured RX queues */
670 queue_select.rx_queues = 0;
671 for (i = 0; i < dev->data->nb_rx_queues; i++)
672 queue_select.rx_queues |= 1 << i;
674 /* Enable configured TX queues */
675 queue_select.tx_queues = 0;
676 for (i = 0; i < dev->data->nb_tx_queues; i++)
677 queue_select.tx_queues |= 1 << i;
679 args.ops = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
680 args.in_args = (u8 *)&queue_select;
681 args.in_args_size = sizeof(queue_select);
682 args.out_buffer = cmd_result_buffer;
683 args.out_size = I40E_AQ_BUF_SZ;
684 err = i40evf_execute_vf_cmd(dev, &args);
686 PMD_DRV_LOG(ERR, "fail to execute command "
687 "OP_DISABLE_QUEUES\n");
693 i40evf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
695 struct i40e_virtchnl_ether_addr_list *list;
696 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
697 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
698 sizeof(struct i40e_virtchnl_ether_addr)];
700 struct vf_cmd_info args;
702 if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
703 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x\n",
704 addr->addr_bytes[0], addr->addr_bytes[1],
705 addr->addr_bytes[2], addr->addr_bytes[3],
706 addr->addr_bytes[4], addr->addr_bytes[5]);
710 list = (struct i40e_virtchnl_ether_addr_list *)cmd_buffer;
711 list->vsi_id = vf->vsi_res->vsi_id;
712 list->num_elements = 1;
713 (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
714 sizeof(addr->addr_bytes));
716 args.ops = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
717 args.in_args = cmd_buffer;
718 args.in_args_size = sizeof(cmd_buffer);
719 args.out_buffer = cmd_result_buffer;
720 args.out_size = I40E_AQ_BUF_SZ;
721 err = i40evf_execute_vf_cmd(dev, &args);
723 PMD_DRV_LOG(ERR, "fail to execute command "
724 "OP_ADD_ETHER_ADDRESS\n");
730 i40evf_del_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
732 struct i40e_virtchnl_ether_addr_list *list;
733 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
734 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
735 sizeof(struct i40e_virtchnl_ether_addr)];
737 struct vf_cmd_info args;
739 if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
740 PMD_DRV_LOG(ERR, "Invalid mac:%x-%x-%x-%x-%x-%x\n",
741 addr->addr_bytes[0], addr->addr_bytes[1],
742 addr->addr_bytes[2], addr->addr_bytes[3],
743 addr->addr_bytes[4], addr->addr_bytes[5]);
747 list = (struct i40e_virtchnl_ether_addr_list *)cmd_buffer;
748 list->vsi_id = vf->vsi_res->vsi_id;
749 list->num_elements = 1;
750 (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
751 sizeof(addr->addr_bytes));
753 args.ops = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
754 args.in_args = cmd_buffer;
755 args.in_args_size = sizeof(cmd_buffer);
756 args.out_buffer = cmd_result_buffer;
757 args.out_size = I40E_AQ_BUF_SZ;
758 err = i40evf_execute_vf_cmd(dev, &args);
760 PMD_DRV_LOG(ERR, "fail to execute command "
761 "OP_DEL_ETHER_ADDRESS\n");
767 i40evf_get_statics(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
769 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
770 struct i40e_virtchnl_queue_select q_stats;
771 struct i40e_eth_stats *pstats;
773 struct vf_cmd_info args;
775 memset(&q_stats, 0, sizeof(q_stats));
776 q_stats.vsi_id = vf->vsi_res->vsi_id;
777 args.ops = I40E_VIRTCHNL_OP_GET_STATS;
778 args.in_args = (u8 *)&q_stats;
779 args.in_args_size = sizeof(q_stats);
780 args.out_buffer = cmd_result_buffer;
781 args.out_size = I40E_AQ_BUF_SZ;
783 err = i40evf_execute_vf_cmd(dev, &args);
785 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS\n");
788 pstats = (struct i40e_eth_stats *)args.out_buffer;
789 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
790 pstats->rx_broadcast;
791 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
793 stats->ierrors = pstats->rx_discards;
794 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
795 stats->ibytes = pstats->rx_bytes;
796 stats->obytes = pstats->tx_bytes;
802 i40evf_add_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
804 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
805 struct i40e_virtchnl_vlan_filter_list *vlan_list;
806 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_vlan_filter_list) +
809 struct vf_cmd_info args;
811 vlan_list = (struct i40e_virtchnl_vlan_filter_list *)cmd_buffer;
812 vlan_list->vsi_id = vf->vsi_res->vsi_id;
813 vlan_list->num_elements = 1;
814 vlan_list->vlan_id[0] = vlanid;
816 args.ops = I40E_VIRTCHNL_OP_ADD_VLAN;
817 args.in_args = (u8 *)&cmd_buffer;
818 args.in_args_size = sizeof(cmd_buffer);
819 args.out_buffer = cmd_result_buffer;
820 args.out_size = I40E_AQ_BUF_SZ;
821 err = i40evf_execute_vf_cmd(dev, &args);
823 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_VLAN\n");
829 i40evf_del_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
831 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
832 struct i40e_virtchnl_vlan_filter_list *vlan_list;
833 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_vlan_filter_list) +
836 struct vf_cmd_info args;
838 vlan_list = (struct i40e_virtchnl_vlan_filter_list *)cmd_buffer;
839 vlan_list->vsi_id = vf->vsi_res->vsi_id;
840 vlan_list->num_elements = 1;
841 vlan_list->vlan_id[0] = vlanid;
843 args.ops = I40E_VIRTCHNL_OP_DEL_VLAN;
844 args.in_args = (u8 *)&cmd_buffer;
845 args.in_args_size = sizeof(cmd_buffer);
846 args.out_buffer = cmd_result_buffer;
847 args.out_size = I40E_AQ_BUF_SZ;
848 err = i40evf_execute_vf_cmd(dev, &args);
850 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_VLAN\n");
856 i40evf_get_link_status(struct rte_eth_dev *dev, struct rte_eth_link *link)
859 struct vf_cmd_info args;
860 struct rte_eth_link *new_link;
862 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_GET_LINK_STAT;
864 args.in_args_size = 0;
865 args.out_buffer = cmd_result_buffer;
866 args.out_size = I40E_AQ_BUF_SZ;
867 err = i40evf_execute_vf_cmd(dev, &args);
869 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_LINK_STAT\n");
873 new_link = (struct rte_eth_link *)args.out_buffer;
874 (void)rte_memcpy(link, new_link, sizeof(link));
879 static struct rte_pci_id pci_id_i40evf_map[] = {
880 #define RTE_PCI_DEV_ID_DECL_I40EVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
881 #include "rte_pci_dev_ids.h"
882 { .vendor_id = 0, /* sentinel */ },
886 i40evf_dev_atomic_write_link_status(struct rte_eth_dev *dev,
887 struct rte_eth_link *link)
889 struct rte_eth_link *dst = &(dev->data->dev_link);
890 struct rte_eth_link *src = link;
892 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
893 *(uint64_t *)src) == 0)
900 i40evf_reset_vf(struct i40e_hw *hw)
904 if (i40e_vf_reset(hw) != I40E_SUCCESS) {
905 PMD_INIT_LOG(ERR, "Reset VF NIC failed\n");
909 * After issuing vf reset command to pf, pf won't necessarily
910 * reset vf, it depends on what state it exactly is. If it's not
911 * initialized yet, it won't have vf reset since it's in a certain
912 * state. If not, it will try to reset. Even vf is reset, pf will
913 * set I40E_VFGEN_RSTAT to COMPLETE first, then wait 10ms and set
914 * it to ACTIVE. In this duration, vf may not catch the moment that
915 * COMPLETE is set. So, for vf, we'll try to wait a long time.
919 for (i = 0; i < MAX_RESET_WAIT_CNT; i++) {
920 reset = rd32(hw, I40E_VFGEN_RSTAT) &
921 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
922 reset = reset >> I40E_VFGEN_RSTAT_VFR_STATE_SHIFT;
923 if (I40E_VFR_COMPLETED == reset || I40E_VFR_VFACTIVE == reset)
929 if (i >= MAX_RESET_WAIT_CNT) {
930 PMD_INIT_LOG(ERR, "Reset VF NIC failed\n");
938 i40evf_init_vf(struct rte_eth_dev *dev)
941 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
942 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
944 err = i40evf_set_mac_type(hw);
946 PMD_INIT_LOG(ERR, "set_mac_type failed: %d\n", err);
950 i40e_init_adminq_parameter(hw);
951 err = i40e_init_adminq(hw);
953 PMD_INIT_LOG(ERR, "init_adminq failed: %d\n", err);
958 /* Reset VF and wait until it's complete */
959 if (i40evf_reset_vf(hw)) {
960 PMD_INIT_LOG(ERR, "reset NIC failed\n");
964 /* VF reset, shutdown admin queue and initialize again */
965 if (i40e_shutdown_adminq(hw) != I40E_SUCCESS) {
966 PMD_INIT_LOG(ERR, "i40e_shutdown_adminq failed\n");
970 i40e_init_adminq_parameter(hw);
971 if (i40e_init_adminq(hw) != I40E_SUCCESS) {
972 PMD_INIT_LOG(ERR, "init_adminq failed\n");
975 if (i40evf_check_api_version(dev) != 0) {
976 PMD_INIT_LOG(ERR, "check_api version failed\n");
979 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
980 (I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource));
981 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
983 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory\n");
987 if (i40evf_get_vf_resource(dev) != 0) {
988 PMD_INIT_LOG(ERR, "i40evf_get_vf_config failed\n");
992 /* got VF config message back from PF, now we can parse it */
993 for (i = 0; i < vf->vf_res->num_vsis; i++) {
994 if (vf->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
995 vf->vsi_res = &vf->vf_res->vsi_res[i];
999 PMD_INIT_LOG(ERR, "no LAN VSI found\n");
1003 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
1004 vf->vsi.type = vf->vsi_res->vsi_type;
1005 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
1007 /* check mac addr, if it's not valid, genrate one */
1008 if (I40E_SUCCESS != i40e_validate_mac_addr(\
1009 vf->vsi_res->default_mac_addr))
1010 eth_random_addr(vf->vsi_res->default_mac_addr);
1012 ether_addr_copy((struct ether_addr *)vf->vsi_res->default_mac_addr,
1013 (struct ether_addr *)hw->mac.addr);
1018 rte_free(vf->vf_res);
1020 i40e_shutdown_adminq(hw); /* ignore error */
1026 i40evf_dev_init(__rte_unused struct eth_driver *eth_drv,
1027 struct rte_eth_dev *eth_dev)
1029 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(\
1030 eth_dev->data->dev_private);
1032 PMD_INIT_FUNC_TRACE();
1034 /* assign ops func pointer */
1035 eth_dev->dev_ops = &i40evf_eth_dev_ops;
1036 eth_dev->rx_pkt_burst = &i40e_recv_pkts;
1037 eth_dev->tx_pkt_burst = &i40e_xmit_pkts;
1040 * For secondary processes, we don't initialise any further as primary
1041 * has already done this work.
1043 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1044 if (eth_dev->data->scattered_rx)
1045 eth_dev->rx_pkt_burst = i40e_recv_scattered_pkts;
1049 hw->vendor_id = eth_dev->pci_dev->id.vendor_id;
1050 hw->device_id = eth_dev->pci_dev->id.device_id;
1051 hw->subsystem_vendor_id = eth_dev->pci_dev->id.subsystem_vendor_id;
1052 hw->subsystem_device_id = eth_dev->pci_dev->id.subsystem_device_id;
1053 hw->bus.device = eth_dev->pci_dev->addr.devid;
1054 hw->bus.func = eth_dev->pci_dev->addr.function;
1055 hw->hw_addr = (void *)eth_dev->pci_dev->mem_resource[0].addr;
1057 if(i40evf_init_vf(eth_dev) != 0) {
1058 PMD_INIT_LOG(ERR, "Init vf failed\n");
1063 eth_dev->data->mac_addrs = rte_zmalloc("i40evf_mac",
1065 if (eth_dev->data->mac_addrs == NULL) {
1066 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
1067 "store MAC addresses", ETHER_ADDR_LEN);
1070 ether_addr_copy((struct ether_addr *)hw->mac.addr,
1071 (struct ether_addr *)eth_dev->data->mac_addrs);
1077 * virtual function driver struct
1079 static struct eth_driver rte_i40evf_pmd = {
1081 .name = "rte_i40evf_pmd",
1082 .id_table = pci_id_i40evf_map,
1083 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1085 .eth_dev_init = i40evf_dev_init,
1086 .dev_private_size = sizeof(struct i40e_vf),
1090 * VF Driver initialization routine.
1091 * Invoked one at EAL init time.
1092 * Register itself as the [Virtual Poll Mode] Driver of PCI Fortville devices.
1095 rte_i40evf_pmd_init(const char *name __rte_unused,
1096 const char *params __rte_unused)
1098 DEBUGFUNC("rte_i40evf_pmd_init");
1100 rte_eth_driver_register(&rte_i40evf_pmd);
1105 static struct rte_driver rte_i40evf_driver = {
1107 .init = rte_i40evf_pmd_init,
1110 PMD_REGISTER_DRIVER(rte_i40evf_driver);
1113 i40evf_dev_configure(struct rte_eth_dev *dev)
1115 return i40evf_init_vlan(dev);
1119 i40evf_init_vlan(struct rte_eth_dev *dev)
1121 struct rte_eth_dev_data *data = dev->data;
1124 /* Apply vlan offload setting */
1125 i40evf_vlan_offload_set(dev, ETH_VLAN_STRIP_MASK);
1127 /* Apply pvid setting */
1128 ret = i40evf_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
1129 data->dev_conf.txmode.hw_vlan_insert_pvid);
1134 i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1136 bool enable_vlan_strip = 0;
1137 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1138 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1140 /* Linux pf host doesn't support vlan offload yet */
1141 if (vf->host_is_dpdk) {
1142 /* Vlan stripping setting */
1143 if (mask & ETH_VLAN_STRIP_MASK) {
1144 /* Enable or disable VLAN stripping */
1145 if (dev_conf->rxmode.hw_vlan_strip)
1146 enable_vlan_strip = 1;
1148 enable_vlan_strip = 0;
1150 i40evf_config_vlan_offload(dev, enable_vlan_strip);
1156 i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
1158 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1159 struct i40e_vsi_vlan_pvid_info info;
1160 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1162 memset(&info, 0, sizeof(info));
1165 /* Linux pf host don't support vlan offload yet */
1166 if (vf->host_is_dpdk) {
1168 info.config.pvid = pvid;
1170 info.config.reject.tagged =
1171 dev_conf->txmode.hw_vlan_reject_tagged;
1172 info.config.reject.untagged =
1173 dev_conf->txmode.hw_vlan_reject_untagged;
1175 return i40evf_config_vlan_pvid(dev, &info);
1182 i40evf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1187 ret = i40evf_add_vlan(dev, vlan_id);
1189 ret = i40evf_del_vlan(dev,vlan_id);
1195 i40evf_rx_init(struct rte_eth_dev *dev)
1198 struct i40e_rx_queue **rxq =
1199 (struct i40e_rx_queue **)dev->data->rx_queues;
1200 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1202 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1203 if (i40e_alloc_rx_queue_mbufs(rxq[i]) != 0) {
1204 PMD_DRV_LOG(ERR, "alloc rx queues mbufs failed\n");
1207 rxq[i]->qrx_tail = hw->hw_addr + I40E_QRX_TAIL1(i);
1208 I40E_PCI_REG_WRITE(rxq[i]->qrx_tail, rxq[i]->nb_rx_desc - 1);
1211 /* Flush the operation to write registers */
1212 I40EVF_WRITE_FLUSH(hw);
1217 /* Release all mbufs */
1218 for (j = 0; j < i; j++)
1219 i40e_rx_queue_release_mbufs(rxq[j]);
1225 i40evf_tx_init(struct rte_eth_dev *dev)
1228 struct i40e_tx_queue **txq =
1229 (struct i40e_tx_queue **)dev->data->tx_queues;
1230 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1232 for (i = 0; i < dev->data->nb_tx_queues; i++)
1233 txq[i]->qtx_tail = hw->hw_addr + I40E_QTX_TAIL1(i);
1237 i40evf_enable_queues_intr(struct i40e_hw *hw)
1239 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1240 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
1241 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
1245 i40evf_disable_queues_intr(struct i40e_hw *hw)
1247 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1252 i40evf_dev_start(struct rte_eth_dev *dev)
1254 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1255 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1256 struct ether_addr mac_addr;
1258 PMD_DRV_LOG(DEBUG, "i40evf_dev_start");
1260 vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1261 if (dev->data->dev_conf.rxmode.jumbo_frame == 1) {
1262 if (vf->max_pkt_len <= ETHER_MAX_LEN ||
1263 vf->max_pkt_len > I40E_FRAME_SIZE_MAX) {
1264 PMD_DRV_LOG(ERR, "maximum packet length must "
1265 "be larger than %u and smaller than %u,"
1266 "as jumbo frame is enabled\n",
1267 (uint32_t)ETHER_MAX_LEN,
1268 (uint32_t)I40E_FRAME_SIZE_MAX);
1269 return I40E_ERR_CONFIG;
1272 if (vf->max_pkt_len < ETHER_MIN_LEN ||
1273 vf->max_pkt_len > ETHER_MAX_LEN) {
1274 PMD_DRV_LOG(ERR, "maximum packet length must be "
1275 "larger than %u and smaller than %u, "
1276 "as jumbo frame is disabled\n",
1277 (uint32_t)ETHER_MIN_LEN,
1278 (uint32_t)ETHER_MAX_LEN);
1279 return I40E_ERR_CONFIG;
1283 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
1284 dev->data->nb_tx_queues);
1286 if (i40evf_rx_init(dev) != 0){
1287 PMD_DRV_LOG(ERR, "failed to do RX init\n");
1291 i40evf_tx_init(dev);
1293 if (i40evf_configure_queues(dev) != 0) {
1294 PMD_DRV_LOG(ERR, "configure queues failed\n");
1297 if (i40evf_config_irq_map(dev)) {
1298 PMD_DRV_LOG(ERR, "config_irq_map failed\n");
1303 (void)rte_memcpy(mac_addr.addr_bytes, hw->mac.addr,
1304 sizeof(mac_addr.addr_bytes));
1305 if (i40evf_add_mac_addr(dev, &mac_addr)) {
1306 PMD_DRV_LOG(ERR, "Failed to add mac addr\n");
1310 if (i40evf_enable_queues(dev) != 0) {
1311 PMD_DRV_LOG(ERR, "enable queues failed\n");
1314 i40evf_enable_queues_intr(hw);
1318 i40evf_del_mac_addr(dev, &mac_addr);
1320 i40e_dev_clear_queues(dev);
1325 i40evf_dev_stop(struct rte_eth_dev *dev)
1327 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1329 PMD_INIT_FUNC_TRACE();
1331 i40evf_disable_queues_intr(hw);
1332 i40evf_disable_queues(dev);
1333 i40e_dev_clear_queues(dev);
1337 i40evf_dev_link_update(struct rte_eth_dev *dev,
1338 __rte_unused int wait_to_complete)
1340 struct rte_eth_link new_link;
1341 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1343 * DPDK pf host provide interfacet to acquire link status
1344 * while Linux driver does not
1346 if (vf->host_is_dpdk)
1347 i40evf_get_link_status(dev, &new_link);
1349 /* Always assume it's up, for Linux driver PF host */
1350 new_link.link_duplex = ETH_LINK_AUTONEG_DUPLEX;
1351 new_link.link_speed = ETH_LINK_SPEED_10000;
1352 new_link.link_status = 1;
1354 i40evf_dev_atomic_write_link_status(dev, &new_link);
1360 i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1362 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1365 /* If enabled, just return */
1366 if (vf->promisc_unicast_enabled)
1369 ret = i40evf_config_promisc(dev, 1, vf->promisc_multicast_enabled);
1371 vf->promisc_unicast_enabled = TRUE;
1375 i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1377 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1380 /* If disabled, just return */
1381 if (!vf->promisc_unicast_enabled)
1384 ret = i40evf_config_promisc(dev, 0, vf->promisc_multicast_enabled);
1386 vf->promisc_unicast_enabled = FALSE;
1390 i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1392 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1395 /* If enabled, just return */
1396 if (vf->promisc_multicast_enabled)
1399 ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 1);
1401 vf->promisc_multicast_enabled = TRUE;
1405 i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1407 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1410 /* If enabled, just return */
1411 if (!vf->promisc_multicast_enabled)
1414 ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 0);
1416 vf->promisc_multicast_enabled = FALSE;
1420 i40evf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1422 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1424 memset(dev_info, 0, sizeof(*dev_info));
1425 dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
1426 dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
1427 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
1428 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
1432 i40evf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1434 memset(stats, 0, sizeof(*stats));
1435 if (i40evf_get_statics(dev, stats))
1436 PMD_DRV_LOG(ERR, "Get statics failed\n");
1440 i40evf_dev_close(struct rte_eth_dev *dev)
1442 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1444 i40evf_dev_stop(dev);
1445 i40evf_reset_vf(hw);
1446 i40e_shutdown_adminq(hw);