4 * Copyright(c) 2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_atomic.h>
35 #include <rte_common.h>
37 #include <rte_ethdev.h>
38 #include <rte_malloc.h>
40 #include <rte_kvargs.h>
42 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <sys/ioctl.h>
51 #include <arpa/inet.h>
53 #include <linux/if_tun.h>
54 #include <linux/if_ether.h>
57 /* Linux based path to the TUN device */
58 #define TUN_TAP_DEV_PATH "/dev/net/tun"
59 #define DEFAULT_TAP_NAME "dtap"
61 #define ETH_TAP_IFACE_ARG "iface"
62 #define ETH_TAP_SPEED_ARG "speed"
64 #ifdef IFF_MULTI_QUEUE
65 #define RTE_PMD_TAP_MAX_QUEUES 16
67 #define RTE_PMD_TAP_MAX_QUEUES 1
70 static struct rte_vdev_driver pmd_tap_drv;
72 static const char *valid_arguments[] = {
80 static volatile uint32_t tap_trigger; /* Rx trigger */
82 static struct rte_eth_link pmd_link = {
83 .link_speed = ETH_SPEED_NUM_10G,
84 .link_duplex = ETH_LINK_FULL_DUPLEX,
85 .link_status = ETH_LINK_DOWN,
86 .link_autoneg = ETH_LINK_SPEED_AUTONEG
90 uint64_t opackets; /* Number of output packets */
91 uint64_t ipackets; /* Number of input packets */
92 uint64_t obytes; /* Number of bytes on output */
93 uint64_t ibytes; /* Number of bytes on input */
94 uint64_t errs; /* Number of error packets */
98 struct rte_mempool *mp; /* Mempool for RX packets */
99 uint32_t trigger_seen; /* Last seen Rx trigger value */
100 uint16_t in_port; /* Port ID */
103 struct pkt_stats stats; /* Stats for this RX queue */
108 struct pkt_stats stats; /* Stats for this TX queue */
111 struct pmd_internals {
112 char name[RTE_ETH_NAME_MAX_LEN]; /* Internal Tap device name */
113 uint16_t nb_queues; /* Number of queues supported */
114 struct ether_addr eth_addr; /* Mac address of the device port */
116 int if_index; /* IF_INDEX for the port */
117 int ioctl_sock; /* socket for ioctl calls */
119 struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
120 struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
124 tap_trigger_cb(int sig __rte_unused)
126 /* Valid trigger values are nonzero */
127 tap_trigger = (tap_trigger + 1) | 0x80000000;
131 tap_ioctl(struct pmd_internals *pmd, unsigned long request,
132 struct ifreq *ifr, int set);
134 /* Tun/Tap allocation routine
136 * name is the number of the interface to use, unless NULL to take the host
140 tun_alloc(struct pmd_internals *pmd, uint16_t qid)
143 #ifdef IFF_MULTI_QUEUE
144 unsigned int features;
148 memset(&ifr, 0, sizeof(struct ifreq));
150 ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
151 snprintf(ifr.ifr_name, IFNAMSIZ, "%s", pmd->name);
153 RTE_LOG(DEBUG, PMD, "ifr_name '%s'\n", ifr.ifr_name);
155 fd = open(TUN_TAP_DEV_PATH, O_RDWR);
157 RTE_LOG(ERR, PMD, "Unable to create TAP interface");
161 #ifdef IFF_MULTI_QUEUE
162 /* Grab the TUN features to verify we can work multi-queue */
163 if (ioctl(fd, TUNGETFEATURES, &features) < 0) {
164 RTE_LOG(ERR, PMD, "TAP unable to get TUN/TAP features\n");
167 RTE_LOG(DEBUG, PMD, " TAP Features %08x\n", features);
169 if (features & IFF_MULTI_QUEUE) {
170 RTE_LOG(DEBUG, PMD, " Multi-queue support for %d queues\n",
171 RTE_PMD_TAP_MAX_QUEUES);
172 ifr.ifr_flags |= IFF_MULTI_QUEUE;
176 ifr.ifr_flags |= IFF_ONE_QUEUE;
177 RTE_LOG(DEBUG, PMD, " Single queue only support\n");
180 /* Set the TUN/TAP configuration and set the name if needed */
181 if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) {
182 RTE_LOG(WARNING, PMD,
183 "Unable to set TUNSETIFF for %s\n",
189 /* Always set the file descriptor to non-blocking */
190 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
191 RTE_LOG(WARNING, PMD,
192 "Unable to set %s to nonblocking\n",
194 perror("F_SETFL, NONBLOCK");
198 /* Set up trigger to optimize empty Rx bursts */
202 int flags = fcntl(fd, F_GETFL);
204 if (flags == -1 || sigaction(SIGIO, NULL, &sa) == -1)
206 if (sa.sa_handler != tap_trigger_cb) {
208 * Make sure SIGIO is not already taken. This is done
209 * as late as possible to leave the application a
210 * chance to set up its own signal handler first.
212 if (sa.sa_handler != SIG_IGN &&
213 sa.sa_handler != SIG_DFL) {
217 sa = (struct sigaction){
218 .sa_flags = SA_RESTART,
219 .sa_handler = tap_trigger_cb,
221 if (sigaction(SIGIO, &sa, NULL) == -1)
224 /* Enable SIGIO on file descriptor */
225 fcntl(fd, F_SETFL, flags | O_ASYNC);
226 fcntl(fd, F_SETOWN, getpid());
229 /* Disable trigger globally in case of error */
231 RTE_LOG(WARNING, PMD, "Rx trigger disabled: %s\n",
238 if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0) < 0)
240 rte_memcpy(&pmd->eth_addr, ifr.ifr_hwaddr.sa_data,
252 /* Callback to handle the rx burst of packets to the correct interface and
253 * file descriptor(s) in a multi-queue setup.
256 pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
259 struct rte_mbuf *mbuf;
260 struct rx_queue *rxq = queue;
262 unsigned long num_rx_bytes = 0;
263 uint32_t trigger = tap_trigger;
265 if (trigger == rxq->trigger_seen)
268 rxq->trigger_seen = trigger;
269 rte_compiler_barrier();
270 for (num_rx = 0; num_rx < nb_pkts; ) {
271 /* allocate the next mbuf */
272 mbuf = rte_pktmbuf_alloc(rxq->mp);
273 if (unlikely(!mbuf)) {
274 RTE_LOG(WARNING, PMD, "TAP unable to allocate mbuf\n");
278 len = read(rxq->fd, rte_pktmbuf_mtod(mbuf, char *),
279 rte_pktmbuf_tailroom(mbuf));
281 rte_pktmbuf_free(mbuf);
285 mbuf->data_len = len;
287 mbuf->port = rxq->in_port;
289 /* account for the receive frame */
290 bufs[num_rx++] = mbuf;
291 num_rx_bytes += mbuf->pkt_len;
293 rxq->stats.ipackets += num_rx;
294 rxq->stats.ibytes += num_rx_bytes;
299 /* Callback to handle sending packets from the tap interface
302 pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
304 struct rte_mbuf *mbuf;
305 struct tx_queue *txq = queue;
307 unsigned long num_tx_bytes = 0;
310 if (unlikely(nb_pkts == 0))
313 for (i = 0; i < nb_pkts; i++) {
314 /* copy the tx frame data */
317 rte_pktmbuf_mtod(mbuf, void *),
318 rte_pktmbuf_pkt_len(mbuf));
323 num_tx_bytes += mbuf->pkt_len;
324 rte_pktmbuf_free(mbuf);
327 txq->stats.opackets += num_tx;
328 txq->stats.errs += nb_pkts - num_tx;
329 txq->stats.obytes += num_tx_bytes;
335 tap_ioctl(struct pmd_internals *pmd, unsigned long request,
336 struct ifreq *ifr, int set)
338 short req_flags = ifr->ifr_flags;
340 snprintf(ifr->ifr_name, IFNAMSIZ, "%s", pmd->name);
343 /* fetch current flags to leave other flags untouched */
344 if (ioctl(pmd->ioctl_sock, SIOCGIFFLAGS, ifr) < 0)
347 ifr->ifr_flags |= req_flags;
349 ifr->ifr_flags &= ~req_flags;
355 RTE_LOG(WARNING, PMD, "%s: ioctl() called with wrong arg\n",
359 if (ioctl(pmd->ioctl_sock, request, ifr) < 0)
364 RTE_LOG(ERR, PMD, "%s: ioctl(%lu) failed with error: %s\n",
365 ifr->ifr_name, request, strerror(errno));
370 tap_link_set_down(struct rte_eth_dev *dev)
372 struct pmd_internals *pmd = dev->data->dev_private;
373 struct ifreq ifr = { .ifr_flags = IFF_UP };
375 dev->data->dev_link.link_status = ETH_LINK_DOWN;
376 return tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 0);
380 tap_link_set_up(struct rte_eth_dev *dev)
382 struct pmd_internals *pmd = dev->data->dev_private;
383 struct ifreq ifr = { .ifr_flags = IFF_UP };
385 dev->data->dev_link.link_status = ETH_LINK_UP;
386 return tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 1);
390 tap_dev_start(struct rte_eth_dev *dev)
392 return tap_link_set_up(dev);
395 /* This function gets called when the current port gets stopped.
398 tap_dev_stop(struct rte_eth_dev *dev)
400 tap_link_set_down(dev);
404 tap_dev_configure(struct rte_eth_dev *dev __rte_unused)
410 tap_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
412 struct pmd_internals *internals = dev->data->dev_private;
414 dev_info->if_index = internals->if_index;
415 dev_info->max_mac_addrs = 1;
416 dev_info->max_rx_pktlen = (uint32_t)ETHER_MAX_VLAN_FRAME_LEN;
417 dev_info->max_rx_queues = internals->nb_queues;
418 dev_info->max_tx_queues = internals->nb_queues;
419 dev_info->min_rx_bufsize = 0;
420 dev_info->pci_dev = NULL;
424 tap_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *tap_stats)
426 unsigned int i, imax;
427 unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
428 unsigned long rx_bytes_total = 0, tx_bytes_total = 0;
429 const struct pmd_internals *pmd = dev->data->dev_private;
431 imax = (pmd->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ?
432 pmd->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS;
434 for (i = 0; i < imax; i++) {
435 tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets;
436 tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes;
437 rx_total += tap_stats->q_ipackets[i];
438 rx_bytes_total += tap_stats->q_ibytes[i];
440 tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets;
441 tap_stats->q_errors[i] = pmd->txq[i].stats.errs;
442 tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes;
443 tx_total += tap_stats->q_opackets[i];
444 tx_err_total += tap_stats->q_errors[i];
445 tx_bytes_total += tap_stats->q_obytes[i];
448 tap_stats->ipackets = rx_total;
449 tap_stats->ibytes = rx_bytes_total;
450 tap_stats->opackets = tx_total;
451 tap_stats->oerrors = tx_err_total;
452 tap_stats->obytes = tx_bytes_total;
456 tap_stats_reset(struct rte_eth_dev *dev)
459 struct pmd_internals *pmd = dev->data->dev_private;
461 for (i = 0; i < pmd->nb_queues; i++) {
462 pmd->rxq[i].stats.ipackets = 0;
463 pmd->rxq[i].stats.ibytes = 0;
465 pmd->txq[i].stats.opackets = 0;
466 pmd->txq[i].stats.errs = 0;
467 pmd->txq[i].stats.obytes = 0;
472 tap_dev_close(struct rte_eth_dev *dev __rte_unused)
475 struct pmd_internals *internals = dev->data->dev_private;
477 tap_link_set_down(dev);
479 for (i = 0; i < internals->nb_queues; i++) {
480 if (internals->rxq[i].fd != -1)
481 close(internals->rxq[i].fd);
482 internals->rxq[i].fd = -1;
483 internals->txq[i].fd = -1;
488 tap_rx_queue_release(void *queue)
490 struct rx_queue *rxq = queue;
492 if (rxq && (rxq->fd > 0)) {
499 tap_tx_queue_release(void *queue)
501 struct tx_queue *txq = queue;
503 if (txq && (txq->fd > 0)) {
510 tap_link_update(struct rte_eth_dev *dev __rte_unused,
511 int wait_to_complete __rte_unused)
517 tap_promisc_enable(struct rte_eth_dev *dev)
519 struct pmd_internals *pmd = dev->data->dev_private;
520 struct ifreq ifr = { .ifr_flags = IFF_PROMISC };
522 dev->data->promiscuous = 1;
523 tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 1);
527 tap_promisc_disable(struct rte_eth_dev *dev)
529 struct pmd_internals *pmd = dev->data->dev_private;
530 struct ifreq ifr = { .ifr_flags = IFF_PROMISC };
532 dev->data->promiscuous = 0;
533 tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 0);
537 tap_allmulti_enable(struct rte_eth_dev *dev)
539 struct pmd_internals *pmd = dev->data->dev_private;
540 struct ifreq ifr = { .ifr_flags = IFF_ALLMULTI };
542 dev->data->all_multicast = 1;
543 tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 1);
547 tap_allmulti_disable(struct rte_eth_dev *dev)
549 struct pmd_internals *pmd = dev->data->dev_private;
550 struct ifreq ifr = { .ifr_flags = IFF_ALLMULTI };
552 dev->data->all_multicast = 0;
553 tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 0);
558 tap_mac_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
560 struct pmd_internals *pmd = dev->data->dev_private;
563 if (is_zero_ether_addr(mac_addr)) {
564 RTE_LOG(ERR, PMD, "%s: can't set an empty MAC address\n",
569 ifr.ifr_hwaddr.sa_family = AF_LOCAL;
570 rte_memcpy(ifr.ifr_hwaddr.sa_data, mac_addr, ETHER_ADDR_LEN);
571 if (tap_ioctl(pmd, SIOCSIFHWADDR, &ifr, 1) < 0)
573 rte_memcpy(&pmd->eth_addr, mac_addr, ETHER_ADDR_LEN);
577 tap_setup_queue(struct rte_eth_dev *dev,
578 struct pmd_internals *internals,
581 struct pmd_internals *pmd = dev->data->dev_private;
582 struct rx_queue *rx = &internals->rxq[qid];
583 struct tx_queue *tx = &internals->txq[qid];
590 RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid %d\n",
592 fd = tun_alloc(pmd, qid);
594 RTE_LOG(ERR, PMD, "tun_alloc(%s, %d) failed\n",
608 rx_setup_queue(struct rte_eth_dev *dev,
609 struct pmd_internals *internals,
612 dev->data->rx_queues[qid] = &internals->rxq[qid];
614 return tap_setup_queue(dev, internals, qid);
618 tx_setup_queue(struct rte_eth_dev *dev,
619 struct pmd_internals *internals,
622 dev->data->tx_queues[qid] = &internals->txq[qid];
624 return tap_setup_queue(dev, internals, qid);
628 tap_rx_queue_setup(struct rte_eth_dev *dev,
629 uint16_t rx_queue_id,
630 uint16_t nb_rx_desc __rte_unused,
631 unsigned int socket_id __rte_unused,
632 const struct rte_eth_rxconf *rx_conf __rte_unused,
633 struct rte_mempool *mp)
635 struct pmd_internals *internals = dev->data->dev_private;
639 if ((rx_queue_id >= internals->nb_queues) || !mp) {
640 RTE_LOG(WARNING, PMD,
641 "nb_queues %d too small or mempool NULL\n",
642 internals->nb_queues);
646 internals->rxq[rx_queue_id].mp = mp;
647 internals->rxq[rx_queue_id].trigger_seen = 1; /* force initial burst */
648 internals->rxq[rx_queue_id].in_port = dev->data->port_id;
650 /* Now get the space available for data in the mbuf */
651 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(mp) -
652 RTE_PKTMBUF_HEADROOM);
654 if (buf_size < ETH_FRAME_LEN) {
655 RTE_LOG(WARNING, PMD,
656 "%s: %d bytes will not fit in mbuf (%d bytes)\n",
657 dev->data->name, ETH_FRAME_LEN, buf_size);
661 fd = rx_setup_queue(dev, internals, rx_queue_id);
665 RTE_LOG(DEBUG, PMD, " RX TAP device name %s, qid %d on fd %d\n",
666 internals->name, rx_queue_id, internals->rxq[rx_queue_id].fd);
672 tap_tx_queue_setup(struct rte_eth_dev *dev,
673 uint16_t tx_queue_id,
674 uint16_t nb_tx_desc __rte_unused,
675 unsigned int socket_id __rte_unused,
676 const struct rte_eth_txconf *tx_conf __rte_unused)
678 struct pmd_internals *internals = dev->data->dev_private;
681 if (tx_queue_id >= internals->nb_queues)
684 ret = tx_setup_queue(dev, internals, tx_queue_id);
688 RTE_LOG(DEBUG, PMD, " TX TAP device name %s, qid %d on fd %d\n",
689 internals->name, tx_queue_id, internals->txq[tx_queue_id].fd);
694 static const struct eth_dev_ops ops = {
695 .dev_start = tap_dev_start,
696 .dev_stop = tap_dev_stop,
697 .dev_close = tap_dev_close,
698 .dev_configure = tap_dev_configure,
699 .dev_infos_get = tap_dev_info,
700 .rx_queue_setup = tap_rx_queue_setup,
701 .tx_queue_setup = tap_tx_queue_setup,
702 .rx_queue_release = tap_rx_queue_release,
703 .tx_queue_release = tap_tx_queue_release,
704 .link_update = tap_link_update,
705 .dev_set_link_up = tap_link_set_up,
706 .dev_set_link_down = tap_link_set_down,
707 .promiscuous_enable = tap_promisc_enable,
708 .promiscuous_disable = tap_promisc_disable,
709 .allmulticast_enable = tap_allmulti_enable,
710 .allmulticast_disable = tap_allmulti_disable,
711 .mac_addr_set = tap_mac_set,
712 .stats_get = tap_stats_get,
713 .stats_reset = tap_stats_reset,
717 eth_dev_tap_create(const char *name, char *tap_name)
719 int numa_node = rte_socket_id();
720 struct rte_eth_dev *dev = NULL;
721 struct pmd_internals *pmd = NULL;
722 struct rte_eth_dev_data *data = NULL;
725 RTE_LOG(DEBUG, PMD, " TAP device on numa %u\n", rte_socket_id());
727 data = rte_zmalloc_socket(tap_name, sizeof(*data), 0, numa_node);
729 RTE_LOG(ERR, PMD, "TAP Failed to allocate data\n");
733 pmd = rte_zmalloc_socket(tap_name, sizeof(*pmd), 0, numa_node);
735 RTE_LOG(ERR, PMD, "TAP Unable to allocate internal struct\n");
739 /* name in allocation and data->name must be consistent */
740 snprintf(data->name, sizeof(data->name), "%s", name);
741 dev = rte_eth_dev_allocate(name);
743 RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n");
747 snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
749 pmd->nb_queues = RTE_PMD_TAP_MAX_QUEUES;
751 pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
752 if (pmd->ioctl_sock == -1) {
754 "TAP Unable to get a socket for management: %s\n",
759 /* Setup some default values */
760 data->dev_private = pmd;
761 data->port_id = dev->data->port_id;
762 data->dev_flags = RTE_ETH_DEV_DETACHABLE;
763 data->kdrv = RTE_KDRV_NONE;
764 data->drv_name = pmd_tap_drv.driver.name;
765 data->numa_node = numa_node;
767 data->dev_link = pmd_link;
768 data->mac_addrs = &pmd->eth_addr;
769 data->nb_rx_queues = pmd->nb_queues;
770 data->nb_tx_queues = pmd->nb_queues;
775 dev->rx_pkt_burst = pmd_rx_burst;
776 dev->tx_pkt_burst = pmd_tx_burst;
778 /* Presetup the fds to -1 as being not valid */
779 for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
787 RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n", name);
792 rte_eth_dev_release_port(dev);
798 set_interface_name(const char *key __rte_unused,
802 char *name = (char *)extra_args;
805 snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", value);
807 snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s%d",
808 DEFAULT_TAP_NAME, (tap_unit - 1));
814 set_interface_speed(const char *key __rte_unused,
818 *(int *)extra_args = (value) ? atoi(value) : ETH_SPEED_NUM_10G;
823 /* Open a TAP interface device.
826 rte_pmd_tap_probe(const char *name, const char *params)
829 struct rte_kvargs *kvlist = NULL;
831 char tap_name[RTE_ETH_NAME_MAX_LEN];
833 speed = ETH_SPEED_NUM_10G;
834 snprintf(tap_name, sizeof(tap_name), "%s%d",
835 DEFAULT_TAP_NAME, tap_unit++);
837 if (params && (params[0] != '\0')) {
838 RTE_LOG(DEBUG, PMD, "paramaters (%s)\n", params);
840 kvlist = rte_kvargs_parse(params, valid_arguments);
842 if (rte_kvargs_count(kvlist, ETH_TAP_SPEED_ARG) == 1) {
843 ret = rte_kvargs_process(kvlist,
845 &set_interface_speed,
851 if (rte_kvargs_count(kvlist, ETH_TAP_IFACE_ARG) == 1) {
852 ret = rte_kvargs_process(kvlist,
861 pmd_link.link_speed = speed;
863 RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
866 ret = eth_dev_tap_create(name, tap_name);
870 RTE_LOG(ERR, PMD, "Failed to create pmd for %s as %s\n",
872 tap_unit--; /* Restore the unit number */
874 rte_kvargs_free(kvlist);
879 /* detach a TAP device.
882 rte_pmd_tap_remove(const char *name)
884 struct rte_eth_dev *eth_dev = NULL;
885 struct pmd_internals *internals;
888 RTE_LOG(DEBUG, PMD, "Closing TUN/TAP Ethernet device on numa %u\n",
891 /* find the ethdev entry */
892 eth_dev = rte_eth_dev_allocated(name);
896 internals = eth_dev->data->dev_private;
897 for (i = 0; i < internals->nb_queues; i++)
898 if (internals->rxq[i].fd != -1)
899 close(internals->rxq[i].fd);
901 close(internals->ioctl_sock);
902 rte_free(eth_dev->data->dev_private);
903 rte_free(eth_dev->data);
905 rte_eth_dev_release_port(eth_dev);
910 static struct rte_vdev_driver pmd_tap_drv = {
911 .probe = rte_pmd_tap_probe,
912 .remove = rte_pmd_tap_remove,
914 RTE_PMD_REGISTER_VDEV(net_tap, pmd_tap_drv);
915 RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap);
916 RTE_PMD_REGISTER_PARAM_STRING(net_tap, "iface=<string>,speed=N");