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 int i40evf_dev_rx_queue_start(struct rte_eth_dev *, uint16_t);
129 static int i40evf_dev_rx_queue_stop(struct rte_eth_dev *, uint16_t);
130 static int i40evf_dev_tx_queue_start(struct rte_eth_dev *, uint16_t);
131 static int i40evf_dev_tx_queue_stop(struct rte_eth_dev *, uint16_t);
132 static struct eth_dev_ops i40evf_eth_dev_ops = {
133 .dev_configure = i40evf_dev_configure,
134 .dev_start = i40evf_dev_start,
135 .dev_stop = i40evf_dev_stop,
136 .promiscuous_enable = i40evf_dev_promiscuous_enable,
137 .promiscuous_disable = i40evf_dev_promiscuous_disable,
138 .allmulticast_enable = i40evf_dev_allmulticast_enable,
139 .allmulticast_disable = i40evf_dev_allmulticast_disable,
140 .link_update = i40evf_dev_link_update,
141 .stats_get = i40evf_dev_stats_get,
142 .dev_close = i40evf_dev_close,
143 .dev_infos_get = i40evf_dev_info_get,
144 .vlan_filter_set = i40evf_vlan_filter_set,
145 .vlan_offload_set = i40evf_vlan_offload_set,
146 .vlan_pvid_set = i40evf_vlan_pvid_set,
147 .rx_queue_start = i40evf_dev_rx_queue_start,
148 .rx_queue_stop = i40evf_dev_rx_queue_stop,
149 .tx_queue_start = i40evf_dev_tx_queue_start,
150 .tx_queue_stop = i40evf_dev_tx_queue_stop,
151 .rx_queue_setup = i40e_dev_rx_queue_setup,
152 .rx_queue_release = i40e_dev_rx_queue_release,
153 .tx_queue_setup = i40e_dev_tx_queue_setup,
154 .tx_queue_release = i40e_dev_tx_queue_release,
158 i40evf_set_mac_type(struct i40e_hw *hw)
160 int status = I40E_ERR_DEVICE_NOT_SUPPORTED;
162 if (hw->vendor_id == I40E_INTEL_VENDOR_ID) {
163 switch (hw->device_id) {
165 case I40E_DEV_ID_VF_HV:
166 hw->mac.type = I40E_MAC_VF;
167 status = I40E_SUCCESS;
178 * Parse admin queue message.
183 * > 0: read cmd result
185 static enum i40evf_aq_result
186 i40evf_parse_pfmsg(struct i40e_vf *vf,
187 struct i40e_arq_event_info *event,
188 struct i40evf_arq_msg_info *data)
190 enum i40e_virtchnl_ops opcode = (enum i40e_virtchnl_ops)\
191 rte_le_to_cpu_32(event->desc.cookie_high);
192 enum i40e_status_code retval = (enum i40e_status_code)\
193 rte_le_to_cpu_32(event->desc.cookie_low);
194 enum i40evf_aq_result ret = I40EVF_MSG_CMD;
197 if (opcode == I40E_VIRTCHNL_OP_EVENT) {
198 struct i40e_virtchnl_pf_event *vpe =
199 (struct i40e_virtchnl_pf_event *)event->msg_buf;
201 /* Initialize ret to sys event */
202 ret = I40EVF_MSG_SYS;
203 switch (vpe->event) {
204 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
206 vpe->event_data.link_event.link_status;
207 vf->pend_msg |= PFMSG_LINK_CHANGE;
208 PMD_DRV_LOG(INFO, "Link status update:%s",
209 vf->link_up ? "up" : "down");
211 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
213 vf->pend_msg |= PFMSG_RESET_IMPENDING;
214 PMD_DRV_LOG(INFO, "vf is reseting");
216 case I40E_VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
217 vf->dev_closed = true;
218 vf->pend_msg |= PFMSG_DRIVER_CLOSE;
219 PMD_DRV_LOG(INFO, "PF driver closed");
222 PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
223 __func__, vpe->event);
226 /* async reply msg on command issued by vf previously */
227 ret = I40EVF_MSG_CMD;
228 /* Actual buffer length read from PF */
229 data->msg_len = event->msg_size;
231 /* fill the ops and result to notify VF */
232 data->result = retval;
239 * Read data in admin queue to get msg from pf driver
241 static enum i40evf_aq_result
242 i40evf_read_pfmsg(struct rte_eth_dev *dev, struct i40evf_arq_msg_info *data)
244 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
245 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
246 struct i40e_arq_event_info event;
248 enum i40evf_aq_result result = I40EVF_MSG_NON;
250 event.msg_size = data->msg_len;
251 event.msg_buf = data->msg;
252 ret = i40e_clean_arq_element(hw, &event, NULL);
253 /* Can't read any msg from adminQ */
255 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
256 result = I40EVF_MSG_NON;
258 result = I40EVF_MSG_ERR;
262 /* Parse the event */
263 result = i40evf_parse_pfmsg(vf, &event, data);
269 * Polling read until command result return from pf driver or meet error.
272 i40evf_wait_cmd_done(struct rte_eth_dev *dev,
273 struct i40evf_arq_msg_info *data)
276 enum i40evf_aq_result ret;
278 #define MAX_TRY_TIMES 10
279 #define ASQ_DELAY_MS 50
281 /* Delay some time first */
282 rte_delay_ms(ASQ_DELAY_MS);
283 ret = i40evf_read_pfmsg(dev, data);
285 if (ret == I40EVF_MSG_CMD)
287 else if (ret == I40EVF_MSG_ERR)
290 /* If don't read msg or read sys event, continue */
291 } while(i++ < MAX_TRY_TIMES);
297 * clear current command. Only call in case execute
298 * _atomic_set_cmd successfully.
301 _clear_cmd(struct i40e_vf *vf)
304 vf->pend_cmd = I40E_VIRTCHNL_OP_UNKNOWN;
308 * Check there is pending cmd in execution. If none, set new command.
311 _atomic_set_cmd(struct i40e_vf *vf, enum i40e_virtchnl_ops ops)
313 int ret = rte_atomic32_cmpset(&vf->pend_cmd,
314 I40E_VIRTCHNL_OP_UNKNOWN, ops);
317 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
323 i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
325 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
326 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
328 struct i40evf_arq_msg_info info;
330 if (_atomic_set_cmd(vf, args->ops))
333 info.msg = args->out_buffer;
334 info.msg_len = args->out_size;
335 info.ops = I40E_VIRTCHNL_OP_UNKNOWN;
336 info.result = I40E_SUCCESS;
338 err = i40e_aq_send_msg_to_pf(hw, args->ops, I40E_SUCCESS,
339 args->in_args, args->in_args_size, NULL);
341 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
345 err = i40evf_wait_cmd_done(dev, &info);
346 /* read message and it's expected one */
347 if (!err && args->ops == info.ops)
350 PMD_DRV_LOG(ERR, "Failed to read message from AdminQ");
351 else if (args->ops != info.ops)
352 PMD_DRV_LOG(ERR, "command mismatch, expect %u, get %u",
353 args->ops, info.ops);
355 return (err | info.result);
359 * Check API version with sync wait until version read or fail from admin queue
362 i40evf_check_api_version(struct rte_eth_dev *dev)
364 struct i40e_virtchnl_version_info version, *pver;
366 struct vf_cmd_info args;
367 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
369 version.major = I40E_VIRTCHNL_VERSION_MAJOR;
370 version.minor = I40E_VIRTCHNL_VERSION_MINOR;
372 args.ops = I40E_VIRTCHNL_OP_VERSION;
373 args.in_args = (uint8_t *)&version;
374 args.in_args_size = sizeof(version);
375 args.out_buffer = cmd_result_buffer;
376 args.out_size = I40E_AQ_BUF_SZ;
378 err = i40evf_execute_vf_cmd(dev, &args);
380 PMD_INIT_LOG(ERR, "fail to execute command OP_VERSION");
384 pver = (struct i40e_virtchnl_version_info *)args.out_buffer;
385 /* We are talking with DPDK host */
386 if (pver->major == I40E_DPDK_VERSION_MAJOR) {
387 vf->host_is_dpdk = TRUE;
388 PMD_DRV_LOG(INFO, "Detect PF host is DPDK app");
390 /* It's linux host driver */
391 else if ((pver->major != version.major) ||
392 (pver->minor != version.minor)) {
393 PMD_INIT_LOG(ERR, "pf/vf API version mismatch. "
394 "(%u.%u)-(%u.%u)", pver->major, pver->minor,
395 version.major, version.minor);
403 i40evf_get_vf_resource(struct rte_eth_dev *dev)
405 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
406 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
408 struct vf_cmd_info args;
411 args.ops = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
413 args.in_args_size = 0;
414 args.out_buffer = cmd_result_buffer;
415 args.out_size = I40E_AQ_BUF_SZ;
417 err = i40evf_execute_vf_cmd(dev, &args);
420 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_VF_RESOURCE");
424 len = sizeof(struct i40e_virtchnl_vf_resource) +
425 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
427 (void)rte_memcpy(vf->vf_res, args.out_buffer,
428 RTE_MIN(args.out_size, len));
429 i40e_vf_parse_hw_config(hw, vf->vf_res);
435 i40evf_config_promisc(struct rte_eth_dev *dev,
437 bool enable_multicast)
439 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
441 struct vf_cmd_info args;
442 struct i40e_virtchnl_promisc_info promisc;
445 promisc.vsi_id = vf->vsi_res->vsi_id;
448 promisc.flags |= I40E_FLAG_VF_UNICAST_PROMISC;
450 if (enable_multicast)
451 promisc.flags |= I40E_FLAG_VF_MULTICAST_PROMISC;
453 args.ops = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
454 args.in_args = (uint8_t *)&promisc;
455 args.in_args_size = sizeof(promisc);
456 args.out_buffer = cmd_result_buffer;
457 args.out_size = I40E_AQ_BUF_SZ;
459 err = i40evf_execute_vf_cmd(dev, &args);
462 PMD_DRV_LOG(ERR, "fail to execute command "
463 "CONFIG_PROMISCUOUS_MODE");
467 /* Configure vlan and double vlan offload. Use flag to specify which part to configure */
469 i40evf_config_vlan_offload(struct rte_eth_dev *dev,
470 bool enable_vlan_strip)
472 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
474 struct vf_cmd_info args;
475 struct i40e_virtchnl_vlan_offload_info offload;
477 offload.vsi_id = vf->vsi_res->vsi_id;
478 offload.enable_vlan_strip = enable_vlan_strip;
480 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD;
481 args.in_args = (uint8_t *)&offload;
482 args.in_args_size = sizeof(offload);
483 args.out_buffer = cmd_result_buffer;
484 args.out_size = I40E_AQ_BUF_SZ;
486 err = i40evf_execute_vf_cmd(dev, &args);
488 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_OFFLOAD");
494 i40evf_config_vlan_pvid(struct rte_eth_dev *dev,
495 struct i40e_vsi_vlan_pvid_info *info)
497 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
499 struct vf_cmd_info args;
500 struct i40e_virtchnl_pvid_info tpid_info;
502 if (dev == NULL || info == NULL) {
503 PMD_DRV_LOG(ERR, "invalid parameters");
504 return I40E_ERR_PARAM;
507 memset(&tpid_info, 0, sizeof(tpid_info));
508 tpid_info.vsi_id = vf->vsi_res->vsi_id;
509 (void)rte_memcpy(&tpid_info.info, info, sizeof(*info));
511 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_PVID;
512 args.in_args = (uint8_t *)&tpid_info;
513 args.in_args_size = sizeof(tpid_info);
514 args.out_buffer = cmd_result_buffer;
515 args.out_size = I40E_AQ_BUF_SZ;
517 err = i40evf_execute_vf_cmd(dev, &args);
519 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_PVID");
525 i40evf_configure_queues(struct rte_eth_dev *dev)
527 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
528 struct i40e_virtchnl_vsi_queue_config_info *queue_info;
529 struct i40e_virtchnl_queue_pair_info *queue_cfg;
530 struct i40e_rx_queue **rxq =
531 (struct i40e_rx_queue **)dev->data->rx_queues;
532 struct i40e_tx_queue **txq =
533 (struct i40e_tx_queue **)dev->data->tx_queues;
534 int i, len, nb_qpairs, num_rxq, num_txq;
536 struct vf_cmd_info args;
537 struct rte_pktmbuf_pool_private *mbp_priv;
539 nb_qpairs = vf->num_queue_pairs;
540 len = sizeof(*queue_info) + sizeof(*queue_cfg) * nb_qpairs;
541 queue_info = rte_zmalloc("queue_info", len, 0);
542 if (queue_info == NULL) {
543 PMD_INIT_LOG(ERR, "failed alloc memory for queue_info");
546 queue_info->vsi_id = vf->vsi_res->vsi_id;
547 queue_info->num_queue_pairs = nb_qpairs;
548 queue_cfg = queue_info->qpair;
550 num_rxq = dev->data->nb_rx_queues;
551 num_txq = dev->data->nb_tx_queues;
553 * PF host driver required to configure queues in pairs, which means
554 * rxq_num should equals to txq_num. The actual usage won't always
555 * work that way. The solution is fills 0 with HW ring option in case
556 * they are not equal.
558 for (i = 0; i < nb_qpairs; i++) {
560 queue_cfg->txq.vsi_id = queue_info->vsi_id;
561 queue_cfg->txq.queue_id = i;
563 queue_cfg->txq.ring_len = txq[i]->nb_tx_desc;
564 queue_cfg->txq.dma_ring_addr = txq[i]->tx_ring_phys_addr;
566 queue_cfg->txq.ring_len = 0;
567 queue_cfg->txq.dma_ring_addr = 0;
571 queue_cfg->rxq.vsi_id = queue_info->vsi_id;
572 queue_cfg->rxq.queue_id = i;
573 queue_cfg->rxq.max_pkt_size = vf->max_pkt_len;
575 mbp_priv = rte_mempool_get_priv(rxq[i]->mp);
576 queue_cfg->rxq.databuffer_size = mbp_priv->mbuf_data_room_size -
577 RTE_PKTMBUF_HEADROOM;;
578 queue_cfg->rxq.ring_len = rxq[i]->nb_rx_desc;
579 queue_cfg->rxq.dma_ring_addr = rxq[i]->rx_ring_phys_addr;;
581 queue_cfg->rxq.ring_len = 0;
582 queue_cfg->rxq.dma_ring_addr = 0;
583 queue_cfg->rxq.databuffer_size = 0;
588 args.ops = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
589 args.in_args = (u8 *)queue_info;
590 args.in_args_size = len;
591 args.out_buffer = cmd_result_buffer;
592 args.out_size = I40E_AQ_BUF_SZ;
593 err = i40evf_execute_vf_cmd(dev, &args);
595 PMD_DRV_LOG(ERR, "fail to execute command "
596 "OP_CONFIG_VSI_QUEUES");
597 rte_free(queue_info);
603 i40evf_config_irq_map(struct rte_eth_dev *dev)
605 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
606 struct vf_cmd_info args;
607 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_irq_map_info) + \
608 sizeof(struct i40e_virtchnl_vector_map)];
609 struct i40e_virtchnl_irq_map_info *map_info;
611 map_info = (struct i40e_virtchnl_irq_map_info *)cmd_buffer;
612 map_info->num_vectors = 1;
613 map_info->vecmap[0].rxitr_idx = RTE_LIBRTE_I40E_ITR_INTERVAL / 2;
614 map_info->vecmap[0].txitr_idx = RTE_LIBRTE_I40E_ITR_INTERVAL / 2;
615 map_info->vecmap[0].vsi_id = vf->vsi_res->vsi_id;
616 /* Alway use default dynamic MSIX interrupt */
617 map_info->vecmap[0].vector_id = I40EVF_VSI_DEFAULT_MSIX_INTR;
618 /* Don't map any tx queue */
619 map_info->vecmap[0].txq_map = 0;
620 map_info->vecmap[0].rxq_map = 0;
621 for (i = 0; i < dev->data->nb_rx_queues; i++)
622 map_info->vecmap[0].rxq_map |= 1 << i;
624 args.ops = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
625 args.in_args = (u8 *)cmd_buffer;
626 args.in_args_size = sizeof(cmd_buffer);
627 args.out_buffer = cmd_result_buffer;
628 args.out_size = I40E_AQ_BUF_SZ;
629 err = i40evf_execute_vf_cmd(dev, &args);
631 PMD_DRV_LOG(ERR, "fail to execute command OP_ENABLE_QUEUES");
637 i40evf_switch_queue(struct rte_eth_dev *dev, bool isrx, uint16_t qid,
640 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
641 struct i40e_virtchnl_queue_select queue_select;
643 struct vf_cmd_info args;
644 memset(&queue_select, 0, sizeof(queue_select));
645 queue_select.vsi_id = vf->vsi_res->vsi_id;
648 queue_select.rx_queues |= 1 << qid;
650 queue_select.tx_queues |= 1 << qid;
653 args.ops = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
655 args.ops = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
656 args.in_args = (u8 *)&queue_select;
657 args.in_args_size = sizeof(queue_select);
658 args.out_buffer = cmd_result_buffer;
659 args.out_size = I40E_AQ_BUF_SZ;
660 err = i40evf_execute_vf_cmd(dev, &args);
662 PMD_DRV_LOG(ERR, "fail to switch %s %u %s",
663 isrx ? "RX" : "TX", qid, on ? "on" : "off");
669 i40evf_start_queues(struct rte_eth_dev *dev)
671 struct rte_eth_dev_data *dev_data = dev->data;
673 struct i40e_rx_queue *rxq;
674 struct i40e_tx_queue *txq;
676 for (i = 0; i < dev->data->nb_rx_queues; i++) {
677 rxq = dev_data->rx_queues[i];
678 if (rxq->rx_deferred_start)
680 if (i40evf_dev_rx_queue_start(dev, i) != 0) {
681 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
686 for (i = 0; i < dev->data->nb_tx_queues; i++) {
687 txq = dev_data->tx_queues[i];
688 if (txq->tx_deferred_start)
690 if (i40evf_dev_tx_queue_start(dev, i) != 0) {
691 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
700 i40evf_stop_queues(struct rte_eth_dev *dev)
704 /* Stop TX queues first */
705 for (i = 0; i < dev->data->nb_tx_queues; i++) {
706 if (i40evf_dev_tx_queue_stop(dev, i) != 0) {
707 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
712 /* Then stop RX queues */
713 for (i = 0; i < dev->data->nb_rx_queues; i++) {
714 if (i40evf_dev_rx_queue_stop(dev, i) != 0) {
715 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
724 i40evf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
726 struct i40e_virtchnl_ether_addr_list *list;
727 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
728 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
729 sizeof(struct i40e_virtchnl_ether_addr)];
731 struct vf_cmd_info args;
733 if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
734 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
735 addr->addr_bytes[0], addr->addr_bytes[1],
736 addr->addr_bytes[2], addr->addr_bytes[3],
737 addr->addr_bytes[4], addr->addr_bytes[5]);
741 list = (struct i40e_virtchnl_ether_addr_list *)cmd_buffer;
742 list->vsi_id = vf->vsi_res->vsi_id;
743 list->num_elements = 1;
744 (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
745 sizeof(addr->addr_bytes));
747 args.ops = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
748 args.in_args = cmd_buffer;
749 args.in_args_size = sizeof(cmd_buffer);
750 args.out_buffer = cmd_result_buffer;
751 args.out_size = I40E_AQ_BUF_SZ;
752 err = i40evf_execute_vf_cmd(dev, &args);
754 PMD_DRV_LOG(ERR, "fail to execute command "
755 "OP_ADD_ETHER_ADDRESS");
761 i40evf_del_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
763 struct i40e_virtchnl_ether_addr_list *list;
764 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
765 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
766 sizeof(struct i40e_virtchnl_ether_addr)];
768 struct vf_cmd_info args;
770 if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
771 PMD_DRV_LOG(ERR, "Invalid mac:%x-%x-%x-%x-%x-%x",
772 addr->addr_bytes[0], addr->addr_bytes[1],
773 addr->addr_bytes[2], addr->addr_bytes[3],
774 addr->addr_bytes[4], addr->addr_bytes[5]);
778 list = (struct i40e_virtchnl_ether_addr_list *)cmd_buffer;
779 list->vsi_id = vf->vsi_res->vsi_id;
780 list->num_elements = 1;
781 (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
782 sizeof(addr->addr_bytes));
784 args.ops = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
785 args.in_args = cmd_buffer;
786 args.in_args_size = sizeof(cmd_buffer);
787 args.out_buffer = cmd_result_buffer;
788 args.out_size = I40E_AQ_BUF_SZ;
789 err = i40evf_execute_vf_cmd(dev, &args);
791 PMD_DRV_LOG(ERR, "fail to execute command "
792 "OP_DEL_ETHER_ADDRESS");
798 i40evf_get_statics(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
800 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
801 struct i40e_virtchnl_queue_select q_stats;
802 struct i40e_eth_stats *pstats;
804 struct vf_cmd_info args;
806 memset(&q_stats, 0, sizeof(q_stats));
807 q_stats.vsi_id = vf->vsi_res->vsi_id;
808 args.ops = I40E_VIRTCHNL_OP_GET_STATS;
809 args.in_args = (u8 *)&q_stats;
810 args.in_args_size = sizeof(q_stats);
811 args.out_buffer = cmd_result_buffer;
812 args.out_size = I40E_AQ_BUF_SZ;
814 err = i40evf_execute_vf_cmd(dev, &args);
816 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
819 pstats = (struct i40e_eth_stats *)args.out_buffer;
820 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
821 pstats->rx_broadcast;
822 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
824 stats->ierrors = pstats->rx_discards;
825 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
826 stats->ibytes = pstats->rx_bytes;
827 stats->obytes = pstats->tx_bytes;
833 i40evf_add_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
835 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
836 struct i40e_virtchnl_vlan_filter_list *vlan_list;
837 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_vlan_filter_list) +
840 struct vf_cmd_info args;
842 vlan_list = (struct i40e_virtchnl_vlan_filter_list *)cmd_buffer;
843 vlan_list->vsi_id = vf->vsi_res->vsi_id;
844 vlan_list->num_elements = 1;
845 vlan_list->vlan_id[0] = vlanid;
847 args.ops = I40E_VIRTCHNL_OP_ADD_VLAN;
848 args.in_args = (u8 *)&cmd_buffer;
849 args.in_args_size = sizeof(cmd_buffer);
850 args.out_buffer = cmd_result_buffer;
851 args.out_size = I40E_AQ_BUF_SZ;
852 err = i40evf_execute_vf_cmd(dev, &args);
854 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_VLAN");
860 i40evf_del_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
862 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
863 struct i40e_virtchnl_vlan_filter_list *vlan_list;
864 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_vlan_filter_list) +
867 struct vf_cmd_info args;
869 vlan_list = (struct i40e_virtchnl_vlan_filter_list *)cmd_buffer;
870 vlan_list->vsi_id = vf->vsi_res->vsi_id;
871 vlan_list->num_elements = 1;
872 vlan_list->vlan_id[0] = vlanid;
874 args.ops = I40E_VIRTCHNL_OP_DEL_VLAN;
875 args.in_args = (u8 *)&cmd_buffer;
876 args.in_args_size = sizeof(cmd_buffer);
877 args.out_buffer = cmd_result_buffer;
878 args.out_size = I40E_AQ_BUF_SZ;
879 err = i40evf_execute_vf_cmd(dev, &args);
881 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_VLAN");
887 i40evf_get_link_status(struct rte_eth_dev *dev, struct rte_eth_link *link)
890 struct vf_cmd_info args;
891 struct rte_eth_link *new_link;
893 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_GET_LINK_STAT;
895 args.in_args_size = 0;
896 args.out_buffer = cmd_result_buffer;
897 args.out_size = I40E_AQ_BUF_SZ;
898 err = i40evf_execute_vf_cmd(dev, &args);
900 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_LINK_STAT");
904 new_link = (struct rte_eth_link *)args.out_buffer;
905 (void)rte_memcpy(link, new_link, sizeof(*link));
910 static struct rte_pci_id pci_id_i40evf_map[] = {
911 #define RTE_PCI_DEV_ID_DECL_I40EVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
912 #include "rte_pci_dev_ids.h"
913 { .vendor_id = 0, /* sentinel */ },
917 i40evf_dev_atomic_write_link_status(struct rte_eth_dev *dev,
918 struct rte_eth_link *link)
920 struct rte_eth_link *dst = &(dev->data->dev_link);
921 struct rte_eth_link *src = link;
923 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
924 *(uint64_t *)src) == 0)
931 i40evf_reset_vf(struct i40e_hw *hw)
935 if (i40e_vf_reset(hw) != I40E_SUCCESS) {
936 PMD_INIT_LOG(ERR, "Reset VF NIC failed");
940 * After issuing vf reset command to pf, pf won't necessarily
941 * reset vf, it depends on what state it exactly is. If it's not
942 * initialized yet, it won't have vf reset since it's in a certain
943 * state. If not, it will try to reset. Even vf is reset, pf will
944 * set I40E_VFGEN_RSTAT to COMPLETE first, then wait 10ms and set
945 * it to ACTIVE. In this duration, vf may not catch the moment that
946 * COMPLETE is set. So, for vf, we'll try to wait a long time.
950 for (i = 0; i < MAX_RESET_WAIT_CNT; i++) {
951 reset = rd32(hw, I40E_VFGEN_RSTAT) &
952 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
953 reset = reset >> I40E_VFGEN_RSTAT_VFR_STATE_SHIFT;
954 if (I40E_VFR_COMPLETED == reset || I40E_VFR_VFACTIVE == reset)
960 if (i >= MAX_RESET_WAIT_CNT) {
961 PMD_INIT_LOG(ERR, "Reset VF NIC failed");
969 i40evf_init_vf(struct rte_eth_dev *dev)
972 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
973 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
975 err = i40evf_set_mac_type(hw);
977 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
981 i40e_init_adminq_parameter(hw);
982 err = i40e_init_adminq(hw);
984 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
989 /* Reset VF and wait until it's complete */
990 if (i40evf_reset_vf(hw)) {
991 PMD_INIT_LOG(ERR, "reset NIC failed");
995 /* VF reset, shutdown admin queue and initialize again */
996 if (i40e_shutdown_adminq(hw) != I40E_SUCCESS) {
997 PMD_INIT_LOG(ERR, "i40e_shutdown_adminq failed");
1001 i40e_init_adminq_parameter(hw);
1002 if (i40e_init_adminq(hw) != I40E_SUCCESS) {
1003 PMD_INIT_LOG(ERR, "init_adminq failed");
1006 if (i40evf_check_api_version(dev) != 0) {
1007 PMD_INIT_LOG(ERR, "check_api version failed");
1010 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
1011 (I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource));
1012 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1014 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1018 if (i40evf_get_vf_resource(dev) != 0) {
1019 PMD_INIT_LOG(ERR, "i40evf_get_vf_config failed");
1023 /* got VF config message back from PF, now we can parse it */
1024 for (i = 0; i < vf->vf_res->num_vsis; i++) {
1025 if (vf->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
1026 vf->vsi_res = &vf->vf_res->vsi_res[i];
1030 PMD_INIT_LOG(ERR, "no LAN VSI found");
1034 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
1035 vf->vsi.type = vf->vsi_res->vsi_type;
1036 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
1038 /* check mac addr, if it's not valid, genrate one */
1039 if (I40E_SUCCESS != i40e_validate_mac_addr(\
1040 vf->vsi_res->default_mac_addr))
1041 eth_random_addr(vf->vsi_res->default_mac_addr);
1043 ether_addr_copy((struct ether_addr *)vf->vsi_res->default_mac_addr,
1044 (struct ether_addr *)hw->mac.addr);
1049 rte_free(vf->vf_res);
1051 i40e_shutdown_adminq(hw); /* ignore error */
1057 i40evf_dev_init(__rte_unused struct eth_driver *eth_drv,
1058 struct rte_eth_dev *eth_dev)
1060 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(\
1061 eth_dev->data->dev_private);
1063 PMD_INIT_FUNC_TRACE();
1065 /* assign ops func pointer */
1066 eth_dev->dev_ops = &i40evf_eth_dev_ops;
1067 eth_dev->rx_pkt_burst = &i40e_recv_pkts;
1068 eth_dev->tx_pkt_burst = &i40e_xmit_pkts;
1071 * For secondary processes, we don't initialise any further as primary
1072 * has already done this work.
1074 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1075 if (eth_dev->data->scattered_rx)
1076 eth_dev->rx_pkt_burst = i40e_recv_scattered_pkts;
1080 hw->vendor_id = eth_dev->pci_dev->id.vendor_id;
1081 hw->device_id = eth_dev->pci_dev->id.device_id;
1082 hw->subsystem_vendor_id = eth_dev->pci_dev->id.subsystem_vendor_id;
1083 hw->subsystem_device_id = eth_dev->pci_dev->id.subsystem_device_id;
1084 hw->bus.device = eth_dev->pci_dev->addr.devid;
1085 hw->bus.func = eth_dev->pci_dev->addr.function;
1086 hw->hw_addr = (void *)eth_dev->pci_dev->mem_resource[0].addr;
1088 if(i40evf_init_vf(eth_dev) != 0) {
1089 PMD_INIT_LOG(ERR, "Init vf failed");
1094 eth_dev->data->mac_addrs = rte_zmalloc("i40evf_mac",
1096 if (eth_dev->data->mac_addrs == NULL) {
1097 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
1098 "store MAC addresses", ETHER_ADDR_LEN);
1101 ether_addr_copy((struct ether_addr *)hw->mac.addr,
1102 (struct ether_addr *)eth_dev->data->mac_addrs);
1108 * virtual function driver struct
1110 static struct eth_driver rte_i40evf_pmd = {
1112 .name = "rte_i40evf_pmd",
1113 .id_table = pci_id_i40evf_map,
1114 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1116 .eth_dev_init = i40evf_dev_init,
1117 .dev_private_size = sizeof(struct i40e_vf),
1121 * VF Driver initialization routine.
1122 * Invoked one at EAL init time.
1123 * Register itself as the [Virtual Poll Mode] Driver of PCI Fortville devices.
1126 rte_i40evf_pmd_init(const char *name __rte_unused,
1127 const char *params __rte_unused)
1129 PMD_INIT_FUNC_TRACE();
1131 rte_eth_driver_register(&rte_i40evf_pmd);
1136 static struct rte_driver rte_i40evf_driver = {
1138 .init = rte_i40evf_pmd_init,
1141 PMD_REGISTER_DRIVER(rte_i40evf_driver);
1144 i40evf_dev_configure(struct rte_eth_dev *dev)
1146 return i40evf_init_vlan(dev);
1150 i40evf_init_vlan(struct rte_eth_dev *dev)
1152 struct rte_eth_dev_data *data = dev->data;
1155 /* Apply vlan offload setting */
1156 i40evf_vlan_offload_set(dev, ETH_VLAN_STRIP_MASK);
1158 /* Apply pvid setting */
1159 ret = i40evf_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
1160 data->dev_conf.txmode.hw_vlan_insert_pvid);
1165 i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1167 bool enable_vlan_strip = 0;
1168 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1169 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1171 /* Linux pf host doesn't support vlan offload yet */
1172 if (vf->host_is_dpdk) {
1173 /* Vlan stripping setting */
1174 if (mask & ETH_VLAN_STRIP_MASK) {
1175 /* Enable or disable VLAN stripping */
1176 if (dev_conf->rxmode.hw_vlan_strip)
1177 enable_vlan_strip = 1;
1179 enable_vlan_strip = 0;
1181 i40evf_config_vlan_offload(dev, enable_vlan_strip);
1187 i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
1189 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1190 struct i40e_vsi_vlan_pvid_info info;
1191 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1193 memset(&info, 0, sizeof(info));
1196 /* Linux pf host don't support vlan offload yet */
1197 if (vf->host_is_dpdk) {
1199 info.config.pvid = pvid;
1201 info.config.reject.tagged =
1202 dev_conf->txmode.hw_vlan_reject_tagged;
1203 info.config.reject.untagged =
1204 dev_conf->txmode.hw_vlan_reject_untagged;
1206 return i40evf_config_vlan_pvid(dev, &info);
1213 i40evf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1215 struct i40e_rx_queue *rxq;
1217 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1219 PMD_INIT_FUNC_TRACE();
1221 if (rx_queue_id < dev->data->nb_rx_queues) {
1222 rxq = dev->data->rx_queues[rx_queue_id];
1224 err = i40e_alloc_rx_queue_mbufs(rxq);
1226 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1232 /* Init the RX tail register. */
1233 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1234 I40EVF_WRITE_FLUSH(hw);
1236 /* Ready to switch the queue on */
1237 err = i40evf_switch_queue(dev, TRUE, rx_queue_id, TRUE);
1240 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1248 i40evf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1250 struct i40e_rx_queue *rxq;
1253 if (rx_queue_id < dev->data->nb_rx_queues) {
1254 rxq = dev->data->rx_queues[rx_queue_id];
1256 err = i40evf_switch_queue(dev, TRUE, rx_queue_id, FALSE);
1259 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1264 i40e_rx_queue_release_mbufs(rxq);
1265 i40e_reset_rx_queue(rxq);
1272 i40evf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1276 PMD_INIT_FUNC_TRACE();
1278 if (tx_queue_id < dev->data->nb_tx_queues) {
1280 /* Ready to switch the queue on */
1281 err = i40evf_switch_queue(dev, FALSE, tx_queue_id, TRUE);
1284 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1292 i40evf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1294 struct i40e_tx_queue *txq;
1297 if (tx_queue_id < dev->data->nb_tx_queues) {
1298 txq = dev->data->tx_queues[tx_queue_id];
1300 err = i40evf_switch_queue(dev, FALSE, tx_queue_id, FALSE);
1303 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
1308 i40e_tx_queue_release_mbufs(txq);
1309 i40e_reset_tx_queue(txq);
1316 i40evf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1321 ret = i40evf_add_vlan(dev, vlan_id);
1323 ret = i40evf_del_vlan(dev,vlan_id);
1329 i40evf_rx_init(struct rte_eth_dev *dev)
1332 struct i40e_rx_queue **rxq =
1333 (struct i40e_rx_queue **)dev->data->rx_queues;
1334 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1336 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1337 rxq[i]->qrx_tail = hw->hw_addr + I40E_QRX_TAIL1(i);
1338 I40E_PCI_REG_WRITE(rxq[i]->qrx_tail, rxq[i]->nb_rx_desc - 1);
1341 /* Flush the operation to write registers */
1342 I40EVF_WRITE_FLUSH(hw);
1348 i40evf_tx_init(struct rte_eth_dev *dev)
1351 struct i40e_tx_queue **txq =
1352 (struct i40e_tx_queue **)dev->data->tx_queues;
1353 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1355 for (i = 0; i < dev->data->nb_tx_queues; i++)
1356 txq[i]->qtx_tail = hw->hw_addr + I40E_QTX_TAIL1(i);
1360 i40evf_enable_queues_intr(struct i40e_hw *hw)
1362 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1363 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
1364 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
1368 i40evf_disable_queues_intr(struct i40e_hw *hw)
1370 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1375 i40evf_dev_start(struct rte_eth_dev *dev)
1377 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1378 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1379 struct ether_addr mac_addr;
1381 PMD_INIT_FUNC_TRACE();
1383 vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1384 if (dev->data->dev_conf.rxmode.jumbo_frame == 1) {
1385 if (vf->max_pkt_len <= ETHER_MAX_LEN ||
1386 vf->max_pkt_len > I40E_FRAME_SIZE_MAX) {
1387 PMD_DRV_LOG(ERR, "maximum packet length must "
1388 "be larger than %u and smaller than %u,"
1389 "as jumbo frame is enabled",
1390 (uint32_t)ETHER_MAX_LEN,
1391 (uint32_t)I40E_FRAME_SIZE_MAX);
1392 return I40E_ERR_CONFIG;
1395 if (vf->max_pkt_len < ETHER_MIN_LEN ||
1396 vf->max_pkt_len > ETHER_MAX_LEN) {
1397 PMD_DRV_LOG(ERR, "maximum packet length must be "
1398 "larger than %u and smaller than %u, "
1399 "as jumbo frame is disabled",
1400 (uint32_t)ETHER_MIN_LEN,
1401 (uint32_t)ETHER_MAX_LEN);
1402 return I40E_ERR_CONFIG;
1406 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
1407 dev->data->nb_tx_queues);
1409 if (i40evf_rx_init(dev) != 0){
1410 PMD_DRV_LOG(ERR, "failed to do RX init");
1414 i40evf_tx_init(dev);
1416 if (i40evf_configure_queues(dev) != 0) {
1417 PMD_DRV_LOG(ERR, "configure queues failed");
1420 if (i40evf_config_irq_map(dev)) {
1421 PMD_DRV_LOG(ERR, "config_irq_map failed");
1426 (void)rte_memcpy(mac_addr.addr_bytes, hw->mac.addr,
1427 sizeof(mac_addr.addr_bytes));
1428 if (i40evf_add_mac_addr(dev, &mac_addr)) {
1429 PMD_DRV_LOG(ERR, "Failed to add mac addr");
1433 if (i40evf_start_queues(dev) != 0) {
1434 PMD_DRV_LOG(ERR, "enable queues failed");
1438 i40evf_enable_queues_intr(hw);
1442 i40evf_del_mac_addr(dev, &mac_addr);
1448 i40evf_dev_stop(struct rte_eth_dev *dev)
1450 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1452 PMD_INIT_FUNC_TRACE();
1454 i40evf_disable_queues_intr(hw);
1455 i40evf_stop_queues(dev);
1459 i40evf_dev_link_update(struct rte_eth_dev *dev,
1460 __rte_unused int wait_to_complete)
1462 struct rte_eth_link new_link;
1463 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1465 * DPDK pf host provide interfacet to acquire link status
1466 * while Linux driver does not
1468 if (vf->host_is_dpdk)
1469 i40evf_get_link_status(dev, &new_link);
1471 /* Always assume it's up, for Linux driver PF host */
1472 new_link.link_duplex = ETH_LINK_AUTONEG_DUPLEX;
1473 new_link.link_speed = ETH_LINK_SPEED_10000;
1474 new_link.link_status = 1;
1476 i40evf_dev_atomic_write_link_status(dev, &new_link);
1482 i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1484 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1487 /* If enabled, just return */
1488 if (vf->promisc_unicast_enabled)
1491 ret = i40evf_config_promisc(dev, 1, vf->promisc_multicast_enabled);
1493 vf->promisc_unicast_enabled = TRUE;
1497 i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1499 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1502 /* If disabled, just return */
1503 if (!vf->promisc_unicast_enabled)
1506 ret = i40evf_config_promisc(dev, 0, vf->promisc_multicast_enabled);
1508 vf->promisc_unicast_enabled = FALSE;
1512 i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1514 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1517 /* If enabled, just return */
1518 if (vf->promisc_multicast_enabled)
1521 ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 1);
1523 vf->promisc_multicast_enabled = TRUE;
1527 i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1529 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1532 /* If enabled, just return */
1533 if (!vf->promisc_multicast_enabled)
1536 ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 0);
1538 vf->promisc_multicast_enabled = FALSE;
1542 i40evf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1544 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1546 memset(dev_info, 0, sizeof(*dev_info));
1547 dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
1548 dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
1549 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
1550 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
1554 i40evf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1556 memset(stats, 0, sizeof(*stats));
1557 if (i40evf_get_statics(dev, stats))
1558 PMD_DRV_LOG(ERR, "Get statics failed");
1562 i40evf_dev_close(struct rte_eth_dev *dev)
1564 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1566 i40evf_dev_stop(dev);
1567 i40evf_reset_vf(hw);
1568 i40e_shutdown_adminq(hw);