4 * Copyright(c) 2010-2016 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>
55 #include <rte_alarm.h>
56 #include <rte_ether.h>
57 #include <rte_ethdev.h>
58 #include <rte_ethdev_pci.h>
59 #include <rte_malloc.h>
62 #include "i40e_logs.h"
63 #include "base/i40e_prototype.h"
64 #include "base/i40e_adminq_cmd.h"
65 #include "base/i40e_type.h"
67 #include "i40e_rxtx.h"
68 #include "i40e_ethdev.h"
70 #define I40EVF_VSI_DEFAULT_MSIX_INTR 1
71 #define I40EVF_VSI_DEFAULT_MSIX_INTR_LNX 0
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 virtchnl_ops ops;
80 enum i40e_status_code result;
87 enum 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 static int i40evf_dev_configure(struct rte_eth_dev *dev);
105 static int i40evf_dev_start(struct rte_eth_dev *dev);
106 static void i40evf_dev_stop(struct rte_eth_dev *dev);
107 static void i40evf_dev_info_get(struct rte_eth_dev *dev,
108 struct rte_eth_dev_info *dev_info);
109 static int i40evf_dev_link_update(struct rte_eth_dev *dev,
110 int wait_to_complete);
111 static void i40evf_dev_stats_get(struct rte_eth_dev *dev,
112 struct rte_eth_stats *stats);
113 static int i40evf_dev_xstats_get(struct rte_eth_dev *dev,
114 struct rte_eth_xstat *xstats, unsigned n);
115 static int i40evf_dev_xstats_get_names(struct rte_eth_dev *dev,
116 struct rte_eth_xstat_name *xstats_names,
118 static void i40evf_dev_xstats_reset(struct rte_eth_dev *dev);
119 static int i40evf_vlan_filter_set(struct rte_eth_dev *dev,
120 uint16_t vlan_id, int on);
121 static void i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
122 static int i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid,
124 static void i40evf_dev_close(struct rte_eth_dev *dev);
125 static void i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev);
126 static void i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev);
127 static void i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev);
128 static void i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev);
129 static int i40evf_init_vlan(struct rte_eth_dev *dev);
130 static int i40evf_dev_rx_queue_start(struct rte_eth_dev *dev,
131 uint16_t rx_queue_id);
132 static int i40evf_dev_rx_queue_stop(struct rte_eth_dev *dev,
133 uint16_t rx_queue_id);
134 static int i40evf_dev_tx_queue_start(struct rte_eth_dev *dev,
135 uint16_t tx_queue_id);
136 static int i40evf_dev_tx_queue_stop(struct rte_eth_dev *dev,
137 uint16_t tx_queue_id);
138 static int i40evf_add_mac_addr(struct rte_eth_dev *dev,
139 struct ether_addr *addr,
142 static void i40evf_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
143 static int i40evf_dev_rss_reta_update(struct rte_eth_dev *dev,
144 struct rte_eth_rss_reta_entry64 *reta_conf,
146 static int i40evf_dev_rss_reta_query(struct rte_eth_dev *dev,
147 struct rte_eth_rss_reta_entry64 *reta_conf,
149 static int i40evf_config_rss(struct i40e_vf *vf);
150 static int i40evf_dev_rss_hash_update(struct rte_eth_dev *dev,
151 struct rte_eth_rss_conf *rss_conf);
152 static int i40evf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
153 struct rte_eth_rss_conf *rss_conf);
154 static int i40evf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
155 static void i40evf_set_default_mac_addr(struct rte_eth_dev *dev,
156 struct ether_addr *mac_addr);
158 i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
160 i40evf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);
161 static void i40evf_handle_pf_event(struct rte_eth_dev *dev,
165 /* Default hash key buffer for RSS */
166 static uint32_t rss_key_default[I40E_VFQF_HKEY_MAX_INDEX + 1];
168 struct rte_i40evf_xstats_name_off {
169 char name[RTE_ETH_XSTATS_NAME_SIZE];
173 static const struct rte_i40evf_xstats_name_off rte_i40evf_stats_strings[] = {
174 {"rx_bytes", offsetof(struct i40e_eth_stats, rx_bytes)},
175 {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
176 {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
177 {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
178 {"rx_dropped_packets", offsetof(struct i40e_eth_stats, rx_discards)},
179 {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
180 rx_unknown_protocol)},
181 {"tx_bytes", offsetof(struct i40e_eth_stats, tx_bytes)},
182 {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
183 {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
184 {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
185 {"tx_dropped_packets", offsetof(struct i40e_eth_stats, tx_discards)},
186 {"tx_error_packets", offsetof(struct i40e_eth_stats, tx_errors)},
189 #define I40EVF_NB_XSTATS (sizeof(rte_i40evf_stats_strings) / \
190 sizeof(rte_i40evf_stats_strings[0]))
192 static const struct eth_dev_ops i40evf_eth_dev_ops = {
193 .dev_configure = i40evf_dev_configure,
194 .dev_start = i40evf_dev_start,
195 .dev_stop = i40evf_dev_stop,
196 .promiscuous_enable = i40evf_dev_promiscuous_enable,
197 .promiscuous_disable = i40evf_dev_promiscuous_disable,
198 .allmulticast_enable = i40evf_dev_allmulticast_enable,
199 .allmulticast_disable = i40evf_dev_allmulticast_disable,
200 .link_update = i40evf_dev_link_update,
201 .stats_get = i40evf_dev_stats_get,
202 .xstats_get = i40evf_dev_xstats_get,
203 .xstats_get_names = i40evf_dev_xstats_get_names,
204 .xstats_reset = i40evf_dev_xstats_reset,
205 .dev_close = i40evf_dev_close,
206 .dev_infos_get = i40evf_dev_info_get,
207 .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
208 .vlan_filter_set = i40evf_vlan_filter_set,
209 .vlan_offload_set = i40evf_vlan_offload_set,
210 .vlan_pvid_set = i40evf_vlan_pvid_set,
211 .rx_queue_start = i40evf_dev_rx_queue_start,
212 .rx_queue_stop = i40evf_dev_rx_queue_stop,
213 .tx_queue_start = i40evf_dev_tx_queue_start,
214 .tx_queue_stop = i40evf_dev_tx_queue_stop,
215 .rx_queue_setup = i40e_dev_rx_queue_setup,
216 .rx_queue_release = i40e_dev_rx_queue_release,
217 .rx_queue_intr_enable = i40evf_dev_rx_queue_intr_enable,
218 .rx_queue_intr_disable = i40evf_dev_rx_queue_intr_disable,
219 .rx_descriptor_done = i40e_dev_rx_descriptor_done,
220 .rx_descriptor_status = i40e_dev_rx_descriptor_status,
221 .tx_descriptor_status = i40e_dev_tx_descriptor_status,
222 .tx_queue_setup = i40e_dev_tx_queue_setup,
223 .tx_queue_release = i40e_dev_tx_queue_release,
224 .rx_queue_count = i40e_dev_rx_queue_count,
225 .rxq_info_get = i40e_rxq_info_get,
226 .txq_info_get = i40e_txq_info_get,
227 .mac_addr_add = i40evf_add_mac_addr,
228 .mac_addr_remove = i40evf_del_mac_addr,
229 .reta_update = i40evf_dev_rss_reta_update,
230 .reta_query = i40evf_dev_rss_reta_query,
231 .rss_hash_update = i40evf_dev_rss_hash_update,
232 .rss_hash_conf_get = i40evf_dev_rss_hash_conf_get,
233 .mtu_set = i40evf_dev_mtu_set,
234 .mac_addr_set = i40evf_set_default_mac_addr,
238 * Read data in admin queue to get msg from pf driver
240 static enum i40evf_aq_result
241 i40evf_read_pfmsg(struct rte_eth_dev *dev, struct i40evf_arq_msg_info *data)
243 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
244 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
245 struct i40e_arq_event_info event;
246 enum virtchnl_ops opcode;
247 enum i40e_status_code retval;
249 enum i40evf_aq_result result = I40EVF_MSG_NON;
251 event.buf_len = data->buf_len;
252 event.msg_buf = data->msg;
253 ret = i40e_clean_arq_element(hw, &event, NULL);
254 /* Can't read any msg from adminQ */
256 if (ret != I40E_ERR_ADMIN_QUEUE_NO_WORK)
257 result = I40EVF_MSG_ERR;
261 opcode = (enum virtchnl_ops)rte_le_to_cpu_32(event.desc.cookie_high);
262 retval = (enum i40e_status_code)rte_le_to_cpu_32(event.desc.cookie_low);
264 if (opcode == VIRTCHNL_OP_EVENT) {
265 struct virtchnl_pf_event *vpe =
266 (struct virtchnl_pf_event *)event.msg_buf;
268 result = I40EVF_MSG_SYS;
269 switch (vpe->event) {
270 case VIRTCHNL_EVENT_LINK_CHANGE:
272 vpe->event_data.link_event.link_status;
274 vpe->event_data.link_event.link_speed;
275 vf->pend_msg |= PFMSG_LINK_CHANGE;
276 PMD_DRV_LOG(INFO, "Link status update:%s",
277 vf->link_up ? "up" : "down");
279 case VIRTCHNL_EVENT_RESET_IMPENDING:
281 vf->pend_msg |= PFMSG_RESET_IMPENDING;
282 PMD_DRV_LOG(INFO, "vf is reseting");
284 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
285 vf->dev_closed = true;
286 vf->pend_msg |= PFMSG_DRIVER_CLOSE;
287 PMD_DRV_LOG(INFO, "PF driver closed");
290 PMD_DRV_LOG(ERR, "%s: Unknown event %d from pf",
291 __func__, vpe->event);
294 /* async reply msg on command issued by vf previously */
295 result = I40EVF_MSG_CMD;
296 /* Actual data length read from PF */
297 data->msg_len = event.msg_len;
300 data->result = retval;
307 * clear current command. Only call in case execute
308 * _atomic_set_cmd successfully.
311 _clear_cmd(struct i40e_vf *vf)
314 vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
318 * Check there is pending cmd in execution. If none, set new command.
321 _atomic_set_cmd(struct i40e_vf *vf, enum virtchnl_ops ops)
323 int ret = rte_atomic32_cmpset(&vf->pend_cmd,
324 VIRTCHNL_OP_UNKNOWN, ops);
327 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
332 #define MAX_TRY_TIMES 200
333 #define ASQ_DELAY_MS 10
336 i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
338 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
339 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
340 struct i40evf_arq_msg_info info;
341 enum i40evf_aq_result ret;
344 if (_atomic_set_cmd(vf, args->ops))
347 info.msg = args->out_buffer;
348 info.buf_len = args->out_size;
349 info.ops = VIRTCHNL_OP_UNKNOWN;
350 info.result = I40E_SUCCESS;
352 err = i40e_aq_send_msg_to_pf(hw, args->ops, I40E_SUCCESS,
353 args->in_args, args->in_args_size, NULL);
355 PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops);
361 case VIRTCHNL_OP_RESET_VF:
362 /*no need to process in this function */
365 case VIRTCHNL_OP_VERSION:
366 case VIRTCHNL_OP_GET_VF_RESOURCES:
367 /* for init adminq commands, need to poll the response */
370 ret = i40evf_read_pfmsg(dev, &info);
371 vf->cmd_retval = info.result;
372 if (ret == I40EVF_MSG_CMD) {
375 } else if (ret == I40EVF_MSG_ERR)
377 rte_delay_ms(ASQ_DELAY_MS);
378 /* If don't read msg or read sys event, continue */
379 } while (i++ < MAX_TRY_TIMES);
384 /* for other adminq in running time, waiting the cmd done flag */
387 if (vf->pend_cmd == VIRTCHNL_OP_UNKNOWN) {
391 rte_delay_ms(ASQ_DELAY_MS);
392 /* If don't read msg or read sys event, continue */
393 } while (i++ < MAX_TRY_TIMES);
397 return err | vf->cmd_retval;
401 * Check API version with sync wait until version read or fail from admin queue
404 i40evf_check_api_version(struct rte_eth_dev *dev)
406 struct virtchnl_version_info version, *pver;
408 struct vf_cmd_info args;
409 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
411 version.major = VIRTCHNL_VERSION_MAJOR;
412 version.minor = VIRTCHNL_VERSION_MINOR;
414 args.ops = VIRTCHNL_OP_VERSION;
415 args.in_args = (uint8_t *)&version;
416 args.in_args_size = sizeof(version);
417 args.out_buffer = vf->aq_resp;
418 args.out_size = I40E_AQ_BUF_SZ;
420 err = i40evf_execute_vf_cmd(dev, &args);
422 PMD_INIT_LOG(ERR, "fail to execute command OP_VERSION");
426 pver = (struct virtchnl_version_info *)args.out_buffer;
427 vf->version_major = pver->major;
428 vf->version_minor = pver->minor;
429 if (vf->version_major == I40E_DPDK_VERSION_MAJOR)
430 PMD_DRV_LOG(INFO, "Peer is DPDK PF host");
431 else if ((vf->version_major == VIRTCHNL_VERSION_MAJOR) &&
432 (vf->version_minor <= VIRTCHNL_VERSION_MINOR))
433 PMD_DRV_LOG(INFO, "Peer is Linux PF host");
435 PMD_INIT_LOG(ERR, "PF/VF API version mismatch:(%u.%u)-(%u.%u)",
436 vf->version_major, vf->version_minor,
437 VIRTCHNL_VERSION_MAJOR,
438 VIRTCHNL_VERSION_MINOR);
446 i40evf_get_vf_resource(struct rte_eth_dev *dev)
448 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
449 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
451 struct vf_cmd_info args;
454 args.ops = VIRTCHNL_OP_GET_VF_RESOURCES;
455 args.out_buffer = vf->aq_resp;
456 args.out_size = I40E_AQ_BUF_SZ;
458 caps = VIRTCHNL_VF_OFFLOAD_L2 |
459 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
460 VIRTCHNL_VF_OFFLOAD_RSS_REG |
461 VIRTCHNL_VF_OFFLOAD_VLAN |
462 VIRTCHNL_VF_OFFLOAD_RX_POLLING;
463 args.in_args = (uint8_t *)∩︀
464 args.in_args_size = sizeof(caps);
467 args.in_args_size = 0;
469 err = i40evf_execute_vf_cmd(dev, &args);
472 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_VF_RESOURCE");
476 len = sizeof(struct virtchnl_vf_resource) +
477 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
479 (void)rte_memcpy(vf->vf_res, args.out_buffer,
480 RTE_MIN(args.out_size, len));
481 i40e_vf_parse_hw_config(hw, vf->vf_res);
487 i40evf_config_promisc(struct rte_eth_dev *dev,
489 bool enable_multicast)
491 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
493 struct vf_cmd_info args;
494 struct virtchnl_promisc_info promisc;
497 promisc.vsi_id = vf->vsi_res->vsi_id;
500 promisc.flags |= FLAG_VF_UNICAST_PROMISC;
502 if (enable_multicast)
503 promisc.flags |= FLAG_VF_MULTICAST_PROMISC;
505 args.ops = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
506 args.in_args = (uint8_t *)&promisc;
507 args.in_args_size = sizeof(promisc);
508 args.out_buffer = vf->aq_resp;
509 args.out_size = I40E_AQ_BUF_SZ;
511 err = i40evf_execute_vf_cmd(dev, &args);
514 PMD_DRV_LOG(ERR, "fail to execute command "
515 "CONFIG_PROMISCUOUS_MODE");
520 i40evf_enable_vlan_strip(struct rte_eth_dev *dev)
522 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
523 struct vf_cmd_info args;
526 memset(&args, 0, sizeof(args));
527 args.ops = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
529 args.in_args_size = 0;
530 args.out_buffer = vf->aq_resp;
531 args.out_size = I40E_AQ_BUF_SZ;
532 ret = i40evf_execute_vf_cmd(dev, &args);
534 PMD_DRV_LOG(ERR, "Failed to execute command of "
535 "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING");
541 i40evf_disable_vlan_strip(struct rte_eth_dev *dev)
543 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
544 struct vf_cmd_info args;
547 memset(&args, 0, sizeof(args));
548 args.ops = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
550 args.in_args_size = 0;
551 args.out_buffer = vf->aq_resp;
552 args.out_size = I40E_AQ_BUF_SZ;
553 ret = i40evf_execute_vf_cmd(dev, &args);
555 PMD_DRV_LOG(ERR, "Failed to execute command of "
556 "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING");
562 i40evf_config_vlan_pvid(struct rte_eth_dev *dev,
563 struct i40e_vsi_vlan_pvid_info *info)
565 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
567 struct vf_cmd_info args;
568 struct virtchnl_pvid_info tpid_info;
571 PMD_DRV_LOG(ERR, "invalid parameters");
572 return I40E_ERR_PARAM;
575 memset(&tpid_info, 0, sizeof(tpid_info));
576 tpid_info.vsi_id = vf->vsi_res->vsi_id;
577 (void)rte_memcpy(&tpid_info.info, info, sizeof(*info));
579 args.ops = (enum virtchnl_ops)I40E_VIRTCHNL_OP_CFG_VLAN_PVID;
580 args.in_args = (uint8_t *)&tpid_info;
581 args.in_args_size = sizeof(tpid_info);
582 args.out_buffer = vf->aq_resp;
583 args.out_size = I40E_AQ_BUF_SZ;
585 err = i40evf_execute_vf_cmd(dev, &args);
587 PMD_DRV_LOG(ERR, "fail to execute command CFG_VLAN_PVID");
593 i40evf_fill_virtchnl_vsi_txq_info(struct virtchnl_txq_info *txq_info,
597 struct i40e_tx_queue *txq)
599 txq_info->vsi_id = vsi_id;
600 txq_info->queue_id = queue_id;
601 if (queue_id < nb_txq) {
602 txq_info->ring_len = txq->nb_tx_desc;
603 txq_info->dma_ring_addr = txq->tx_ring_phys_addr;
608 i40evf_fill_virtchnl_vsi_rxq_info(struct virtchnl_rxq_info *rxq_info,
612 uint32_t max_pkt_size,
613 struct i40e_rx_queue *rxq)
615 rxq_info->vsi_id = vsi_id;
616 rxq_info->queue_id = queue_id;
617 rxq_info->max_pkt_size = max_pkt_size;
618 if (queue_id < nb_rxq) {
619 rxq_info->ring_len = rxq->nb_rx_desc;
620 rxq_info->dma_ring_addr = rxq->rx_ring_phys_addr;
621 rxq_info->databuffer_size =
622 (rte_pktmbuf_data_room_size(rxq->mp) -
623 RTE_PKTMBUF_HEADROOM);
627 /* It configures VSI queues to co-work with Linux PF host */
629 i40evf_configure_vsi_queues(struct rte_eth_dev *dev)
631 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
632 struct i40e_rx_queue **rxq =
633 (struct i40e_rx_queue **)dev->data->rx_queues;
634 struct i40e_tx_queue **txq =
635 (struct i40e_tx_queue **)dev->data->tx_queues;
636 struct virtchnl_vsi_queue_config_info *vc_vqci;
637 struct virtchnl_queue_pair_info *vc_qpi;
638 struct vf_cmd_info args;
639 uint16_t i, nb_qp = vf->num_queue_pairs;
640 const uint32_t size =
641 I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqci, nb_qp);
645 memset(buff, 0, sizeof(buff));
646 vc_vqci = (struct virtchnl_vsi_queue_config_info *)buff;
647 vc_vqci->vsi_id = vf->vsi_res->vsi_id;
648 vc_vqci->num_queue_pairs = nb_qp;
650 for (i = 0, vc_qpi = vc_vqci->qpair; i < nb_qp; i++, vc_qpi++) {
651 i40evf_fill_virtchnl_vsi_txq_info(&vc_qpi->txq,
652 vc_vqci->vsi_id, i, dev->data->nb_tx_queues, txq[i]);
653 i40evf_fill_virtchnl_vsi_rxq_info(&vc_qpi->rxq,
654 vc_vqci->vsi_id, i, dev->data->nb_rx_queues,
655 vf->max_pkt_len, rxq[i]);
657 memset(&args, 0, sizeof(args));
658 args.ops = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
659 args.in_args = (uint8_t *)vc_vqci;
660 args.in_args_size = size;
661 args.out_buffer = vf->aq_resp;
662 args.out_size = I40E_AQ_BUF_SZ;
663 ret = i40evf_execute_vf_cmd(dev, &args);
665 PMD_DRV_LOG(ERR, "Failed to execute command of "
666 "VIRTCHNL_OP_CONFIG_VSI_QUEUES");
671 /* It configures VSI queues to co-work with DPDK PF host */
673 i40evf_configure_vsi_queues_ext(struct rte_eth_dev *dev)
675 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
676 struct i40e_rx_queue **rxq =
677 (struct i40e_rx_queue **)dev->data->rx_queues;
678 struct i40e_tx_queue **txq =
679 (struct i40e_tx_queue **)dev->data->tx_queues;
680 struct virtchnl_vsi_queue_config_ext_info *vc_vqcei;
681 struct virtchnl_queue_pair_ext_info *vc_qpei;
682 struct vf_cmd_info args;
683 uint16_t i, nb_qp = vf->num_queue_pairs;
684 const uint32_t size =
685 I40E_VIRTCHNL_CONFIG_VSI_QUEUES_SIZE(vc_vqcei, nb_qp);
689 memset(buff, 0, sizeof(buff));
690 vc_vqcei = (struct virtchnl_vsi_queue_config_ext_info *)buff;
691 vc_vqcei->vsi_id = vf->vsi_res->vsi_id;
692 vc_vqcei->num_queue_pairs = nb_qp;
693 vc_qpei = vc_vqcei->qpair;
694 for (i = 0; i < nb_qp; i++, vc_qpei++) {
695 i40evf_fill_virtchnl_vsi_txq_info(&vc_qpei->txq,
696 vc_vqcei->vsi_id, i, dev->data->nb_tx_queues, txq[i]);
697 i40evf_fill_virtchnl_vsi_rxq_info(&vc_qpei->rxq,
698 vc_vqcei->vsi_id, i, dev->data->nb_rx_queues,
699 vf->max_pkt_len, rxq[i]);
700 if (i < dev->data->nb_rx_queues)
702 * It adds extra info for configuring VSI queues, which
703 * is needed to enable the configurable crc stripping
706 vc_qpei->rxq_ext.crcstrip =
707 dev->data->dev_conf.rxmode.hw_strip_crc;
709 memset(&args, 0, sizeof(args));
711 (enum virtchnl_ops)VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT;
712 args.in_args = (uint8_t *)vc_vqcei;
713 args.in_args_size = size;
714 args.out_buffer = vf->aq_resp;
715 args.out_size = I40E_AQ_BUF_SZ;
716 ret = i40evf_execute_vf_cmd(dev, &args);
718 PMD_DRV_LOG(ERR, "Failed to execute command of "
719 "VIRTCHNL_OP_CONFIG_VSI_QUEUES_EXT");
725 i40evf_configure_queues(struct rte_eth_dev *dev)
727 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
729 if (vf->version_major == I40E_DPDK_VERSION_MAJOR)
730 /* To support DPDK PF host */
731 return i40evf_configure_vsi_queues_ext(dev);
733 /* To support Linux PF host */
734 return i40evf_configure_vsi_queues(dev);
738 i40evf_config_irq_map(struct rte_eth_dev *dev)
740 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
741 struct vf_cmd_info args;
742 uint8_t cmd_buffer[sizeof(struct virtchnl_irq_map_info) + \
743 sizeof(struct virtchnl_vector_map)];
744 struct virtchnl_irq_map_info *map_info;
745 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
746 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
750 if (rte_intr_allow_others(intr_handle)) {
751 if (vf->version_major == I40E_DPDK_VERSION_MAJOR)
752 vector_id = I40EVF_VSI_DEFAULT_MSIX_INTR;
754 vector_id = I40EVF_VSI_DEFAULT_MSIX_INTR_LNX;
756 vector_id = I40E_MISC_VEC_ID;
759 map_info = (struct virtchnl_irq_map_info *)cmd_buffer;
760 map_info->num_vectors = 1;
761 map_info->vecmap[0].rxitr_idx = I40E_ITR_INDEX_DEFAULT;
762 map_info->vecmap[0].vsi_id = vf->vsi_res->vsi_id;
763 /* Alway use default dynamic MSIX interrupt */
764 map_info->vecmap[0].vector_id = vector_id;
765 /* Don't map any tx queue */
766 map_info->vecmap[0].txq_map = 0;
767 map_info->vecmap[0].rxq_map = 0;
768 for (i = 0; i < dev->data->nb_rx_queues; i++) {
769 map_info->vecmap[0].rxq_map |= 1 << i;
770 if (rte_intr_dp_is_en(intr_handle))
771 intr_handle->intr_vec[i] = vector_id;
774 args.ops = VIRTCHNL_OP_CONFIG_IRQ_MAP;
775 args.in_args = (u8 *)cmd_buffer;
776 args.in_args_size = sizeof(cmd_buffer);
777 args.out_buffer = vf->aq_resp;
778 args.out_size = I40E_AQ_BUF_SZ;
779 err = i40evf_execute_vf_cmd(dev, &args);
781 PMD_DRV_LOG(ERR, "fail to execute command OP_ENABLE_QUEUES");
787 i40evf_switch_queue(struct rte_eth_dev *dev, bool isrx, uint16_t qid,
790 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
791 struct virtchnl_queue_select queue_select;
793 struct vf_cmd_info args;
794 memset(&queue_select, 0, sizeof(queue_select));
795 queue_select.vsi_id = vf->vsi_res->vsi_id;
798 queue_select.rx_queues |= 1 << qid;
800 queue_select.tx_queues |= 1 << qid;
803 args.ops = VIRTCHNL_OP_ENABLE_QUEUES;
805 args.ops = VIRTCHNL_OP_DISABLE_QUEUES;
806 args.in_args = (u8 *)&queue_select;
807 args.in_args_size = sizeof(queue_select);
808 args.out_buffer = vf->aq_resp;
809 args.out_size = I40E_AQ_BUF_SZ;
810 err = i40evf_execute_vf_cmd(dev, &args);
812 PMD_DRV_LOG(ERR, "fail to switch %s %u %s",
813 isrx ? "RX" : "TX", qid, on ? "on" : "off");
819 i40evf_start_queues(struct rte_eth_dev *dev)
821 struct rte_eth_dev_data *dev_data = dev->data;
823 struct i40e_rx_queue *rxq;
824 struct i40e_tx_queue *txq;
826 for (i = 0; i < dev->data->nb_rx_queues; i++) {
827 rxq = dev_data->rx_queues[i];
828 if (rxq->rx_deferred_start)
830 if (i40evf_dev_rx_queue_start(dev, i) != 0) {
831 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
836 for (i = 0; i < dev->data->nb_tx_queues; i++) {
837 txq = dev_data->tx_queues[i];
838 if (txq->tx_deferred_start)
840 if (i40evf_dev_tx_queue_start(dev, i) != 0) {
841 PMD_DRV_LOG(ERR, "Fail to start queue %u", i);
850 i40evf_stop_queues(struct rte_eth_dev *dev)
854 /* Stop TX queues first */
855 for (i = 0; i < dev->data->nb_tx_queues; i++) {
856 if (i40evf_dev_tx_queue_stop(dev, i) != 0) {
857 PMD_DRV_LOG(ERR, "Fail to stop queue %u", i);
862 /* Then stop RX queues */
863 for (i = 0; i < dev->data->nb_rx_queues; i++) {
864 if (i40evf_dev_rx_queue_stop(dev, i) != 0) {
865 PMD_DRV_LOG(ERR, "Fail to stop queue %u", i);
874 i40evf_add_mac_addr(struct rte_eth_dev *dev,
875 struct ether_addr *addr,
876 __rte_unused uint32_t index,
877 __rte_unused uint32_t pool)
879 struct virtchnl_ether_addr_list *list;
880 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
881 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) + \
882 sizeof(struct virtchnl_ether_addr)];
884 struct vf_cmd_info args;
886 if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
887 PMD_DRV_LOG(ERR, "Invalid mac:%x:%x:%x:%x:%x:%x",
888 addr->addr_bytes[0], addr->addr_bytes[1],
889 addr->addr_bytes[2], addr->addr_bytes[3],
890 addr->addr_bytes[4], addr->addr_bytes[5]);
891 return I40E_ERR_INVALID_MAC_ADDR;
894 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
895 list->vsi_id = vf->vsi_res->vsi_id;
896 list->num_elements = 1;
897 (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
898 sizeof(addr->addr_bytes));
900 args.ops = VIRTCHNL_OP_ADD_ETH_ADDR;
901 args.in_args = cmd_buffer;
902 args.in_args_size = sizeof(cmd_buffer);
903 args.out_buffer = vf->aq_resp;
904 args.out_size = I40E_AQ_BUF_SZ;
905 err = i40evf_execute_vf_cmd(dev, &args);
907 PMD_DRV_LOG(ERR, "fail to execute command "
908 "OP_ADD_ETHER_ADDRESS");
914 i40evf_del_mac_addr_by_addr(struct rte_eth_dev *dev,
915 struct ether_addr *addr)
917 struct virtchnl_ether_addr_list *list;
918 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
919 uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) + \
920 sizeof(struct virtchnl_ether_addr)];
922 struct vf_cmd_info args;
924 if (i40e_validate_mac_addr(addr->addr_bytes) != I40E_SUCCESS) {
925 PMD_DRV_LOG(ERR, "Invalid mac:%x-%x-%x-%x-%x-%x",
926 addr->addr_bytes[0], addr->addr_bytes[1],
927 addr->addr_bytes[2], addr->addr_bytes[3],
928 addr->addr_bytes[4], addr->addr_bytes[5]);
932 list = (struct virtchnl_ether_addr_list *)cmd_buffer;
933 list->vsi_id = vf->vsi_res->vsi_id;
934 list->num_elements = 1;
935 (void)rte_memcpy(list->list[0].addr, addr->addr_bytes,
936 sizeof(addr->addr_bytes));
938 args.ops = VIRTCHNL_OP_DEL_ETH_ADDR;
939 args.in_args = cmd_buffer;
940 args.in_args_size = sizeof(cmd_buffer);
941 args.out_buffer = vf->aq_resp;
942 args.out_size = I40E_AQ_BUF_SZ;
943 err = i40evf_execute_vf_cmd(dev, &args);
945 PMD_DRV_LOG(ERR, "fail to execute command "
946 "OP_DEL_ETHER_ADDRESS");
951 i40evf_del_mac_addr(struct rte_eth_dev *dev, uint32_t index)
953 struct rte_eth_dev_data *data = dev->data;
954 struct ether_addr *addr;
956 addr = &data->mac_addrs[index];
958 i40evf_del_mac_addr_by_addr(dev, addr);
962 i40evf_update_stats(struct rte_eth_dev *dev, struct i40e_eth_stats **pstats)
964 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
965 struct virtchnl_queue_select q_stats;
967 struct vf_cmd_info args;
969 memset(&q_stats, 0, sizeof(q_stats));
970 q_stats.vsi_id = vf->vsi_res->vsi_id;
971 args.ops = VIRTCHNL_OP_GET_STATS;
972 args.in_args = (u8 *)&q_stats;
973 args.in_args_size = sizeof(q_stats);
974 args.out_buffer = vf->aq_resp;
975 args.out_size = I40E_AQ_BUF_SZ;
977 err = i40evf_execute_vf_cmd(dev, &args);
979 PMD_DRV_LOG(ERR, "fail to execute command OP_GET_STATS");
983 *pstats = (struct i40e_eth_stats *)args.out_buffer;
988 i40evf_get_statistics(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
991 struct i40e_eth_stats *pstats = NULL;
993 ret = i40evf_update_stats(dev, &pstats);
997 stats->ipackets = pstats->rx_unicast + pstats->rx_multicast +
998 pstats->rx_broadcast;
999 stats->opackets = pstats->tx_broadcast + pstats->tx_multicast +
1001 stats->imissed = pstats->rx_discards;
1002 stats->oerrors = pstats->tx_errors + pstats->tx_discards;
1003 stats->ibytes = pstats->rx_bytes;
1004 stats->obytes = pstats->tx_bytes;
1010 i40evf_dev_xstats_reset(struct rte_eth_dev *dev)
1012 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1013 struct i40e_eth_stats *pstats = NULL;
1015 /* read stat values to clear hardware registers */
1016 i40evf_update_stats(dev, &pstats);
1018 /* set stats offset base on current values */
1019 vf->vsi.eth_stats_offset = vf->vsi.eth_stats;
1022 static int i40evf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1023 struct rte_eth_xstat_name *xstats_names,
1024 __rte_unused unsigned limit)
1028 if (xstats_names != NULL)
1029 for (i = 0; i < I40EVF_NB_XSTATS; i++) {
1030 snprintf(xstats_names[i].name,
1031 sizeof(xstats_names[i].name),
1032 "%s", rte_i40evf_stats_strings[i].name);
1034 return I40EVF_NB_XSTATS;
1037 static int i40evf_dev_xstats_get(struct rte_eth_dev *dev,
1038 struct rte_eth_xstat *xstats, unsigned n)
1042 struct i40e_eth_stats *pstats = NULL;
1044 if (n < I40EVF_NB_XSTATS)
1045 return I40EVF_NB_XSTATS;
1047 ret = i40evf_update_stats(dev, &pstats);
1054 /* loop over xstats array and values from pstats */
1055 for (i = 0; i < I40EVF_NB_XSTATS; i++) {
1057 xstats[i].value = *(uint64_t *)(((char *)pstats) +
1058 rte_i40evf_stats_strings[i].offset);
1061 return I40EVF_NB_XSTATS;
1065 i40evf_add_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
1067 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1068 struct virtchnl_vlan_filter_list *vlan_list;
1069 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1072 struct vf_cmd_info args;
1074 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1075 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1076 vlan_list->num_elements = 1;
1077 vlan_list->vlan_id[0] = vlanid;
1079 args.ops = VIRTCHNL_OP_ADD_VLAN;
1080 args.in_args = (u8 *)&cmd_buffer;
1081 args.in_args_size = sizeof(cmd_buffer);
1082 args.out_buffer = vf->aq_resp;
1083 args.out_size = I40E_AQ_BUF_SZ;
1084 err = i40evf_execute_vf_cmd(dev, &args);
1086 PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_VLAN");
1092 i40evf_del_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
1094 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1095 struct virtchnl_vlan_filter_list *vlan_list;
1096 uint8_t cmd_buffer[sizeof(struct virtchnl_vlan_filter_list) +
1099 struct vf_cmd_info args;
1101 vlan_list = (struct virtchnl_vlan_filter_list *)cmd_buffer;
1102 vlan_list->vsi_id = vf->vsi_res->vsi_id;
1103 vlan_list->num_elements = 1;
1104 vlan_list->vlan_id[0] = vlanid;
1106 args.ops = VIRTCHNL_OP_DEL_VLAN;
1107 args.in_args = (u8 *)&cmd_buffer;
1108 args.in_args_size = sizeof(cmd_buffer);
1109 args.out_buffer = vf->aq_resp;
1110 args.out_size = I40E_AQ_BUF_SZ;
1111 err = i40evf_execute_vf_cmd(dev, &args);
1113 PMD_DRV_LOG(ERR, "fail to execute command OP_DEL_VLAN");
1118 static const struct rte_pci_id pci_id_i40evf_map[] = {
1119 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_VF) },
1120 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_VF_HV) },
1121 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_A0_VF) },
1122 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_VF) },
1123 { .vendor_id = 0, /* sentinel */ },
1127 i40evf_dev_atomic_write_link_status(struct rte_eth_dev *dev,
1128 struct rte_eth_link *link)
1130 struct rte_eth_link *dst = &(dev->data->dev_link);
1131 struct rte_eth_link *src = link;
1133 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
1134 *(uint64_t *)src) == 0)
1142 i40evf_disable_irq0(struct i40e_hw *hw)
1144 /* Disable all interrupt types */
1145 I40E_WRITE_REG(hw, I40E_VFINT_ICR0_ENA1, 0);
1146 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTL01,
1147 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
1148 I40EVF_WRITE_FLUSH(hw);
1153 i40evf_enable_irq0(struct i40e_hw *hw)
1155 /* Enable admin queue interrupt trigger */
1158 i40evf_disable_irq0(hw);
1159 val = I40E_READ_REG(hw, I40E_VFINT_ICR0_ENA1);
1160 val |= I40E_VFINT_ICR0_ENA1_ADMINQ_MASK |
1161 I40E_VFINT_ICR0_ENA1_LINK_STAT_CHANGE_MASK;
1162 I40E_WRITE_REG(hw, I40E_VFINT_ICR0_ENA1, val);
1164 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTL01,
1165 I40E_VFINT_DYN_CTL01_INTENA_MASK |
1166 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK |
1167 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
1169 I40EVF_WRITE_FLUSH(hw);
1173 i40evf_reset_vf(struct i40e_hw *hw)
1177 if (i40e_vf_reset(hw) != I40E_SUCCESS) {
1178 PMD_INIT_LOG(ERR, "Reset VF NIC failed");
1182 * After issuing vf reset command to pf, pf won't necessarily
1183 * reset vf, it depends on what state it exactly is. If it's not
1184 * initialized yet, it won't have vf reset since it's in a certain
1185 * state. If not, it will try to reset. Even vf is reset, pf will
1186 * set I40E_VFGEN_RSTAT to COMPLETE first, then wait 10ms and set
1187 * it to ACTIVE. In this duration, vf may not catch the moment that
1188 * COMPLETE is set. So, for vf, we'll try to wait a long time.
1192 for (i = 0; i < MAX_RESET_WAIT_CNT; i++) {
1193 reset = rd32(hw, I40E_VFGEN_RSTAT) &
1194 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1195 reset = reset >> I40E_VFGEN_RSTAT_VFR_STATE_SHIFT;
1196 if (VIRTCHNL_VFR_COMPLETED == reset || VIRTCHNL_VFR_VFACTIVE == reset)
1202 if (i >= MAX_RESET_WAIT_CNT) {
1203 PMD_INIT_LOG(ERR, "Reset VF NIC failed");
1211 i40evf_init_vf(struct rte_eth_dev *dev)
1214 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1215 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1217 i40e_calc_itr_interval(I40E_QUEUE_ITR_INTERVAL_MAX);
1219 vf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1220 vf->dev_data = dev->data;
1221 err = i40e_set_mac_type(hw);
1223 PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
1227 i40e_init_adminq_parameter(hw);
1228 err = i40e_init_adminq(hw);
1230 PMD_INIT_LOG(ERR, "init_adminq failed: %d", err);
1234 /* Reset VF and wait until it's complete */
1235 if (i40evf_reset_vf(hw)) {
1236 PMD_INIT_LOG(ERR, "reset NIC failed");
1240 /* VF reset, shutdown admin queue and initialize again */
1241 if (i40e_shutdown_adminq(hw) != I40E_SUCCESS) {
1242 PMD_INIT_LOG(ERR, "i40e_shutdown_adminq failed");
1246 i40e_init_adminq_parameter(hw);
1247 if (i40e_init_adminq(hw) != I40E_SUCCESS) {
1248 PMD_INIT_LOG(ERR, "init_adminq failed");
1251 vf->aq_resp = rte_zmalloc("vf_aq_resp", I40E_AQ_BUF_SZ, 0);
1253 PMD_INIT_LOG(ERR, "unable to allocate vf_aq_resp memory");
1256 if (i40evf_check_api_version(dev) != 0) {
1257 PMD_INIT_LOG(ERR, "check_api version failed");
1260 bufsz = sizeof(struct virtchnl_vf_resource) +
1261 (I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource));
1262 vf->vf_res = rte_zmalloc("vf_res", bufsz, 0);
1264 PMD_INIT_LOG(ERR, "unable to allocate vf_res memory");
1268 if (i40evf_get_vf_resource(dev) != 0) {
1269 PMD_INIT_LOG(ERR, "i40evf_get_vf_config failed");
1273 /* got VF config message back from PF, now we can parse it */
1274 for (i = 0; i < vf->vf_res->num_vsis; i++) {
1275 if (vf->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
1276 vf->vsi_res = &vf->vf_res->vsi_res[i];
1280 PMD_INIT_LOG(ERR, "no LAN VSI found");
1284 if (hw->mac.type == I40E_MAC_X722_VF)
1285 vf->flags = I40E_FLAG_RSS_AQ_CAPABLE;
1286 vf->vsi.vsi_id = vf->vsi_res->vsi_id;
1287 vf->vsi.type = (enum i40e_vsi_type)vf->vsi_res->vsi_type;
1288 vf->vsi.nb_qps = vf->vsi_res->num_queue_pairs;
1289 vf->vsi.adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1291 /* Store the MAC address configured by host, or generate random one */
1292 if (is_valid_assigned_ether_addr((struct ether_addr *)hw->mac.addr))
1293 vf->flags |= I40E_FLAG_VF_MAC_BY_PF;
1295 eth_random_addr(hw->mac.addr); /* Generate a random one */
1297 /* If the PF host is not DPDK, set the interval of ITR0 to max*/
1298 if (vf->version_major != I40E_DPDK_VERSION_MAJOR) {
1299 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTL01,
1300 (I40E_ITR_INDEX_DEFAULT <<
1301 I40E_VFINT_DYN_CTL0_ITR_INDX_SHIFT) |
1303 I40E_VFINT_DYN_CTL0_INTERVAL_SHIFT));
1304 I40EVF_WRITE_FLUSH(hw);
1310 rte_free(vf->vf_res);
1312 i40e_shutdown_adminq(hw); /* ignore error */
1318 i40evf_uninit_vf(struct rte_eth_dev *dev)
1320 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1321 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1323 PMD_INIT_FUNC_TRACE();
1325 if (hw->adapter_stopped == 0)
1326 i40evf_dev_close(dev);
1327 rte_free(vf->vf_res);
1329 rte_free(vf->aq_resp);
1336 i40evf_handle_pf_event(struct rte_eth_dev *dev, uint8_t *msg,
1337 __rte_unused uint16_t msglen)
1339 struct virtchnl_pf_event *pf_msg =
1340 (struct virtchnl_pf_event *)msg;
1341 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1343 switch (pf_msg->event) {
1344 case VIRTCHNL_EVENT_RESET_IMPENDING:
1345 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_RESET_IMPENDING event");
1346 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
1349 case VIRTCHNL_EVENT_LINK_CHANGE:
1350 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_LINK_CHANGE event");
1351 vf->link_up = pf_msg->event_data.link_event.link_status;
1352 vf->link_speed = pf_msg->event_data.link_event.link_speed;
1354 case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
1355 PMD_DRV_LOG(DEBUG, "VIRTCHNL_EVENT_PF_DRIVER_CLOSE event");
1358 PMD_DRV_LOG(ERR, " unknown event received %u", pf_msg->event);
1364 i40evf_handle_aq_msg(struct rte_eth_dev *dev)
1366 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1367 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1368 struct i40e_arq_event_info info;
1369 uint16_t pending, aq_opc;
1370 enum virtchnl_ops msg_opc;
1371 enum i40e_status_code msg_ret;
1374 info.buf_len = I40E_AQ_BUF_SZ;
1376 PMD_DRV_LOG(ERR, "Buffer for adminq resp should not be NULL");
1379 info.msg_buf = vf->aq_resp;
1383 ret = i40e_clean_arq_element(hw, &info, &pending);
1385 if (ret != I40E_SUCCESS) {
1386 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ,"
1390 aq_opc = rte_le_to_cpu_16(info.desc.opcode);
1391 /* For the message sent from pf to vf, opcode is stored in
1392 * cookie_high of struct i40e_aq_desc, while return error code
1393 * are stored in cookie_low, Which is done by
1394 * i40e_aq_send_msg_to_vf in PF driver.*/
1395 msg_opc = (enum virtchnl_ops)rte_le_to_cpu_32(
1396 info.desc.cookie_high);
1397 msg_ret = (enum i40e_status_code)rte_le_to_cpu_32(
1398 info.desc.cookie_low);
1400 case i40e_aqc_opc_send_msg_to_vf:
1401 if (msg_opc == VIRTCHNL_OP_EVENT)
1403 i40evf_handle_pf_event(dev, info.msg_buf,
1406 /* read message and it's expected one */
1407 if (msg_opc == vf->pend_cmd) {
1408 vf->cmd_retval = msg_ret;
1409 /* prevent compiler reordering */
1410 rte_compiler_barrier();
1413 PMD_DRV_LOG(ERR, "command mismatch,"
1414 "expect %u, get %u",
1415 vf->pend_cmd, msg_opc);
1416 PMD_DRV_LOG(DEBUG, "adminq response is received,"
1417 " opcode = %d", msg_opc);
1421 PMD_DRV_LOG(ERR, "Request %u is not supported yet",
1429 * Interrupt handler triggered by NIC for handling
1430 * specific interrupt. Only adminq interrupt is processed in VF.
1433 * Pointer to interrupt handle.
1435 * The address of parameter (struct rte_eth_dev *) regsitered before.
1441 i40evf_dev_interrupt_handler(void *param)
1443 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1444 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1447 i40evf_disable_irq0(hw);
1449 /* read out interrupt causes */
1450 icr0 = I40E_READ_REG(hw, I40E_VFINT_ICR01);
1452 /* No interrupt event indicated */
1453 if (!(icr0 & I40E_VFINT_ICR01_INTEVENT_MASK)) {
1454 PMD_DRV_LOG(DEBUG, "No interrupt event, nothing to do");
1458 if (icr0 & I40E_VFINT_ICR01_ADMINQ_MASK) {
1459 PMD_DRV_LOG(DEBUG, "ICR01_ADMINQ is reported");
1460 i40evf_handle_aq_msg(dev);
1463 /* Link Status Change interrupt */
1464 if (icr0 & I40E_VFINT_ICR01_LINK_STAT_CHANGE_MASK)
1465 PMD_DRV_LOG(DEBUG, "LINK_STAT_CHANGE is reported,"
1469 i40evf_enable_irq0(hw);
1470 rte_intr_enable(dev->intr_handle);
1474 i40evf_dev_init(struct rte_eth_dev *eth_dev)
1477 = I40E_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1478 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1480 PMD_INIT_FUNC_TRACE();
1482 /* assign ops func pointer */
1483 eth_dev->dev_ops = &i40evf_eth_dev_ops;
1484 eth_dev->rx_pkt_burst = &i40e_recv_pkts;
1485 eth_dev->tx_pkt_burst = &i40e_xmit_pkts;
1488 * For secondary processes, we don't initialise any further as primary
1489 * has already done this work.
1491 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1492 i40e_set_rx_function(eth_dev);
1493 i40e_set_tx_function(eth_dev);
1496 i40e_set_default_ptype_table(eth_dev);
1497 rte_eth_copy_pci_info(eth_dev, pci_dev);
1498 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1500 hw->vendor_id = pci_dev->id.vendor_id;
1501 hw->device_id = pci_dev->id.device_id;
1502 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1503 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1504 hw->bus.device = pci_dev->addr.devid;
1505 hw->bus.func = pci_dev->addr.function;
1506 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1507 hw->adapter_stopped = 0;
1509 if(i40evf_init_vf(eth_dev) != 0) {
1510 PMD_INIT_LOG(ERR, "Init vf failed");
1514 /* register callback func to eal lib */
1515 rte_intr_callback_register(&pci_dev->intr_handle,
1516 i40evf_dev_interrupt_handler, (void *)eth_dev);
1518 /* enable uio intr after callback register */
1519 rte_intr_enable(&pci_dev->intr_handle);
1521 /* configure and enable device interrupt */
1522 i40evf_enable_irq0(hw);
1525 eth_dev->data->mac_addrs = rte_zmalloc("i40evf_mac",
1526 ETHER_ADDR_LEN * I40E_NUM_MACADDR_MAX,
1528 if (eth_dev->data->mac_addrs == NULL) {
1529 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
1530 " store MAC addresses",
1531 ETHER_ADDR_LEN * I40E_NUM_MACADDR_MAX);
1534 ether_addr_copy((struct ether_addr *)hw->mac.addr,
1535 ð_dev->data->mac_addrs[0]);
1541 i40evf_dev_uninit(struct rte_eth_dev *eth_dev)
1543 PMD_INIT_FUNC_TRACE();
1545 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1548 eth_dev->dev_ops = NULL;
1549 eth_dev->rx_pkt_burst = NULL;
1550 eth_dev->tx_pkt_burst = NULL;
1552 if (i40evf_uninit_vf(eth_dev) != 0) {
1553 PMD_INIT_LOG(ERR, "i40evf_uninit_vf failed");
1557 rte_free(eth_dev->data->mac_addrs);
1558 eth_dev->data->mac_addrs = NULL;
1563 static int eth_i40evf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1564 struct rte_pci_device *pci_dev)
1566 return rte_eth_dev_pci_generic_probe(pci_dev,
1567 sizeof(struct i40e_adapter), i40evf_dev_init);
1570 static int eth_i40evf_pci_remove(struct rte_pci_device *pci_dev)
1572 return rte_eth_dev_pci_generic_remove(pci_dev, i40evf_dev_uninit);
1576 * virtual function driver struct
1578 static struct rte_pci_driver rte_i40evf_pmd = {
1579 .id_table = pci_id_i40evf_map,
1580 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1581 .probe = eth_i40evf_pci_probe,
1582 .remove = eth_i40evf_pci_remove,
1585 RTE_PMD_REGISTER_PCI(net_i40e_vf, rte_i40evf_pmd);
1586 RTE_PMD_REGISTER_PCI_TABLE(net_i40e_vf, pci_id_i40evf_map);
1587 RTE_PMD_REGISTER_KMOD_DEP(net_i40e_vf, "* igb_uio | vfio-pci");
1590 i40evf_dev_configure(struct rte_eth_dev *dev)
1592 struct i40e_adapter *ad =
1593 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1594 struct rte_eth_conf *conf = &dev->data->dev_conf;
1597 /* Initialize to TRUE. If any of Rx queues doesn't meet the bulk
1598 * allocation or vector Rx preconditions we will reset it.
1600 ad->rx_bulk_alloc_allowed = true;
1601 ad->rx_vec_allowed = true;
1602 ad->tx_simple_allowed = true;
1603 ad->tx_vec_allowed = true;
1605 /* For non-DPDK PF drivers, VF has no ability to disable HW
1606 * CRC strip, and is implicitly enabled by the PF.
1608 if (!conf->rxmode.hw_strip_crc) {
1609 vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1610 if ((vf->version_major == VIRTCHNL_VERSION_MAJOR) &&
1611 (vf->version_minor <= VIRTCHNL_VERSION_MINOR)) {
1612 /* Peer is running non-DPDK PF driver. */
1613 PMD_INIT_LOG(ERR, "VF can't disable HW CRC Strip");
1618 return i40evf_init_vlan(dev);
1622 i40evf_init_vlan(struct rte_eth_dev *dev)
1624 struct rte_eth_dev_data *data = dev->data;
1627 /* Apply vlan offload setting */
1628 i40evf_vlan_offload_set(dev, ETH_VLAN_STRIP_MASK);
1630 /* Apply pvid setting */
1631 ret = i40evf_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
1632 data->dev_conf.txmode.hw_vlan_insert_pvid);
1637 i40evf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1639 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1641 /* Vlan stripping setting */
1642 if (mask & ETH_VLAN_STRIP_MASK) {
1643 /* Enable or disable VLAN stripping */
1644 if (dev_conf->rxmode.hw_vlan_strip)
1645 i40evf_enable_vlan_strip(dev);
1647 i40evf_disable_vlan_strip(dev);
1652 i40evf_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
1654 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1655 struct i40e_vsi_vlan_pvid_info info;
1656 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1658 memset(&info, 0, sizeof(info));
1661 /* Linux pf host don't support vlan offload yet */
1662 if (vf->version_major == I40E_DPDK_VERSION_MAJOR) {
1664 info.config.pvid = pvid;
1666 info.config.reject.tagged =
1667 dev_conf->txmode.hw_vlan_reject_tagged;
1668 info.config.reject.untagged =
1669 dev_conf->txmode.hw_vlan_reject_untagged;
1671 return i40evf_config_vlan_pvid(dev, &info);
1678 i40evf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1680 struct i40e_rx_queue *rxq;
1682 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1684 PMD_INIT_FUNC_TRACE();
1686 if (rx_queue_id < dev->data->nb_rx_queues) {
1687 rxq = dev->data->rx_queues[rx_queue_id];
1689 err = i40e_alloc_rx_queue_mbufs(rxq);
1691 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
1697 /* Init the RX tail register. */
1698 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1699 I40EVF_WRITE_FLUSH(hw);
1701 /* Ready to switch the queue on */
1702 err = i40evf_switch_queue(dev, TRUE, rx_queue_id, TRUE);
1705 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
1708 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1715 i40evf_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1717 struct i40e_rx_queue *rxq;
1720 if (rx_queue_id < dev->data->nb_rx_queues) {
1721 rxq = dev->data->rx_queues[rx_queue_id];
1723 err = i40evf_switch_queue(dev, TRUE, rx_queue_id, FALSE);
1726 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
1731 i40e_rx_queue_release_mbufs(rxq);
1732 i40e_reset_rx_queue(rxq);
1733 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1740 i40evf_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1744 PMD_INIT_FUNC_TRACE();
1746 if (tx_queue_id < dev->data->nb_tx_queues) {
1748 /* Ready to switch the queue on */
1749 err = i40evf_switch_queue(dev, FALSE, tx_queue_id, TRUE);
1752 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
1755 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
1762 i40evf_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1764 struct i40e_tx_queue *txq;
1767 if (tx_queue_id < dev->data->nb_tx_queues) {
1768 txq = dev->data->tx_queues[tx_queue_id];
1770 err = i40evf_switch_queue(dev, FALSE, tx_queue_id, FALSE);
1773 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u off",
1778 i40e_tx_queue_release_mbufs(txq);
1779 i40e_reset_tx_queue(txq);
1780 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
1787 i40evf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1792 ret = i40evf_add_vlan(dev, vlan_id);
1794 ret = i40evf_del_vlan(dev,vlan_id);
1800 i40evf_rxq_init(struct rte_eth_dev *dev, struct i40e_rx_queue *rxq)
1802 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1803 struct rte_eth_dev_data *dev_data = dev->data;
1804 struct rte_pktmbuf_pool_private *mbp_priv;
1805 uint16_t buf_size, len;
1807 rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL1(rxq->queue_id);
1808 I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
1809 I40EVF_WRITE_FLUSH(hw);
1811 /* Calculate the maximum packet length allowed */
1812 mbp_priv = rte_mempool_get_priv(rxq->mp);
1813 buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
1814 RTE_PKTMBUF_HEADROOM);
1815 rxq->hs_mode = i40e_header_split_none;
1816 rxq->rx_hdr_len = 0;
1817 rxq->rx_buf_len = RTE_ALIGN(buf_size, (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
1818 len = rxq->rx_buf_len * I40E_MAX_CHAINED_RX_BUFFERS;
1819 rxq->max_pkt_len = RTE_MIN(len,
1820 dev_data->dev_conf.rxmode.max_rx_pkt_len);
1823 * Check if the jumbo frame and maximum packet length are set correctly
1825 if (dev_data->dev_conf.rxmode.jumbo_frame == 1) {
1826 if (rxq->max_pkt_len <= ETHER_MAX_LEN ||
1827 rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
1828 PMD_DRV_LOG(ERR, "maximum packet length must be "
1829 "larger than %u and smaller than %u, as jumbo "
1830 "frame is enabled", (uint32_t)ETHER_MAX_LEN,
1831 (uint32_t)I40E_FRAME_SIZE_MAX);
1832 return I40E_ERR_CONFIG;
1835 if (rxq->max_pkt_len < ETHER_MIN_LEN ||
1836 rxq->max_pkt_len > ETHER_MAX_LEN) {
1837 PMD_DRV_LOG(ERR, "maximum packet length must be "
1838 "larger than %u and smaller than %u, as jumbo "
1839 "frame is disabled", (uint32_t)ETHER_MIN_LEN,
1840 (uint32_t)ETHER_MAX_LEN);
1841 return I40E_ERR_CONFIG;
1845 if (dev_data->dev_conf.rxmode.enable_scatter ||
1846 (rxq->max_pkt_len + 2 * I40E_VLAN_TAG_SIZE) > buf_size) {
1847 dev_data->scattered_rx = 1;
1854 i40evf_rx_init(struct rte_eth_dev *dev)
1856 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1858 int ret = I40E_SUCCESS;
1859 struct i40e_rx_queue **rxq =
1860 (struct i40e_rx_queue **)dev->data->rx_queues;
1862 i40evf_config_rss(vf);
1863 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1864 if (!rxq[i] || !rxq[i]->q_set)
1866 ret = i40evf_rxq_init(dev, rxq[i]);
1867 if (ret != I40E_SUCCESS)
1870 if (ret == I40E_SUCCESS)
1871 i40e_set_rx_function(dev);
1877 i40evf_tx_init(struct rte_eth_dev *dev)
1880 struct i40e_tx_queue **txq =
1881 (struct i40e_tx_queue **)dev->data->tx_queues;
1882 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1884 for (i = 0; i < dev->data->nb_tx_queues; i++)
1885 txq[i]->qtx_tail = hw->hw_addr + I40E_QTX_TAIL1(i);
1887 i40e_set_tx_function(dev);
1891 i40evf_enable_queues_intr(struct rte_eth_dev *dev)
1893 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1894 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1895 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1896 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1898 if (!rte_intr_allow_others(intr_handle)) {
1900 I40E_VFINT_DYN_CTL01,
1901 I40E_VFINT_DYN_CTL01_INTENA_MASK |
1902 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK |
1903 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
1904 I40EVF_WRITE_FLUSH(hw);
1908 if (vf->version_major == I40E_DPDK_VERSION_MAJOR)
1909 /* To support DPDK PF host */
1911 I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR - 1),
1912 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
1913 I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
1914 /* If host driver is kernel driver, do nothing.
1915 * Interrupt 0 is used for rx packets, but don't set
1916 * I40E_VFINT_DYN_CTL01,
1917 * because it is already done in i40evf_enable_irq0.
1920 I40EVF_WRITE_FLUSH(hw);
1924 i40evf_disable_queues_intr(struct rte_eth_dev *dev)
1926 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
1927 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1928 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1929 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1931 if (!rte_intr_allow_others(intr_handle)) {
1932 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTL01,
1933 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
1934 I40EVF_WRITE_FLUSH(hw);
1938 if (vf->version_major == I40E_DPDK_VERSION_MAJOR)
1940 I40E_VFINT_DYN_CTLN1(I40EVF_VSI_DEFAULT_MSIX_INTR
1943 /* If host driver is kernel driver, do nothing.
1944 * Interrupt 0 is used for rx packets, but don't zero
1945 * I40E_VFINT_DYN_CTL01,
1946 * because interrupt 0 is also used for adminq processing.
1949 I40EVF_WRITE_FLUSH(hw);
1953 i40evf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1955 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1956 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1957 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1959 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
1962 msix_intr = intr_handle->intr_vec[queue_id];
1963 if (msix_intr == I40E_MISC_VEC_ID)
1964 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTL01,
1965 I40E_VFINT_DYN_CTL01_INTENA_MASK |
1966 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK |
1967 (0 << I40E_VFINT_DYN_CTL01_ITR_INDX_SHIFT) |
1969 I40E_VFINT_DYN_CTL01_INTERVAL_SHIFT));
1972 I40E_VFINT_DYN_CTLN1(msix_intr -
1974 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
1975 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK |
1976 (0 << I40E_VFINT_DYN_CTLN1_ITR_INDX_SHIFT) |
1978 I40E_VFINT_DYN_CTLN1_INTERVAL_SHIFT));
1980 I40EVF_WRITE_FLUSH(hw);
1982 rte_intr_enable(&pci_dev->intr_handle);
1988 i40evf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1990 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1991 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1992 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1995 msix_intr = intr_handle->intr_vec[queue_id];
1996 if (msix_intr == I40E_MISC_VEC_ID)
1997 I40E_WRITE_REG(hw, I40E_VFINT_DYN_CTL01, 0);
2000 I40E_VFINT_DYN_CTLN1(msix_intr -
2004 I40EVF_WRITE_FLUSH(hw);
2010 i40evf_add_del_all_mac_addr(struct rte_eth_dev *dev, bool add)
2012 struct virtchnl_ether_addr_list *list;
2013 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2018 struct ether_addr *addr;
2019 struct vf_cmd_info args;
2023 len = sizeof(struct virtchnl_ether_addr_list);
2024 for (i = begin; i < I40E_NUM_MACADDR_MAX; i++, next_begin++) {
2025 if (is_zero_ether_addr(&dev->data->mac_addrs[i]))
2027 len += sizeof(struct virtchnl_ether_addr);
2028 if (len >= I40E_AQ_BUF_SZ) {
2034 list = rte_zmalloc("i40evf_del_mac_buffer", len, 0);
2036 PMD_DRV_LOG(ERR, "fail to allocate memory");
2040 for (i = begin; i < next_begin; i++) {
2041 addr = &dev->data->mac_addrs[i];
2042 if (is_zero_ether_addr(addr))
2044 (void)rte_memcpy(list->list[j].addr, addr->addr_bytes,
2045 sizeof(addr->addr_bytes));
2046 PMD_DRV_LOG(DEBUG, "add/rm mac:%x:%x:%x:%x:%x:%x",
2047 addr->addr_bytes[0], addr->addr_bytes[1],
2048 addr->addr_bytes[2], addr->addr_bytes[3],
2049 addr->addr_bytes[4], addr->addr_bytes[5]);
2052 list->vsi_id = vf->vsi_res->vsi_id;
2053 list->num_elements = j;
2054 args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
2055 VIRTCHNL_OP_DEL_ETH_ADDR;
2056 args.in_args = (uint8_t *)list;
2057 args.in_args_size = len;
2058 args.out_buffer = vf->aq_resp;
2059 args.out_size = I40E_AQ_BUF_SZ;
2060 err = i40evf_execute_vf_cmd(dev, &args);
2062 PMD_DRV_LOG(ERR, "fail to execute command %s",
2063 add ? "OP_ADD_ETHER_ADDRESS" :
2064 "OP_DEL_ETHER_ADDRESS");
2067 } while (begin < I40E_NUM_MACADDR_MAX);
2071 i40evf_dev_start(struct rte_eth_dev *dev)
2073 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2074 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2075 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2076 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2077 uint32_t intr_vector = 0;
2079 PMD_INIT_FUNC_TRACE();
2081 hw->adapter_stopped = 0;
2083 vf->max_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
2084 vf->num_queue_pairs = RTE_MAX(dev->data->nb_rx_queues,
2085 dev->data->nb_tx_queues);
2087 /* check and configure queue intr-vector mapping */
2088 if (dev->data->dev_conf.intr_conf.rxq != 0) {
2089 intr_vector = dev->data->nb_rx_queues;
2090 if (rte_intr_efd_enable(intr_handle, intr_vector))
2094 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
2095 intr_handle->intr_vec =
2096 rte_zmalloc("intr_vec",
2097 dev->data->nb_rx_queues * sizeof(int), 0);
2098 if (!intr_handle->intr_vec) {
2099 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
2100 " intr_vec", dev->data->nb_rx_queues);
2105 if (i40evf_rx_init(dev) != 0){
2106 PMD_DRV_LOG(ERR, "failed to do RX init");
2110 i40evf_tx_init(dev);
2112 if (i40evf_configure_queues(dev) != 0) {
2113 PMD_DRV_LOG(ERR, "configure queues failed");
2116 if (i40evf_config_irq_map(dev)) {
2117 PMD_DRV_LOG(ERR, "config_irq_map failed");
2121 /* Set all mac addrs */
2122 i40evf_add_del_all_mac_addr(dev, TRUE);
2124 if (i40evf_start_queues(dev) != 0) {
2125 PMD_DRV_LOG(ERR, "enable queues failed");
2129 i40evf_enable_queues_intr(dev);
2133 i40evf_add_del_all_mac_addr(dev, FALSE);
2139 i40evf_dev_stop(struct rte_eth_dev *dev)
2141 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2142 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2144 PMD_INIT_FUNC_TRACE();
2146 i40evf_stop_queues(dev);
2147 i40evf_disable_queues_intr(dev);
2148 i40e_dev_clear_queues(dev);
2150 /* Clean datapath event and queue/vec mapping */
2151 rte_intr_efd_disable(intr_handle);
2152 if (intr_handle->intr_vec) {
2153 rte_free(intr_handle->intr_vec);
2154 intr_handle->intr_vec = NULL;
2156 /* remove all mac addrs */
2157 i40evf_add_del_all_mac_addr(dev, FALSE);
2162 i40evf_dev_link_update(struct rte_eth_dev *dev,
2163 __rte_unused int wait_to_complete)
2165 struct rte_eth_link new_link;
2166 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2168 * DPDK pf host provide interfacet to acquire link status
2169 * while Linux driver does not
2172 /* Linux driver PF host */
2173 switch (vf->link_speed) {
2174 case I40E_LINK_SPEED_100MB:
2175 new_link.link_speed = ETH_SPEED_NUM_100M;
2177 case I40E_LINK_SPEED_1GB:
2178 new_link.link_speed = ETH_SPEED_NUM_1G;
2180 case I40E_LINK_SPEED_10GB:
2181 new_link.link_speed = ETH_SPEED_NUM_10G;
2183 case I40E_LINK_SPEED_20GB:
2184 new_link.link_speed = ETH_SPEED_NUM_20G;
2186 case I40E_LINK_SPEED_25GB:
2187 new_link.link_speed = ETH_SPEED_NUM_25G;
2189 case I40E_LINK_SPEED_40GB:
2190 new_link.link_speed = ETH_SPEED_NUM_40G;
2193 new_link.link_speed = ETH_SPEED_NUM_100M;
2196 /* full duplex only */
2197 new_link.link_duplex = ETH_LINK_FULL_DUPLEX;
2198 new_link.link_status = vf->link_up ? ETH_LINK_UP :
2201 i40evf_dev_atomic_write_link_status(dev, &new_link);
2207 i40evf_dev_promiscuous_enable(struct rte_eth_dev *dev)
2209 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2212 /* If enabled, just return */
2213 if (vf->promisc_unicast_enabled)
2216 ret = i40evf_config_promisc(dev, 1, vf->promisc_multicast_enabled);
2218 vf->promisc_unicast_enabled = TRUE;
2222 i40evf_dev_promiscuous_disable(struct rte_eth_dev *dev)
2224 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2227 /* If disabled, just return */
2228 if (!vf->promisc_unicast_enabled)
2231 ret = i40evf_config_promisc(dev, 0, vf->promisc_multicast_enabled);
2233 vf->promisc_unicast_enabled = FALSE;
2237 i40evf_dev_allmulticast_enable(struct rte_eth_dev *dev)
2239 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2242 /* If enabled, just return */
2243 if (vf->promisc_multicast_enabled)
2246 ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 1);
2248 vf->promisc_multicast_enabled = TRUE;
2252 i40evf_dev_allmulticast_disable(struct rte_eth_dev *dev)
2254 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2257 /* If enabled, just return */
2258 if (!vf->promisc_multicast_enabled)
2261 ret = i40evf_config_promisc(dev, vf->promisc_unicast_enabled, 0);
2263 vf->promisc_multicast_enabled = FALSE;
2267 i40evf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2269 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2271 memset(dev_info, 0, sizeof(*dev_info));
2272 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2273 dev_info->max_rx_queues = vf->vsi_res->num_queue_pairs;
2274 dev_info->max_tx_queues = vf->vsi_res->num_queue_pairs;
2275 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
2276 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
2277 dev_info->hash_key_size = (I40E_VFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
2278 dev_info->reta_size = ETH_RSS_RETA_SIZE_64;
2279 dev_info->flow_type_rss_offloads = I40E_RSS_OFFLOAD_ALL;
2280 dev_info->max_mac_addrs = I40E_NUM_MACADDR_MAX;
2281 dev_info->rx_offload_capa =
2282 DEV_RX_OFFLOAD_VLAN_STRIP |
2283 DEV_RX_OFFLOAD_QINQ_STRIP |
2284 DEV_RX_OFFLOAD_IPV4_CKSUM |
2285 DEV_RX_OFFLOAD_UDP_CKSUM |
2286 DEV_RX_OFFLOAD_TCP_CKSUM;
2287 dev_info->tx_offload_capa =
2288 DEV_TX_OFFLOAD_VLAN_INSERT |
2289 DEV_TX_OFFLOAD_QINQ_INSERT |
2290 DEV_TX_OFFLOAD_IPV4_CKSUM |
2291 DEV_TX_OFFLOAD_UDP_CKSUM |
2292 DEV_TX_OFFLOAD_TCP_CKSUM |
2293 DEV_TX_OFFLOAD_SCTP_CKSUM;
2295 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2297 .pthresh = I40E_DEFAULT_RX_PTHRESH,
2298 .hthresh = I40E_DEFAULT_RX_HTHRESH,
2299 .wthresh = I40E_DEFAULT_RX_WTHRESH,
2301 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
2305 dev_info->default_txconf = (struct rte_eth_txconf) {
2307 .pthresh = I40E_DEFAULT_TX_PTHRESH,
2308 .hthresh = I40E_DEFAULT_TX_HTHRESH,
2309 .wthresh = I40E_DEFAULT_TX_WTHRESH,
2311 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
2312 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
2313 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2314 ETH_TXQ_FLAGS_NOOFFLOADS,
2317 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
2318 .nb_max = I40E_MAX_RING_DESC,
2319 .nb_min = I40E_MIN_RING_DESC,
2320 .nb_align = I40E_ALIGN_RING_DESC,
2323 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
2324 .nb_max = I40E_MAX_RING_DESC,
2325 .nb_min = I40E_MIN_RING_DESC,
2326 .nb_align = I40E_ALIGN_RING_DESC,
2331 i40evf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2333 if (i40evf_get_statistics(dev, stats))
2334 PMD_DRV_LOG(ERR, "Get statistics failed");
2338 i40evf_dev_close(struct rte_eth_dev *dev)
2340 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2341 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2342 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2344 i40evf_dev_stop(dev);
2345 hw->adapter_stopped = 1;
2346 i40e_dev_free_queues(dev);
2347 i40evf_reset_vf(hw);
2348 i40e_shutdown_adminq(hw);
2349 /* disable uio intr before callback unregister */
2350 rte_intr_disable(intr_handle);
2352 /* unregister callback func from eal lib */
2353 rte_intr_callback_unregister(intr_handle,
2354 i40evf_dev_interrupt_handler, dev);
2355 i40evf_disable_irq0(hw);
2359 i40evf_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
2361 struct i40e_vf *vf = I40E_VSI_TO_VF(vsi);
2362 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2368 if (vf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2369 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id, FALSE,
2372 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
2376 uint32_t *lut_dw = (uint32_t *)lut;
2377 uint16_t i, lut_size_dw = lut_size / 4;
2379 for (i = 0; i < lut_size_dw; i++)
2380 lut_dw[i] = I40E_READ_REG(hw, I40E_VFQF_HLUT(i));
2387 i40evf_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
2396 vf = I40E_VSI_TO_VF(vsi);
2397 hw = I40E_VSI_TO_HW(vsi);
2399 if (vf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2400 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id, FALSE,
2403 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
2407 uint32_t *lut_dw = (uint32_t *)lut;
2408 uint16_t i, lut_size_dw = lut_size / 4;
2410 for (i = 0; i < lut_size_dw; i++)
2411 I40E_WRITE_REG(hw, I40E_VFQF_HLUT(i), lut_dw[i]);
2412 I40EVF_WRITE_FLUSH(hw);
2419 i40evf_dev_rss_reta_update(struct rte_eth_dev *dev,
2420 struct rte_eth_rss_reta_entry64 *reta_conf,
2423 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2425 uint16_t i, idx, shift;
2428 if (reta_size != ETH_RSS_RETA_SIZE_64) {
2429 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2430 "(%d) doesn't match the number of hardware can "
2431 "support (%d)", reta_size, ETH_RSS_RETA_SIZE_64);
2435 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
2437 PMD_DRV_LOG(ERR, "No memory can be allocated");
2440 ret = i40evf_get_rss_lut(&vf->vsi, lut, reta_size);
2443 for (i = 0; i < reta_size; i++) {
2444 idx = i / RTE_RETA_GROUP_SIZE;
2445 shift = i % RTE_RETA_GROUP_SIZE;
2446 if (reta_conf[idx].mask & (1ULL << shift))
2447 lut[i] = reta_conf[idx].reta[shift];
2449 ret = i40evf_set_rss_lut(&vf->vsi, lut, reta_size);
2458 i40evf_dev_rss_reta_query(struct rte_eth_dev *dev,
2459 struct rte_eth_rss_reta_entry64 *reta_conf,
2462 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2463 uint16_t i, idx, shift;
2467 if (reta_size != ETH_RSS_RETA_SIZE_64) {
2468 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2469 "(%d) doesn't match the number of hardware can "
2470 "support (%d)", reta_size, ETH_RSS_RETA_SIZE_64);
2474 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
2476 PMD_DRV_LOG(ERR, "No memory can be allocated");
2480 ret = i40evf_get_rss_lut(&vf->vsi, lut, reta_size);
2483 for (i = 0; i < reta_size; i++) {
2484 idx = i / RTE_RETA_GROUP_SIZE;
2485 shift = i % RTE_RETA_GROUP_SIZE;
2486 if (reta_conf[idx].mask & (1ULL << shift))
2487 reta_conf[idx].reta[shift] = lut[i];
2497 i40evf_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
2499 struct i40e_vf *vf = I40E_VSI_TO_VF(vsi);
2500 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2503 if (!key || key_len == 0) {
2504 PMD_DRV_LOG(DEBUG, "No key to be configured");
2506 } else if (key_len != (I40E_VFQF_HKEY_MAX_INDEX + 1) *
2508 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
2512 if (vf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2513 struct i40e_aqc_get_set_rss_key_data *key_dw =
2514 (struct i40e_aqc_get_set_rss_key_data *)key;
2516 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
2518 PMD_INIT_LOG(ERR, "Failed to configure RSS key "
2521 uint32_t *hash_key = (uint32_t *)key;
2524 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
2525 i40e_write_rx_ctl(hw, I40E_VFQF_HKEY(i), hash_key[i]);
2526 I40EVF_WRITE_FLUSH(hw);
2533 i40evf_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
2535 struct i40e_vf *vf = I40E_VSI_TO_VF(vsi);
2536 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2539 if (!key || !key_len)
2542 if (vf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2543 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
2544 (struct i40e_aqc_get_set_rss_key_data *)key);
2546 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
2550 uint32_t *key_dw = (uint32_t *)key;
2553 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
2554 key_dw[i] = i40e_read_rx_ctl(hw, I40E_VFQF_HKEY(i));
2556 *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
2562 i40evf_hw_rss_hash_set(struct i40e_vf *vf, struct rte_eth_rss_conf *rss_conf)
2564 struct i40e_hw *hw = I40E_VF_TO_HW(vf);
2565 uint64_t rss_hf, hena;
2568 ret = i40evf_set_rss_key(&vf->vsi, rss_conf->rss_key,
2569 rss_conf->rss_key_len);
2573 rss_hf = rss_conf->rss_hf;
2574 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_VFQF_HENA(0));
2575 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_VFQF_HENA(1))) << 32;
2576 if (hw->mac.type == I40E_MAC_X722)
2577 hena &= ~I40E_RSS_HENA_ALL_X722;
2579 hena &= ~I40E_RSS_HENA_ALL;
2580 hena |= i40e_config_hena(rss_hf, hw->mac.type);
2581 i40e_write_rx_ctl(hw, I40E_VFQF_HENA(0), (uint32_t)hena);
2582 i40e_write_rx_ctl(hw, I40E_VFQF_HENA(1), (uint32_t)(hena >> 32));
2583 I40EVF_WRITE_FLUSH(hw);
2589 i40evf_disable_rss(struct i40e_vf *vf)
2591 struct i40e_hw *hw = I40E_VF_TO_HW(vf);
2594 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_VFQF_HENA(0));
2595 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_VFQF_HENA(1))) << 32;
2596 if (hw->mac.type == I40E_MAC_X722)
2597 hena &= ~I40E_RSS_HENA_ALL_X722;
2599 hena &= ~I40E_RSS_HENA_ALL;
2600 i40e_write_rx_ctl(hw, I40E_VFQF_HENA(0), (uint32_t)hena);
2601 i40e_write_rx_ctl(hw, I40E_VFQF_HENA(1), (uint32_t)(hena >> 32));
2602 I40EVF_WRITE_FLUSH(hw);
2606 i40evf_config_rss(struct i40e_vf *vf)
2608 struct i40e_hw *hw = I40E_VF_TO_HW(vf);
2609 struct rte_eth_rss_conf rss_conf;
2610 uint32_t i, j, lut = 0, nb_q = (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
2613 if (vf->dev_data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS) {
2614 i40evf_disable_rss(vf);
2615 PMD_DRV_LOG(DEBUG, "RSS not configured");
2619 num = RTE_MIN(vf->dev_data->nb_rx_queues, I40E_MAX_QP_NUM_PER_VF);
2620 /* Fill out the look up table */
2621 for (i = 0, j = 0; i < nb_q; i++, j++) {
2624 lut = (lut << 8) | j;
2626 I40E_WRITE_REG(hw, I40E_VFQF_HLUT(i >> 2), lut);
2629 rss_conf = vf->dev_data->dev_conf.rx_adv_conf.rss_conf;
2630 if ((rss_conf.rss_hf & I40E_RSS_OFFLOAD_ALL) == 0) {
2631 i40evf_disable_rss(vf);
2632 PMD_DRV_LOG(DEBUG, "No hash flag is set");
2636 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
2637 (I40E_VFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
2638 /* Calculate the default hash key */
2639 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
2640 rss_key_default[i] = (uint32_t)rte_rand();
2641 rss_conf.rss_key = (uint8_t *)rss_key_default;
2642 rss_conf.rss_key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
2646 return i40evf_hw_rss_hash_set(vf, &rss_conf);
2650 i40evf_dev_rss_hash_update(struct rte_eth_dev *dev,
2651 struct rte_eth_rss_conf *rss_conf)
2653 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2654 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2655 uint64_t rss_hf = rss_conf->rss_hf & I40E_RSS_OFFLOAD_ALL;
2658 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_VFQF_HENA(0));
2659 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_VFQF_HENA(1))) << 32;
2660 if (!(hena & ((hw->mac.type == I40E_MAC_X722)
2661 ? I40E_RSS_HENA_ALL_X722
2662 : I40E_RSS_HENA_ALL))) { /* RSS disabled */
2663 if (rss_hf != 0) /* Enable RSS */
2669 if (rss_hf == 0) /* Disable RSS */
2672 return i40evf_hw_rss_hash_set(vf, rss_conf);
2676 i40evf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
2677 struct rte_eth_rss_conf *rss_conf)
2679 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2680 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2683 i40evf_get_rss_key(&vf->vsi, rss_conf->rss_key,
2684 &rss_conf->rss_key_len);
2686 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_VFQF_HENA(0));
2687 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_VFQF_HENA(1))) << 32;
2688 rss_conf->rss_hf = i40e_parse_hena(hena);
2694 i40evf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
2696 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2697 struct rte_eth_dev_data *dev_data = vf->dev_data;
2698 uint32_t frame_size = mtu + I40E_ETH_OVERHEAD;
2701 /* check if mtu is within the allowed range */
2702 if ((mtu < ETHER_MIN_MTU) || (frame_size > I40E_FRAME_SIZE_MAX))
2705 /* mtu setting is forbidden if port is start */
2706 if (dev_data->dev_started) {
2707 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
2712 if (frame_size > ETHER_MAX_LEN)
2713 dev_data->dev_conf.rxmode.jumbo_frame = 1;
2715 dev_data->dev_conf.rxmode.jumbo_frame = 0;
2717 dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
2723 i40evf_set_default_mac_addr(struct rte_eth_dev *dev,
2724 struct ether_addr *mac_addr)
2726 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
2728 if (!is_valid_assigned_ether_addr(mac_addr)) {
2729 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
2733 if (is_same_ether_addr(mac_addr, dev->data->mac_addrs))
2736 if (vf->flags & I40E_FLAG_VF_MAC_BY_PF)
2739 i40evf_del_mac_addr_by_addr(dev, dev->data->mac_addrs);
2741 i40evf_add_mac_addr(dev, mac_addr, 0, 0);