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;
87 enum i40e_virtchnl_ops ops;
89 uint32_t in_args_size;
91 /* Input & output type. pass in buffer size and pass out
92 * actual return result
97 enum i40evf_aq_result {
98 I40EVF_MSG_ERR = -1, /* Meet error when accessing admin queue */
99 I40EVF_MSG_NON, /* Read nothing from admin queue */
100 I40EVF_MSG_SYS, /* Read system msg from admin queue */
101 I40EVF_MSG_CMD, /* Read async command result */
104 /* A share buffer to store the command result from PF driver */
105 static uint8_t cmd_result_buffer[I40E_AQ_BUF_SZ];
107 static int i40evf_dev_configure(struct rte_eth_dev *dev);
108 static int i40evf_dev_start(struct rte_eth_dev *dev);
109 static void i40evf_dev_stop(struct rte_eth_dev *dev);
110 static void i40evf_dev_info_get(struct rte_eth_dev *dev,
111 struct rte_eth_dev_info *dev_info);
112 static int i40evf_dev_link_update(struct rte_eth_dev *dev,
113 __rte_unused int wait_to_complete);
114 static void i40evf_dev_stats_get(struct rte_eth_dev *dev,
115 struct rte_eth_stats *stats);
116 static int i40evf_vlan_filter_set(struct rte_eth_dev *dev,
117 uint16_t vlan_id, int on);
118 static void i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
119 static int i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid,
121 static void i40evf_dev_close(struct rte_eth_dev *dev);
122 static void i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev);
123 static void i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev);
124 static void i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev);
125 static void i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev);
126 static int i40evf_get_link_status(struct rte_eth_dev *dev,
127 struct rte_eth_link *link);
128 static int i40evf_init_vlan(struct rte_eth_dev *dev);
129 static int i40evf_config_rss(struct i40e_vf *vf);
130 static int i40evf_dev_rss_hash_update(struct rte_eth_dev *dev,
131 struct rte_eth_rss_conf *rss_conf);
132 static int i40evf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
133 struct rte_eth_rss_conf *rss_conf);
134 static int i40evf_dev_rx_queue_start(struct rte_eth_dev *, uint16_t);
135 static int i40evf_dev_rx_queue_stop(struct rte_eth_dev *, uint16_t);
136 static int i40evf_dev_tx_queue_start(struct rte_eth_dev *, uint16_t);
137 static int i40evf_dev_tx_queue_stop(struct rte_eth_dev *, uint16_t);
139 /* Default hash key buffer for RSS */
140 static uint32_t rss_key_default[I40E_VFQF_HKEY_MAX_INDEX + 1];
142 static struct eth_dev_ops i40evf_eth_dev_ops = {
143 .dev_configure = i40evf_dev_configure,
144 .dev_start = i40evf_dev_start,
145 .dev_stop = i40evf_dev_stop,
146 .promiscuous_enable = i40evf_dev_promiscuous_enable,
147 .promiscuous_disable = i40evf_dev_promiscuous_disable,
148 .allmulticast_enable = i40evf_dev_allmulticast_enable,
149 .allmulticast_disable = i40evf_dev_allmulticast_disable,
150 .link_update = i40evf_dev_link_update,
151 .stats_get = i40evf_dev_stats_get,
152 .dev_close = i40evf_dev_close,
153 .dev_infos_get = i40evf_dev_info_get,
154 .vlan_filter_set = i40evf_vlan_filter_set,
155 .vlan_offload_set = i40evf_vlan_offload_set,
156 .vlan_pvid_set = i40evf_vlan_pvid_set,
157 .rx_queue_start = i40evf_dev_rx_queue_start,
158 .rx_queue_stop = i40evf_dev_rx_queue_stop,
159 .tx_queue_start = i40evf_dev_tx_queue_start,
160 .tx_queue_stop = i40evf_dev_tx_queue_stop,
161 .rx_queue_setup = i40e_dev_rx_queue_setup,
162 .rx_queue_release = i40e_dev_rx_queue_release,
163 .tx_queue_setup = i40e_dev_tx_queue_setup,
164 .tx_queue_release = i40e_dev_tx_queue_release,
165 .rss_hash_update = i40evf_dev_rss_hash_update,
166 .rss_hash_conf_get = i40evf_dev_rss_hash_conf_get,
170 i40evf_set_mac_type(struct i40e_hw *hw)
172 int status = I40E_ERR_DEVICE_NOT_SUPPORTED;
174 if (hw->vendor_id == I40E_INTEL_VENDOR_ID) {
175 switch (hw->device_id) {
177 case I40E_DEV_ID_VF_HV:
178 hw->mac.type = I40E_MAC_VF;
179 status = I40E_SUCCESS;
190 * Parse admin queue message.
195 * > 0: read cmd result
197 static enum i40evf_aq_result
198 i40evf_parse_pfmsg(struct i40e_vf *vf,
199 struct i40e_arq_event_info *event,
200 struct i40evf_arq_msg_info *data)
202 enum i40e_virtchnl_ops opcode = (enum i40e_virtchnl_ops)\
203 rte_le_to_cpu_32(event->desc.cookie_high);
204 enum i40e_status_code retval = (enum i40e_status_code)\
205 rte_le_to_cpu_32(event->desc.cookie_low);
206 enum i40evf_aq_result ret = I40EVF_MSG_CMD;
209 if (opcode == I40E_VIRTCHNL_OP_EVENT) {
210 struct i40e_virtchnl_pf_event *vpe =
211 (struct i40e_virtchnl_pf_event *)event->msg_buf;
213 /* Initialize ret to sys event */
214 ret = I40EVF_MSG_SYS;
215 switch (vpe->event) {
216 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
218 vpe->event_data.link_event.link_status;
219 vf->pend_msg |= PFMSG_LINK_CHANGE;
220 PMD_DRV_LOG(INFO, "Link status update:%s",
221 vf->link_up ? "up" : "down");
223 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
225 vf->pend_msg |= PFMSG_RESET_IMPENDING;
226 PMD_DRV_LOG(INFO, "vf is reseting");
228 case I40E_VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
229 vf->dev_closed = true;
230 vf->pend_msg |= PFMSG_DRIVER_CLOSE;
231 PMD_DRV_LOG(INFO, "PF driver closed");
234 PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
235 __func__, vpe->event);
238 /* async reply msg on command issued by vf previously */
239 ret = I40EVF_MSG_CMD;
240 /* Actual data length read from PF */
241 data->msg_len = event->msg_len;
243 /* fill the ops and result to notify VF */
244 data->result = retval;
251 * Read data in admin queue to get msg from pf driver
253 static enum i40evf_aq_result
254 i40evf_read_pfmsg(struct rte_eth_dev *dev, struct i40evf_arq_msg_info *data)
256 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
257 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
258 struct i40e_arq_event_info event;
260 enum i40evf_aq_result result = I40EVF_MSG_NON;
262 event.buf_len = data->buf_len;
263 event.msg_buf = data->msg;
264 ret = i40e_clean_arq_element(hw, &event, NULL);
265 /* Can't read any msg from adminQ */
267 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
268 result = I40EVF_MSG_NON;
270 result = I40EVF_MSG_ERR;
274 /* Parse the event */
275 result = i40evf_parse_pfmsg(vf, &event, data);
281 * Polling read until command result return from pf driver or meet error.
284 i40evf_wait_cmd_done(struct rte_eth_dev *dev,
285 struct i40evf_arq_msg_info *data)
288 enum i40evf_aq_result ret;
290 #define MAX_TRY_TIMES 10
291 #define ASQ_DELAY_MS 50
293 /* Delay some time first */
294 rte_delay_ms(ASQ_DELAY_MS);
295 ret = i40evf_read_pfmsg(dev, data);
296 if (ret == I40EVF_MSG_CMD)
298 else if (ret == I40EVF_MSG_ERR)
301 /* If don't read msg or read sys event, continue */
302 } while(i++ < MAX_TRY_TIMES);
308 * clear current command. Only call in case execute
309 * _atomic_set_cmd successfully.
312 _clear_cmd(struct i40e_vf *vf)
315 vf->pend_cmd = I40E_VIRTCHNL_OP_UNKNOWN;
319 * Check there is pending cmd in execution. If none, set new command.
322 _atomic_set_cmd(struct i40e_vf *vf, enum i40e_virtchnl_ops ops)
324 int ret = rte_atomic32_cmpset(&vf->pend_cmd,
325 I40E_VIRTCHNL_OP_UNKNOWN, ops);
328 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
334 i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
336 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
337 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
339 struct i40evf_arq_msg_info info;
341 if (_atomic_set_cmd(vf, args->ops))
344 info.msg = args->out_buffer;
345 info.buf_len = args->out_size;
346 info.ops = I40E_VIRTCHNL_OP_UNKNOWN;
347 info.result = I40E_SUCCESS;
349 err = i40e_aq_send_msg_to_pf(hw, args->ops, I40E_SUCCESS,
350 args->in_args, args->in_args_size, NULL);
352 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
356 err = i40evf_wait_cmd_done(dev, &info);
357 /* read message and it's expected one */
358 if (!err && args->ops == info.ops)
361 PMD_DRV_LOG(ERR, "Failed to read message from AdminQ");
362 else if (args->ops != info.ops)
363 PMD_DRV_LOG(ERR, "command mismatch, expect %u, get %u",
364 args->ops, info.ops);
366 return (err | info.result);
370 * Check API version with sync wait until version read or fail from admin queue
373 i40evf_check_api_version(struct rte_eth_dev *dev)
375 struct i40e_virtchnl_version_info version, *pver;
377 struct vf_cmd_info args;
378 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
380 version.major = I40E_VIRTCHNL_VERSION_MAJOR;
381 version.minor = I40E_VIRTCHNL_VERSION_MINOR;
383 args.ops = I40E_VIRTCHNL_OP_VERSION;
384 args.in_args = (uint8_t *)&version;
385 args.in_args_size = sizeof(version);
386 args.out_buffer = cmd_result_buffer;
387 args.out_size = I40E_AQ_BUF_SZ;
389 err = i40evf_execute_vf_cmd(dev, &args);
391 PMD_INIT_LOG(ERR, "fail to execute command OP_VERSION");
395 pver = (struct i40e_virtchnl_version_info *)args.out_buffer;
396 vf->version_major = pver->major;
397 vf->version_minor = pver->minor;
398 if (vf->version_major == I40E_DPDK_VERSION_MAJOR)
399 PMD_DRV_LOG(INFO, "Peer is DPDK PF host");
400 else if ((vf->version_major == I40E_VIRTCHNL_VERSION_MAJOR) &&
401 (vf->version_minor == I40E_VIRTCHNL_VERSION_MINOR))
402 PMD_DRV_LOG(INFO, "Peer is Linux PF host");
404 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
405 vf->version_major, vf->version_minor,
406 I40E_VIRTCHNL_VERSION_MAJOR,
407 I40E_VIRTCHNL_VERSION_MINOR);
415 i40evf_get_vf_resource(struct rte_eth_dev *dev)
417 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
418 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
420 struct vf_cmd_info args;
423 args.ops = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
425 args.in_args_size = 0;
426 args.out_buffer = cmd_result_buffer;
427 args.out_size = I40E_AQ_BUF_SZ;
429 err = i40evf_execute_vf_cmd(dev, &args);
432 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_VF_RESOURCE");
436 len = sizeof(struct i40e_virtchnl_vf_resource) +
437 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
439 (void)rte_memcpy(vf->vf_res, args.out_buffer,
440 RTE_MIN(args.out_size, len));
441 i40e_vf_parse_hw_config(hw, vf->vf_res);
447 i40evf_config_promisc(struct rte_eth_dev *dev,
449 bool enable_multicast)
451 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
453 struct vf_cmd_info args;
454 struct i40e_virtchnl_promisc_info promisc;
457 promisc.vsi_id = vf->vsi_res->vsi_id;
460 promisc.flags |= I40E_FLAG_VF_UNICAST_PROMISC;
462 if (enable_multicast)
463 promisc.flags |= I40E_FLAG_VF_MULTICAST_PROMISC;
465 args.ops = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
466 args.in_args = (uint8_t *)&promisc;
467 args.in_args_size = sizeof(promisc);
468 args.out_buffer = cmd_result_buffer;
469 args.out_size = I40E_AQ_BUF_SZ;
471 err = i40evf_execute_vf_cmd(dev, &args);
474 PMD_DRV_LOG(ERR, "fail to execute command "
475 "CONFIG_PROMISCUOUS_MODE");
479 /* Configure vlan and double vlan offload. Use flag to specify which part to configure */
481 i40evf_config_vlan_offload(struct rte_eth_dev *dev,
482 bool enable_vlan_strip)
484 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
486 struct vf_cmd_info args;
487 struct i40e_virtchnl_vlan_offload_info offload;
489 offload.vsi_id = vf->vsi_res->vsi_id;
490 offload.enable_vlan_strip = enable_vlan_strip;
492 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_OFFLOAD;
493 args.in_args = (uint8_t *)&offload;
494 args.in_args_size = sizeof(offload);
495 args.out_buffer = cmd_result_buffer;
496 args.out_size = I40E_AQ_BUF_SZ;
498 err = i40evf_execute_vf_cmd(dev, &args);
500 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_OFFLOAD");
506 i40evf_config_vlan_pvid(struct rte_eth_dev *dev,
507 struct i40e_vsi_vlan_pvid_info *info)
509 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
511 struct vf_cmd_info args;
512 struct i40e_virtchnl_pvid_info tpid_info;
514 if (dev == NULL || info == NULL) {
515 PMD_DRV_LOG(ERR, "invalid parameters");
516 return I40E_ERR_PARAM;
519 memset(&tpid_info, 0, sizeof(tpid_info));
520 tpid_info.vsi_id = vf->vsi_res->vsi_id;
521 (void)rte_memcpy(&tpid_info.info, info, sizeof(*info));
523 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_PVID;
524 args.in_args = (uint8_t *)&tpid_info;
525 args.in_args_size = sizeof(tpid_info);
526 args.out_buffer = cmd_result_buffer;
527 args.out_size = I40E_AQ_BUF_SZ;
529 err = i40evf_execute_vf_cmd(dev, &args);
531 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_PVID");
537 i40evf_fill_virtchnl_vsi_txq_info(struct i40e_virtchnl_txq_info *txq_info,
541 struct i40e_tx_queue *txq)
543 txq_info->vsi_id = vsi_id;
544 txq_info->queue_id = queue_id;
545 if (queue_id < nb_txq) {
546 txq_info->ring_len = txq->nb_tx_desc;
547 txq_info->dma_ring_addr = txq->tx_ring_phys_addr;
552 i40evf_fill_virtchnl_vsi_rxq_info(struct i40e_virtchnl_rxq_info *rxq_info,
556 uint32_t max_pkt_size,
557 struct i40e_rx_queue *rxq)
559 rxq_info->vsi_id = vsi_id;
560 rxq_info->queue_id = queue_id;
561 rxq_info->max_pkt_size = max_pkt_size;
562 if (queue_id < nb_rxq) {
563 struct rte_pktmbuf_pool_private *mbp_priv;
565 rxq_info->ring_len = rxq->nb_rx_desc;
566 rxq_info->dma_ring_addr = rxq->rx_ring_phys_addr;
567 mbp_priv = rte_mempool_get_priv(rxq->mp);
568 rxq_info->databuffer_size =
569 mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
573 /* It configures VSI queues to co-work with Linux PF host */
575 i40evf_configure_vsi_queues(struct rte_eth_dev *dev)
577 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
578 struct i40e_rx_queue **rxq =
579 (struct i40e_rx_queue **)dev->data->rx_queues;
580 struct i40e_tx_queue **txq =
581 (struct i40e_tx_queue **)dev->data->tx_queues;
582 struct i40e_virtchnl_vsi_queue_config_info *vc_vqci;
583 struct i40e_virtchnl_queue_pair_info *vc_qpi;
584 struct vf_cmd_info args;
585 uint16_t i, nb_qp = vf->num_queue_pairs;
586 const uint32_t size =
587 I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqci, nb_qp);
591 memset(buff, 0, sizeof(buff));
592 vc_vqci = (struct i40e_virtchnl_vsi_queue_config_info *)buff;
593 vc_vqci->vsi_id = vf->vsi_res->vsi_id;
594 vc_vqci->num_queue_pairs = nb_qp;
596 for (i = 0, vc_qpi = vc_vqci->qpair; i < nb_qp; i++, vc_qpi++) {
597 i40evf_fill_virtchnl_vsi_txq_info(&vc_qpi->txq,
598 vc_vqci->vsi_id, i, dev->data->nb_tx_queues, txq[i]);
599 i40evf_fill_virtchnl_vsi_rxq_info(&vc_qpi->rxq,
600 vc_vqci->vsi_id, i, dev->data->nb_rx_queues,
601 vf->max_pkt_len, rxq[i]);
603 memset(&args, 0, sizeof(args));
604 args.ops = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
605 args.in_args = (uint8_t *)vc_vqci;
606 args.in_args_size = size;
607 args.out_buffer = cmd_result_buffer;
608 args.out_size = I40E_AQ_BUF_SZ;
609 ret = i40evf_execute_vf_cmd(dev, &args);
611 PMD_DRV_LOG(ERR, "Failed to execute command of "
612 "I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES\n");
617 /* It configures VSI queues to co-work with DPDK PF host */
619 i40evf_configure_vsi_queues_ext(struct rte_eth_dev *dev)
621 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
622 struct i40e_rx_queue **rxq =
623 (struct i40e_rx_queue **)dev->data->rx_queues;
624 struct i40e_tx_queue **txq =
625 (struct i40e_tx_queue **)dev->data->tx_queues;
626 struct i40e_virtchnl_vsi_queue_config_ext_info *vc_vqcei;
627 struct i40e_virtchnl_queue_pair_ext_info *vc_qpei;
628 struct vf_cmd_info args;
629 uint16_t i, nb_qp = vf->num_queue_pairs;
630 const uint32_t size =
631 I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqcei, nb_qp);
635 memset(buff, 0, sizeof(buff));
636 vc_vqcei = (struct i40e_virtchnl_vsi_queue_config_ext_info *)buff;
637 vc_vqcei->vsi_id = vf->vsi_res->vsi_id;
638 vc_vqcei->num_queue_pairs = nb_qp;
639 vc_qpei = vc_vqcei->qpair;
640 for (i = 0; i < nb_qp; i++, vc_qpei++) {
641 i40evf_fill_virtchnl_vsi_txq_info(&vc_qpei->txq,
642 vc_vqcei->vsi_id, i, dev->data->nb_tx_queues, txq[i]);
643 i40evf_fill_virtchnl_vsi_rxq_info(&vc_qpei->rxq,
644 vc_vqcei->vsi_id, i, dev->data->nb_rx_queues,
645 vf->max_pkt_len, rxq[i]);
646 if (i < dev->data->nb_rx_queues)
648 * It adds extra info for configuring VSI queues, which
649 * is needed to enable the configurable crc stripping
652 vc_qpei->rxq_ext.crcstrip =
653 dev->data->dev_conf.rxmode.hw_strip_crc;
655 memset(&args, 0, sizeof(args));
657 (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT;
658 args.in_args = (uint8_t *)vc_vqcei;
659 args.in_args_size = size;
660 args.out_buffer = cmd_result_buffer;
661 args.out_size = I40E_AQ_BUF_SZ;
662 ret = i40evf_execute_vf_cmd(dev, &args);
664 PMD_DRV_LOG(ERR, "Failed to execute command of "
665 "I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT\n");
671 i40evf_configure_queues(struct rte_eth_dev *dev)
673 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
675 if (vf->version_major == I40E_DPDK_VERSION_MAJOR)
676 /* To support DPDK PF host */
677 return i40evf_configure_vsi_queues_ext(dev);
679 /* To support Linux PF host */
680 return i40evf_configure_vsi_queues(dev);
684 i40evf_config_irq_map(struct rte_eth_dev *dev)
686 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
687 struct vf_cmd_info args;
688 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_irq_map_info) + \
689 sizeof(struct i40e_virtchnl_vector_map)];
690 struct i40e_virtchnl_irq_map_info *map_info;
692 map_info = (struct i40e_virtchnl_irq_map_info *)cmd_buffer;
693 map_info->num_vectors = 1;
694 map_info->vecmap[0].rxitr_idx = RTE_LIBRTE_I40E_ITR_INTERVAL / 2;
695 map_info->vecmap[0].txitr_idx = RTE_LIBRTE_I40E_ITR_INTERVAL / 2;
696 map_info->vecmap[0].vsi_id = vf->vsi_res->vsi_id;
697 /* Alway use default dynamic MSIX interrupt */
698 map_info->vecmap[0].vector_id = I40EVF_VSI_DEFAULT_MSIX_INTR;
699 /* Don't map any tx queue */
700 map_info->vecmap[0].txq_map = 0;
701 map_info->vecmap[0].rxq_map = 0;
702 for (i = 0; i < dev->data->nb_rx_queues; i++)
703 map_info->vecmap[0].rxq_map |= 1 << i;
705 args.ops = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
706 args.in_args = (u8 *)cmd_buffer;
707 args.in_args_size = sizeof(cmd_buffer);
708 args.out_buffer = cmd_result_buffer;
709 args.out_size = I40E_AQ_BUF_SZ;
710 err = i40evf_execute_vf_cmd(dev, &args);
712 PMD_DRV_LOG(ERR, "fail to execute command OP_ENABLE_QUEUES");
718 i40evf_switch_queue(struct rte_eth_dev *dev, bool isrx, uint16_t qid,
721 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
722 struct i40e_virtchnl_queue_select queue_select;
724 struct vf_cmd_info args;
725 memset(&queue_select, 0, sizeof(queue_select));
726 queue_select.vsi_id = vf->vsi_res->vsi_id;
729 queue_select.rx_queues |= 1 << qid;
731 queue_select.tx_queues |= 1 << qid;
734 args.ops = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
736 args.ops = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
737 args.in_args = (u8 *)&queue_select;
738 args.in_args_size = sizeof(queue_select);
739 args.out_buffer = cmd_result_buffer;
740 args.out_size = I40E_AQ_BUF_SZ;
741 err = i40evf_execute_vf_cmd(dev, &args);
743 PMD_DRV_LOG(ERR, "fail to switch %s %u %s",
744 isrx ? "RX" : "TX", qid, on ? "on" : "off");
750 i40evf_start_queues(struct rte_eth_dev *dev)
752 struct rte_eth_dev_data *dev_data = dev->data;
754 struct i40e_rx_queue *rxq;
755 struct i40e_tx_queue *txq;
757 for (i = 0; i < dev->data->nb_rx_queues; i++) {
758 rxq = dev_data->rx_queues[i];
759 if (rxq->rx_deferred_start)
761 if (i40evf_dev_rx_queue_start(dev, i) != 0) {
762 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
767 for (i = 0; i < dev->data->nb_tx_queues; i++) {
768 txq = dev_data->tx_queues[i];
769 if (txq->tx_deferred_start)
771 if (i40evf_dev_tx_queue_start(dev, i) != 0) {
772 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
781 i40evf_stop_queues(struct rte_eth_dev *dev)
785 /* Stop TX queues first */
786 for (i = 0; i < dev->data->nb_tx_queues; i++) {
787 if (i40evf_dev_tx_queue_stop(dev, i) != 0) {
788 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
793 /* Then stop RX queues */
794 for (i = 0; i < dev->data->nb_rx_queues; i++) {
795 if (i40evf_dev_rx_queue_stop(dev, i) != 0) {
796 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
805 i40evf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
807 struct i40e_virtchnl_ether_addr_list *list;
808 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
809 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
810 sizeof(struct i40e_virtchnl_ether_addr)];
812 struct vf_cmd_info args;
814 if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
815 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
816 addr->addr_bytes[0], addr->addr_bytes[1],
817 addr->addr_bytes[2], addr->addr_bytes[3],
818 addr->addr_bytes[4], addr->addr_bytes[5]);
822 list = (struct i40e_virtchnl_ether_addr_list *)cmd_buffer;
823 list->vsi_id = vf->vsi_res->vsi_id;
824 list->num_elements = 1;
825 (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
826 sizeof(addr->addr_bytes));
828 args.ops = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
829 args.in_args = cmd_buffer;
830 args.in_args_size = sizeof(cmd_buffer);
831 args.out_buffer = cmd_result_buffer;
832 args.out_size = I40E_AQ_BUF_SZ;
833 err = i40evf_execute_vf_cmd(dev, &args);
835 PMD_DRV_LOG(ERR, "fail to execute command "
836 "OP_ADD_ETHER_ADDRESS");
842 i40evf_del_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
844 struct i40e_virtchnl_ether_addr_list *list;
845 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
846 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_ether_addr_list) + \
847 sizeof(struct i40e_virtchnl_ether_addr)];
849 struct vf_cmd_info args;
851 if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
852 PMD_DRV_LOG(ERR, "Invalid mac:%x-%x-%x-%x-%x-%x",
853 addr->addr_bytes[0], addr->addr_bytes[1],
854 addr->addr_bytes[2], addr->addr_bytes[3],
855 addr->addr_bytes[4], addr->addr_bytes[5]);
859 list = (struct i40e_virtchnl_ether_addr_list *)cmd_buffer;
860 list->vsi_id = vf->vsi_res->vsi_id;
861 list->num_elements = 1;
862 (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
863 sizeof(addr->addr_bytes));
865 args.ops = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
866 args.in_args = cmd_buffer;
867 args.in_args_size = sizeof(cmd_buffer);
868 args.out_buffer = cmd_result_buffer;
869 args.out_size = I40E_AQ_BUF_SZ;
870 err = i40evf_execute_vf_cmd(dev, &args);
872 PMD_DRV_LOG(ERR, "fail to execute command "
873 "OP_DEL_ETHER_ADDRESS");
879 i40evf_get_statics(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
881 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
882 struct i40e_virtchnl_queue_select q_stats;
883 struct i40e_eth_stats *pstats;
885 struct vf_cmd_info args;
887 memset(&q_stats, 0, sizeof(q_stats));
888 q_stats.vsi_id = vf->vsi_res->vsi_id;
889 args.ops = I40E_VIRTCHNL_OP_GET_STATS;
890 args.in_args = (u8 *)&q_stats;
891 args.in_args_size = sizeof(q_stats);
892 args.out_buffer = cmd_result_buffer;
893 args.out_size = I40E_AQ_BUF_SZ;
895 err = i40evf_execute_vf_cmd(dev, &args);
897 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
900 pstats = (struct i40e_eth_stats *)args.out_buffer;
901 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
902 pstats->rx_broadcast;
903 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
905 stats->ierrors = pstats->rx_discards;
906 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
907 stats->ibytes = pstats->rx_bytes;
908 stats->obytes = pstats->tx_bytes;
914 i40evf_add_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
916 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
917 struct i40e_virtchnl_vlan_filter_list *vlan_list;
918 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_vlan_filter_list) +
921 struct vf_cmd_info args;
923 vlan_list = (struct i40e_virtchnl_vlan_filter_list *)cmd_buffer;
924 vlan_list->vsi_id = vf->vsi_res->vsi_id;
925 vlan_list->num_elements = 1;
926 vlan_list->vlan_id[0] = vlanid;
928 args.ops = I40E_VIRTCHNL_OP_ADD_VLAN;
929 args.in_args = (u8 *)&cmd_buffer;
930 args.in_args_size = sizeof(cmd_buffer);
931 args.out_buffer = cmd_result_buffer;
932 args.out_size = I40E_AQ_BUF_SZ;
933 err = i40evf_execute_vf_cmd(dev, &args);
935 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_VLAN");
941 i40evf_del_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
943 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
944 struct i40e_virtchnl_vlan_filter_list *vlan_list;
945 uint8_t cmd_buffer[sizeof(struct i40e_virtchnl_vlan_filter_list) +
948 struct vf_cmd_info args;
950 vlan_list = (struct i40e_virtchnl_vlan_filter_list *)cmd_buffer;
951 vlan_list->vsi_id = vf->vsi_res->vsi_id;
952 vlan_list->num_elements = 1;
953 vlan_list->vlan_id[0] = vlanid;
955 args.ops = I40E_VIRTCHNL_OP_DEL_VLAN;
956 args.in_args = (u8 *)&cmd_buffer;
957 args.in_args_size = sizeof(cmd_buffer);
958 args.out_buffer = cmd_result_buffer;
959 args.out_size = I40E_AQ_BUF_SZ;
960 err = i40evf_execute_vf_cmd(dev, &args);
962 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_VLAN");
968 i40evf_get_link_status(struct rte_eth_dev *dev, struct rte_eth_link *link)
971 struct vf_cmd_info args;
972 struct rte_eth_link *new_link;
974 args.ops = (enum i40e_virtchnl_ops)I40E_VIRTCHNL_OP_GET_LINK_STAT;
976 args.in_args_size = 0;
977 args.out_buffer = cmd_result_buffer;
978 args.out_size = I40E_AQ_BUF_SZ;
979 err = i40evf_execute_vf_cmd(dev, &args);
981 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_LINK_STAT");
985 new_link = (struct rte_eth_link *)args.out_buffer;
986 (void)rte_memcpy(link, new_link, sizeof(*link));
991 static struct rte_pci_id pci_id_i40evf_map[] = {
992 #define RTE_PCI_DEV_ID_DECL_I40EVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
993 #include "rte_pci_dev_ids.h"
994 { .vendor_id = 0, /* sentinel */ },
998 i40evf_dev_atomic_write_link_status(struct rte_eth_dev *dev,
999 struct rte_eth_link *link)
1001 struct rte_eth_link *dst = &(dev->data->dev_link);
1002 struct rte_eth_link *src = link;
1004 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1005 *(uint64_t *)src) == 0)
1012 i40evf_reset_vf(struct i40e_hw *hw)
1016 if (i40e_vf_reset(hw) != I40E_SUCCESS) {
1017 PMD_INIT_LOG(ERR, "Reset VF NIC failed");
1021 * After issuing vf reset command to pf, pf won't necessarily
1022 * reset vf, it depends on what state it exactly is. If it's not
1023 * initialized yet, it won't have vf reset since it's in a certain
1024 * state. If not, it will try to reset. Even vf is reset, pf will
1025 * set I40E_VFGEN_RSTAT to COMPLETE first, then wait 10ms and set
1026 * it to ACTIVE. In this duration, vf may not catch the moment that
1027 * COMPLETE is set. So, for vf, we'll try to wait a long time.
1031 for (i = 0; i < MAX_RESET_WAIT_CNT; i++) {
1032 reset = rd32(hw, I40E_VFGEN_RSTAT) &
1033 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1034 reset = reset >> I40E_VFGEN_RSTAT_VFR_STATE_SHIFT;
1035 if (I40E_VFR_COMPLETED == reset || I40E_VFR_VFACTIVE == reset)
1041 if (i >= MAX_RESET_WAIT_CNT) {
1042 PMD_INIT_LOG(ERR, "Reset VF NIC failed");
1050 i40evf_init_vf(struct rte_eth_dev *dev)
1053 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1054 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1056 vf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1057 vf->dev_data = dev->data;
1058 err = i40evf_set_mac_type(hw);
1060 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1064 i40e_init_adminq_parameter(hw);
1065 err = i40e_init_adminq(hw);
1067 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1072 /* Reset VF and wait until it's complete */
1073 if (i40evf_reset_vf(hw)) {
1074 PMD_INIT_LOG(ERR, "reset NIC failed");
1078 /* VF reset, shutdown admin queue and initialize again */
1079 if (i40e_shutdown_adminq(hw) != I40E_SUCCESS) {
1080 PMD_INIT_LOG(ERR, "i40e_shutdown_adminq failed");
1084 i40e_init_adminq_parameter(hw);
1085 if (i40e_init_adminq(hw) != I40E_SUCCESS) {
1086 PMD_INIT_LOG(ERR, "init_adminq failed");
1089 if (i40evf_check_api_version(dev) != 0) {
1090 PMD_INIT_LOG(ERR, "check_api version failed");
1093 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
1094 (I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource));
1095 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1097 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1101 if (i40evf_get_vf_resource(dev) != 0) {
1102 PMD_INIT_LOG(ERR, "i40evf_get_vf_config failed");
1106 /* got VF config message back from PF, now we can parse it */
1107 for (i = 0; i < vf->vf_res->num_vsis; i++) {
1108 if (vf->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
1109 vf->vsi_res = &vf->vf_res->vsi_res[i];
1113 PMD_INIT_LOG(ERR, "no LAN VSI found");
1117 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
1118 vf->vsi.type = vf->vsi_res->vsi_type;
1119 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
1121 /* check mac addr, if it's not valid, genrate one */
1122 if (I40E_SUCCESS != i40e_validate_mac_addr(\
1123 vf->vsi_res->default_mac_addr))
1124 eth_random_addr(vf->vsi_res->default_mac_addr);
1126 ether_addr_copy((struct ether_addr *)vf->vsi_res->default_mac_addr,
1127 (struct ether_addr *)hw->mac.addr);
1132 rte_free(vf->vf_res);
1134 i40e_shutdown_adminq(hw); /* ignore error */
1140 i40evf_dev_init(__rte_unused struct eth_driver *eth_drv,
1141 struct rte_eth_dev *eth_dev)
1143 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(\
1144 eth_dev->data->dev_private);
1146 PMD_INIT_FUNC_TRACE();
1148 /* assign ops func pointer */
1149 eth_dev->dev_ops = &i40evf_eth_dev_ops;
1150 eth_dev->rx_pkt_burst = &i40e_recv_pkts;
1151 eth_dev->tx_pkt_burst = &i40e_xmit_pkts;
1154 * For secondary processes, we don't initialise any further as primary
1155 * has already done this work.
1157 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1158 if (eth_dev->data->scattered_rx)
1159 eth_dev->rx_pkt_burst = i40e_recv_scattered_pkts;
1163 hw->vendor_id = eth_dev->pci_dev->id.vendor_id;
1164 hw->device_id = eth_dev->pci_dev->id.device_id;
1165 hw->subsystem_vendor_id = eth_dev->pci_dev->id.subsystem_vendor_id;
1166 hw->subsystem_device_id = eth_dev->pci_dev->id.subsystem_device_id;
1167 hw->bus.device = eth_dev->pci_dev->addr.devid;
1168 hw->bus.func = eth_dev->pci_dev->addr.function;
1169 hw->hw_addr = (void *)eth_dev->pci_dev->mem_resource[0].addr;
1171 if(i40evf_init_vf(eth_dev) != 0) {
1172 PMD_INIT_LOG(ERR, "Init vf failed");
1177 eth_dev->data->mac_addrs = rte_zmalloc("i40evf_mac",
1179 if (eth_dev->data->mac_addrs == NULL) {
1180 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
1181 "store MAC addresses", ETHER_ADDR_LEN);
1184 ether_addr_copy((struct ether_addr *)hw->mac.addr,
1185 (struct ether_addr *)eth_dev->data->mac_addrs);
1191 * virtual function driver struct
1193 static struct eth_driver rte_i40evf_pmd = {
1195 .name = "rte_i40evf_pmd",
1196 .id_table = pci_id_i40evf_map,
1197 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1199 .eth_dev_init = i40evf_dev_init,
1200 .dev_private_size = sizeof(struct i40e_vf),
1204 * VF Driver initialization routine.
1205 * Invoked one at EAL init time.
1206 * Register itself as the [Virtual Poll Mode] Driver of PCI Fortville devices.
1209 rte_i40evf_pmd_init(const char *name __rte_unused,
1210 const char *params __rte_unused)
1212 PMD_INIT_FUNC_TRACE();
1214 rte_eth_driver_register(&rte_i40evf_pmd);
1219 static struct rte_driver rte_i40evf_driver = {
1221 .init = rte_i40evf_pmd_init,
1224 PMD_REGISTER_DRIVER(rte_i40evf_driver);
1227 i40evf_dev_configure(struct rte_eth_dev *dev)
1229 return i40evf_init_vlan(dev);
1233 i40evf_init_vlan(struct rte_eth_dev *dev)
1235 struct rte_eth_dev_data *data = dev->data;
1238 /* Apply vlan offload setting */
1239 i40evf_vlan_offload_set(dev, ETH_VLAN_STRIP_MASK);
1241 /* Apply pvid setting */
1242 ret = i40evf_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
1243 data->dev_conf.txmode.hw_vlan_insert_pvid);
1248 i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1250 bool enable_vlan_strip = 0;
1251 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1252 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1254 /* Linux pf host doesn't support vlan offload yet */
1255 if (vf->version_major == I40E_DPDK_VERSION_MAJOR) {
1256 /* Vlan stripping setting */
1257 if (mask & ETH_VLAN_STRIP_MASK) {
1258 /* Enable or disable VLAN stripping */
1259 if (dev_conf->rxmode.hw_vlan_strip)
1260 enable_vlan_strip = 1;
1262 enable_vlan_strip = 0;
1264 i40evf_config_vlan_offload(dev, enable_vlan_strip);
1270 i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
1272 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1273 struct i40e_vsi_vlan_pvid_info info;
1274 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1276 memset(&info, 0, sizeof(info));
1279 /* Linux pf host don't support vlan offload yet */
1280 if (vf->version_major == I40E_DPDK_VERSION_MAJOR) {
1282 info.config.pvid = pvid;
1284 info.config.reject.tagged =
1285 dev_conf->txmode.hw_vlan_reject_tagged;
1286 info.config.reject.untagged =
1287 dev_conf->txmode.hw_vlan_reject_untagged;
1289 return i40evf_config_vlan_pvid(dev, &info);
1296 i40evf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1298 struct i40e_rx_queue *rxq;
1300 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1302 PMD_INIT_FUNC_TRACE();
1304 if (rx_queue_id < dev->data->nb_rx_queues) {
1305 rxq = dev->data->rx_queues[rx_queue_id];
1307 err = i40e_alloc_rx_queue_mbufs(rxq);
1309 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1315 /* Init the RX tail register. */
1316 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1317 I40EVF_WRITE_FLUSH(hw);
1319 /* Ready to switch the queue on */
1320 err = i40evf_switch_queue(dev, TRUE, rx_queue_id, TRUE);
1323 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1331 i40evf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1333 struct i40e_rx_queue *rxq;
1336 if (rx_queue_id < dev->data->nb_rx_queues) {
1337 rxq = dev->data->rx_queues[rx_queue_id];
1339 err = i40evf_switch_queue(dev, TRUE, rx_queue_id, FALSE);
1342 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1347 i40e_rx_queue_release_mbufs(rxq);
1348 i40e_reset_rx_queue(rxq);
1355 i40evf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1359 PMD_INIT_FUNC_TRACE();
1361 if (tx_queue_id < dev->data->nb_tx_queues) {
1363 /* Ready to switch the queue on */
1364 err = i40evf_switch_queue(dev, FALSE, tx_queue_id, TRUE);
1367 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1375 i40evf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1377 struct i40e_tx_queue *txq;
1380 if (tx_queue_id < dev->data->nb_tx_queues) {
1381 txq = dev->data->tx_queues[tx_queue_id];
1383 err = i40evf_switch_queue(dev, FALSE, tx_queue_id, FALSE);
1386 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
1391 i40e_tx_queue_release_mbufs(txq);
1392 i40e_reset_tx_queue(txq);
1399 i40evf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1404 ret = i40evf_add_vlan(dev, vlan_id);
1406 ret = i40evf_del_vlan(dev,vlan_id);
1412 i40evf_rx_init(struct rte_eth_dev *dev)
1414 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1416 struct i40e_rx_queue **rxq =
1417 (struct i40e_rx_queue **)dev->data->rx_queues;
1418 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1420 i40evf_config_rss(vf);
1421 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1422 rxq[i]->qrx_tail = hw->hw_addr + I40E_QRX_TAIL1(i);
1423 I40E_PCI_REG_WRITE(rxq[i]->qrx_tail, rxq[i]->nb_rx_desc - 1);
1426 /* Flush the operation to write registers */
1427 I40EVF_WRITE_FLUSH(hw);
1433 i40evf_tx_init(struct rte_eth_dev *dev)
1436 struct i40e_tx_queue **txq =
1437 (struct i40e_tx_queue **)dev->data->tx_queues;
1438 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1440 for (i = 0; i < dev->data->nb_tx_queues; i++)
1441 txq[i]->qtx_tail = hw->hw_addr + I40E_QTX_TAIL1(i);
1445 i40evf_enable_queues_intr(struct i40e_hw *hw)
1447 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1448 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
1449 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
1453 i40evf_disable_queues_intr(struct i40e_hw *hw)
1455 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1460 i40evf_dev_start(struct rte_eth_dev *dev)
1462 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1463 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1464 struct ether_addr mac_addr;
1466 PMD_INIT_FUNC_TRACE();
1468 vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
1469 if (dev->data->dev_conf.rxmode.jumbo_frame == 1) {
1470 if (vf->max_pkt_len <= ETHER_MAX_LEN ||
1471 vf->max_pkt_len > I40E_FRAME_SIZE_MAX) {
1472 PMD_DRV_LOG(ERR, "maximum packet length must "
1473 "be larger than %u and smaller than %u,"
1474 "as jumbo frame is enabled",
1475 (uint32_t)ETHER_MAX_LEN,
1476 (uint32_t)I40E_FRAME_SIZE_MAX);
1477 return I40E_ERR_CONFIG;
1480 if (vf->max_pkt_len < ETHER_MIN_LEN ||
1481 vf->max_pkt_len > ETHER_MAX_LEN) {
1482 PMD_DRV_LOG(ERR, "maximum packet length must be "
1483 "larger than %u and smaller than %u, "
1484 "as jumbo frame is disabled",
1485 (uint32_t)ETHER_MIN_LEN,
1486 (uint32_t)ETHER_MAX_LEN);
1487 return I40E_ERR_CONFIG;
1491 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
1492 dev->data->nb_tx_queues);
1494 if (i40evf_rx_init(dev) != 0){
1495 PMD_DRV_LOG(ERR, "failed to do RX init");
1499 i40evf_tx_init(dev);
1501 if (i40evf_configure_queues(dev) != 0) {
1502 PMD_DRV_LOG(ERR, "configure queues failed");
1505 if (i40evf_config_irq_map(dev)) {
1506 PMD_DRV_LOG(ERR, "config_irq_map failed");
1511 (void)rte_memcpy(mac_addr.addr_bytes, hw->mac.addr,
1512 sizeof(mac_addr.addr_bytes));
1513 if (i40evf_add_mac_addr(dev, &mac_addr)) {
1514 PMD_DRV_LOG(ERR, "Failed to add mac addr");
1518 if (i40evf_start_queues(dev) != 0) {
1519 PMD_DRV_LOG(ERR, "enable queues failed");
1523 i40evf_enable_queues_intr(hw);
1527 i40evf_del_mac_addr(dev, &mac_addr);
1533 i40evf_dev_stop(struct rte_eth_dev *dev)
1535 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1537 PMD_INIT_FUNC_TRACE();
1539 i40evf_disable_queues_intr(hw);
1540 i40evf_stop_queues(dev);
1544 i40evf_dev_link_update(struct rte_eth_dev *dev,
1545 __rte_unused int wait_to_complete)
1547 struct rte_eth_link new_link;
1548 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1550 * DPDK pf host provide interfacet to acquire link status
1551 * while Linux driver does not
1553 if (vf->version_major == I40E_DPDK_VERSION_MAJOR)
1554 i40evf_get_link_status(dev, &new_link);
1556 /* Always assume it's up, for Linux driver PF host */
1557 new_link.link_duplex = ETH_LINK_AUTONEG_DUPLEX;
1558 new_link.link_speed = ETH_LINK_SPEED_10000;
1559 new_link.link_status = 1;
1561 i40evf_dev_atomic_write_link_status(dev, &new_link);
1567 i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1569 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1572 /* If enabled, just return */
1573 if (vf->promisc_unicast_enabled)
1576 ret = i40evf_config_promisc(dev, 1, vf->promisc_multicast_enabled);
1578 vf->promisc_unicast_enabled = TRUE;
1582 i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1584 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1587 /* If disabled, just return */
1588 if (!vf->promisc_unicast_enabled)
1591 ret = i40evf_config_promisc(dev, 0, vf->promisc_multicast_enabled);
1593 vf->promisc_unicast_enabled = FALSE;
1597 i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1599 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1602 /* If enabled, just return */
1603 if (vf->promisc_multicast_enabled)
1606 ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 1);
1608 vf->promisc_multicast_enabled = TRUE;
1612 i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1614 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1617 /* If enabled, just return */
1618 if (!vf->promisc_multicast_enabled)
1621 ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 0);
1623 vf->promisc_multicast_enabled = FALSE;
1627 i40evf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1629 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1631 memset(dev_info, 0, sizeof(*dev_info));
1632 dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
1633 dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
1634 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
1635 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
1639 i40evf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1641 memset(stats, 0, sizeof(*stats));
1642 if (i40evf_get_statics(dev, stats))
1643 PMD_DRV_LOG(ERR, "Get statics failed");
1647 i40evf_dev_close(struct rte_eth_dev *dev)
1649 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1651 i40evf_dev_stop(dev);
1652 i40evf_reset_vf(hw);
1653 i40e_shutdown_adminq(hw);
1657 i40evf_hw_rss_hash_set(struct i40e_hw *hw, struct rte_eth_rss_conf *rss_conf)
1660 uint8_t hash_key_len;
1661 uint64_t rss_hf, hena;
1663 hash_key = (uint32_t *)(rss_conf->rss_key);
1664 hash_key_len = rss_conf->rss_key_len;
1665 if (hash_key != NULL && hash_key_len >=
1666 (I40E_VFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
1669 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1670 I40E_WRITE_REG(hw, I40E_VFQF_HKEY(i), hash_key[i]);
1673 rss_hf = rss_conf->rss_hf;
1674 hena = (uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(0));
1675 hena |= ((uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(1))) << 32;
1676 hena &= ~I40E_RSS_HENA_ALL;
1677 hena |= i40e_config_hena(rss_hf);
1678 I40E_WRITE_REG(hw, I40E_VFQF_HENA(0), (uint32_t)hena);
1679 I40E_WRITE_REG(hw, I40E_VFQF_HENA(1), (uint32_t)(hena >> 32));
1680 I40EVF_WRITE_FLUSH(hw);
1686 i40evf_disable_rss(struct i40e_vf *vf)
1688 struct i40e_hw *hw = I40E_VF_TO_HW(vf);
1691 hena = (uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(0));
1692 hena |= ((uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(1))) << 32;
1693 hena &= ~I40E_RSS_HENA_ALL;
1694 I40E_WRITE_REG(hw, I40E_VFQF_HENA(0), (uint32_t)hena);
1695 I40E_WRITE_REG(hw, I40E_VFQF_HENA(1), (uint32_t)(hena >> 32));
1696 I40EVF_WRITE_FLUSH(hw);
1700 i40evf_config_rss(struct i40e_vf *vf)
1702 struct i40e_hw *hw = I40E_VF_TO_HW(vf);
1703 struct rte_eth_rss_conf rss_conf;
1704 uint32_t i, j, lut = 0, nb_q = (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
1706 if (vf->dev_data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
1707 i40evf_disable_rss(vf);
1708 PMD_DRV_LOG(DEBUG, "RSS not configured\n");
1712 /* Fill out the look up table */
1713 for (i = 0, j = 0; i < nb_q; i++, j++) {
1714 if (j >= vf->num_queue_pairs)
1716 lut = (lut << 8) | j;
1718 I40E_WRITE_REG(hw, I40E_VFQF_HLUT(i >> 2), lut);
1721 rss_conf = vf->dev_data->dev_conf.rx_adv_conf.rss_conf;
1722 if ((rss_conf.rss_hf & I40E_RSS_OFFLOAD_ALL) == 0) {
1723 i40evf_disable_rss(vf);
1724 PMD_DRV_LOG(DEBUG, "No hash flag is set\n");
1728 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len < nb_q) {
1729 /* Calculate the default hash key */
1730 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1731 rss_key_default[i] = (uint32_t)rte_rand();
1732 rss_conf.rss_key = (uint8_t *)rss_key_default;
1733 rss_conf.rss_key_len = nb_q;
1736 return i40evf_hw_rss_hash_set(hw, &rss_conf);
1740 i40evf_dev_rss_hash_update(struct rte_eth_dev *dev,
1741 struct rte_eth_rss_conf *rss_conf)
1743 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1744 uint64_t rss_hf = rss_conf->rss_hf & I40E_RSS_OFFLOAD_ALL;
1747 hena = (uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(0));
1748 hena |= ((uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(1))) << 32;
1749 if (!(hena & I40E_RSS_HENA_ALL)) { /* RSS disabled */
1750 if (rss_hf != 0) /* Enable RSS */
1756 if (rss_hf == 0) /* Disable RSS */
1759 return i40evf_hw_rss_hash_set(hw, rss_conf);
1763 i40evf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1764 struct rte_eth_rss_conf *rss_conf)
1766 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1767 uint32_t *hash_key = (uint32_t *)(rss_conf->rss_key);
1772 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1773 hash_key[i] = I40E_READ_REG(hw, I40E_VFQF_HKEY(i));
1774 rss_conf->rss_key_len = i * sizeof(uint32_t);
1776 hena = (uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(0));
1777 hena |= ((uint64_t)I40E_READ_REG(hw, I40E_VFQF_HENA(1))) << 32;
1778 rss_conf->rss_hf = i40e_parse_hena(hena);