Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <stdint.h>
6 : : #include <string.h>
7 : : #include <stdio.h>
8 : : #include <stdlib.h>
9 : : #include <errno.h>
10 : : #include <unistd.h>
11 : :
12 : : #include <ethdev_driver.h>
13 : : #include <rte_memcpy.h>
14 : : #include <rte_string_fns.h>
15 : : #include <rte_memzone.h>
16 : : #include <rte_malloc.h>
17 : : #include <rte_branch_prediction.h>
18 : : #include <rte_ether.h>
19 : : #include <rte_ip.h>
20 : : #include <rte_arp.h>
21 : : #include <rte_common.h>
22 : : #include <rte_errno.h>
23 : : #include <rte_cpuflags.h>
24 : : #include <rte_vect.h>
25 : : #include <rte_memory.h>
26 : : #include <rte_eal_paging.h>
27 : : #include <rte_eal.h>
28 : : #include <dev_driver.h>
29 : : #include <rte_cycles.h>
30 : : #include <rte_kvargs.h>
31 : :
32 : : #include "virtio_ethdev.h"
33 : : #include "virtio.h"
34 : : #include "virtio_logs.h"
35 : : #include "virtqueue.h"
36 : : #include "virtio_cvq.h"
37 : : #include "virtio_rxtx.h"
38 : : #include "virtio_rxtx_simple.h"
39 : : #include "virtio_user/virtio_user_dev.h"
40 : :
41 : : static int virtio_dev_configure(struct rte_eth_dev *dev);
42 : : static int virtio_dev_start(struct rte_eth_dev *dev);
43 : : static int virtio_dev_promiscuous_enable(struct rte_eth_dev *dev);
44 : : static int virtio_dev_promiscuous_disable(struct rte_eth_dev *dev);
45 : : static int virtio_dev_allmulticast_enable(struct rte_eth_dev *dev);
46 : : static int virtio_dev_allmulticast_disable(struct rte_eth_dev *dev);
47 : : static uint32_t virtio_dev_speed_capa_get(uint32_t speed);
48 : : static int virtio_dev_devargs_parse(struct rte_devargs *devargs,
49 : : uint32_t *speed,
50 : : int *vectorized);
51 : : static int virtio_dev_info_get(struct rte_eth_dev *dev,
52 : : struct rte_eth_dev_info *dev_info);
53 : : static int virtio_dev_link_update(struct rte_eth_dev *dev,
54 : : int wait_to_complete);
55 : : static int virtio_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
56 : : static int virtio_dev_rss_hash_update(struct rte_eth_dev *dev,
57 : : struct rte_eth_rss_conf *rss_conf);
58 : : static int virtio_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
59 : : struct rte_eth_rss_conf *rss_conf);
60 : : static int virtio_dev_rss_reta_update(struct rte_eth_dev *dev,
61 : : struct rte_eth_rss_reta_entry64 *reta_conf,
62 : : uint16_t reta_size);
63 : : static int virtio_dev_rss_reta_query(struct rte_eth_dev *dev,
64 : : struct rte_eth_rss_reta_entry64 *reta_conf,
65 : : uint16_t reta_size);
66 : :
67 : : static void virtio_set_hwaddr(struct virtio_hw *hw);
68 : : static void virtio_get_hwaddr(struct virtio_hw *hw);
69 : :
70 : : static int virtio_dev_stats_get(struct rte_eth_dev *dev,
71 : : struct rte_eth_stats *stats,
72 : : struct eth_queue_stats *qstats);
73 : : static int virtio_dev_xstats_get(struct rte_eth_dev *dev,
74 : : struct rte_eth_xstat *xstats, unsigned n);
75 : : static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
76 : : struct rte_eth_xstat_name *xstats_names,
77 : : unsigned limit);
78 : : static int virtio_dev_stats_reset(struct rte_eth_dev *dev);
79 : : static void virtio_dev_free_mbufs(struct rte_eth_dev *dev);
80 : : static int virtio_vlan_filter_set(struct rte_eth_dev *dev,
81 : : uint16_t vlan_id, int on);
82 : : static int virtio_mac_addr_add(struct rte_eth_dev *dev,
83 : : struct rte_ether_addr *mac_addr,
84 : : uint32_t index, uint32_t vmdq);
85 : : static void virtio_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
86 : : static int virtio_mac_addr_set(struct rte_eth_dev *dev,
87 : : struct rte_ether_addr *mac_addr);
88 : :
89 : : static int virtio_intr_disable(struct rte_eth_dev *dev);
90 : : static int virtio_get_monitor_addr(void *rx_queue,
91 : : struct rte_power_monitor_cond *pmc);
92 : :
93 : : static void virtio_notify_peers(struct rte_eth_dev *dev);
94 : : static void virtio_ack_link_announce(struct rte_eth_dev *dev);
95 : :
96 : : static int virtio_rx_burst_mode_get(struct rte_eth_dev *dev,
97 : : __rte_unused uint16_t queue_id, struct rte_eth_burst_mode *mode);
98 : : static int virtio_tx_burst_mode_get(struct rte_eth_dev *dev,
99 : : __rte_unused uint16_t queue_id, struct rte_eth_burst_mode *mode);
100 : :
101 : : struct rte_virtio_xstats_name_off {
102 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
103 : : unsigned offset;
104 : : };
105 : :
106 : : /* [rt]x_qX_ is prepended to the name string here */
107 : : static const struct rte_virtio_xstats_name_off rte_virtio_rxq_stat_strings[] = {
108 : : {"good_packets", offsetof(struct virtnet_rx, stats.packets)},
109 : : {"good_bytes", offsetof(struct virtnet_rx, stats.bytes)},
110 : : {"errors", offsetof(struct virtnet_rx, stats.errors)},
111 : : {"multicast_packets", offsetof(struct virtnet_rx, stats.multicast)},
112 : : {"broadcast_packets", offsetof(struct virtnet_rx, stats.broadcast)},
113 : : {"undersize_packets", offsetof(struct virtnet_rx, stats.size_bins[0])},
114 : : {"size_64_packets", offsetof(struct virtnet_rx, stats.size_bins[1])},
115 : : {"size_65_127_packets", offsetof(struct virtnet_rx, stats.size_bins[2])},
116 : : {"size_128_255_packets", offsetof(struct virtnet_rx, stats.size_bins[3])},
117 : : {"size_256_511_packets", offsetof(struct virtnet_rx, stats.size_bins[4])},
118 : : {"size_512_1023_packets", offsetof(struct virtnet_rx, stats.size_bins[5])},
119 : : {"size_1024_1518_packets", offsetof(struct virtnet_rx, stats.size_bins[6])},
120 : : {"size_1519_max_packets", offsetof(struct virtnet_rx, stats.size_bins[7])},
121 : : };
122 : :
123 : : /* [rt]x_qX_ is prepended to the name string here */
124 : : static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = {
125 : : {"good_packets", offsetof(struct virtnet_tx, stats.packets)},
126 : : {"good_bytes", offsetof(struct virtnet_tx, stats.bytes)},
127 : : {"multicast_packets", offsetof(struct virtnet_tx, stats.multicast)},
128 : : {"broadcast_packets", offsetof(struct virtnet_tx, stats.broadcast)},
129 : : {"undersize_packets", offsetof(struct virtnet_tx, stats.size_bins[0])},
130 : : {"size_64_packets", offsetof(struct virtnet_tx, stats.size_bins[1])},
131 : : {"size_65_127_packets", offsetof(struct virtnet_tx, stats.size_bins[2])},
132 : : {"size_128_255_packets", offsetof(struct virtnet_tx, stats.size_bins[3])},
133 : : {"size_256_511_packets", offsetof(struct virtnet_tx, stats.size_bins[4])},
134 : : {"size_512_1023_packets", offsetof(struct virtnet_tx, stats.size_bins[5])},
135 : : {"size_1024_1518_packets", offsetof(struct virtnet_tx, stats.size_bins[6])},
136 : : {"size_1519_max_packets", offsetof(struct virtnet_tx, stats.size_bins[7])},
137 : : };
138 : :
139 : : #define VIRTIO_NB_RXQ_XSTATS (sizeof(rte_virtio_rxq_stat_strings) / \
140 : : sizeof(rte_virtio_rxq_stat_strings[0]))
141 : : #define VIRTIO_NB_TXQ_XSTATS (sizeof(rte_virtio_txq_stat_strings) / \
142 : : sizeof(rte_virtio_txq_stat_strings[0]))
143 : :
144 : : struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
145 : :
146 : : static int
147 : 0 : virtio_set_multiple_queues_rss(struct rte_eth_dev *dev, uint16_t nb_queues)
148 : : {
149 : 0 : struct virtio_hw *hw = dev->data->dev_private;
150 : : struct virtio_pmd_ctrl ctrl;
151 : : struct virtio_net_ctrl_rss rss;
152 : : int dlen, ret;
153 : :
154 : 0 : rss.hash_types = hw->rss_hash_types & VIRTIO_NET_HASH_TYPE_MASK;
155 : : RTE_BUILD_BUG_ON(!RTE_IS_POWER_OF_2(VIRTIO_NET_RSS_RETA_SIZE));
156 : 0 : rss.indirection_table_mask = VIRTIO_NET_RSS_RETA_SIZE - 1;
157 : 0 : rss.unclassified_queue = 0;
158 : 0 : memcpy(rss.indirection_table, hw->rss_reta, VIRTIO_NET_RSS_RETA_SIZE * sizeof(uint16_t));
159 : 0 : rss.max_tx_vq = nb_queues;
160 : 0 : rss.hash_key_length = VIRTIO_NET_RSS_KEY_SIZE;
161 : 0 : memcpy(rss.hash_key_data, hw->rss_key, VIRTIO_NET_RSS_KEY_SIZE);
162 : :
163 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_MQ;
164 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_MQ_RSS_CONFIG;
165 : : memcpy(ctrl.data, &rss, sizeof(rss));
166 : :
167 : 0 : dlen = sizeof(rss);
168 : :
169 : 0 : ret = virtio_send_command(hw->cvq, &ctrl, &dlen, 1);
170 [ # # ]: 0 : if (ret) {
171 : 0 : PMD_INIT_LOG(ERR, "RSS multiqueue configured but send command failed");
172 : 0 : return -EINVAL;
173 : : }
174 : :
175 : : return 0;
176 : : }
177 : :
178 : : static int
179 : 0 : virtio_set_multiple_queues_auto(struct rte_eth_dev *dev, uint16_t nb_queues)
180 : : {
181 : 0 : struct virtio_hw *hw = dev->data->dev_private;
182 : : struct virtio_pmd_ctrl ctrl;
183 : : int dlen;
184 : : int ret;
185 : :
186 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_MQ;
187 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET;
188 : : memcpy(ctrl.data, &nb_queues, sizeof(uint16_t));
189 : :
190 : 0 : dlen = sizeof(uint16_t);
191 : :
192 : 0 : ret = virtio_send_command(hw->cvq, &ctrl, &dlen, 1);
193 [ # # ]: 0 : if (ret) {
194 : 0 : PMD_INIT_LOG(ERR, "Multiqueue configured but send command "
195 : : "failed, this is too late now...");
196 : 0 : return -EINVAL;
197 : : }
198 : :
199 : : return 0;
200 : : }
201 : :
202 : : static int
203 : 0 : virtio_set_multiple_queues(struct rte_eth_dev *dev, uint16_t nb_queues)
204 : : {
205 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
206 : :
207 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_RSS))
208 : 0 : return virtio_set_multiple_queues_rss(dev, nb_queues);
209 : : else
210 : 0 : return virtio_set_multiple_queues_auto(dev, nb_queues);
211 : : }
212 : :
213 : : static uint16_t
214 : : virtio_get_nr_vq(struct virtio_hw *hw)
215 : : {
216 : 0 : uint16_t nr_vq = hw->max_queue_pairs * 2;
217 : :
218 [ # # # # : 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VQ))
# # ]
219 : 0 : nr_vq += 1;
220 : :
221 : : return nr_vq;
222 : : }
223 : :
224 : : static void
225 : 0 : virtio_control_queue_notify(struct virtqueue *vq, __rte_unused void *cookie)
226 : : {
227 : : virtqueue_notify(vq);
228 : 0 : }
229 : :
230 : : static int
231 : 0 : virtio_init_queue(struct rte_eth_dev *dev, uint16_t queue_idx)
232 : : {
233 : : char vq_name[VIRTQUEUE_MAX_NAME_SZ];
234 : : unsigned int vq_size;
235 : 0 : struct virtio_hw *hw = dev->data->dev_private;
236 : : struct virtqueue *vq;
237 [ # # ]: 0 : int queue_type = virtio_get_queue_type(hw, queue_idx);
238 : : int ret;
239 : 0 : int numa_node = dev->device->numa_node;
240 : :
241 : 0 : PMD_INIT_LOG(INFO, "setting up queue: %u on NUMA node %d",
242 : : queue_idx, numa_node);
243 : :
244 : : /*
245 : : * Read the virtqueue size from the Queue Size field
246 : : * Always power of 2 and if 0 virtqueue does not exist
247 : : */
248 : 0 : vq_size = VIRTIO_OPS(hw)->get_queue_num(hw, queue_idx);
249 : 0 : PMD_INIT_LOG(DEBUG, "vq_size: %u", vq_size);
250 [ # # ]: 0 : if (vq_size == 0) {
251 : 0 : PMD_INIT_LOG(ERR, "virtqueue does not exist");
252 : 0 : return -EINVAL;
253 : : }
254 : :
255 [ # # ]: 0 : if (!virtio_with_packed_queue(hw) && !rte_is_power_of_2(vq_size)) {
256 : 0 : PMD_INIT_LOG(ERR, "split virtqueue size is not power of 2");
257 : 0 : return -EINVAL;
258 : : }
259 : :
260 : 0 : snprintf(vq_name, sizeof(vq_name), "port%d_vq%d", dev->data->port_id, queue_idx);
261 : :
262 : 0 : vq = virtqueue_alloc(hw, queue_idx, vq_size, queue_type, numa_node, vq_name);
263 [ # # ]: 0 : if (!vq) {
264 : 0 : PMD_INIT_LOG(ERR, "virtqueue init failed");
265 : 0 : return -ENOMEM;
266 : : }
267 : :
268 : 0 : hw->vqs[queue_idx] = vq;
269 : :
270 [ # # ]: 0 : if (queue_type == VTNET_CQ) {
271 : 0 : hw->cvq = &vq->cq;
272 : 0 : vq->cq.notify_queue = &virtio_control_queue_notify;
273 : : }
274 : :
275 [ # # ]: 0 : if (VIRTIO_OPS(hw)->setup_queue(hw, vq) < 0) {
276 : 0 : PMD_INIT_LOG(ERR, "setup_queue failed");
277 : : ret = -EINVAL;
278 : 0 : goto clean_vq;
279 : : }
280 : :
281 : : return 0;
282 : :
283 : : clean_vq:
284 [ # # ]: 0 : if (queue_type == VTNET_CQ)
285 : 0 : hw->cvq = NULL;
286 : 0 : virtqueue_free(vq);
287 : 0 : hw->vqs[queue_idx] = NULL;
288 : :
289 : 0 : return ret;
290 : : }
291 : :
292 : : static void
293 [ # # ]: 0 : virtio_free_queues(struct virtio_hw *hw)
294 : : {
295 : : uint16_t nr_vq = virtio_get_nr_vq(hw);
296 : : struct virtqueue *vq;
297 : : uint16_t i;
298 : :
299 [ # # ]: 0 : if (hw->vqs == NULL)
300 : : return;
301 : :
302 [ # # ]: 0 : for (i = 0; i < nr_vq; i++) {
303 : 0 : vq = hw->vqs[i];
304 [ # # ]: 0 : if (!vq)
305 : 0 : continue;
306 : 0 : virtqueue_free(vq);
307 : 0 : hw->vqs[i] = NULL;
308 : : }
309 : :
310 : 0 : rte_free(hw->vqs);
311 : 0 : hw->vqs = NULL;
312 : : }
313 : :
314 : : static int
315 : 0 : virtio_alloc_queues(struct rte_eth_dev *dev)
316 : : {
317 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
318 : : uint16_t nr_vq = virtio_get_nr_vq(hw);
319 : : uint16_t i;
320 : : int ret;
321 : :
322 : 0 : hw->vqs = rte_zmalloc(NULL, sizeof(struct virtqueue *) * nr_vq, 0);
323 [ # # ]: 0 : if (!hw->vqs) {
324 : 0 : PMD_INIT_LOG(ERR, "failed to allocate vqs");
325 : 0 : return -ENOMEM;
326 : : }
327 : :
328 [ # # ]: 0 : for (i = 0; i < nr_vq; i++) {
329 : 0 : ret = virtio_init_queue(dev, i);
330 [ # # ]: 0 : if (ret < 0) {
331 : 0 : virtio_free_queues(hw);
332 : 0 : return ret;
333 : : }
334 : : }
335 : :
336 : : return 0;
337 : : }
338 : :
339 : : static void virtio_queues_unbind_intr(struct rte_eth_dev *dev);
340 : :
341 : : static void
342 : : virtio_free_rss(struct virtio_hw *hw)
343 : : {
344 : 0 : rte_free(hw->rss_key);
345 : 0 : hw->rss_key = NULL;
346 : :
347 : 0 : rte_free(hw->rss_reta);
348 : 0 : hw->rss_reta = NULL;
349 : : }
350 : :
351 : : int
352 : 0 : virtio_dev_close(struct rte_eth_dev *dev)
353 : : {
354 : 0 : struct virtio_hw *hw = dev->data->dev_private;
355 : : struct rte_eth_intr_conf *intr_conf = &dev->data->dev_conf.intr_conf;
356 : :
357 : 0 : PMD_INIT_LOG(DEBUG, "virtio_dev_close");
358 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
359 : : return 0;
360 : :
361 [ # # ]: 0 : if (!hw->opened)
362 : : return 0;
363 : 0 : hw->opened = 0;
364 : :
365 : : /* reset the NIC */
366 [ # # ]: 0 : if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
367 : 0 : VIRTIO_OPS(hw)->set_config_irq(hw, VIRTIO_MSI_NO_VECTOR);
368 [ # # ]: 0 : if (intr_conf->rxq)
369 : 0 : virtio_queues_unbind_intr(dev);
370 : :
371 [ # # ]: 0 : if (intr_conf->lsc || intr_conf->rxq) {
372 : 0 : virtio_intr_disable(dev);
373 : 0 : rte_intr_efd_disable(dev->intr_handle);
374 : 0 : rte_intr_vec_list_free(dev->intr_handle);
375 : : }
376 : :
377 : 0 : virtio_reset(hw);
378 : 0 : virtio_dev_free_mbufs(dev);
379 : 0 : virtio_free_queues(hw);
380 : : virtio_free_rss(hw);
381 : :
382 : 0 : return VIRTIO_OPS(hw)->dev_close(hw);
383 : : }
384 : :
385 : : static int
386 : 0 : virtio_dev_promiscuous_enable(struct rte_eth_dev *dev)
387 : : {
388 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
389 : : struct virtio_pmd_ctrl ctrl;
390 : : int dlen[1];
391 : : int ret;
392 : :
393 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
394 : 0 : PMD_INIT_LOG(INFO, "host does not support rx control");
395 : 0 : return -ENOTSUP;
396 : : }
397 : :
398 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
399 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_PROMISC;
400 : 0 : ctrl.data[0] = 1;
401 : 0 : dlen[0] = 1;
402 : :
403 : 0 : ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
404 [ # # ]: 0 : if (ret) {
405 : 0 : PMD_INIT_LOG(ERR, "Failed to enable promisc");
406 : 0 : return -EAGAIN;
407 : : }
408 : :
409 : : return 0;
410 : : }
411 : :
412 : : static int
413 : 0 : virtio_dev_promiscuous_disable(struct rte_eth_dev *dev)
414 : : {
415 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
416 : : struct virtio_pmd_ctrl ctrl;
417 : : int dlen[1];
418 : : int ret;
419 : :
420 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
421 : 0 : PMD_INIT_LOG(INFO, "host does not support rx control");
422 : 0 : return -ENOTSUP;
423 : : }
424 : :
425 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
426 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_PROMISC;
427 : 0 : ctrl.data[0] = 0;
428 : 0 : dlen[0] = 1;
429 : :
430 : 0 : ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
431 [ # # ]: 0 : if (ret) {
432 : 0 : PMD_INIT_LOG(ERR, "Failed to disable promisc");
433 : 0 : return -EAGAIN;
434 : : }
435 : :
436 : : return 0;
437 : : }
438 : :
439 : : static int
440 : 0 : virtio_dev_allmulticast_enable(struct rte_eth_dev *dev)
441 : : {
442 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
443 : : struct virtio_pmd_ctrl ctrl;
444 : : int dlen[1];
445 : : int ret;
446 : :
447 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
448 : 0 : PMD_INIT_LOG(INFO, "host does not support rx control");
449 : 0 : return -ENOTSUP;
450 : : }
451 : :
452 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
453 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_ALLMULTI;
454 : 0 : ctrl.data[0] = 1;
455 : 0 : dlen[0] = 1;
456 : :
457 : 0 : ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
458 [ # # ]: 0 : if (ret) {
459 : 0 : PMD_INIT_LOG(ERR, "Failed to enable allmulticast");
460 : 0 : return -EAGAIN;
461 : : }
462 : :
463 : : return 0;
464 : : }
465 : :
466 : : static int
467 : 0 : virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
468 : : {
469 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
470 : : struct virtio_pmd_ctrl ctrl;
471 : : int dlen[1];
472 : : int ret;
473 : :
474 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
475 : 0 : PMD_INIT_LOG(INFO, "host does not support rx control");
476 : 0 : return -ENOTSUP;
477 : : }
478 : :
479 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
480 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_ALLMULTI;
481 : 0 : ctrl.data[0] = 0;
482 : 0 : dlen[0] = 1;
483 : :
484 : 0 : ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
485 [ # # ]: 0 : if (ret) {
486 : 0 : PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
487 : 0 : return -EAGAIN;
488 : : }
489 : :
490 : : return 0;
491 : : }
492 : :
493 : : uint16_t
494 [ # # ]: 0 : virtio_rx_mem_pool_buf_size(struct rte_mempool *mp)
495 : : {
496 : 0 : return rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM;
497 : : }
498 : :
499 : : bool
500 : 0 : virtio_rx_check_scatter(uint16_t max_rx_pkt_len, uint16_t rx_buf_size,
501 : : bool rx_scatter_enabled, const char **error)
502 : : {
503 [ # # ]: 0 : if (!rx_scatter_enabled && max_rx_pkt_len > rx_buf_size) {
504 : 0 : *error = "Rx scatter is disabled and RxQ mbuf pool object size is too small";
505 : 0 : return false;
506 : : }
507 : :
508 : : return true;
509 : : }
510 : :
511 : : static bool
512 : 0 : virtio_check_scatter_on_all_rx_queues(struct rte_eth_dev *dev,
513 : : uint16_t frame_size)
514 : : {
515 : 0 : struct virtio_hw *hw = dev->data->dev_private;
516 : : struct virtnet_rx *rxvq;
517 : : struct virtqueue *vq;
518 : : unsigned int qidx;
519 : : uint16_t buf_size;
520 : : const char *error;
521 : :
522 [ # # ]: 0 : if (hw->vqs == NULL)
523 : : return true;
524 : :
525 [ # # ]: 0 : for (qidx = 0; qidx < hw->max_queue_pairs; qidx++) {
526 : 0 : vq = hw->vqs[2 * qidx + VTNET_SQ_RQ_QUEUE_IDX];
527 [ # # ]: 0 : if (vq == NULL)
528 : 0 : continue;
529 : :
530 : : rxvq = &vq->rxq;
531 [ # # ]: 0 : if (rxvq->mpool == NULL)
532 : 0 : continue;
533 : 0 : buf_size = virtio_rx_mem_pool_buf_size(rxvq->mpool);
534 : :
535 [ # # ]: 0 : if (!virtio_rx_check_scatter(frame_size, buf_size,
536 : 0 : hw->rx_ol_scatter, &error)) {
537 : 0 : PMD_INIT_LOG(ERR, "MTU check for RxQ %u failed: %s",
538 : : qidx, error);
539 : 0 : return false;
540 : : }
541 : : }
542 : :
543 : : return true;
544 : : }
545 : :
546 : : #define VLAN_TAG_LEN 4 /* 802.3ac tag (not DMA'd) */
547 : : static int
548 : 0 : virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
549 : : {
550 : 0 : struct virtio_hw *hw = dev->data->dev_private;
551 : 0 : uint32_t ether_hdr_len = RTE_ETHER_HDR_LEN + VLAN_TAG_LEN +
552 : 0 : hw->vtnet_hdr_size;
553 : 0 : uint32_t frame_size = mtu + ether_hdr_len;
554 : 0 : uint32_t max_frame_size = hw->max_mtu + ether_hdr_len;
555 : :
556 : 0 : max_frame_size = RTE_MIN(max_frame_size, VIRTIO_MAX_RX_PKTLEN);
557 : :
558 [ # # ]: 0 : if (mtu < RTE_ETHER_MIN_MTU || frame_size > max_frame_size) {
559 : 0 : PMD_INIT_LOG(ERR, "MTU should be between %d and %d",
560 : : RTE_ETHER_MIN_MTU, max_frame_size - ether_hdr_len);
561 : 0 : return -EINVAL;
562 : : }
563 : :
564 [ # # ]: 0 : if (!virtio_check_scatter_on_all_rx_queues(dev, frame_size)) {
565 : 0 : PMD_INIT_LOG(ERR, "MTU vs Rx scatter and Rx buffers check failed");
566 : 0 : return -EINVAL;
567 : : }
568 : :
569 : 0 : hw->max_rx_pkt_len = frame_size;
570 : :
571 : 0 : return 0;
572 : : }
573 : :
574 : : static int
575 : 0 : virtio_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
576 : : {
577 : 0 : struct virtio_hw *hw = dev->data->dev_private;
578 : 0 : struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];
579 [ # # ]: 0 : struct virtqueue *vq = virtnet_rxq_to_vq(rxvq);
580 : :
581 : : virtqueue_enable_intr(vq);
582 [ # # ]: 0 : virtio_mb(hw->weak_barriers);
583 : 0 : return 0;
584 : : }
585 : :
586 : : static int
587 : 0 : virtio_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
588 : : {
589 : 0 : struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];
590 [ # # ]: 0 : struct virtqueue *vq = virtnet_rxq_to_vq(rxvq);
591 : :
592 : : virtqueue_disable_intr(vq);
593 : 0 : return 0;
594 : : }
595 : :
596 : : static int
597 : 0 : virtio_dev_priv_dump(struct rte_eth_dev *dev, FILE *f)
598 : : {
599 : 0 : struct virtio_hw *hw = dev->data->dev_private;
600 : :
601 : 0 : fprintf(f, "guest_features: 0x%" PRIx64 "\n", hw->guest_features);
602 : 0 : fprintf(f, "vtnet_hdr_size: %u\n", hw->vtnet_hdr_size);
603 : 0 : fprintf(f, "use_vec: rx-%u tx-%u\n", hw->use_vec_rx, hw->use_vec_tx);
604 : 0 : fprintf(f, "use_inorder: rx-%u tx-%u\n", hw->use_inorder_rx, hw->use_inorder_tx);
605 : 0 : fprintf(f, "intr_lsc: %u\n", hw->intr_lsc);
606 : 0 : fprintf(f, "max_mtu: %u\n", hw->max_mtu);
607 : 0 : fprintf(f, "max_rx_pkt_len: %zu\n", hw->max_rx_pkt_len);
608 : 0 : fprintf(f, "max_queue_pairs: %u\n", hw->max_queue_pairs);
609 : 0 : fprintf(f, "req_guest_features: 0x%" PRIx64 "\n", hw->req_guest_features);
610 : :
611 : 0 : return 0;
612 : : }
613 : :
614 : : static void
615 : 0 : virtio_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
616 : : struct rte_eth_rxq_info *qinfo)
617 : : {
618 : 0 : uint16_t vq_idx = 2 * rx_queue_id + VTNET_SQ_RQ_QUEUE_IDX;
619 : 0 : struct virtio_hw *hw = dev->data->dev_private;
620 : 0 : struct virtqueue *vq = hw->vqs[vq_idx];
621 : :
622 : 0 : qinfo->nb_desc = vq->vq_nentries;
623 : 0 : }
624 : :
625 : : static void
626 : 0 : virtio_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
627 : : struct rte_eth_txq_info *qinfo)
628 : : {
629 : 0 : uint16_t vq_idx = 2 * tx_queue_id + VTNET_SQ_TQ_QUEUE_IDX;
630 : 0 : struct virtio_hw *hw = dev->data->dev_private;
631 : 0 : struct virtqueue *vq = hw->vqs[vq_idx];
632 : :
633 : 0 : qinfo->nb_desc = vq->vq_nentries;
634 : 0 : }
635 : :
636 : : /*
637 : : * dev_ops for virtio, bare necessities for basic operation
638 : : */
639 : : static const struct eth_dev_ops virtio_eth_dev_ops = {
640 : : .dev_configure = virtio_dev_configure,
641 : : .dev_start = virtio_dev_start,
642 : : .dev_stop = virtio_dev_stop,
643 : : .dev_close = virtio_dev_close,
644 : : .promiscuous_enable = virtio_dev_promiscuous_enable,
645 : : .promiscuous_disable = virtio_dev_promiscuous_disable,
646 : : .allmulticast_enable = virtio_dev_allmulticast_enable,
647 : : .allmulticast_disable = virtio_dev_allmulticast_disable,
648 : : .mtu_set = virtio_mtu_set,
649 : : .dev_infos_get = virtio_dev_info_get,
650 : : .rxq_info_get = virtio_rxq_info_get,
651 : : .txq_info_get = virtio_txq_info_get,
652 : : .stats_get = virtio_dev_stats_get,
653 : : .xstats_get = virtio_dev_xstats_get,
654 : : .xstats_get_names = virtio_dev_xstats_get_names,
655 : : .stats_reset = virtio_dev_stats_reset,
656 : : .xstats_reset = virtio_dev_stats_reset,
657 : : .link_update = virtio_dev_link_update,
658 : : .vlan_offload_set = virtio_dev_vlan_offload_set,
659 : : .rx_queue_setup = virtio_dev_rx_queue_setup,
660 : : .rx_queue_intr_enable = virtio_dev_rx_queue_intr_enable,
661 : : .rx_queue_intr_disable = virtio_dev_rx_queue_intr_disable,
662 : : .tx_queue_setup = virtio_dev_tx_queue_setup,
663 : : .rx_burst_mode_get = virtio_rx_burst_mode_get,
664 : : .tx_burst_mode_get = virtio_tx_burst_mode_get,
665 : : .rss_hash_update = virtio_dev_rss_hash_update,
666 : : .rss_hash_conf_get = virtio_dev_rss_hash_conf_get,
667 : : .reta_update = virtio_dev_rss_reta_update,
668 : : .reta_query = virtio_dev_rss_reta_query,
669 : : .vlan_filter_set = virtio_vlan_filter_set,
670 : : .mac_addr_add = virtio_mac_addr_add,
671 : : .mac_addr_remove = virtio_mac_addr_remove,
672 : : .mac_addr_set = virtio_mac_addr_set,
673 : : .get_monitor_addr = virtio_get_monitor_addr,
674 : : .eth_dev_priv_dump = virtio_dev_priv_dump,
675 : : };
676 : :
677 : : /*
678 : : * dev_ops for virtio-user in secondary processes, as we just have
679 : : * some limited supports currently.
680 : : */
681 : : const struct eth_dev_ops virtio_user_secondary_eth_dev_ops = {
682 : : .dev_infos_get = virtio_dev_info_get,
683 : : .stats_get = virtio_dev_stats_get,
684 : : .xstats_get = virtio_dev_xstats_get,
685 : : .xstats_get_names = virtio_dev_xstats_get_names,
686 : : .stats_reset = virtio_dev_stats_reset,
687 : : .xstats_reset = virtio_dev_stats_reset,
688 : : };
689 : :
690 : : static void
691 : 0 : virtio_update_stats(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
692 : : struct eth_queue_stats *qstats)
693 : : {
694 : : unsigned i;
695 : :
696 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
697 : 0 : const struct virtnet_tx *txvq = dev->data->tx_queues[i];
698 [ # # ]: 0 : if (txvq == NULL)
699 : 0 : continue;
700 : :
701 : 0 : stats->opackets += txvq->stats.packets;
702 : 0 : stats->obytes += txvq->stats.bytes;
703 : :
704 [ # # ]: 0 : if (qstats != NULL && i < dev->data->nb_tx_queues) {
705 : 0 : qstats[i].q_opackets = txvq->stats.packets;
706 : 0 : qstats[i].q_obytes = txvq->stats.bytes;
707 : : }
708 : : }
709 : :
710 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
711 : 0 : const struct virtnet_rx *rxvq = dev->data->rx_queues[i];
712 [ # # ]: 0 : if (rxvq == NULL)
713 : 0 : continue;
714 : :
715 : 0 : stats->ipackets += rxvq->stats.packets;
716 : 0 : stats->ibytes += rxvq->stats.bytes;
717 : 0 : stats->ierrors += rxvq->stats.errors;
718 : :
719 [ # # ]: 0 : if (qstats != NULL && i < dev->data->nb_rx_queues) {
720 : 0 : qstats[i].q_ipackets = rxvq->stats.packets;
721 : 0 : qstats[i].q_ibytes = rxvq->stats.bytes;
722 : : }
723 : : }
724 : :
725 : 0 : stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
726 : 0 : }
727 : :
728 : 0 : static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
729 : : struct rte_eth_xstat_name *xstats_names,
730 : : __rte_unused unsigned limit)
731 : : {
732 : : unsigned i;
733 : : unsigned count = 0;
734 : : unsigned t;
735 : :
736 : 0 : unsigned nstats = dev->data->nb_tx_queues * VIRTIO_NB_TXQ_XSTATS +
737 : 0 : dev->data->nb_rx_queues * VIRTIO_NB_RXQ_XSTATS;
738 : :
739 [ # # ]: 0 : if (xstats_names != NULL) {
740 : : /* Note: limit checked in rte_eth_xstats_names() */
741 : :
742 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
743 : 0 : struct virtnet_rx *rxvq = dev->data->rx_queues[i];
744 [ # # ]: 0 : if (rxvq == NULL)
745 : 0 : continue;
746 [ # # ]: 0 : for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
747 : 0 : snprintf(xstats_names[count].name,
748 : : sizeof(xstats_names[count].name),
749 : : "rx_q%u_%s", i,
750 : 0 : rte_virtio_rxq_stat_strings[t].name);
751 : 0 : count++;
752 : : }
753 : : }
754 : :
755 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
756 : 0 : struct virtnet_tx *txvq = dev->data->tx_queues[i];
757 [ # # ]: 0 : if (txvq == NULL)
758 : 0 : continue;
759 [ # # ]: 0 : for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
760 : 0 : snprintf(xstats_names[count].name,
761 : : sizeof(xstats_names[count].name),
762 : : "tx_q%u_%s", i,
763 : 0 : rte_virtio_txq_stat_strings[t].name);
764 : 0 : count++;
765 : : }
766 : : }
767 : 0 : return count;
768 : : }
769 : 0 : return nstats;
770 : : }
771 : :
772 : : static int
773 : 0 : virtio_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
774 : : unsigned n)
775 : : {
776 : : unsigned i;
777 : : unsigned count = 0;
778 : :
779 : 0 : unsigned nstats = dev->data->nb_tx_queues * VIRTIO_NB_TXQ_XSTATS +
780 : 0 : dev->data->nb_rx_queues * VIRTIO_NB_RXQ_XSTATS;
781 : :
782 [ # # ]: 0 : if (n < nstats)
783 : 0 : return nstats;
784 : :
785 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
786 : 0 : struct virtnet_rx *rxvq = dev->data->rx_queues[i];
787 : :
788 [ # # ]: 0 : if (rxvq == NULL)
789 : 0 : continue;
790 : :
791 : : unsigned t;
792 : :
793 [ # # ]: 0 : for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
794 : 0 : xstats[count].value = *(uint64_t *)(((char *)rxvq) +
795 : 0 : rte_virtio_rxq_stat_strings[t].offset);
796 : 0 : xstats[count].id = count;
797 : 0 : count++;
798 : : }
799 : : }
800 : :
801 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
802 : 0 : struct virtnet_tx *txvq = dev->data->tx_queues[i];
803 : :
804 [ # # ]: 0 : if (txvq == NULL)
805 : 0 : continue;
806 : :
807 : : unsigned t;
808 : :
809 [ # # ]: 0 : for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
810 : 0 : xstats[count].value = *(uint64_t *)(((char *)txvq) +
811 : 0 : rte_virtio_txq_stat_strings[t].offset);
812 : 0 : xstats[count].id = count;
813 : 0 : count++;
814 : : }
815 : : }
816 : :
817 : 0 : return count;
818 : : }
819 : :
820 : : static int
821 : 0 : virtio_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
822 : : struct eth_queue_stats *qstats)
823 : : {
824 : 0 : virtio_update_stats(dev, stats, qstats);
825 : :
826 : 0 : return 0;
827 : : }
828 : :
829 : : static int
830 : 0 : virtio_dev_stats_reset(struct rte_eth_dev *dev)
831 : : {
832 : : unsigned int i;
833 : :
834 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
835 : 0 : struct virtnet_tx *txvq = dev->data->tx_queues[i];
836 [ # # ]: 0 : if (txvq == NULL)
837 : 0 : continue;
838 : :
839 : 0 : txvq->stats.packets = 0;
840 : 0 : txvq->stats.bytes = 0;
841 : 0 : txvq->stats.multicast = 0;
842 : 0 : txvq->stats.broadcast = 0;
843 : 0 : memset(txvq->stats.size_bins, 0,
844 : : sizeof(txvq->stats.size_bins[0]) * 8);
845 : : }
846 : :
847 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
848 : 0 : struct virtnet_rx *rxvq = dev->data->rx_queues[i];
849 [ # # ]: 0 : if (rxvq == NULL)
850 : 0 : continue;
851 : :
852 : 0 : rxvq->stats.packets = 0;
853 : 0 : rxvq->stats.bytes = 0;
854 : 0 : rxvq->stats.errors = 0;
855 : 0 : rxvq->stats.multicast = 0;
856 : 0 : rxvq->stats.broadcast = 0;
857 : 0 : memset(rxvq->stats.size_bins, 0,
858 : : sizeof(rxvq->stats.size_bins[0]) * 8);
859 : : }
860 : :
861 : 0 : return 0;
862 : : }
863 : :
864 : : static void
865 : : virtio_set_hwaddr(struct virtio_hw *hw)
866 : : {
867 : 0 : virtio_write_dev_config(hw,
868 : : offsetof(struct virtio_net_config, mac),
869 : : &hw->mac_addr, RTE_ETHER_ADDR_LEN);
870 : 0 : }
871 : :
872 : : static void
873 [ # # ]: 0 : virtio_get_hwaddr(struct virtio_hw *hw)
874 : : {
875 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_MAC)) {
876 : 0 : virtio_read_dev_config(hw,
877 : : offsetof(struct virtio_net_config, mac),
878 : 0 : &hw->mac_addr, RTE_ETHER_ADDR_LEN);
879 : : } else {
880 : 0 : rte_eth_random_addr(&hw->mac_addr[0]);
881 : : virtio_set_hwaddr(hw);
882 : : }
883 : 0 : }
884 : :
885 : : static int
886 [ # # ]: 0 : virtio_mac_table_set(struct virtio_hw *hw,
887 : : const struct virtio_net_ctrl_mac *uc,
888 : : const struct virtio_net_ctrl_mac *mc)
889 : : {
890 : : struct virtio_pmd_ctrl ctrl;
891 : : int err, len[2];
892 : :
893 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
894 : 0 : PMD_DRV_LOG(INFO, "host does not support mac table");
895 : 0 : return -1;
896 : : }
897 : :
898 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_MAC;
899 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_MAC_TABLE_SET;
900 : :
901 : 0 : len[0] = uc->entries * RTE_ETHER_ADDR_LEN + sizeof(uc->entries);
902 : 0 : memcpy(ctrl.data, uc, len[0]);
903 : :
904 : 0 : len[1] = mc->entries * RTE_ETHER_ADDR_LEN + sizeof(mc->entries);
905 : 0 : memcpy(ctrl.data + len[0], mc, len[1]);
906 : :
907 : 0 : err = virtio_send_command(hw->cvq, &ctrl, len, 2);
908 [ # # ]: 0 : if (err != 0)
909 : 0 : PMD_DRV_LOG(NOTICE, "mac table set failed: %d", err);
910 : : return err;
911 : : }
912 : :
913 : : static int
914 : 0 : virtio_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
915 : : uint32_t index, uint32_t vmdq __rte_unused)
916 : : {
917 : 0 : struct virtio_hw *hw = dev->data->dev_private;
918 : 0 : const struct rte_ether_addr *addrs = dev->data->mac_addrs;
919 : : unsigned int i;
920 : : struct virtio_net_ctrl_mac *uc, *mc;
921 : :
922 [ # # ]: 0 : if (index >= VIRTIO_MAX_MAC_ADDRS) {
923 : 0 : PMD_DRV_LOG(ERR, "mac address index %u out of range", index);
924 : 0 : return -EINVAL;
925 : : }
926 : :
927 : 0 : uc = alloca(VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN +
928 : : sizeof(uc->entries));
929 : 0 : uc->entries = 0;
930 : 0 : mc = alloca(VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN +
931 : : sizeof(mc->entries));
932 : 0 : mc->entries = 0;
933 : :
934 [ # # ]: 0 : for (i = 0; i < VIRTIO_MAX_MAC_ADDRS; i++) {
935 : : const struct rte_ether_addr *addr
936 [ # # ]: 0 : = (i == index) ? mac_addr : addrs + i;
937 : : struct virtio_net_ctrl_mac *tbl
938 [ # # ]: 0 : = rte_is_multicast_ether_addr(addr) ? mc : uc;
939 : :
940 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr))
941 : : break;
942 : 0 : memcpy(&tbl->macs[tbl->entries++], addr, RTE_ETHER_ADDR_LEN);
943 : : }
944 : :
945 : 0 : return virtio_mac_table_set(hw, uc, mc);
946 : : }
947 : :
948 : : static void
949 : 0 : virtio_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
950 : : {
951 : 0 : struct virtio_hw *hw = dev->data->dev_private;
952 : 0 : struct rte_ether_addr *addrs = dev->data->mac_addrs;
953 : : struct virtio_net_ctrl_mac *uc, *mc;
954 : : unsigned int i;
955 : :
956 [ # # ]: 0 : if (index >= VIRTIO_MAX_MAC_ADDRS) {
957 : 0 : PMD_DRV_LOG(ERR, "mac address index %u out of range", index);
958 : 0 : return;
959 : : }
960 : :
961 : 0 : uc = alloca(VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN +
962 : : sizeof(uc->entries));
963 : 0 : uc->entries = 0;
964 : 0 : mc = alloca(VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN +
965 : : sizeof(mc->entries));
966 : 0 : mc->entries = 0;
967 : :
968 [ # # ]: 0 : for (i = 0; i < VIRTIO_MAX_MAC_ADDRS; i++) {
969 : : struct virtio_net_ctrl_mac *tbl;
970 : :
971 [ # # # # ]: 0 : if (i == index || rte_is_zero_ether_addr(addrs + i))
972 : 0 : continue;
973 : :
974 [ # # ]: 0 : tbl = rte_is_multicast_ether_addr(addrs + i) ? mc : uc;
975 : 0 : memcpy(&tbl->macs[tbl->entries++], addrs + i,
976 : : RTE_ETHER_ADDR_LEN);
977 : : }
978 : :
979 : 0 : virtio_mac_table_set(hw, uc, mc);
980 : : }
981 : :
982 : : static int
983 : 0 : virtio_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
984 : : {
985 : 0 : struct virtio_hw *hw = dev->data->dev_private;
986 : :
987 [ # # ]: 0 : memcpy(hw->mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
988 : :
989 : : /* Use atomic update if available */
990 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
991 : : struct virtio_pmd_ctrl ctrl;
992 : 0 : int len = RTE_ETHER_ADDR_LEN;
993 : :
994 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_MAC;
995 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_MAC_ADDR_SET;
996 : :
997 : : memcpy(ctrl.data, mac_addr, RTE_ETHER_ADDR_LEN);
998 : 0 : return virtio_send_command(hw->cvq, &ctrl, &len, 1);
999 : : }
1000 : :
1001 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_MAC))
1002 : : return -ENOTSUP;
1003 : :
1004 : : virtio_set_hwaddr(hw);
1005 : 0 : return 0;
1006 : : }
1007 : :
1008 : : #define CLB_VAL_IDX 0
1009 : : #define CLB_MSK_IDX 1
1010 : : #define CLB_MATCH_IDX 2
1011 : : static int
1012 : 0 : virtio_monitor_callback(const uint64_t value,
1013 : : const uint64_t opaque[RTE_POWER_MONITOR_OPAQUE_SZ])
1014 : : {
1015 : 0 : const uint64_t m = opaque[CLB_MSK_IDX];
1016 : 0 : const uint64_t v = opaque[CLB_VAL_IDX];
1017 : 0 : const uint64_t c = opaque[CLB_MATCH_IDX];
1018 : :
1019 [ # # ]: 0 : if (c)
1020 [ # # ]: 0 : return (value & m) == v ? -1 : 0;
1021 : : else
1022 [ # # ]: 0 : return (value & m) == v ? 0 : -1;
1023 : : }
1024 : :
1025 : : static int
1026 : 0 : virtio_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
1027 : : {
1028 : : struct virtnet_rx *rxvq = rx_queue;
1029 : 0 : struct virtqueue *vq = virtnet_rxq_to_vq(rxvq);
1030 : : struct virtio_hw *hw;
1031 : :
1032 [ # # ]: 0 : if (vq == NULL)
1033 : : return -EINVAL;
1034 : :
1035 [ # # ]: 0 : hw = vq->hw;
1036 [ # # ]: 0 : if (virtio_with_packed_queue(hw)) {
1037 : : struct vring_packed_desc *desc;
1038 : 0 : desc = vq->vq_packed.ring.desc;
1039 : 0 : pmc->addr = &desc[vq->vq_used_cons_idx].flags;
1040 [ # # ]: 0 : if (vq->vq_packed.used_wrap_counter)
1041 : 0 : pmc->opaque[CLB_VAL_IDX] =
1042 : : VRING_PACKED_DESC_F_AVAIL_USED;
1043 : : else
1044 : 0 : pmc->opaque[CLB_VAL_IDX] = 0;
1045 : 0 : pmc->opaque[CLB_MSK_IDX] = VRING_PACKED_DESC_F_AVAIL_USED;
1046 : 0 : pmc->opaque[CLB_MATCH_IDX] = 1;
1047 : 0 : pmc->size = sizeof(desc[vq->vq_used_cons_idx].flags);
1048 : : } else {
1049 : 0 : pmc->addr = &vq->vq_split.ring.used->idx;
1050 : 0 : pmc->opaque[CLB_VAL_IDX] = vq->vq_used_cons_idx
1051 : 0 : & (vq->vq_nentries - 1);
1052 : 0 : pmc->opaque[CLB_MSK_IDX] = vq->vq_nentries - 1;
1053 : 0 : pmc->opaque[CLB_MATCH_IDX] = 0;
1054 : 0 : pmc->size = sizeof(vq->vq_split.ring.used->idx);
1055 : : }
1056 : 0 : pmc->fn = virtio_monitor_callback;
1057 : :
1058 : 0 : return 0;
1059 : : }
1060 : :
1061 : : static int
1062 : 0 : virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1063 : : {
1064 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
1065 : : struct virtio_pmd_ctrl ctrl;
1066 : : int len;
1067 : :
1068 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN))
1069 : : return -ENOTSUP;
1070 : :
1071 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_VLAN;
1072 : 0 : ctrl.hdr.cmd = on ? VIRTIO_NET_CTRL_VLAN_ADD : VIRTIO_NET_CTRL_VLAN_DEL;
1073 : : memcpy(ctrl.data, &vlan_id, sizeof(vlan_id));
1074 : 0 : len = sizeof(vlan_id);
1075 : :
1076 : 0 : return virtio_send_command(hw->cvq, &ctrl, &len, 1);
1077 : : }
1078 : :
1079 : : static int
1080 : 0 : virtio_intr_unmask(struct rte_eth_dev *dev)
1081 : : {
1082 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1083 : :
1084 [ # # ]: 0 : if (rte_intr_ack(dev->intr_handle) < 0)
1085 : : return -1;
1086 : :
1087 [ # # ]: 0 : if (VIRTIO_OPS(hw)->intr_detect)
1088 : 0 : VIRTIO_OPS(hw)->intr_detect(hw);
1089 : :
1090 : : return 0;
1091 : : }
1092 : :
1093 : : static int
1094 : 0 : virtio_intr_enable(struct rte_eth_dev *dev)
1095 : : {
1096 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1097 : :
1098 [ # # ]: 0 : if (rte_intr_enable(dev->intr_handle) < 0)
1099 : : return -1;
1100 : :
1101 [ # # ]: 0 : if (VIRTIO_OPS(hw)->intr_detect)
1102 : 0 : VIRTIO_OPS(hw)->intr_detect(hw);
1103 : :
1104 : : return 0;
1105 : : }
1106 : :
1107 : : static int
1108 : 0 : virtio_intr_disable(struct rte_eth_dev *dev)
1109 : : {
1110 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1111 : :
1112 [ # # ]: 0 : if (rte_intr_disable(dev->intr_handle) < 0)
1113 : : return -1;
1114 : :
1115 [ # # ]: 0 : if (VIRTIO_OPS(hw)->intr_detect)
1116 : 0 : VIRTIO_OPS(hw)->intr_detect(hw);
1117 : :
1118 : : return 0;
1119 : : }
1120 : :
1121 : : static int
1122 : 0 : virtio_ethdev_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
1123 : : {
1124 : : uint64_t host_features;
1125 : :
1126 : : /* Prepare guest_features: feature that driver wants to support */
1127 : 0 : PMD_INIT_LOG(DEBUG, "guest_features before negotiate = %" PRIx64,
1128 : : req_features);
1129 : :
1130 : : /* Read device(host) feature bits */
1131 : 0 : host_features = VIRTIO_OPS(hw)->get_features(hw);
1132 : 0 : PMD_INIT_LOG(DEBUG, "host_features before negotiate = %" PRIx64,
1133 : : host_features);
1134 : :
1135 : : /* If supported, ensure MTU value is valid before acknowledging it. */
1136 [ # # ]: 0 : if (host_features & req_features & (1ULL << VIRTIO_NET_F_MTU)) {
1137 : : struct virtio_net_config config;
1138 : :
1139 : 0 : virtio_read_dev_config(hw,
1140 : : offsetof(struct virtio_net_config, mtu),
1141 : : &config.mtu, sizeof(config.mtu));
1142 : :
1143 [ # # ]: 0 : if (config.mtu < RTE_ETHER_MIN_MTU)
1144 : 0 : req_features &= ~(1ULL << VIRTIO_NET_F_MTU);
1145 : : }
1146 : :
1147 : : /*
1148 : : * Negotiate features: Subset of device feature bits are written back
1149 : : * guest feature bits.
1150 : : */
1151 : 0 : hw->guest_features = req_features;
1152 : 0 : hw->guest_features = virtio_negotiate_features(hw, host_features);
1153 : 0 : PMD_INIT_LOG(DEBUG, "features after negotiate = %" PRIx64,
1154 : : hw->guest_features);
1155 : :
1156 [ # # ]: 0 : if (VIRTIO_OPS(hw)->features_ok(hw) < 0)
1157 : : return -1;
1158 : :
1159 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_F_VERSION_1)) {
1160 : 0 : virtio_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);
1161 : :
1162 [ # # ]: 0 : if (!(virtio_get_status(hw) & VIRTIO_CONFIG_STATUS_FEATURES_OK)) {
1163 : 0 : PMD_INIT_LOG(ERR, "Failed to set FEATURES_OK status!");
1164 : 0 : return -1;
1165 : : }
1166 : : }
1167 : :
1168 : 0 : hw->req_guest_features = req_features;
1169 : :
1170 : 0 : return 0;
1171 : : }
1172 : :
1173 : : static void
1174 : 0 : virtio_notify_peers(struct rte_eth_dev *dev)
1175 : : {
1176 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1177 : : struct virtnet_rx *rxvq;
1178 : : struct rte_mbuf *rarp_mbuf;
1179 : :
1180 [ # # ]: 0 : if (!dev->data->rx_queues)
1181 : 0 : return;
1182 : :
1183 : 0 : rxvq = dev->data->rx_queues[0];
1184 [ # # ]: 0 : if (!rxvq)
1185 : : return;
1186 : :
1187 : 0 : rarp_mbuf = rte_net_make_rarp_packet(rxvq->mpool,
1188 : 0 : (struct rte_ether_addr *)hw->mac_addr);
1189 [ # # ]: 0 : if (rarp_mbuf == NULL) {
1190 : 0 : PMD_DRV_LOG(ERR, "failed to make RARP packet.");
1191 : 0 : return;
1192 : : }
1193 : :
1194 : 0 : rte_spinlock_lock(&hw->state_lock);
1195 [ # # ]: 0 : if (hw->started == 0) {
1196 : : /* If virtio port just stopped, no need to send RARP */
1197 : 0 : rte_pktmbuf_free(rarp_mbuf);
1198 : 0 : goto out;
1199 : : }
1200 : 0 : hw->started = 0;
1201 : :
1202 : : /*
1203 : : * Prevent the worker threads from touching queues to avoid contention,
1204 : : * 1 ms should be enough for the ongoing Tx function to finish.
1205 : : */
1206 : : rte_delay_ms(1);
1207 : :
1208 : 0 : hw->inject_pkts = &rarp_mbuf;
1209 : 0 : dev->tx_pkt_burst(dev->data->tx_queues[0], &rarp_mbuf, 1);
1210 : 0 : hw->inject_pkts = NULL;
1211 : :
1212 : 0 : hw->started = 1;
1213 : :
1214 : 0 : out:
1215 : : rte_spinlock_unlock(&hw->state_lock);
1216 : : }
1217 : :
1218 : : static void
1219 : 0 : virtio_ack_link_announce(struct rte_eth_dev *dev)
1220 : : {
1221 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1222 : : struct virtio_pmd_ctrl ctrl;
1223 : :
1224 : 0 : ctrl.hdr.class = VIRTIO_NET_CTRL_ANNOUNCE;
1225 : 0 : ctrl.hdr.cmd = VIRTIO_NET_CTRL_ANNOUNCE_ACK;
1226 : :
1227 : 0 : virtio_send_command(hw->cvq, &ctrl, NULL, 0);
1228 : 0 : }
1229 : :
1230 : : /*
1231 : : * Process virtio config changed interrupt. Call the callback
1232 : : * if link state changed, generate gratuitous RARP packet if
1233 : : * the status indicates an ANNOUNCE.
1234 : : */
1235 : : void
1236 : 0 : virtio_interrupt_handler(void *param)
1237 : : {
1238 : : struct rte_eth_dev *dev = param;
1239 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1240 : : uint8_t isr;
1241 : : uint16_t status;
1242 : :
1243 : : /* Read interrupt status which clears interrupt */
1244 : 0 : isr = virtio_get_isr(hw);
1245 : 0 : PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
1246 : :
1247 [ # # ]: 0 : if (virtio_intr_unmask(dev) < 0)
1248 : 0 : PMD_DRV_LOG(ERR, "interrupt enable failed");
1249 : :
1250 [ # # ]: 0 : if (isr & VIRTIO_ISR_CONFIG) {
1251 [ # # ]: 0 : if (virtio_dev_link_update(dev, 0) == 0)
1252 : 0 : rte_eth_dev_callback_process(dev,
1253 : : RTE_ETH_EVENT_INTR_LSC,
1254 : : NULL);
1255 : :
1256 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS)) {
1257 : 0 : virtio_read_dev_config(hw,
1258 : : offsetof(struct virtio_net_config, status),
1259 : : &status, sizeof(status));
1260 [ # # ]: 0 : if (status & VIRTIO_NET_S_ANNOUNCE) {
1261 : 0 : virtio_notify_peers(dev);
1262 [ # # ]: 0 : if (hw->cvq)
1263 : 0 : virtio_ack_link_announce(dev);
1264 : : }
1265 : : }
1266 : : }
1267 : 0 : }
1268 : :
1269 : : static const struct {
1270 : : eth_tx_burst_t pkt_burst;
1271 : : const char *info;
1272 : : } virtio_tx_burst_info[] = {
1273 : : { virtio_xmit_pkts, "Scalar"},
1274 : : { virtio_xmit_pkts_packed, "Scalar packed ring"},
1275 : : { virtio_xmit_pkts_inorder, "Scalar in order"},
1276 : : { virtio_xmit_pkts_packed_vec, "Vector packed ring"},
1277 : : };
1278 : :
1279 : : static int
1280 : 0 : virtio_tx_burst_mode_get(struct rte_eth_dev *dev,
1281 : : __rte_unused uint16_t queue_id,
1282 : : struct rte_eth_burst_mode *mode)
1283 : : {
1284 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
1285 : : size_t i;
1286 : :
1287 [ # # ]: 0 : for (i = 0; i < RTE_DIM(virtio_tx_burst_info); i++) {
1288 [ # # ]: 0 : if (pkt_burst == virtio_tx_burst_info[i].pkt_burst) {
1289 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
1290 : 0 : virtio_tx_burst_info[i].info);
1291 : 0 : return 0;
1292 : : }
1293 : : }
1294 : :
1295 : : return -EINVAL;
1296 : : }
1297 : :
1298 : : static const struct {
1299 : : eth_rx_burst_t pkt_burst;
1300 : : const char *info;
1301 : : } virtio_rx_burst_info[] = {
1302 : : { virtio_recv_pkts, "Scalar"},
1303 : : { virtio_recv_pkts_packed, "Scalar standard packed ring"},
1304 : : { virtio_recv_pkts_inorder, "Scalar"},
1305 : : { virtio_recv_mergeable_pkts, "Scalar mergeable"},
1306 : : { virtio_recv_mergeable_pkts_packed, "Scalar mergeable packed ring"},
1307 : : #ifdef RTE_ARCH_x86
1308 : : { virtio_recv_pkts_vec, "Vector SSE"},
1309 : : { virtio_recv_pkts_packed_vec, "Vector AVX512 packed ring"},
1310 : : #elif defined(RTE_ARCH_ARM)
1311 : : { virtio_recv_pkts_vec, "Vector NEON"},
1312 : : { virtio_recv_pkts_packed_vec, "Vector NEON packed ring"},
1313 : : #elif defined(RTE_ARCH_PPC_64)
1314 : : { virtio_recv_pkts_vec, "Vector Altivec"},
1315 : : { virtio_recv_pkts_packed_vec, "Vector Altivec packed ring"},
1316 : : #endif
1317 : : };
1318 : :
1319 : : static int
1320 : 0 : virtio_rx_burst_mode_get(struct rte_eth_dev *dev,
1321 : : __rte_unused uint16_t queue_id,
1322 : : struct rte_eth_burst_mode *mode)
1323 : : {
1324 : 0 : eth_tx_burst_t pkt_burst = dev->rx_pkt_burst;
1325 : : size_t i;
1326 : :
1327 [ # # ]: 0 : for (i = 0; i < RTE_DIM(virtio_rx_burst_info); i++) {
1328 [ # # ]: 0 : if (pkt_burst == virtio_rx_burst_info[i].pkt_burst) {
1329 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
1330 : 0 : virtio_rx_burst_info[i].info);
1331 : 0 : return 0;
1332 : : }
1333 : : }
1334 : :
1335 : : return -EINVAL;
1336 : : }
1337 : :
1338 : : /* set rx and tx handlers according to what is supported */
1339 : : static void
1340 : 0 : set_rxtx_funcs(struct rte_eth_dev *eth_dev)
1341 : : {
1342 : 0 : struct virtio_hw *hw = eth_dev->data->dev_private;
1343 : :
1344 [ # # ]: 0 : eth_dev->tx_pkt_prepare = virtio_xmit_pkts_prepare;
1345 [ # # ]: 0 : if (virtio_with_packed_queue(hw)) {
1346 [ # # ]: 0 : PMD_INIT_LOG(INFO,
1347 : : "virtio: using packed ring %s Tx path on port %u",
1348 : : hw->use_vec_tx ? "vectorized" : "standard",
1349 : : eth_dev->data->port_id);
1350 [ # # ]: 0 : if (hw->use_vec_tx)
1351 : 0 : eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed_vec;
1352 : : else
1353 : 0 : eth_dev->tx_pkt_burst = virtio_xmit_pkts_packed;
1354 : : } else {
1355 [ # # ]: 0 : if (hw->use_inorder_tx) {
1356 : 0 : PMD_INIT_LOG(INFO, "virtio: using inorder Tx path on port %u",
1357 : : eth_dev->data->port_id);
1358 : 0 : eth_dev->tx_pkt_burst = virtio_xmit_pkts_inorder;
1359 : : } else {
1360 : 0 : PMD_INIT_LOG(INFO, "virtio: using standard Tx path on port %u",
1361 : : eth_dev->data->port_id);
1362 : 0 : eth_dev->tx_pkt_burst = virtio_xmit_pkts;
1363 : : }
1364 : : }
1365 : :
1366 [ # # ]: 0 : if (virtio_with_packed_queue(hw)) {
1367 [ # # ]: 0 : if (hw->use_vec_rx) {
1368 : 0 : PMD_INIT_LOG(INFO,
1369 : : "virtio: using packed ring vectorized Rx path on port %u",
1370 : : eth_dev->data->port_id);
1371 : 0 : eth_dev->rx_pkt_burst =
1372 : : &virtio_recv_pkts_packed_vec;
1373 [ # # ]: 0 : } else if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
1374 : 0 : PMD_INIT_LOG(INFO,
1375 : : "virtio: using packed ring mergeable buffer Rx path on port %u",
1376 : : eth_dev->data->port_id);
1377 : 0 : eth_dev->rx_pkt_burst =
1378 : : &virtio_recv_mergeable_pkts_packed;
1379 : : } else {
1380 : 0 : PMD_INIT_LOG(INFO,
1381 : : "virtio: using packed ring standard Rx path on port %u",
1382 : : eth_dev->data->port_id);
1383 : 0 : eth_dev->rx_pkt_burst = &virtio_recv_pkts_packed;
1384 : : }
1385 : : } else {
1386 [ # # ]: 0 : if (hw->use_vec_rx) {
1387 : 0 : PMD_INIT_LOG(INFO, "virtio: using vectorized Rx path on port %u",
1388 : : eth_dev->data->port_id);
1389 : 0 : eth_dev->rx_pkt_burst = virtio_recv_pkts_vec;
1390 [ # # ]: 0 : } else if (hw->use_inorder_rx) {
1391 : 0 : PMD_INIT_LOG(INFO,
1392 : : "virtio: using inorder Rx path on port %u",
1393 : : eth_dev->data->port_id);
1394 : 0 : eth_dev->rx_pkt_burst = &virtio_recv_pkts_inorder;
1395 [ # # ]: 0 : } else if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
1396 : 0 : PMD_INIT_LOG(INFO,
1397 : : "virtio: using mergeable buffer Rx path on port %u",
1398 : : eth_dev->data->port_id);
1399 : 0 : eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts;
1400 : : } else {
1401 : 0 : PMD_INIT_LOG(INFO, "virtio: using standard Rx path on port %u",
1402 : : eth_dev->data->port_id);
1403 : 0 : eth_dev->rx_pkt_burst = &virtio_recv_pkts;
1404 : : }
1405 : : }
1406 : :
1407 : 0 : }
1408 : :
1409 : : /* Only support 1:1 queue/interrupt mapping so far.
1410 : : * TODO: support n:1 queue/interrupt mapping when there are limited number of
1411 : : * interrupt vectors (<N+1).
1412 : : */
1413 : : static int
1414 : 0 : virtio_queues_bind_intr(struct rte_eth_dev *dev)
1415 : : {
1416 : : uint32_t i;
1417 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1418 : :
1419 : 0 : PMD_INIT_LOG(INFO, "queue/interrupt binding");
1420 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; ++i) {
1421 [ # # ]: 0 : if (rte_intr_vec_list_index_set(dev->intr_handle, i,
1422 : 0 : i + 1))
1423 : 0 : return -rte_errno;
1424 [ # # ]: 0 : if (VIRTIO_OPS(hw)->set_queue_irq(hw, hw->vqs[i * 2], i + 1) ==
1425 : : VIRTIO_MSI_NO_VECTOR) {
1426 : 0 : PMD_DRV_LOG(ERR, "failed to set queue vector");
1427 : 0 : return -EBUSY;
1428 : : }
1429 : : }
1430 : :
1431 : : return 0;
1432 : : }
1433 : :
1434 : : static void
1435 : 0 : virtio_queues_unbind_intr(struct rte_eth_dev *dev)
1436 : : {
1437 : : uint32_t i;
1438 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1439 : :
1440 : 0 : PMD_INIT_LOG(INFO, "queue/interrupt unbinding");
1441 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; ++i)
1442 : 0 : VIRTIO_OPS(hw)->set_queue_irq(hw,
1443 : 0 : hw->vqs[i * VTNET_CQ],
1444 : : VIRTIO_MSI_NO_VECTOR);
1445 : 0 : }
1446 : :
1447 : : static int
1448 : 0 : virtio_configure_intr(struct rte_eth_dev *dev)
1449 : : {
1450 : 0 : struct virtio_hw *hw = dev->data->dev_private;
1451 : : int ret;
1452 : :
1453 [ # # ]: 0 : if (!rte_intr_cap_multiple(dev->intr_handle)) {
1454 : 0 : PMD_INIT_LOG(ERR, "Multiple intr vector not supported");
1455 : 0 : return -ENOTSUP;
1456 : : }
1457 : :
1458 : 0 : ret = rte_intr_efd_enable(dev->intr_handle, dev->data->nb_rx_queues);
1459 [ # # ]: 0 : if (ret < 0) {
1460 : 0 : PMD_INIT_LOG(ERR, "Fail to create eventfd");
1461 : 0 : return ret;
1462 : : }
1463 : :
1464 : 0 : ret = rte_intr_vec_list_alloc(dev->intr_handle, "intr_vec",
1465 : 0 : hw->max_queue_pairs);
1466 [ # # ]: 0 : if (ret < 0) {
1467 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %u rxq vectors",
1468 : : hw->max_queue_pairs);
1469 : 0 : return ret;
1470 : : }
1471 : :
1472 [ # # ]: 0 : if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {
1473 : : /* Re-register callback to update max_intr */
1474 : 0 : rte_intr_callback_unregister(dev->intr_handle,
1475 : : virtio_interrupt_handler,
1476 : : dev);
1477 : 0 : rte_intr_callback_register(dev->intr_handle,
1478 : : virtio_interrupt_handler,
1479 : : dev);
1480 : : }
1481 : :
1482 : : /* DO NOT try to remove this! This function will enable msix, or QEMU
1483 : : * will encounter SIGSEGV when DRIVER_OK is sent.
1484 : : * And for legacy devices, this should be done before queue/vec binding
1485 : : * to change the config size from 20 to 24, or VIRTIO_MSI_QUEUE_VECTOR
1486 : : * (22) will be ignored.
1487 : : */
1488 [ # # ]: 0 : if (virtio_intr_enable(dev) < 0) {
1489 : 0 : PMD_DRV_LOG(ERR, "interrupt enable failed");
1490 : 0 : return -EINVAL;
1491 : : }
1492 : :
1493 : 0 : ret = virtio_queues_bind_intr(dev);
1494 [ # # ]: 0 : if (ret < 0) {
1495 : 0 : PMD_INIT_LOG(ERR, "Failed to bind queue/interrupt");
1496 : 0 : return ret;
1497 : : }
1498 : :
1499 : : return 0;
1500 : : }
1501 : :
1502 : : static void
1503 : 0 : virtio_get_speed_duplex(struct rte_eth_dev *eth_dev,
1504 : : struct rte_eth_link *link)
1505 : : {
1506 : 0 : struct virtio_hw *hw = eth_dev->data->dev_private;
1507 : : struct virtio_net_config *config;
1508 : : struct virtio_net_config local_config;
1509 : :
1510 : : config = &local_config;
1511 : 0 : virtio_read_dev_config(hw,
1512 : : offsetof(struct virtio_net_config, speed),
1513 : : &config->speed, sizeof(config->speed));
1514 : 0 : virtio_read_dev_config(hw,
1515 : : offsetof(struct virtio_net_config, duplex),
1516 : : &config->duplex, sizeof(config->duplex));
1517 : 0 : hw->speed = config->speed;
1518 : 0 : hw->duplex = config->duplex;
1519 [ # # ]: 0 : if (link != NULL) {
1520 : 0 : link->link_duplex = hw->duplex;
1521 : 0 : link->link_speed = hw->speed;
1522 : : }
1523 : 0 : PMD_INIT_LOG(DEBUG, "link speed = %d, duplex = %d",
1524 : : hw->speed, hw->duplex);
1525 : 0 : }
1526 : :
1527 : : static uint64_t
1528 : 0 : ethdev_to_virtio_rss_offloads(uint64_t ethdev_hash_types)
1529 : : {
1530 : : uint64_t virtio_hash_types = 0;
1531 : :
1532 [ # # ]: 0 : if (ethdev_hash_types & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
1533 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER))
1534 : : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_IPV4;
1535 : :
1536 [ # # ]: 0 : if (ethdev_hash_types & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
1537 : 0 : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_TCPV4;
1538 : :
1539 [ # # ]: 0 : if (ethdev_hash_types & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
1540 : 0 : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_UDPV4;
1541 : :
1542 [ # # ]: 0 : if (ethdev_hash_types & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
1543 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER))
1544 : 0 : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_IPV6;
1545 : :
1546 [ # # ]: 0 : if (ethdev_hash_types & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
1547 : 0 : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_TCPV6;
1548 : :
1549 [ # # ]: 0 : if (ethdev_hash_types & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
1550 : 0 : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_UDPV6;
1551 : :
1552 [ # # ]: 0 : if (ethdev_hash_types & RTE_ETH_RSS_IPV6_EX)
1553 : 0 : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_IP_EX;
1554 : :
1555 [ # # ]: 0 : if (ethdev_hash_types & RTE_ETH_RSS_IPV6_TCP_EX)
1556 : 0 : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_TCP_EX;
1557 : :
1558 [ # # ]: 0 : if (ethdev_hash_types & RTE_ETH_RSS_IPV6_UDP_EX)
1559 : 0 : virtio_hash_types |= VIRTIO_NET_HASH_TYPE_UDP_EX;
1560 : :
1561 : 0 : return virtio_hash_types;
1562 : : }
1563 : :
1564 : : static uint64_t
1565 : 0 : virtio_to_ethdev_rss_offloads(uint64_t virtio_hash_types)
1566 : : {
1567 : : uint64_t rss_offloads = 0;
1568 : :
1569 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_IPV4)
1570 : : rss_offloads |= RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
1571 : : RTE_ETH_RSS_NONFRAG_IPV4_OTHER;
1572 : :
1573 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_TCPV4)
1574 : 0 : rss_offloads |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
1575 : :
1576 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_UDPV4)
1577 : 0 : rss_offloads |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
1578 : :
1579 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_IPV6)
1580 : 0 : rss_offloads |= RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
1581 : : RTE_ETH_RSS_NONFRAG_IPV6_OTHER;
1582 : :
1583 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_TCPV6)
1584 : 0 : rss_offloads |= RTE_ETH_RSS_NONFRAG_IPV6_TCP;
1585 : :
1586 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_UDPV6)
1587 : 0 : rss_offloads |= RTE_ETH_RSS_NONFRAG_IPV6_UDP;
1588 : :
1589 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_IP_EX)
1590 : 0 : rss_offloads |= RTE_ETH_RSS_IPV6_EX;
1591 : :
1592 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_TCP_EX)
1593 : 0 : rss_offloads |= RTE_ETH_RSS_IPV6_TCP_EX;
1594 : :
1595 [ # # ]: 0 : if (virtio_hash_types & VIRTIO_NET_HASH_TYPE_UDP_EX)
1596 : 0 : rss_offloads |= RTE_ETH_RSS_IPV6_UDP_EX;
1597 : :
1598 : 0 : return rss_offloads;
1599 : : }
1600 : :
1601 : : static int
1602 : 0 : virtio_dev_get_rss_config(struct virtio_hw *hw, uint32_t *rss_hash_types)
1603 : : {
1604 : : struct virtio_net_config local_config;
1605 : : struct virtio_net_config *config = &local_config;
1606 : :
1607 : 0 : virtio_read_dev_config(hw,
1608 : : offsetof(struct virtio_net_config, rss_max_key_size),
1609 : : &config->rss_max_key_size,
1610 : : sizeof(config->rss_max_key_size));
1611 [ # # ]: 0 : if (config->rss_max_key_size < VIRTIO_NET_RSS_KEY_SIZE) {
1612 : 0 : PMD_INIT_LOG(ERR, "Invalid device RSS max key size (%u)",
1613 : : config->rss_max_key_size);
1614 : 0 : return -EINVAL;
1615 : : }
1616 : :
1617 : 0 : virtio_read_dev_config(hw,
1618 : : offsetof(struct virtio_net_config,
1619 : : rss_max_indirection_table_length),
1620 : : &config->rss_max_indirection_table_length,
1621 : : sizeof(config->rss_max_indirection_table_length));
1622 [ # # ]: 0 : if (config->rss_max_indirection_table_length < VIRTIO_NET_RSS_RETA_SIZE) {
1623 : 0 : PMD_INIT_LOG(ERR, "Invalid device RSS max reta size (%u)",
1624 : : config->rss_max_indirection_table_length);
1625 : 0 : return -EINVAL;
1626 : : }
1627 : :
1628 : 0 : virtio_read_dev_config(hw,
1629 : : offsetof(struct virtio_net_config, supported_hash_types),
1630 : : &config->supported_hash_types,
1631 : : sizeof(config->supported_hash_types));
1632 [ # # ]: 0 : if ((config->supported_hash_types & VIRTIO_NET_HASH_TYPE_MASK) == 0) {
1633 : 0 : PMD_INIT_LOG(ERR, "Invalid device RSS hash types (0x%x)",
1634 : : config->supported_hash_types);
1635 : 0 : return -EINVAL;
1636 : : }
1637 : :
1638 : 0 : *rss_hash_types = config->supported_hash_types & VIRTIO_NET_HASH_TYPE_MASK;
1639 : :
1640 : 0 : PMD_INIT_LOG(DEBUG, "Device RSS config:");
1641 : 0 : PMD_INIT_LOG(DEBUG, "\t-Max key size: %u", config->rss_max_key_size);
1642 : 0 : PMD_INIT_LOG(DEBUG, "\t-Max reta size: %u", config->rss_max_indirection_table_length);
1643 : 0 : PMD_INIT_LOG(DEBUG, "\t-Supported hash types: 0x%x", *rss_hash_types);
1644 : :
1645 : 0 : return 0;
1646 : : }
1647 : :
1648 : : static int
1649 : 0 : virtio_dev_rss_hash_update(struct rte_eth_dev *dev,
1650 : : struct rte_eth_rss_conf *rss_conf)
1651 : : {
1652 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
1653 : : char old_rss_key[VIRTIO_NET_RSS_KEY_SIZE];
1654 : : uint32_t old_hash_types;
1655 : : uint16_t nb_queues;
1656 : : int ret;
1657 : :
1658 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_RSS))
1659 : : return -ENOTSUP;
1660 : :
1661 [ # # ]: 0 : if (rss_conf->rss_hf & ~virtio_to_ethdev_rss_offloads(VIRTIO_NET_HASH_TYPE_MASK))
1662 : : return -EINVAL;
1663 : :
1664 : 0 : old_hash_types = hw->rss_hash_types;
1665 : 0 : hw->rss_hash_types = ethdev_to_virtio_rss_offloads(rss_conf->rss_hf);
1666 : :
1667 [ # # # # ]: 0 : if (rss_conf->rss_key && rss_conf->rss_key_len) {
1668 [ # # ]: 0 : if (rss_conf->rss_key_len != VIRTIO_NET_RSS_KEY_SIZE) {
1669 : 0 : PMD_INIT_LOG(ERR, "Driver only supports %u RSS key length",
1670 : : VIRTIO_NET_RSS_KEY_SIZE);
1671 : : ret = -EINVAL;
1672 : 0 : goto restore_types;
1673 : : }
1674 : 0 : memcpy(old_rss_key, hw->rss_key, VIRTIO_NET_RSS_KEY_SIZE);
1675 : : memcpy(hw->rss_key, rss_conf->rss_key, VIRTIO_NET_RSS_KEY_SIZE);
1676 : : }
1677 : :
1678 : 0 : nb_queues = RTE_MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
1679 : 0 : ret = virtio_set_multiple_queues_rss(dev, nb_queues);
1680 [ # # ]: 0 : if (ret < 0) {
1681 : 0 : PMD_INIT_LOG(ERR, "Failed to apply new RSS config to the device");
1682 : 0 : goto restore_key;
1683 : : }
1684 : :
1685 : : return 0;
1686 : : restore_key:
1687 [ # # # # ]: 0 : if (rss_conf->rss_key && rss_conf->rss_key_len)
1688 : 0 : memcpy(hw->rss_key, old_rss_key, VIRTIO_NET_RSS_KEY_SIZE);
1689 : 0 : restore_types:
1690 : 0 : hw->rss_hash_types = old_hash_types;
1691 : :
1692 : 0 : return ret;
1693 : : }
1694 : :
1695 : : static int
1696 : 0 : virtio_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1697 : : struct rte_eth_rss_conf *rss_conf)
1698 : : {
1699 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
1700 : :
1701 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_RSS))
1702 : : return -ENOTSUP;
1703 : :
1704 [ # # # # ]: 0 : if (rss_conf->rss_key && rss_conf->rss_key_len >= VIRTIO_NET_RSS_KEY_SIZE)
1705 : 0 : memcpy(rss_conf->rss_key, hw->rss_key, VIRTIO_NET_RSS_KEY_SIZE);
1706 : 0 : rss_conf->rss_key_len = VIRTIO_NET_RSS_KEY_SIZE;
1707 : 0 : rss_conf->rss_hf = virtio_to_ethdev_rss_offloads(hw->rss_hash_types);
1708 : :
1709 : 0 : return 0;
1710 : : }
1711 : :
1712 : 0 : static int virtio_dev_rss_reta_update(struct rte_eth_dev *dev,
1713 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1714 : : uint16_t reta_size)
1715 : : {
1716 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
1717 : : uint16_t nb_queues;
1718 : : uint16_t old_reta[VIRTIO_NET_RSS_RETA_SIZE];
1719 : : int idx, pos, i, ret;
1720 : :
1721 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_RSS))
1722 : : return -ENOTSUP;
1723 : :
1724 [ # # ]: 0 : if (reta_size != VIRTIO_NET_RSS_RETA_SIZE)
1725 : : return -EINVAL;
1726 : :
1727 : 0 : memcpy(old_reta, hw->rss_reta, sizeof(old_reta));
1728 : :
1729 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
1730 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
1731 : 0 : pos = i % RTE_ETH_RETA_GROUP_SIZE;
1732 : :
1733 [ # # ]: 0 : if (((reta_conf[idx].mask >> pos) & 0x1) == 0)
1734 : 0 : continue;
1735 : :
1736 : 0 : hw->rss_reta[i] = reta_conf[idx].reta[pos];
1737 : : }
1738 : :
1739 : 0 : nb_queues = RTE_MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
1740 : 0 : ret = virtio_set_multiple_queues_rss(dev, nb_queues);
1741 [ # # ]: 0 : if (ret < 0) {
1742 : 0 : PMD_INIT_LOG(ERR, "Failed to apply new RETA to the device");
1743 : 0 : memcpy(hw->rss_reta, old_reta, sizeof(old_reta));
1744 : : }
1745 : :
1746 : 0 : hw->rss_rx_queues = dev->data->nb_rx_queues;
1747 : :
1748 : 0 : return ret;
1749 : : }
1750 : :
1751 : 0 : static int virtio_dev_rss_reta_query(struct rte_eth_dev *dev,
1752 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1753 : : uint16_t reta_size)
1754 : : {
1755 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
1756 : : int idx, i;
1757 : :
1758 [ # # ]: 0 : if (!virtio_with_feature(hw, VIRTIO_NET_F_RSS))
1759 : : return -ENOTSUP;
1760 : :
1761 [ # # ]: 0 : if (reta_size != VIRTIO_NET_RSS_RETA_SIZE)
1762 : : return -EINVAL;
1763 : :
1764 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
1765 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
1766 : 0 : reta_conf[idx].reta[i % RTE_ETH_RETA_GROUP_SIZE] = hw->rss_reta[i];
1767 : : }
1768 : :
1769 : : return 0;
1770 : : }
1771 : :
1772 : : /*
1773 : : * As default RSS hash key, it uses the default key of the
1774 : : * Intel IXGBE devices. It can be updated by the application
1775 : : * with any 40B key value.
1776 : : */
1777 : : static uint8_t rss_intel_key[VIRTIO_NET_RSS_KEY_SIZE] = {
1778 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
1779 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
1780 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
1781 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
1782 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
1783 : : };
1784 : :
1785 : : static int
1786 : 0 : virtio_dev_rss_init(struct rte_eth_dev *eth_dev)
1787 : : {
1788 : 0 : struct virtio_hw *hw = eth_dev->data->dev_private;
1789 : 0 : uint16_t nb_rx_queues = eth_dev->data->nb_rx_queues;
1790 : : struct rte_eth_rss_conf *rss_conf;
1791 : : int ret, i;
1792 : :
1793 [ # # ]: 0 : if (!nb_rx_queues) {
1794 : 0 : PMD_INIT_LOG(ERR, "Cannot init RSS if no Rx queues");
1795 : 0 : return -EINVAL;
1796 : : }
1797 : :
1798 : : rss_conf = ð_dev->data->dev_conf.rx_adv_conf.rss_conf;
1799 : :
1800 : 0 : ret = virtio_dev_get_rss_config(hw, &hw->rss_hash_types);
1801 [ # # ]: 0 : if (ret)
1802 : : return ret;
1803 : :
1804 [ # # ]: 0 : if (rss_conf->rss_hf) {
1805 : : /* Ensure requested hash types are supported by the device */
1806 [ # # ]: 0 : if (rss_conf->rss_hf & ~virtio_to_ethdev_rss_offloads(hw->rss_hash_types))
1807 : : return -EINVAL;
1808 : :
1809 : 0 : hw->rss_hash_types = ethdev_to_virtio_rss_offloads(rss_conf->rss_hf);
1810 : : }
1811 : :
1812 [ # # ]: 0 : if (!hw->rss_key) {
1813 : : /* Setup default RSS key if not already setup by the user */
1814 : 0 : hw->rss_key = rte_malloc_socket("rss_key",
1815 : : VIRTIO_NET_RSS_KEY_SIZE, 0,
1816 : 0 : eth_dev->device->numa_node);
1817 [ # # ]: 0 : if (!hw->rss_key) {
1818 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate RSS key");
1819 : 0 : return -ENOMEM;
1820 : : }
1821 : : }
1822 : :
1823 [ # # # # ]: 0 : if (rss_conf->rss_key && rss_conf->rss_key_len) {
1824 [ # # ]: 0 : if (rss_conf->rss_key_len != VIRTIO_NET_RSS_KEY_SIZE) {
1825 : 0 : PMD_INIT_LOG(ERR, "Driver only supports %u RSS key length",
1826 : : VIRTIO_NET_RSS_KEY_SIZE);
1827 : 0 : return -EINVAL;
1828 : : }
1829 : 0 : memcpy(hw->rss_key, rss_conf->rss_key, VIRTIO_NET_RSS_KEY_SIZE);
1830 : : } else {
1831 : 0 : memcpy(hw->rss_key, rss_intel_key, VIRTIO_NET_RSS_KEY_SIZE);
1832 : : }
1833 : :
1834 [ # # ]: 0 : if (!hw->rss_reta) {
1835 : : /* Setup default RSS reta if not already setup by the user */
1836 : 0 : hw->rss_reta = rte_zmalloc_socket("rss_reta",
1837 : : VIRTIO_NET_RSS_RETA_SIZE * sizeof(uint16_t), 0,
1838 : 0 : eth_dev->device->numa_node);
1839 [ # # ]: 0 : if (!hw->rss_reta) {
1840 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate RSS reta");
1841 : 0 : return -ENOMEM;
1842 : : }
1843 : :
1844 : 0 : hw->rss_rx_queues = 0;
1845 : : }
1846 : :
1847 : : /* Re-initialize the RSS reta if the number of RX queues has changed */
1848 [ # # ]: 0 : if (hw->rss_rx_queues != nb_rx_queues) {
1849 [ # # ]: 0 : for (i = 0; i < VIRTIO_NET_RSS_RETA_SIZE; i++)
1850 : 0 : hw->rss_reta[i] = i % nb_rx_queues;
1851 : 0 : hw->rss_rx_queues = nb_rx_queues;
1852 : : }
1853 : :
1854 : : return 0;
1855 : : }
1856 : :
1857 : : #define DUPLEX_UNKNOWN 0xff
1858 : : /* reset device and renegotiate features if needed */
1859 : : static int
1860 : 0 : virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
1861 : : {
1862 : 0 : struct virtio_hw *hw = eth_dev->data->dev_private;
1863 : : struct virtio_net_config *config;
1864 : : struct virtio_net_config local_config;
1865 : : int ret;
1866 : :
1867 : : /* Reset the device although not necessary at startup */
1868 : 0 : virtio_reset(hw);
1869 : :
1870 [ # # ]: 0 : if (hw->vqs) {
1871 : 0 : virtio_dev_free_mbufs(eth_dev);
1872 : 0 : virtio_free_queues(hw);
1873 : : }
1874 : :
1875 : : /* Tell the host we've noticed this device. */
1876 : 0 : virtio_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);
1877 : :
1878 : : /* Tell the host we've known how to drive the device. */
1879 : 0 : virtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);
1880 [ # # ]: 0 : if (virtio_ethdev_negotiate_features(hw, req_features) < 0)
1881 : : return -EINVAL;
1882 : :
1883 : 0 : hw->weak_barriers = !virtio_with_feature(hw, VIRTIO_F_ORDER_PLATFORM);
1884 : :
1885 : : /* If host does not support both status and MSI-X then disable LSC */
1886 [ # # # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS) && hw->intr_lsc)
1887 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
1888 : : else
1889 : 0 : eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
1890 : :
1891 : : /* Setting up rx_header size for the device */
1892 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_HASH_REPORT))
1893 : 0 : hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr_hash_report);
1894 [ # # # # ]: 0 : else if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) ||
1895 [ # # ]: 0 : virtio_with_feature(hw, VIRTIO_F_VERSION_1) ||
1896 : : virtio_with_packed_queue(hw))
1897 : 0 : hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf);
1898 : : else
1899 : 0 : hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr);
1900 : :
1901 : : /* Copy the permanent MAC address to: virtio_hw */
1902 : 0 : virtio_get_hwaddr(hw);
1903 : 0 : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac_addr,
1904 : 0 : ð_dev->data->mac_addrs[0]);
1905 : 0 : PMD_INIT_LOG(DEBUG,
1906 : : "PORT MAC: " RTE_ETHER_ADDR_PRT_FMT,
1907 : : hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
1908 : : hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
1909 : :
1910 [ # # # # ]: 0 : hw->get_speed_via_feat = hw->speed == RTE_ETH_SPEED_NUM_UNKNOWN &&
1911 : : virtio_with_feature(hw, VIRTIO_NET_F_SPEED_DUPLEX);
1912 [ # # ]: 0 : if (hw->get_speed_via_feat)
1913 : 0 : virtio_get_speed_duplex(eth_dev, NULL);
1914 [ # # ]: 0 : if (hw->duplex == DUPLEX_UNKNOWN)
1915 : 0 : hw->duplex = RTE_ETH_LINK_FULL_DUPLEX;
1916 : 0 : PMD_INIT_LOG(DEBUG, "link speed = %d, duplex = %d",
1917 : : hw->speed, hw->duplex);
1918 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VQ)) {
1919 : : config = &local_config;
1920 : :
1921 : 0 : virtio_read_dev_config(hw,
1922 : : offsetof(struct virtio_net_config, mac),
1923 : : &config->mac, sizeof(config->mac));
1924 : :
1925 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS)) {
1926 : 0 : virtio_read_dev_config(hw,
1927 : : offsetof(struct virtio_net_config, status),
1928 : : &config->status, sizeof(config->status));
1929 : : } else {
1930 : 0 : PMD_INIT_LOG(DEBUG,
1931 : : "VIRTIO_NET_F_STATUS is not supported");
1932 : 0 : config->status = 0;
1933 : : }
1934 : :
1935 [ # # # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_MQ) ||
1936 : : virtio_with_feature(hw, VIRTIO_NET_F_RSS)) {
1937 : 0 : virtio_read_dev_config(hw,
1938 : : offsetof(struct virtio_net_config, max_virtqueue_pairs),
1939 : : &config->max_virtqueue_pairs,
1940 : : sizeof(config->max_virtqueue_pairs));
1941 : : } else {
1942 : 0 : PMD_INIT_LOG(DEBUG,
1943 : : "Neither VIRTIO_NET_F_MQ nor VIRTIO_NET_F_RSS are supported");
1944 : 0 : config->max_virtqueue_pairs = 1;
1945 : : }
1946 : :
1947 [ # # ]: 0 : hw->max_queue_pairs = config->max_virtqueue_pairs;
1948 : :
1949 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_MTU)) {
1950 : 0 : virtio_read_dev_config(hw,
1951 : : offsetof(struct virtio_net_config, mtu),
1952 : : &config->mtu,
1953 : : sizeof(config->mtu));
1954 : :
1955 : : /*
1956 : : * MTU value has already been checked at negotiation
1957 : : * time, but check again in case it has changed since
1958 : : * then, which should not happen.
1959 : : */
1960 [ # # ]: 0 : if (config->mtu < RTE_ETHER_MIN_MTU) {
1961 : 0 : PMD_INIT_LOG(ERR, "invalid max MTU value (%u)",
1962 : : config->mtu);
1963 : 0 : return -EINVAL;
1964 : : }
1965 : :
1966 : 0 : hw->max_mtu = config->mtu;
1967 : : /* Set initial MTU to maximum one supported by vhost */
1968 : 0 : eth_dev->data->mtu = config->mtu;
1969 : :
1970 : : } else {
1971 : 0 : hw->max_mtu = VIRTIO_MAX_RX_PKTLEN - RTE_ETHER_HDR_LEN -
1972 : 0 : VLAN_TAG_LEN - hw->vtnet_hdr_size;
1973 : : }
1974 : :
1975 [ # # ]: 0 : hw->rss_hash_types = 0;
1976 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_RSS)) {
1977 : 0 : ret = virtio_dev_rss_init(eth_dev);
1978 [ # # ]: 0 : if (ret < 0)
1979 : : return ret;
1980 : : }
1981 : :
1982 : 0 : PMD_INIT_LOG(DEBUG, "config->max_virtqueue_pairs=%d",
1983 : : config->max_virtqueue_pairs);
1984 : 0 : PMD_INIT_LOG(DEBUG, "config->status=%d", config->status);
1985 : 0 : PMD_INIT_LOG(DEBUG,
1986 : : "PORT MAC: " RTE_ETHER_ADDR_PRT_FMT,
1987 : : config->mac[0], config->mac[1],
1988 : : config->mac[2], config->mac[3],
1989 : : config->mac[4], config->mac[5]);
1990 : : } else {
1991 : 0 : PMD_INIT_LOG(DEBUG, "config->max_virtqueue_pairs=1");
1992 : 0 : hw->max_queue_pairs = 1;
1993 : 0 : hw->max_mtu = VIRTIO_MAX_RX_PKTLEN - RTE_ETHER_HDR_LEN -
1994 : 0 : VLAN_TAG_LEN - hw->vtnet_hdr_size;
1995 : : }
1996 : :
1997 : 0 : ret = virtio_alloc_queues(eth_dev);
1998 [ # # ]: 0 : if (ret < 0)
1999 : : return ret;
2000 : :
2001 [ # # ]: 0 : if (eth_dev->data->dev_conf.intr_conf.rxq) {
2002 : 0 : ret = virtio_configure_intr(eth_dev);
2003 [ # # ]: 0 : if (ret < 0) {
2004 : 0 : PMD_INIT_LOG(ERR, "failed to configure interrupt");
2005 : 0 : virtio_free_queues(hw);
2006 : 0 : return ret;
2007 : : }
2008 : : }
2009 : :
2010 [ # # ]: 0 : if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
2011 : : /* Enable vector (0) for Link State Interrupt */
2012 [ # # ]: 0 : if (VIRTIO_OPS(hw)->set_config_irq(hw, 0) ==
2013 : : VIRTIO_MSI_NO_VECTOR) {
2014 : 0 : PMD_DRV_LOG(ERR, "failed to set config vector");
2015 : 0 : return -EBUSY;
2016 : : }
2017 : :
2018 : 0 : virtio_reinit_complete(hw);
2019 : :
2020 : 0 : return 0;
2021 : : }
2022 : :
2023 : : /*
2024 : : * This function is based on probe() function in virtio_pci.c
2025 : : * It returns 0 on success.
2026 : : */
2027 : : int
2028 : 0 : eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
2029 : : {
2030 : 0 : struct virtio_hw *hw = eth_dev->data->dev_private;
2031 : 0 : uint32_t speed = RTE_ETH_SPEED_NUM_UNKNOWN;
2032 : 0 : int vectorized = 0;
2033 : : int ret;
2034 : :
2035 : : if (sizeof(struct virtio_net_hdr_hash_report) > RTE_PKTMBUF_HEADROOM) {
2036 : : PMD_INIT_LOG(ERR,
2037 : : "Not sufficient headroom required = %d, avail = %d",
2038 : : (int)sizeof(struct virtio_net_hdr_mrg_rxbuf),
2039 : : RTE_PKTMBUF_HEADROOM);
2040 : :
2041 : : return -1;
2042 : : }
2043 : :
2044 : 0 : eth_dev->dev_ops = &virtio_eth_dev_ops;
2045 : :
2046 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
2047 : 0 : set_rxtx_funcs(eth_dev);
2048 : 0 : return 0;
2049 : : }
2050 : :
2051 : 0 : ret = virtio_dev_devargs_parse(eth_dev->device->devargs, &speed, &vectorized);
2052 [ # # ]: 0 : if (ret < 0)
2053 : : return ret;
2054 : 0 : hw->speed = speed;
2055 : 0 : hw->duplex = DUPLEX_UNKNOWN;
2056 : :
2057 : : /* Allocate memory for storing MAC addresses */
2058 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("virtio",
2059 : : VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN, 0);
2060 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
2061 : 0 : PMD_INIT_LOG(ERR,
2062 : : "Failed to allocate %d bytes needed to store MAC addresses",
2063 : : VIRTIO_MAX_MAC_ADDRS * RTE_ETHER_ADDR_LEN);
2064 : 0 : return -ENOMEM;
2065 : : }
2066 : :
2067 : : rte_spinlock_init(&hw->state_lock);
2068 : :
2069 [ # # ]: 0 : if (vectorized) {
2070 : 0 : hw->use_vec_rx = 1;
2071 : 0 : hw->use_vec_tx = 1;
2072 : : }
2073 : :
2074 : : /* reset device and negotiate default features */
2075 : 0 : ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
2076 [ # # ]: 0 : if (ret < 0)
2077 : 0 : goto err_virtio_init;
2078 : :
2079 [ # # ]: 0 : if (vectorized) {
2080 [ # # ]: 0 : if (!virtio_with_packed_queue(hw)) {
2081 : 0 : hw->use_vec_tx = 0;
2082 : : } else {
2083 : : #if !defined(CC_AVX512_SUPPORT) && !defined(RTE_ARCH_ARM)
2084 : : hw->use_vec_rx = 0;
2085 : : hw->use_vec_tx = 0;
2086 : : PMD_DRV_LOG(INFO,
2087 : : "building environment do not support packed ring vectorized");
2088 : : #endif
2089 : : }
2090 : : }
2091 : :
2092 : 0 : hw->opened = 1;
2093 : :
2094 : 0 : return 0;
2095 : :
2096 : : err_virtio_init:
2097 : 0 : rte_free(eth_dev->data->mac_addrs);
2098 : 0 : eth_dev->data->mac_addrs = NULL;
2099 : 0 : return ret;
2100 : : }
2101 : :
2102 : : static uint32_t
2103 : 0 : virtio_dev_speed_capa_get(uint32_t speed)
2104 : : {
2105 [ # # # # : 0 : switch (speed) {
# # # # #
# # ]
2106 : : case RTE_ETH_SPEED_NUM_10G:
2107 : : return RTE_ETH_LINK_SPEED_10G;
2108 : 0 : case RTE_ETH_SPEED_NUM_20G:
2109 : 0 : return RTE_ETH_LINK_SPEED_20G;
2110 : 0 : case RTE_ETH_SPEED_NUM_25G:
2111 : 0 : return RTE_ETH_LINK_SPEED_25G;
2112 : 0 : case RTE_ETH_SPEED_NUM_40G:
2113 : 0 : return RTE_ETH_LINK_SPEED_40G;
2114 : 0 : case RTE_ETH_SPEED_NUM_50G:
2115 : 0 : return RTE_ETH_LINK_SPEED_50G;
2116 : 0 : case RTE_ETH_SPEED_NUM_56G:
2117 : 0 : return RTE_ETH_LINK_SPEED_56G;
2118 : 0 : case RTE_ETH_SPEED_NUM_100G:
2119 : 0 : return RTE_ETH_LINK_SPEED_100G;
2120 : 0 : case RTE_ETH_SPEED_NUM_200G:
2121 : 0 : return RTE_ETH_LINK_SPEED_200G;
2122 : 0 : case RTE_ETH_SPEED_NUM_400G:
2123 : 0 : return RTE_ETH_LINK_SPEED_400G;
2124 : 0 : case RTE_ETH_SPEED_NUM_800G:
2125 : 0 : return RTE_ETH_LINK_SPEED_800G;
2126 : 0 : default:
2127 : 0 : return 0;
2128 : : }
2129 : : }
2130 : :
2131 : 0 : static int vectorized_check_handler(__rte_unused const char *key,
2132 : : const char *value, void *ret_val)
2133 : : {
2134 [ # # ]: 0 : if (value == NULL || ret_val == NULL)
2135 : : return -EINVAL;
2136 : :
2137 [ # # ]: 0 : if (strcmp(value, "1") == 0)
2138 : 0 : *(int *)ret_val = 1;
2139 : : else
2140 : 0 : *(int *)ret_val = 0;
2141 : :
2142 : : return 0;
2143 : : }
2144 : :
2145 : : #define VIRTIO_ARG_SPEED "speed"
2146 : : #define VIRTIO_ARG_VECTORIZED "vectorized"
2147 : :
2148 : : static int
2149 : 0 : link_speed_handler(const char *key __rte_unused,
2150 : : const char *value, void *ret_val)
2151 : : {
2152 : : uint32_t val;
2153 [ # # ]: 0 : if (!value || !ret_val)
2154 : : return -EINVAL;
2155 : 0 : val = strtoul(value, NULL, 0);
2156 : : /* validate input */
2157 [ # # ]: 0 : if (virtio_dev_speed_capa_get(val) == 0)
2158 : : return -EINVAL;
2159 : 0 : *(uint32_t *)ret_val = val;
2160 : :
2161 : 0 : return 0;
2162 : : }
2163 : :
2164 : :
2165 : : static int
2166 : 0 : virtio_dev_devargs_parse(struct rte_devargs *devargs, uint32_t *speed, int *vectorized)
2167 : : {
2168 : : struct rte_kvargs *kvlist;
2169 : : int ret = 0;
2170 : :
2171 [ # # ]: 0 : if (devargs == NULL)
2172 : : return 0;
2173 : :
2174 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
2175 [ # # ]: 0 : if (kvlist == NULL) {
2176 : 0 : PMD_INIT_LOG(ERR, "error when parsing param");
2177 : 0 : return 0;
2178 : : }
2179 : :
2180 [ # # # # ]: 0 : if (speed && rte_kvargs_count(kvlist, VIRTIO_ARG_SPEED) == 1) {
2181 : 0 : ret = rte_kvargs_process(kvlist,
2182 : : VIRTIO_ARG_SPEED,
2183 : : link_speed_handler, speed);
2184 [ # # ]: 0 : if (ret < 0) {
2185 : 0 : PMD_INIT_LOG(ERR, "Failed to parse %s",
2186 : : VIRTIO_ARG_SPEED);
2187 : 0 : goto exit;
2188 : : }
2189 : : }
2190 : :
2191 [ # # # # ]: 0 : if (vectorized &&
2192 : 0 : rte_kvargs_count(kvlist, VIRTIO_ARG_VECTORIZED) == 1) {
2193 : 0 : ret = rte_kvargs_process(kvlist,
2194 : : VIRTIO_ARG_VECTORIZED,
2195 : : vectorized_check_handler, vectorized);
2196 [ # # ]: 0 : if (ret < 0) {
2197 : 0 : PMD_INIT_LOG(ERR, "Failed to parse %s",
2198 : : VIRTIO_ARG_VECTORIZED);
2199 : 0 : goto exit;
2200 : : }
2201 : : }
2202 : :
2203 : 0 : exit:
2204 : 0 : rte_kvargs_free(kvlist);
2205 : 0 : return ret;
2206 : : }
2207 : :
2208 : : static uint8_t
2209 : : rx_offload_enabled(struct virtio_hw *hw)
2210 : : {
2211 [ # # ]: 0 : return virtio_with_feature(hw, VIRTIO_NET_F_GUEST_CSUM) ||
2212 [ # # # # ]: 0 : virtio_with_feature(hw, VIRTIO_NET_F_GUEST_TSO4) ||
2213 : : virtio_with_feature(hw, VIRTIO_NET_F_GUEST_TSO6);
2214 : : }
2215 : :
2216 : : static uint8_t
2217 : : tx_offload_enabled(struct virtio_hw *hw)
2218 : : {
2219 [ # # ]: 0 : return virtio_with_feature(hw, VIRTIO_NET_F_CSUM) ||
2220 [ # # # # ]: 0 : virtio_with_feature(hw, VIRTIO_NET_F_HOST_TSO4) ||
2221 : : virtio_with_feature(hw, VIRTIO_NET_F_HOST_TSO6);
2222 : : }
2223 : :
2224 : : /*
2225 : : * Configure virtio device
2226 : : * It returns 0 on success.
2227 : : */
2228 : : static int
2229 : 0 : virtio_dev_configure(struct rte_eth_dev *dev)
2230 : : {
2231 : 0 : const struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
2232 : : const struct rte_eth_txmode *txmode = &dev->data->dev_conf.txmode;
2233 : 0 : struct virtio_hw *hw = dev->data->dev_private;
2234 : 0 : uint32_t ether_hdr_len = RTE_ETHER_HDR_LEN + VLAN_TAG_LEN +
2235 : 0 : hw->vtnet_hdr_size;
2236 : 0 : uint64_t rx_offloads = rxmode->offloads;
2237 : 0 : uint64_t tx_offloads = txmode->offloads;
2238 : : uint64_t req_features;
2239 : : int ret;
2240 : :
2241 : 0 : PMD_INIT_LOG(DEBUG, "configure");
2242 : : req_features = VIRTIO_PMD_DEFAULT_GUEST_FEATURES;
2243 : :
2244 [ # # ]: 0 : if (rxmode->mq_mode != RTE_ETH_MQ_RX_NONE && rxmode->mq_mode != RTE_ETH_MQ_RX_RSS) {
2245 : 0 : PMD_DRV_LOG(ERR,
2246 : : "Unsupported Rx multi queue mode %d",
2247 : : rxmode->mq_mode);
2248 : 0 : return -EINVAL;
2249 : : }
2250 : :
2251 [ # # ]: 0 : if (txmode->mq_mode != RTE_ETH_MQ_TX_NONE) {
2252 : 0 : PMD_DRV_LOG(ERR,
2253 : : "Unsupported Tx multi queue mode %d",
2254 : : txmode->mq_mode);
2255 : 0 : return -EINVAL;
2256 : : }
2257 : :
2258 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq) {
2259 : 0 : ret = virtio_init_device(dev, hw->req_guest_features);
2260 [ # # ]: 0 : if (ret < 0)
2261 : : return ret;
2262 : : }
2263 : :
2264 [ # # ]: 0 : if (rxmode->mq_mode == RTE_ETH_MQ_RX_RSS)
2265 : : req_features |= (1ULL << VIRTIO_NET_F_RSS);
2266 : :
2267 [ # # ]: 0 : if (rxmode->mtu > hw->max_mtu)
2268 : 0 : req_features &= ~(1ULL << VIRTIO_NET_F_MTU);
2269 : :
2270 : 0 : hw->max_rx_pkt_len = ether_hdr_len + rxmode->mtu;
2271 : :
2272 [ # # ]: 0 : if (rx_offloads & (RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
2273 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM))
2274 : 0 : req_features |= (1ULL << VIRTIO_NET_F_GUEST_CSUM);
2275 : :
2276 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)
2277 : 0 : req_features |=
2278 : : (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
2279 : : (1ULL << VIRTIO_NET_F_GUEST_TSO6);
2280 : :
2281 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH)
2282 : 0 : req_features |=
2283 : : (1ULL << VIRTIO_NET_F_HASH_REPORT);
2284 : :
2285 [ # # ]: 0 : if (tx_offloads & (RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
2286 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM))
2287 : 0 : req_features |= (1ULL << VIRTIO_NET_F_CSUM);
2288 : :
2289 [ # # ]: 0 : if (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_TSO)
2290 : 0 : req_features |=
2291 : : (1ULL << VIRTIO_NET_F_HOST_TSO4) |
2292 : : (1ULL << VIRTIO_NET_F_HOST_TSO6);
2293 : :
2294 : : /* if request features changed, reinit the device */
2295 [ # # ]: 0 : if (req_features != hw->req_guest_features) {
2296 : 0 : ret = virtio_init_device(dev, req_features);
2297 [ # # ]: 0 : if (ret < 0)
2298 : : return ret;
2299 : : }
2300 : :
2301 : : /* if queues are not allocated, reinit the device */
2302 [ # # ]: 0 : if (hw->vqs == NULL) {
2303 : 0 : ret = virtio_init_device(dev, hw->req_guest_features);
2304 [ # # ]: 0 : if (ret < 0)
2305 : : return ret;
2306 : : }
2307 : :
2308 [ # # # # ]: 0 : if ((rxmode->mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) &&
2309 : : !virtio_with_feature(hw, VIRTIO_NET_F_RSS)) {
2310 : 0 : PMD_DRV_LOG(ERR, "RSS support requested but not supported by the device");
2311 : 0 : return -ENOTSUP;
2312 : : }
2313 : :
2314 [ # # ]: 0 : if ((rx_offloads & (RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
2315 [ # # ]: 0 : RTE_ETH_RX_OFFLOAD_TCP_CKSUM)) &&
2316 : : !virtio_with_feature(hw, VIRTIO_NET_F_GUEST_CSUM)) {
2317 : 0 : PMD_DRV_LOG(ERR,
2318 : : "rx checksum not available on this host");
2319 : 0 : return -ENOTSUP;
2320 : : }
2321 : :
2322 [ # # # # ]: 0 : if ((rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) &&
2323 [ # # ]: 0 : (!virtio_with_feature(hw, VIRTIO_NET_F_GUEST_TSO4) ||
2324 : : !virtio_with_feature(hw, VIRTIO_NET_F_GUEST_TSO6))) {
2325 : 0 : PMD_DRV_LOG(ERR,
2326 : : "Large Receive Offload not available on this host");
2327 : 0 : return -ENOTSUP;
2328 : : }
2329 : :
2330 : : /* start control queue */
2331 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VQ))
2332 : 0 : virtio_dev_cq_start(dev);
2333 : :
2334 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
2335 : 0 : hw->vlan_strip = 1;
2336 : :
2337 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH)
2338 : 0 : hw->has_hash_report = 1;
2339 : :
2340 : 0 : hw->rx_ol_scatter = (rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER);
2341 : :
2342 [ # # # # ]: 0 : if ((rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) &&
2343 : : !virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN)) {
2344 : 0 : PMD_DRV_LOG(ERR,
2345 : : "vlan filtering not available on this host");
2346 : 0 : return -ENOTSUP;
2347 : : }
2348 : :
2349 [ # # ]: 0 : hw->has_tx_offload = tx_offload_enabled(hw);
2350 [ # # ]: 0 : hw->has_rx_offload = rx_offload_enabled(hw);
2351 : :
2352 [ # # ]: 0 : if (virtio_with_packed_queue(hw)) {
2353 : : #if defined(RTE_ARCH_X86_64) && defined(CC_AVX512_SUPPORT)
2354 [ # # # # ]: 0 : if ((hw->use_vec_rx || hw->use_vec_tx) &&
2355 [ # # ]: 0 : (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) ||
2356 [ # # ]: 0 : !virtio_with_feature(hw, VIRTIO_F_IN_ORDER) ||
2357 [ # # ]: 0 : !virtio_with_feature(hw, VIRTIO_F_VERSION_1) ||
2358 : 0 : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_512)) {
2359 : 0 : PMD_DRV_LOG(INFO,
2360 : : "disabled packed ring vectorized path for requirements not met");
2361 : 0 : hw->use_vec_rx = 0;
2362 : 0 : hw->use_vec_tx = 0;
2363 : : }
2364 : : #elif defined(RTE_ARCH_ARM)
2365 : : if ((hw->use_vec_rx || hw->use_vec_tx) &&
2366 : : (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON) ||
2367 : : !virtio_with_feature(hw, VIRTIO_F_IN_ORDER) ||
2368 : : !virtio_with_feature(hw, VIRTIO_F_VERSION_1) ||
2369 : : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)) {
2370 : : PMD_DRV_LOG(INFO,
2371 : : "disabled packed ring vectorized path for requirements not met");
2372 : : hw->use_vec_rx = 0;
2373 : : hw->use_vec_tx = 0;
2374 : : }
2375 : : #else
2376 : : hw->use_vec_rx = 0;
2377 : : hw->use_vec_tx = 0;
2378 : : #endif
2379 : :
2380 [ # # ]: 0 : if (hw->use_vec_rx) {
2381 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
2382 : 0 : PMD_DRV_LOG(INFO,
2383 : : "disabled packed ring vectorized rx for mrg_rxbuf enabled");
2384 : 0 : hw->use_vec_rx = 0;
2385 : : }
2386 : :
2387 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) {
2388 : 0 : PMD_DRV_LOG(INFO,
2389 : : "disabled packed ring vectorized rx for TCP_LRO enabled");
2390 : 0 : hw->use_vec_rx = 0;
2391 : : }
2392 : :
2393 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH) {
2394 : 0 : PMD_DRV_LOG(INFO,
2395 : : "disabled packed ring vectorized rx for RSS_HASH enabled");
2396 : 0 : hw->use_vec_rx = 0;
2397 : : }
2398 : : }
2399 : : } else {
2400 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_F_IN_ORDER)) {
2401 : 0 : hw->use_inorder_tx = 1;
2402 : 0 : hw->use_inorder_rx = 1;
2403 : 0 : hw->use_vec_rx = 0;
2404 : : }
2405 : :
2406 [ # # ]: 0 : if (hw->use_vec_rx) {
2407 : : #if defined RTE_ARCH_ARM
2408 : : if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON)) {
2409 : : PMD_DRV_LOG(INFO,
2410 : : "disabled split ring vectorized path for requirement not met");
2411 : : hw->use_vec_rx = 0;
2412 : : }
2413 : : #endif
2414 [ # # ]: 0 : if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
2415 : 0 : PMD_DRV_LOG(INFO,
2416 : : "disabled split ring vectorized rx for mrg_rxbuf enabled");
2417 : 0 : hw->use_vec_rx = 0;
2418 : : }
2419 : :
2420 [ # # ]: 0 : if (rx_offloads & (RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
2421 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
2422 : : RTE_ETH_RX_OFFLOAD_TCP_LRO |
2423 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP)) {
2424 : 0 : PMD_DRV_LOG(INFO,
2425 : : "disabled split ring vectorized rx for offloading enabled");
2426 : 0 : hw->use_vec_rx = 0;
2427 : : }
2428 : :
2429 [ # # ]: 0 : if (rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
2430 : 0 : PMD_DRV_LOG(INFO,
2431 : : "disabled split ring vectorized rx, max SIMD bitwidth too low");
2432 : 0 : hw->use_vec_rx = 0;
2433 : : }
2434 : : }
2435 : : }
2436 : :
2437 : : return 0;
2438 : : }
2439 : :
2440 : :
2441 : : static int
2442 : 0 : virtio_dev_start(struct rte_eth_dev *dev)
2443 : : {
2444 : : uint16_t nb_queues, i;
2445 : : struct virtqueue *vq;
2446 : 0 : struct virtio_hw *hw = dev->data->dev_private;
2447 : : int ret;
2448 : :
2449 : : /* Finish the initialization of the queues */
2450 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2451 : 0 : ret = virtio_dev_rx_queue_setup_finish(dev, i);
2452 [ # # ]: 0 : if (ret < 0)
2453 : 0 : return ret;
2454 : : }
2455 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2456 : 0 : ret = virtio_dev_tx_queue_setup_finish(dev, i);
2457 [ # # ]: 0 : if (ret < 0)
2458 : 0 : return ret;
2459 : : }
2460 : :
2461 : : /* check if lsc interrupt feature is enabled */
2462 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc) {
2463 [ # # ]: 0 : if (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)) {
2464 : 0 : PMD_DRV_LOG(ERR, "link status not supported by host");
2465 : 0 : return -ENOTSUP;
2466 : : }
2467 : : }
2468 : :
2469 : : /* Enable uio/vfio intr/eventfd mapping: although we already did that
2470 : : * in device configure, but it could be unmapped when device is
2471 : : * stopped.
2472 : : */
2473 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc ||
2474 : : dev->data->dev_conf.intr_conf.rxq) {
2475 : 0 : virtio_intr_disable(dev);
2476 : :
2477 : : /* Setup interrupt callback */
2478 [ # # ]: 0 : if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
2479 : 0 : rte_intr_callback_register(dev->intr_handle,
2480 : : virtio_interrupt_handler,
2481 : : dev);
2482 : :
2483 [ # # ]: 0 : if (virtio_intr_enable(dev) < 0) {
2484 : 0 : PMD_DRV_LOG(ERR, "interrupt enable failed");
2485 : 0 : return -EIO;
2486 : : }
2487 : : }
2488 : :
2489 : : /*Notify the backend
2490 : : *Otherwise the tap backend might already stop its queue due to fullness.
2491 : : *vhost backend will have no chance to be waked up
2492 : : */
2493 : 0 : nb_queues = RTE_MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
2494 [ # # ]: 0 : if (hw->max_queue_pairs > 1) {
2495 [ # # ]: 0 : if (virtio_set_multiple_queues(dev, nb_queues) != 0)
2496 : : return -EINVAL;
2497 : : }
2498 : :
2499 : 0 : PMD_INIT_LOG(DEBUG, "nb_queues=%u (port=%u)", nb_queues,
2500 : : dev->data->port_id);
2501 : :
2502 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2503 : 0 : vq = virtnet_rxq_to_vq(dev->data->rx_queues[i]);
2504 : : /* Flush the old packets */
2505 : 0 : virtqueue_rxvq_flush(vq);
2506 : : virtqueue_notify(vq);
2507 : : }
2508 : :
2509 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2510 : 0 : vq = virtnet_txq_to_vq(dev->data->tx_queues[i]);
2511 : : virtqueue_notify(vq);
2512 : : }
2513 : :
2514 : 0 : PMD_INIT_LOG(DEBUG, "Notified backend at initialization (port=%u)",
2515 : : dev->data->port_id);
2516 : :
2517 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2518 : : vq = virtnet_rxq_to_vq(dev->data->rx_queues[i]);
2519 : : VIRTQUEUE_DUMP(vq);
2520 : : }
2521 : :
2522 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2523 : : vq = virtnet_txq_to_vq(dev->data->tx_queues[i]);
2524 : : VIRTQUEUE_DUMP(vq);
2525 : : }
2526 : :
2527 : 0 : set_rxtx_funcs(dev);
2528 : 0 : hw->started = 1;
2529 : :
2530 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
2531 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2532 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2533 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2534 : :
2535 : : /* Initialize Link state */
2536 : 0 : virtio_dev_link_update(dev, 0);
2537 : :
2538 : 0 : return 0;
2539 : : }
2540 : :
2541 : 0 : static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
2542 : : {
2543 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
2544 : : uint16_t nr_vq = virtio_get_nr_vq(hw);
2545 : : const char *type __rte_unused;
2546 : : unsigned int i, mbuf_num = 0;
2547 : : struct virtqueue *vq;
2548 : : struct rte_mbuf *buf;
2549 : : int queue_type;
2550 : :
2551 [ # # ]: 0 : if (hw->vqs == NULL)
2552 : : return;
2553 : :
2554 [ # # ]: 0 : for (i = 0; i < nr_vq; i++) {
2555 : 0 : vq = hw->vqs[i];
2556 [ # # ]: 0 : if (!vq)
2557 : 0 : continue;
2558 : :
2559 [ # # ]: 0 : queue_type = virtio_get_queue_type(hw, i);
2560 : : if (queue_type == VTNET_RQ)
2561 : : type = "rxq";
2562 [ # # ]: 0 : else if (queue_type == VTNET_TQ)
2563 : : type = "txq";
2564 : : else
2565 : 0 : continue;
2566 : :
2567 : 0 : PMD_INIT_LOG(DEBUG,
2568 : : "Before freeing %s[%d] used and unused buf",
2569 : : type, i);
2570 : : VIRTQUEUE_DUMP(vq);
2571 : :
2572 [ # # ]: 0 : while ((buf = virtqueue_detach_unused(vq)) != NULL) {
2573 : 0 : rte_pktmbuf_free(buf);
2574 : 0 : mbuf_num++;
2575 : : }
2576 : :
2577 : 0 : PMD_INIT_LOG(DEBUG,
2578 : : "After freeing %s[%d] used and unused buf",
2579 : : type, i);
2580 : : VIRTQUEUE_DUMP(vq);
2581 : : }
2582 : :
2583 : 0 : PMD_INIT_LOG(DEBUG, "%d mbufs freed", mbuf_num);
2584 : : }
2585 : :
2586 : : static void
2587 : 0 : virtio_tx_completed_cleanup(struct rte_eth_dev *dev)
2588 : : {
2589 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
2590 : : struct virtqueue *vq;
2591 : : int qidx;
2592 : : void (*xmit_cleanup)(struct virtqueue *vq, uint16_t nb_used);
2593 : :
2594 [ # # ]: 0 : if (virtio_with_packed_queue(hw)) {
2595 [ # # ]: 0 : if (hw->use_vec_tx)
2596 : : xmit_cleanup = &virtio_xmit_cleanup_inorder_packed;
2597 [ # # ]: 0 : else if (virtio_with_feature(hw, VIRTIO_F_IN_ORDER))
2598 : : xmit_cleanup = &virtio_xmit_cleanup_inorder_packed;
2599 : : else
2600 : : xmit_cleanup = &virtio_xmit_cleanup_normal_packed;
2601 : : } else {
2602 [ # # ]: 0 : if (hw->use_inorder_tx)
2603 : : xmit_cleanup = &virtio_xmit_cleanup_inorder;
2604 : : else
2605 : : xmit_cleanup = &virtio_xmit_cleanup;
2606 : : }
2607 : :
2608 [ # # ]: 0 : for (qidx = 0; qidx < hw->max_queue_pairs; qidx++) {
2609 : 0 : vq = hw->vqs[2 * qidx + VTNET_SQ_TQ_QUEUE_IDX];
2610 [ # # ]: 0 : if (vq != NULL)
2611 : 0 : xmit_cleanup(vq, virtqueue_nused(vq));
2612 : : }
2613 : 0 : }
2614 : :
2615 : : /*
2616 : : * Stop device: disable interrupt and mark link down
2617 : : */
2618 : : int
2619 : 0 : virtio_dev_stop(struct rte_eth_dev *dev)
2620 : : {
2621 : 0 : struct virtio_hw *hw = dev->data->dev_private;
2622 : : struct rte_eth_link link;
2623 : : struct rte_eth_intr_conf *intr_conf = &dev->data->dev_conf.intr_conf;
2624 : : uint16_t i;
2625 : :
2626 : 0 : PMD_INIT_LOG(DEBUG, "stop");
2627 : 0 : dev->data->dev_started = 0;
2628 : :
2629 : 0 : rte_spinlock_lock(&hw->state_lock);
2630 [ # # ]: 0 : if (!hw->started)
2631 : 0 : goto out_unlock;
2632 : 0 : hw->started = 0;
2633 : :
2634 : 0 : virtio_tx_completed_cleanup(dev);
2635 : :
2636 [ # # ]: 0 : if (intr_conf->lsc || intr_conf->rxq) {
2637 : 0 : virtio_intr_disable(dev);
2638 : :
2639 : : /* Reset interrupt callback */
2640 [ # # ]: 0 : if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {
2641 : 0 : rte_intr_callback_unregister(dev->intr_handle,
2642 : : virtio_interrupt_handler,
2643 : : dev);
2644 : : }
2645 : : }
2646 : :
2647 : : memset(&link, 0, sizeof(link));
2648 : 0 : rte_eth_linkstatus_set(dev, &link);
2649 : 0 : out_unlock:
2650 : : rte_spinlock_unlock(&hw->state_lock);
2651 : :
2652 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
2653 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
2654 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2655 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
2656 : :
2657 : 0 : return 0;
2658 : : }
2659 : :
2660 : : static int
2661 : 0 : virtio_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
2662 : : {
2663 : : struct rte_eth_link link;
2664 : : uint16_t status;
2665 [ # # ]: 0 : struct virtio_hw *hw = dev->data->dev_private;
2666 : :
2667 : : memset(&link, 0, sizeof(link));
2668 : 0 : link.link_duplex = hw->duplex;
2669 : 0 : link.link_speed = hw->speed;
2670 : 0 : link.link_autoneg = RTE_ETH_LINK_AUTONEG;
2671 : :
2672 [ # # ]: 0 : if (!hw->started) {
2673 : : link.link_status = RTE_ETH_LINK_DOWN;
2674 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
2675 [ # # ]: 0 : } else if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS)) {
2676 : 0 : PMD_INIT_LOG(DEBUG, "Get link status from hw");
2677 : 0 : virtio_read_dev_config(hw,
2678 : : offsetof(struct virtio_net_config, status),
2679 : : &status, sizeof(status));
2680 [ # # ]: 0 : if ((status & VIRTIO_NET_S_LINK_UP) == 0) {
2681 : : link.link_status = RTE_ETH_LINK_DOWN;
2682 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
2683 : 0 : PMD_INIT_LOG(DEBUG, "Port %d is down",
2684 : : dev->data->port_id);
2685 : : } else {
2686 : 0 : link.link_status = RTE_ETH_LINK_UP;
2687 [ # # ]: 0 : if (hw->get_speed_via_feat)
2688 : 0 : virtio_get_speed_duplex(dev, &link);
2689 : 0 : PMD_INIT_LOG(DEBUG, "Port %d is up",
2690 : : dev->data->port_id);
2691 : : }
2692 : : } else {
2693 : 0 : link.link_status = RTE_ETH_LINK_UP;
2694 [ # # ]: 0 : if (hw->get_speed_via_feat)
2695 : 0 : virtio_get_speed_duplex(dev, &link);
2696 : : }
2697 : :
2698 : 0 : return rte_eth_linkstatus_set(dev, &link);
2699 : : }
2700 : :
2701 : : static int
2702 : 0 : virtio_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2703 : : {
2704 : 0 : const struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
2705 : 0 : struct virtio_hw *hw = dev->data->dev_private;
2706 : 0 : uint64_t offloads = rxmode->offloads;
2707 : :
2708 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
2709 [ # # # # ]: 0 : if ((offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) &&
2710 : : !virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN)) {
2711 : :
2712 : 0 : PMD_DRV_LOG(NOTICE,
2713 : : "vlan filtering not available on this host");
2714 : :
2715 : 0 : return -ENOTSUP;
2716 : : }
2717 : : }
2718 : :
2719 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK)
2720 : 0 : hw->vlan_strip = !!(offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
2721 : :
2722 : : return 0;
2723 : : }
2724 : :
2725 : : static int
2726 : 0 : virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2727 : : {
2728 : : uint64_t tso_mask, host_features;
2729 : 0 : uint32_t rss_hash_types = 0;
2730 : 0 : struct virtio_hw *hw = dev->data->dev_private;
2731 : 0 : dev_info->speed_capa = virtio_dev_speed_capa_get(hw->speed);
2732 : :
2733 : 0 : dev_info->max_rx_queues =
2734 : 0 : RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
2735 : 0 : dev_info->max_tx_queues =
2736 : : RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_TX_QUEUES);
2737 : 0 : dev_info->min_rx_bufsize = VIRTIO_MIN_RX_BUFSIZE;
2738 : 0 : dev_info->max_rx_pktlen = VIRTIO_MAX_RX_PKTLEN;
2739 : 0 : dev_info->max_mac_addrs = VIRTIO_MAX_MAC_ADDRS;
2740 : 0 : dev_info->max_mtu = hw->max_mtu;
2741 : :
2742 : 0 : host_features = VIRTIO_OPS(hw)->get_features(hw);
2743 : 0 : dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2744 [ # # ]: 0 : if (host_features & (1ULL << VIRTIO_NET_F_MRG_RXBUF))
2745 : 0 : dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_SCATTER;
2746 [ # # ]: 0 : if (host_features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
2747 : 0 : dev_info->rx_offload_capa |=
2748 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
2749 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM;
2750 : : }
2751 [ # # ]: 0 : if (host_features & (1ULL << VIRTIO_NET_F_CTRL_VLAN))
2752 : 0 : dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
2753 : : tso_mask = (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
2754 : : (1ULL << VIRTIO_NET_F_GUEST_TSO6);
2755 [ # # ]: 0 : if ((host_features & tso_mask) == tso_mask)
2756 : 0 : dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
2757 : :
2758 : 0 : dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
2759 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
2760 [ # # ]: 0 : if (host_features & (1ULL << VIRTIO_NET_F_CSUM)) {
2761 : 0 : dev_info->tx_offload_capa |=
2762 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
2763 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
2764 : : }
2765 : : tso_mask = (1ULL << VIRTIO_NET_F_HOST_TSO4) |
2766 : : (1ULL << VIRTIO_NET_F_HOST_TSO6);
2767 [ # # ]: 0 : if ((host_features & tso_mask) == tso_mask)
2768 : 0 : dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_TCP_TSO;
2769 : :
2770 [ # # ]: 0 : if (host_features & (1ULL << VIRTIO_NET_F_RSS)) {
2771 : 0 : virtio_dev_get_rss_config(hw, &rss_hash_types);
2772 : 0 : dev_info->hash_key_size = VIRTIO_NET_RSS_KEY_SIZE;
2773 : 0 : dev_info->reta_size = VIRTIO_NET_RSS_RETA_SIZE;
2774 : 0 : dev_info->flow_type_rss_offloads =
2775 : 0 : virtio_to_ethdev_rss_offloads(rss_hash_types);
2776 : : } else {
2777 : 0 : dev_info->hash_key_size = 0;
2778 : 0 : dev_info->reta_size = 0;
2779 : 0 : dev_info->flow_type_rss_offloads = 0;
2780 : : }
2781 : :
2782 [ # # ]: 0 : if (host_features & (1ULL << VIRTIO_NET_F_HASH_REPORT))
2783 : 0 : dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
2784 : :
2785 [ # # ]: 0 : if (host_features & (1ULL << VIRTIO_F_RING_PACKED)) {
2786 : : /*
2787 : : * According to 2.7 Packed Virtqueues,
2788 : : * 2.7.10.1 Structure Size and Alignment:
2789 : : * The Queue Size value does not have to be a power of 2.
2790 : : */
2791 : 0 : dev_info->rx_desc_lim.nb_max = UINT16_MAX;
2792 : 0 : dev_info->tx_desc_lim.nb_max = UINT16_MAX;
2793 : : } else {
2794 : : /*
2795 : : * According to 2.6 Split Virtqueues:
2796 : : * Queue Size value is always a power of 2. The maximum Queue
2797 : : * Size value is 32768.
2798 : : */
2799 : 0 : dev_info->rx_desc_lim.nb_max = 32768;
2800 : 0 : dev_info->tx_desc_lim.nb_max = 32768;
2801 : : }
2802 : : /*
2803 : : * Actual minimum is not the same for virtqueues of different kinds,
2804 : : * but to avoid tangling the code with separate branches, rely on
2805 : : * default thresholds since desc number must be at least of their size.
2806 : : */
2807 : 0 : dev_info->rx_desc_lim.nb_min = RTE_MAX(DEFAULT_RX_FREE_THRESH,
2808 : : RTE_VIRTIO_VPMD_RX_REARM_THRESH);
2809 : 0 : dev_info->tx_desc_lim.nb_min = DEFAULT_TX_FREE_THRESH;
2810 : 0 : dev_info->rx_desc_lim.nb_align = 1;
2811 : 0 : dev_info->tx_desc_lim.nb_align = 1;
2812 : :
2813 : 0 : return 0;
2814 : : }
2815 : :
2816 [ - + ]: 302 : RTE_LOG_REGISTER_SUFFIX(virtio_logtype_init, init, NOTICE);
2817 [ - + ]: 302 : RTE_LOG_REGISTER_SUFFIX(virtio_logtype_driver, driver, NOTICE);
|