Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2018 Microsoft Corp.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include <stdio.h>
7 : : #include <stdint.h>
8 : : #include <string.h>
9 : : #include <stdbool.h>
10 : : #include <errno.h>
11 : : #include <unistd.h>
12 : : #include <dirent.h>
13 : : #include <fcntl.h>
14 : : #include <sys/types.h>
15 : : #include <sys/uio.h>
16 : :
17 : : #include <rte_ether.h>
18 : : #include <rte_ethdev.h>
19 : : #include <ethdev_driver.h>
20 : : #include <rte_lcore.h>
21 : : #include <rte_memory.h>
22 : : #include <bus_vmbus_driver.h>
23 : : #include <rte_pci.h>
24 : : #include <bus_pci_driver.h>
25 : : #include <rte_log.h>
26 : : #include <rte_string_fns.h>
27 : : #include <rte_alarm.h>
28 : :
29 : : #include "hn_logs.h"
30 : : #include "hn_var.h"
31 : : #include "hn_nvs.h"
32 : :
33 : : /* Search for VF with matching MAC address, return port id */
34 : 0 : static int hn_vf_match(const struct rte_eth_dev *dev)
35 : : {
36 : 0 : const struct rte_ether_addr *mac = dev->data->mac_addrs;
37 : : int i;
38 : :
39 [ # # ]: 0 : RTE_ETH_FOREACH_DEV(i) {
40 : 0 : const struct rte_eth_dev *vf_dev = &rte_eth_devices[i];
41 : 0 : const struct rte_ether_addr *vf_mac = vf_dev->data->mac_addrs;
42 : :
43 [ # # ]: 0 : if (vf_dev == dev)
44 : 0 : continue;
45 : :
46 [ # # ]: 0 : if (rte_is_same_ether_addr(mac, vf_mac))
47 : 0 : return i;
48 : : }
49 : : return -ENOENT;
50 : : }
51 : :
52 : :
53 : : /*
54 : : * Attach new PCI VF device and return the port_id
55 : : */
56 : 0 : static int hn_vf_attach(struct rte_eth_dev *dev, struct hn_data *hv)
57 : : {
58 : 0 : struct rte_eth_dev_owner owner = { .id = RTE_ETH_DEV_NO_OWNER };
59 : : int port, ret;
60 : :
61 [ # # ]: 0 : if (hv->vf_ctx.vf_attached) {
62 : 0 : PMD_DRV_LOG(ERR, "VF already attached");
63 : 0 : return 0;
64 : : }
65 : :
66 : 0 : port = hn_vf_match(dev);
67 [ # # ]: 0 : if (port < 0) {
68 : 0 : PMD_DRV_LOG(NOTICE, "Couldn't find port for VF");
69 : 0 : return port;
70 : : }
71 : :
72 : 0 : PMD_DRV_LOG(NOTICE, "found matching VF port %d", port);
73 : 0 : ret = rte_eth_dev_owner_get(port, &owner);
74 [ # # ]: 0 : if (ret < 0) {
75 : 0 : PMD_DRV_LOG(ERR, "Can not find owner for port %d", port);
76 : 0 : return ret;
77 : : }
78 : :
79 [ # # ]: 0 : if (owner.id != RTE_ETH_DEV_NO_OWNER) {
80 : 0 : PMD_DRV_LOG(ERR, "Port %u already owned by other device %s",
81 : : port, owner.name);
82 : 0 : return -EBUSY;
83 : : }
84 : :
85 : 0 : ret = rte_eth_dev_owner_set(port, &hv->owner);
86 [ # # ]: 0 : if (ret < 0) {
87 : 0 : PMD_DRV_LOG(ERR, "Can set owner for port %d", port);
88 : 0 : return ret;
89 : : }
90 : :
91 : 0 : PMD_DRV_LOG(DEBUG, "Attach VF device %u", port);
92 : 0 : hv->vf_ctx.vf_attached = true;
93 : 0 : hv->vf_ctx.vf_port = port;
94 : 0 : return 0;
95 : : }
96 : :
97 : : static void hn_vf_remove(struct hn_data *hv);
98 : :
99 : 0 : static void hn_remove_delayed(void *args)
100 : : {
101 : : struct hn_data *hv = args;
102 : 0 : uint16_t port_id = hv->vf_ctx.vf_port;
103 : 0 : struct rte_device *dev = rte_eth_devices[port_id].device;
104 : : int ret;
105 : :
106 : : /* Tell VSP to switch data path to synthetic */
107 : 0 : hn_vf_remove(hv);
108 : :
109 : 0 : PMD_DRV_LOG(NOTICE, "Start to remove port %d", port_id);
110 : 0 : rte_rwlock_write_lock(&hv->vf_lock);
111 : :
112 : : /* Give back ownership */
113 : 0 : ret = rte_eth_dev_owner_unset(port_id, hv->owner.id);
114 [ # # ]: 0 : if (ret)
115 : 0 : PMD_DRV_LOG(ERR, "rte_eth_dev_owner_unset failed ret=%d",
116 : : ret);
117 : 0 : hv->vf_ctx.vf_attached = false;
118 : :
119 : 0 : ret = rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_INTR_RMV,
120 : : hn_eth_rmv_event_callback, hv);
121 [ # # ]: 0 : if (ret)
122 : 0 : PMD_DRV_LOG(ERR,
123 : : "rte_eth_dev_callback_unregister failed ret=%d",
124 : : ret);
125 : :
126 : : /* Detach and release port_id from system */
127 : 0 : ret = rte_eth_dev_stop(port_id);
128 [ # # ]: 0 : if (ret)
129 : 0 : PMD_DRV_LOG(ERR, "rte_eth_dev_stop failed port_id=%u ret=%d",
130 : : port_id, ret);
131 : :
132 : : /* Record the device parameters for possible hotplug events */
133 [ # # # # ]: 0 : if (dev->devargs && dev->devargs->args)
134 : 0 : hv->vf_devargs = strdup(dev->devargs->args);
135 : :
136 : 0 : ret = rte_eth_dev_close(port_id);
137 [ # # ]: 0 : if (ret)
138 : 0 : PMD_DRV_LOG(ERR, "rte_eth_dev_close failed port_id=%u ret=%d",
139 : : port_id, ret);
140 : :
141 : 0 : ret = rte_dev_remove(dev);
142 : 0 : hv->vf_ctx.vf_state = vf_removed;
143 : :
144 : : rte_rwlock_write_unlock(&hv->vf_lock);
145 : 0 : }
146 : :
147 : 0 : int hn_eth_rmv_event_callback(uint16_t port_id,
148 : : enum rte_eth_event_type event __rte_unused,
149 : : void *cb_arg, void *out __rte_unused)
150 : : {
151 : : struct hn_data *hv = cb_arg;
152 : :
153 : 0 : PMD_DRV_LOG(NOTICE, "Removing VF portid %d", port_id);
154 : 0 : rte_eal_alarm_set(1, hn_remove_delayed, hv);
155 : :
156 : 0 : return 0;
157 : : }
158 : :
159 : 0 : static int hn_setup_vf_queues(int port, struct rte_eth_dev *dev)
160 : : {
161 : : struct hn_rx_queue *rx_queue;
162 : : struct rte_eth_txq_info txinfo;
163 : : struct rte_eth_rxq_info rxinfo;
164 : : int i, ret = 0;
165 : :
166 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
167 : 0 : ret = rte_eth_tx_queue_info_get(dev->data->port_id, i, &txinfo);
168 [ # # ]: 0 : if (ret) {
169 : 0 : PMD_DRV_LOG(ERR,
170 : : "rte_eth_tx_queue_info_get failed ret=%d",
171 : : ret);
172 : 0 : return ret;
173 : : }
174 : :
175 : 0 : ret = rte_eth_tx_queue_setup(port, i, txinfo.nb_desc, 0,
176 : : &txinfo.conf);
177 [ # # ]: 0 : if (ret) {
178 : 0 : PMD_DRV_LOG(ERR,
179 : : "rte_eth_tx_queue_setup failed ret=%d",
180 : : ret);
181 : 0 : return ret;
182 : : }
183 : : }
184 : :
185 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
186 : 0 : ret = rte_eth_rx_queue_info_get(dev->data->port_id, i, &rxinfo);
187 [ # # ]: 0 : if (ret) {
188 : 0 : PMD_DRV_LOG(ERR,
189 : : "rte_eth_rx_queue_info_get failed ret=%d",
190 : : ret);
191 : 0 : return ret;
192 : : }
193 : :
194 : 0 : rx_queue = dev->data->rx_queues[i];
195 : :
196 : 0 : ret = rte_eth_rx_queue_setup(port, i, rxinfo.nb_desc, 0,
197 : : &rxinfo.conf, rx_queue->mb_pool);
198 [ # # ]: 0 : if (ret) {
199 : 0 : PMD_DRV_LOG(ERR,
200 : : "rte_eth_rx_queue_setup failed ret=%d",
201 : : ret);
202 : 0 : return ret;
203 : : }
204 : : }
205 : :
206 : : return ret;
207 : : }
208 : :
209 : : int hn_vf_add(struct rte_eth_dev *dev, struct hn_data *hv);
210 : :
211 : 0 : static void hn_vf_add_retry(void *args)
212 : : {
213 : : struct rte_eth_dev *dev = args;
214 : 0 : struct hn_data *hv = dev->data->dev_private;
215 : :
216 : 0 : hn_vf_add(dev, hv);
217 : 0 : }
218 : :
219 : : int hn_vf_configure(struct rte_eth_dev *dev,
220 : : const struct rte_eth_conf *dev_conf);
221 : :
222 : : /* Add new VF device to synthetic device */
223 : 0 : int hn_vf_add(struct rte_eth_dev *dev, struct hn_data *hv)
224 : : {
225 : : int ret, port;
226 : :
227 [ # # # # ]: 0 : if (!hv->vf_ctx.vf_vsp_reported || hv->vf_ctx.vf_vsc_switched)
228 : : return 0;
229 : :
230 : 0 : rte_rwlock_write_lock(&hv->vf_lock);
231 : :
232 : 0 : ret = hn_vf_attach(dev, hv);
233 [ # # ]: 0 : if (ret) {
234 : 0 : PMD_DRV_LOG(NOTICE,
235 : : "RNDIS reports VF but device not found, retrying");
236 : 0 : rte_eal_alarm_set(1000000, hn_vf_add_retry, dev);
237 : 0 : goto exit;
238 : : }
239 : :
240 : 0 : port = hv->vf_ctx.vf_port;
241 : :
242 : : /* If the primary device has started, this is a VF hot add.
243 : : * Configure and start VF device.
244 : : */
245 [ # # ]: 0 : if (dev->data->dev_started) {
246 [ # # ]: 0 : if (rte_eth_devices[port].data->dev_started) {
247 : 0 : PMD_DRV_LOG(ERR, "VF already started on hot add");
248 : 0 : goto exit;
249 : : }
250 : :
251 : 0 : PMD_DRV_LOG(NOTICE, "configuring VF port %d", port);
252 : 0 : ret = hn_vf_configure(dev, &dev->data->dev_conf);
253 [ # # ]: 0 : if (ret) {
254 : 0 : PMD_DRV_LOG(ERR, "Failed to configure VF port %d",
255 : : port);
256 : 0 : goto exit;
257 : : }
258 : :
259 : 0 : ret = hn_setup_vf_queues(port, dev);
260 [ # # ]: 0 : if (ret) {
261 : 0 : PMD_DRV_LOG(ERR,
262 : : "Failed to configure VF queues port %d",
263 : : port);
264 : 0 : goto exit;
265 : : }
266 : :
267 : 0 : ret = hn_vf_mtu_set(dev, dev->data->mtu);
268 [ # # ]: 0 : if (ret) {
269 : 0 : PMD_DRV_LOG(ERR, "Failed to set VF MTU");
270 : 0 : goto exit;
271 : : }
272 : :
273 : 0 : PMD_DRV_LOG(NOTICE, "Starting VF port %d", port);
274 : 0 : ret = rte_eth_dev_start(port);
275 [ # # ]: 0 : if (ret) {
276 : 0 : PMD_DRV_LOG(ERR, "rte_eth_dev_start failed ret=%d",
277 : : ret);
278 : 0 : goto exit;
279 : : }
280 : 0 : hv->vf_ctx.vf_state = vf_started;
281 : : }
282 : :
283 : 0 : ret = hn_nvs_set_datapath(hv, NVS_DATAPATH_VF);
284 [ # # ]: 0 : if (ret == 0)
285 : 0 : hv->vf_ctx.vf_vsc_switched = true;
286 : :
287 : 0 : exit:
288 : : rte_rwlock_write_unlock(&hv->vf_lock);
289 : 0 : return ret;
290 : : }
291 : :
292 : : /* Switch data path to VF device */
293 : 0 : static void hn_vf_remove(struct hn_data *hv)
294 : : {
295 : : int ret;
296 : :
297 [ # # ]: 0 : if (!hv->vf_ctx.vf_vsc_switched) {
298 : 0 : PMD_DRV_LOG(ERR, "VF path not active");
299 : 0 : return;
300 : : }
301 : :
302 : 0 : rte_rwlock_write_lock(&hv->vf_lock);
303 [ # # ]: 0 : if (!hv->vf_ctx.vf_vsc_switched) {
304 : 0 : PMD_DRV_LOG(ERR, "VF path not active");
305 : : } else {
306 : : /* Stop incoming packets from arriving on VF */
307 : 0 : ret = hn_nvs_set_datapath(hv, NVS_DATAPATH_SYNTHETIC);
308 [ # # ]: 0 : if (ret == 0)
309 : 0 : hv->vf_ctx.vf_vsc_switched = false;
310 : : }
311 : : rte_rwlock_write_unlock(&hv->vf_lock);
312 : : }
313 : :
314 : : /* Handle VF association message from host */
315 : : void
316 : 0 : hn_nvs_handle_vfassoc(struct rte_eth_dev *dev,
317 : : const struct vmbus_chanpkt_hdr *hdr,
318 : : const void *data)
319 : : {
320 [ # # ]: 0 : struct hn_data *hv = dev->data->dev_private;
321 : : const struct hn_nvs_vf_association *vf_assoc = data;
322 : :
323 [ # # ]: 0 : if (unlikely(vmbus_chanpkt_datalen(hdr) < sizeof(*vf_assoc))) {
324 : 0 : PMD_DRV_LOG(ERR, "invalid vf association NVS");
325 : 0 : return;
326 : : }
327 : :
328 [ # # ]: 0 : PMD_DRV_LOG(DEBUG, "VF serial %u %s port %u",
329 : : vf_assoc->serial,
330 : : vf_assoc->allocated ? "add to" : "remove from",
331 : : dev->data->port_id);
332 : :
333 : 0 : hv->vf_ctx.vf_vsp_reported = vf_assoc->allocated;
334 : :
335 [ # # ]: 0 : if (dev->state == RTE_ETH_DEV_ATTACHED) {
336 [ # # ]: 0 : if (vf_assoc->allocated)
337 : 0 : hn_vf_add(dev, hv);
338 : : else
339 : 0 : hn_vf_remove(hv);
340 : : }
341 : : }
342 : :
343 : : static void
344 : : hn_vf_merge_desc_lim(struct rte_eth_desc_lim *lim,
345 : : const struct rte_eth_desc_lim *vf_lim)
346 : : {
347 : 0 : lim->nb_max = RTE_MIN(vf_lim->nb_max, lim->nb_max);
348 : 0 : lim->nb_min = RTE_MAX(vf_lim->nb_min, lim->nb_min);
349 : 0 : lim->nb_align = RTE_MAX(vf_lim->nb_align, lim->nb_align);
350 : 0 : lim->nb_seg_max = RTE_MIN(vf_lim->nb_seg_max, lim->nb_seg_max);
351 : 0 : lim->nb_mtu_seg_max = RTE_MIN(vf_lim->nb_seg_max, lim->nb_seg_max);
352 : : }
353 : :
354 : : /*
355 : : * Merge the info from the VF and synthetic path.
356 : : * use the default config of the VF
357 : : * and the minimum number of queues and buffer sizes.
358 : : */
359 : 0 : static int hn_vf_info_merge(struct rte_eth_dev *vf_dev,
360 : : struct rte_eth_dev_info *info)
361 : : {
362 : : struct rte_eth_dev_info vf_info;
363 : : int ret;
364 : :
365 : 0 : ret = rte_eth_dev_info_get(vf_dev->data->port_id, &vf_info);
366 [ # # ]: 0 : if (ret != 0)
367 : : return ret;
368 : :
369 : 0 : info->speed_capa = vf_info.speed_capa;
370 : 0 : info->default_rxportconf = vf_info.default_rxportconf;
371 : 0 : info->default_txportconf = vf_info.default_txportconf;
372 : :
373 : 0 : info->max_rx_queues = RTE_MIN(vf_info.max_rx_queues,
374 : : info->max_rx_queues);
375 : 0 : info->rx_offload_capa &= vf_info.rx_offload_capa;
376 : 0 : info->rx_queue_offload_capa &= vf_info.rx_queue_offload_capa;
377 : 0 : info->flow_type_rss_offloads &= vf_info.flow_type_rss_offloads;
378 : :
379 : 0 : info->max_tx_queues = RTE_MIN(vf_info.max_tx_queues,
380 : : info->max_tx_queues);
381 : 0 : info->tx_offload_capa &= vf_info.tx_offload_capa;
382 : 0 : info->tx_queue_offload_capa &= vf_info.tx_queue_offload_capa;
383 : : hn_vf_merge_desc_lim(&info->tx_desc_lim, &vf_info.tx_desc_lim);
384 : :
385 : 0 : info->min_rx_bufsize = RTE_MAX(vf_info.min_rx_bufsize,
386 : : info->min_rx_bufsize);
387 : 0 : info->max_rx_pktlen = RTE_MAX(vf_info.max_rx_pktlen,
388 : : info->max_rx_pktlen);
389 : : hn_vf_merge_desc_lim(&info->rx_desc_lim, &vf_info.rx_desc_lim);
390 : :
391 : 0 : return 0;
392 : : }
393 : :
394 : 0 : int hn_vf_info_get(struct hn_data *hv, struct rte_eth_dev_info *info)
395 : : {
396 : : struct rte_eth_dev *vf_dev;
397 : : int ret = 0;
398 : :
399 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
400 : : vf_dev = hn_get_vf_dev(hv);
401 : : if (vf_dev)
402 : 0 : ret = hn_vf_info_merge(vf_dev, info);
403 : : rte_rwlock_read_unlock(&hv->vf_lock);
404 : 0 : return ret;
405 : : }
406 : :
407 : 0 : int hn_vf_configure(struct rte_eth_dev *dev,
408 : : const struct rte_eth_conf *dev_conf)
409 : : {
410 : 0 : struct hn_data *hv = dev->data->dev_private;
411 : 0 : struct rte_eth_conf vf_conf = *dev_conf;
412 : : int ret = 0;
413 : :
414 : : /* link state interrupt does not matter here. */
415 : 0 : vf_conf.intr_conf.lsc = 0;
416 : :
417 : : /* need to monitor removal event */
418 : 0 : vf_conf.intr_conf.rmv = 1;
419 : :
420 [ # # ]: 0 : if (hv->vf_ctx.vf_attached) {
421 : 0 : ret = rte_eth_dev_callback_register(hv->vf_ctx.vf_port,
422 : : RTE_ETH_EVENT_INTR_RMV,
423 : : hn_eth_rmv_event_callback,
424 : : hv);
425 [ # # ]: 0 : if (ret) {
426 : 0 : PMD_DRV_LOG(ERR,
427 : : "Registering callback failed for vf port %d ret %d",
428 : : hv->vf_ctx.vf_port, ret);
429 : 0 : return ret;
430 : : }
431 : :
432 : 0 : ret = rte_eth_dev_configure(hv->vf_ctx.vf_port,
433 : 0 : dev->data->nb_rx_queues,
434 : 0 : dev->data->nb_tx_queues,
435 : : &vf_conf);
436 [ # # ]: 0 : if (ret) {
437 : 0 : PMD_DRV_LOG(ERR, "VF configuration failed: %d", ret);
438 : :
439 : 0 : rte_eth_dev_callback_unregister(hv->vf_ctx.vf_port,
440 : : RTE_ETH_EVENT_INTR_RMV,
441 : : hn_eth_rmv_event_callback,
442 : : hv);
443 : :
444 : 0 : return ret;
445 : : }
446 : :
447 : 0 : hv->vf_ctx.vf_state = vf_configured;
448 : : }
449 : :
450 : : return ret;
451 : : }
452 : :
453 : : /* Configure VF if present.
454 : : * VF device will have the same number of queues as the synthetic device
455 : : */
456 : 0 : int hn_vf_configure_locked(struct rte_eth_dev *dev,
457 : : const struct rte_eth_conf *dev_conf)
458 : : {
459 : 0 : struct hn_data *hv = dev->data->dev_private;
460 : : int ret = 0;
461 : :
462 : 0 : rte_rwlock_write_lock(&hv->vf_lock);
463 : 0 : ret = hn_vf_configure(dev, dev_conf);
464 : : rte_rwlock_write_unlock(&hv->vf_lock);
465 : :
466 : 0 : return ret;
467 : : }
468 : :
469 : 0 : const uint32_t *hn_vf_supported_ptypes(struct rte_eth_dev *dev)
470 : : {
471 : 0 : struct hn_data *hv = dev->data->dev_private;
472 : : struct rte_eth_dev *vf_dev;
473 : : const uint32_t *ptypes = NULL;
474 : :
475 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
476 : : vf_dev = hn_get_vf_dev(hv);
477 [ # # ]: 0 : if (vf_dev && vf_dev->dev_ops->dev_supported_ptypes_get)
478 : 0 : ptypes = (*vf_dev->dev_ops->dev_supported_ptypes_get)(vf_dev);
479 : : rte_rwlock_read_unlock(&hv->vf_lock);
480 : :
481 : 0 : return ptypes;
482 : : }
483 : :
484 : 0 : int hn_vf_start(struct rte_eth_dev *dev)
485 : : {
486 : 0 : struct hn_data *hv = dev->data->dev_private;
487 : : struct rte_eth_dev *vf_dev;
488 : : int ret = 0;
489 : :
490 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
491 : : vf_dev = hn_get_vf_dev(hv);
492 : : if (vf_dev)
493 : 0 : ret = rte_eth_dev_start(vf_dev->data->port_id);
494 : : rte_rwlock_read_unlock(&hv->vf_lock);
495 : 0 : return ret;
496 : : }
497 : :
498 : 0 : int hn_vf_stop(struct rte_eth_dev *dev)
499 : : {
500 : 0 : struct hn_data *hv = dev->data->dev_private;
501 : : struct rte_eth_dev *vf_dev;
502 : : int ret = 0;
503 : :
504 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
505 : : vf_dev = hn_get_vf_dev(hv);
506 : : if (vf_dev) {
507 : 0 : ret = rte_eth_dev_stop(vf_dev->data->port_id);
508 [ # # ]: 0 : if (ret != 0)
509 : 0 : PMD_DRV_LOG(ERR, "Failed to stop device on port %u",
510 : : vf_dev->data->port_id);
511 : : }
512 : : rte_rwlock_read_unlock(&hv->vf_lock);
513 : :
514 : 0 : return ret;
515 : : }
516 : :
517 : : /* If VF is present, then cascade configuration down */
518 : : #define VF_ETHDEV_FUNC(dev, func) \
519 : : { \
520 : : struct hn_data *hv = (dev)->data->dev_private; \
521 : : struct rte_eth_dev *vf_dev; \
522 : : rte_rwlock_read_lock(&hv->vf_lock); \
523 : : vf_dev = hn_get_vf_dev(hv); \
524 : : if (vf_dev) \
525 : : func(vf_dev->data->port_id); \
526 : : rte_rwlock_read_unlock(&hv->vf_lock); \
527 : : }
528 : :
529 : : /* If VF is present, then cascade configuration down */
530 : : #define VF_ETHDEV_FUNC_RET_STATUS(dev, func) \
531 : : { \
532 : : struct hn_data *hv = (dev)->data->dev_private; \
533 : : struct rte_eth_dev *vf_dev; \
534 : : int ret = 0; \
535 : : rte_rwlock_read_lock(&hv->vf_lock); \
536 : : vf_dev = hn_get_vf_dev(hv); \
537 : : if (vf_dev) \
538 : : ret = func(vf_dev->data->port_id); \
539 : : rte_rwlock_read_unlock(&hv->vf_lock); \
540 : : return ret; \
541 : : }
542 : :
543 : 0 : int hn_vf_close(struct rte_eth_dev *dev)
544 : : {
545 : : int ret = 0;
546 : 0 : struct hn_data *hv = dev->data->dev_private;
547 : :
548 : 0 : rte_eal_alarm_cancel(hn_vf_add_retry, dev);
549 : :
550 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
551 [ # # ]: 0 : if (hv->vf_ctx.vf_attached) {
552 : 0 : rte_eth_dev_callback_unregister(hv->vf_ctx.vf_port,
553 : : RTE_ETH_EVENT_INTR_RMV,
554 : : hn_eth_rmv_event_callback,
555 : : hv);
556 : 0 : rte_eal_alarm_cancel(hn_remove_delayed, hv);
557 : 0 : ret = rte_eth_dev_close(hv->vf_ctx.vf_port);
558 : 0 : hv->vf_ctx.vf_attached = false;
559 : : }
560 : : rte_rwlock_read_unlock(&hv->vf_lock);
561 : :
562 : 0 : return ret;
563 : : }
564 : :
565 : 0 : int hn_vf_stats_reset(struct rte_eth_dev *dev)
566 : : {
567 : 0 : VF_ETHDEV_FUNC_RET_STATUS(dev, rte_eth_stats_reset);
568 : : }
569 : :
570 : 0 : int hn_vf_allmulticast_enable(struct rte_eth_dev *dev)
571 : : {
572 : 0 : VF_ETHDEV_FUNC_RET_STATUS(dev, rte_eth_allmulticast_enable);
573 : : }
574 : :
575 : 0 : int hn_vf_allmulticast_disable(struct rte_eth_dev *dev)
576 : : {
577 : 0 : VF_ETHDEV_FUNC_RET_STATUS(dev, rte_eth_allmulticast_disable);
578 : : }
579 : :
580 : 0 : int hn_vf_promiscuous_enable(struct rte_eth_dev *dev)
581 : : {
582 : 0 : VF_ETHDEV_FUNC_RET_STATUS(dev, rte_eth_promiscuous_enable);
583 : : }
584 : :
585 : 0 : int hn_vf_promiscuous_disable(struct rte_eth_dev *dev)
586 : : {
587 : 0 : VF_ETHDEV_FUNC_RET_STATUS(dev, rte_eth_promiscuous_disable);
588 : : }
589 : :
590 : 0 : int hn_vf_mc_addr_list(struct rte_eth_dev *dev,
591 : : struct rte_ether_addr *mc_addr_set,
592 : : uint32_t nb_mc_addr)
593 : : {
594 : 0 : struct hn_data *hv = dev->data->dev_private;
595 : : struct rte_eth_dev *vf_dev;
596 : : int ret = 0;
597 : :
598 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
599 : : vf_dev = hn_get_vf_dev(hv);
600 : : if (vf_dev)
601 : 0 : ret = rte_eth_dev_set_mc_addr_list(vf_dev->data->port_id,
602 : : mc_addr_set, nb_mc_addr);
603 : : rte_rwlock_read_unlock(&hv->vf_lock);
604 : 0 : return ret;
605 : : }
606 : :
607 : 0 : int hn_vf_tx_queue_setup(struct rte_eth_dev *dev,
608 : : uint16_t queue_idx, uint16_t nb_desc,
609 : : unsigned int socket_id,
610 : : const struct rte_eth_txconf *tx_conf)
611 : : {
612 : 0 : struct hn_data *hv = dev->data->dev_private;
613 : : struct rte_eth_dev *vf_dev;
614 : : int ret = 0;
615 : :
616 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
617 : : vf_dev = hn_get_vf_dev(hv);
618 : : if (vf_dev)
619 : 0 : ret = rte_eth_tx_queue_setup(vf_dev->data->port_id,
620 : : queue_idx, nb_desc,
621 : : socket_id, tx_conf);
622 : : rte_rwlock_read_unlock(&hv->vf_lock);
623 : 0 : return ret;
624 : : }
625 : :
626 : 0 : void hn_vf_tx_queue_release(struct hn_data *hv, uint16_t queue_id)
627 : : {
628 : : struct rte_eth_dev *vf_dev;
629 : :
630 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
631 : : vf_dev = hn_get_vf_dev(hv);
632 [ # # ]: 0 : if (vf_dev && vf_dev->dev_ops->tx_queue_release)
633 : 0 : (*vf_dev->dev_ops->tx_queue_release)(vf_dev, queue_id);
634 : :
635 : : rte_rwlock_read_unlock(&hv->vf_lock);
636 : 0 : }
637 : :
638 : 0 : int hn_vf_rx_queue_setup(struct rte_eth_dev *dev,
639 : : uint16_t queue_idx, uint16_t nb_desc,
640 : : unsigned int socket_id,
641 : : const struct rte_eth_rxconf *rx_conf,
642 : : struct rte_mempool *mp)
643 : : {
644 : 0 : struct hn_data *hv = dev->data->dev_private;
645 : : struct rte_eth_dev *vf_dev;
646 : : int ret = 0;
647 : :
648 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
649 : : vf_dev = hn_get_vf_dev(hv);
650 : : if (vf_dev)
651 : 0 : ret = rte_eth_rx_queue_setup(vf_dev->data->port_id,
652 : : queue_idx, nb_desc,
653 : : socket_id, rx_conf, mp);
654 : : rte_rwlock_read_unlock(&hv->vf_lock);
655 : 0 : return ret;
656 : : }
657 : :
658 : 0 : void hn_vf_rx_queue_release(struct hn_data *hv, uint16_t queue_id)
659 : : {
660 : : struct rte_eth_dev *vf_dev;
661 : :
662 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
663 : : vf_dev = hn_get_vf_dev(hv);
664 [ # # ]: 0 : if (vf_dev && vf_dev->dev_ops->rx_queue_release)
665 : 0 : (*vf_dev->dev_ops->rx_queue_release)(vf_dev, queue_id);
666 : : rte_rwlock_read_unlock(&hv->vf_lock);
667 : 0 : }
668 : :
669 : 0 : int hn_vf_stats_get(struct rte_eth_dev *dev,
670 : : struct rte_eth_stats *stats)
671 : : {
672 : 0 : struct hn_data *hv = dev->data->dev_private;
673 : : struct rte_eth_dev *vf_dev;
674 : : int ret = 0;
675 : :
676 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
677 : : vf_dev = hn_get_vf_dev(hv);
678 : : if (vf_dev)
679 : 0 : ret = rte_eth_stats_get(vf_dev->data->port_id, stats);
680 : : rte_rwlock_read_unlock(&hv->vf_lock);
681 : 0 : return ret;
682 : : }
683 : :
684 : 0 : int hn_vf_xstats_get_names(struct rte_eth_dev *dev,
685 : : struct rte_eth_xstat_name *names,
686 : : unsigned int n)
687 : : {
688 : 0 : struct hn_data *hv = dev->data->dev_private;
689 : : struct rte_eth_dev *vf_dev;
690 : : int i, count = 0;
691 : :
692 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
693 : : vf_dev = hn_get_vf_dev(hv);
694 : : if (vf_dev)
695 : 0 : count = rte_eth_xstats_get_names(vf_dev->data->port_id,
696 : : names, n);
697 : : rte_rwlock_read_unlock(&hv->vf_lock);
698 : :
699 : : /* add vf_ prefix to xstat names */
700 [ # # ]: 0 : if (names) {
701 [ # # ]: 0 : for (i = 0; i < count; i++) {
702 : : char tmp[RTE_ETH_XSTATS_NAME_SIZE];
703 : :
704 : 0 : snprintf(tmp, sizeof(tmp), "vf_%s", names[i].name);
705 : : strlcpy(names[i].name, tmp, sizeof(names[i].name));
706 : : }
707 : : }
708 : :
709 : 0 : return count;
710 : : }
711 : :
712 : 0 : int hn_vf_xstats_get(struct rte_eth_dev *dev,
713 : : struct rte_eth_xstat *xstats,
714 : : unsigned int offset,
715 : : unsigned int n)
716 : : {
717 : 0 : struct hn_data *hv = dev->data->dev_private;
718 : : struct rte_eth_dev *vf_dev;
719 : : int i, count = 0;
720 : :
721 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
722 : : vf_dev = hn_get_vf_dev(hv);
723 : : if (vf_dev)
724 : 0 : count = rte_eth_xstats_get(vf_dev->data->port_id,
725 : 0 : xstats + offset, n - offset);
726 : : rte_rwlock_read_unlock(&hv->vf_lock);
727 : :
728 : : /* Offset id's for VF stats */
729 [ # # ]: 0 : if (count > 0) {
730 [ # # ]: 0 : for (i = 0; i < count; i++)
731 : 0 : xstats[i + offset].id += offset;
732 : : }
733 : :
734 : 0 : return count;
735 : : }
736 : :
737 : 0 : int hn_vf_xstats_reset(struct rte_eth_dev *dev)
738 : : {
739 : 0 : struct hn_data *hv = dev->data->dev_private;
740 : : struct rte_eth_dev *vf_dev;
741 : : int ret;
742 : :
743 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
744 : : vf_dev = hn_get_vf_dev(hv);
745 : : if (vf_dev)
746 : 0 : ret = rte_eth_xstats_reset(vf_dev->data->port_id);
747 : : else
748 : : ret = -EINVAL;
749 : : rte_rwlock_read_unlock(&hv->vf_lock);
750 : :
751 : 0 : return ret;
752 : : }
753 : :
754 : 0 : int hn_vf_rss_hash_update(struct rte_eth_dev *dev,
755 : : struct rte_eth_rss_conf *rss_conf)
756 : : {
757 : 0 : struct hn_data *hv = dev->data->dev_private;
758 : : struct rte_eth_dev *vf_dev;
759 : : int ret = 0;
760 : :
761 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
762 : : vf_dev = hn_get_vf_dev(hv);
763 [ # # ]: 0 : if (vf_dev && vf_dev->dev_ops->rss_hash_update)
764 : 0 : ret = vf_dev->dev_ops->rss_hash_update(vf_dev, rss_conf);
765 : : rte_rwlock_read_unlock(&hv->vf_lock);
766 : :
767 : 0 : return ret;
768 : : }
769 : :
770 : 0 : int hn_vf_reta_hash_update(struct rte_eth_dev *dev,
771 : : struct rte_eth_rss_reta_entry64 *reta_conf,
772 : : uint16_t reta_size)
773 : : {
774 : 0 : struct hn_data *hv = dev->data->dev_private;
775 : : struct rte_eth_dev *vf_dev;
776 : : int ret = 0;
777 : :
778 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
779 : : vf_dev = hn_get_vf_dev(hv);
780 [ # # ]: 0 : if (vf_dev && vf_dev->dev_ops->reta_update)
781 : 0 : ret = vf_dev->dev_ops->reta_update(vf_dev,
782 : : reta_conf, reta_size);
783 : : rte_rwlock_read_unlock(&hv->vf_lock);
784 : :
785 : 0 : return ret;
786 : : }
787 : :
788 : 0 : int hn_vf_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
789 : : {
790 : 0 : struct hn_data *hv = dev->data->dev_private;
791 : : struct rte_eth_dev *vf_dev;
792 : : int ret = 0;
793 : :
794 : 0 : rte_rwlock_read_lock(&hv->vf_lock);
795 : : vf_dev = hn_get_vf_dev(hv);
796 [ # # # # ]: 0 : if (hv->vf_ctx.vf_vsc_switched && vf_dev)
797 : 0 : ret = vf_dev->dev_ops->mtu_set(vf_dev, mtu);
798 : : rte_rwlock_read_unlock(&hv->vf_lock);
799 : :
800 : 0 : return ret;
801 : : }
|