| 420 | } |
| 421 | |
| 422 | void |
| 423 | ff_kni_alloc(uint16_t port_id, unsigned socket_id, int port_idx, |
| 424 | unsigned ring_queue_size) |
| 425 | { |
| 426 | if (rte_eal_process_type() == RTE_PROC_PRIMARY) { |
| 427 | struct rte_ether_addr addr = {{0}}; |
| 428 | int ret; |
| 429 | |
| 430 | kni_stat[port_id] = (struct kni_interface_stats*)rte_zmalloc( |
| 431 | "kni:stat_lcore", |
| 432 | sizeof(struct kni_interface_stats), |
| 433 | RTE_CACHE_LINE_SIZE); |
| 434 | |
| 435 | if (kni_stat[port_id] == NULL) { |
| 436 | rte_panic("rte_zmalloc kni_interface_stats failed\n"); |
| 437 | } |
| 438 | |
| 439 | kni_stat[port_id]->rx_packets = 0; |
| 440 | kni_stat[port_id]->rx_dropped = 0; |
| 441 | kni_stat[port_id]->tx_packets = 0; |
| 442 | kni_stat[port_id]->tx_dropped = 0; |
| 443 | |
| 444 | /* Get the interface default mac address */ |
| 445 | rte_eth_macaddr_get(port_id, |
| 446 | (struct rte_ether_addr *)&addr); |
| 447 | printf("ff_kni_alloc get Port %u MAC:"RTE_ETHER_ADDR_PRT_FMT"\n", |
| 448 | (unsigned)port_id, RTE_ETHER_ADDR_BYTES(&addr)); |
| 449 | |
| 450 | /* |
| 451 | * to add virtio port for exception path(KNI), |
| 452 | * see https://doc.dpdk.org/guides/howto/virtio_user_as_exception_path.html#virtio-user-as-exception-path |
| 453 | */ |
| 454 | char port_name[32]; |
| 455 | char port_args[256]; |
| 456 | |
| 457 | /* set the name and arguments */ |
| 458 | snprintf(port_name, sizeof(port_name), "virtio_user%u", port_id); |
| 459 | snprintf(port_args, sizeof(port_args), |
| 460 | "path=/dev/vhost-net,queues=1,queue_size=%u,iface=veth%d,mac=" RTE_ETHER_ADDR_PRT_FMT, |
| 461 | ring_queue_size, port_id, RTE_ETHER_ADDR_BYTES(&addr)); |
| 462 | printf("ff_kni_alloc to rte_eal_hotplug_add virtio user port, portname:%s, portargs:%s\n", |
| 463 | port_name, port_args); |
| 464 | |
| 465 | /* add the vdev for virtio_user */ |
| 466 | if (rte_eal_hotplug_add("vdev", port_name, port_args) < 0) { |
| 467 | rte_exit(EXIT_FAILURE, "ff_kni_alloc cannot create virtio user paired port for port %u\n", port_id); |
| 468 | } |
| 469 | |
| 470 | kni_stat[port_id]->port_id = port_idx + nb_dev_ports; |
| 471 | } |
| 472 | |
| 473 | char ring_name[RTE_KNI_NAMESIZE]; |
| 474 | snprintf((char*)ring_name, RTE_KNI_NAMESIZE, "kni_ring_%u", port_id); |
| 475 | |
| 476 | if (rte_eal_process_type() == RTE_PROC_PRIMARY) { |
| 477 | kni_rp[port_id] = rte_ring_create(ring_name, ring_queue_size, |
| 478 | socket_id, RING_F_SC_DEQ); |
| 479 |
no test coverage detected