4 * Copyright(c) 2014 John W. Linville <linville@tuxdriver.com>
6 * Originally based upon librte_pmd_pcap code:
8 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
9 * Copyright(c) 2014 6WIND S.A.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * * Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * * Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in
20 * the documentation and/or other materials provided with the
22 * * Neither the name of Intel Corporation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <rte_ethdev.h>
41 #include <rte_malloc.h>
42 #include <rte_kvargs.h>
45 #include <linux/if_ether.h>
46 #include <linux/if_packet.h>
47 #include <arpa/inet.h>
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <sys/ioctl.h>
56 #define ETH_AF_PACKET_IFACE_ARG "iface"
57 #define ETH_AF_PACKET_NUM_Q_ARG "qpairs"
58 #define ETH_AF_PACKET_BLOCKSIZE_ARG "blocksz"
59 #define ETH_AF_PACKET_FRAMESIZE_ARG "framesz"
60 #define ETH_AF_PACKET_FRAMECOUNT_ARG "framecnt"
62 #define DFLT_BLOCK_SIZE (1 << 12)
63 #define DFLT_FRAME_SIZE (1 << 11)
64 #define DFLT_FRAME_COUNT (1 << 9)
66 #define RTE_PMD_AF_PACKET_MAX_RINGS 16
73 unsigned int framecount;
74 unsigned int framenum;
76 struct rte_mempool *mb_pool;
79 volatile unsigned long rx_pkts;
80 volatile unsigned long err_pkts;
81 volatile unsigned long rx_bytes;
86 unsigned int frame_data_size;
90 unsigned int framecount;
91 unsigned int framenum;
93 volatile unsigned long tx_pkts;
94 volatile unsigned long err_pkts;
95 volatile unsigned long tx_bytes;
98 struct pmd_internals {
102 struct ether_addr eth_addr;
104 struct tpacket_req req;
106 struct pkt_rx_queue rx_queue[RTE_PMD_AF_PACKET_MAX_RINGS];
107 struct pkt_tx_queue tx_queue[RTE_PMD_AF_PACKET_MAX_RINGS];
110 static const char *valid_arguments[] = {
111 ETH_AF_PACKET_IFACE_ARG,
112 ETH_AF_PACKET_NUM_Q_ARG,
113 ETH_AF_PACKET_BLOCKSIZE_ARG,
114 ETH_AF_PACKET_FRAMESIZE_ARG,
115 ETH_AF_PACKET_FRAMECOUNT_ARG,
119 static struct rte_eth_link pmd_link = {
120 .link_speed = ETH_SPEED_NUM_10G,
121 .link_duplex = ETH_LINK_FULL_DUPLEX,
122 .link_status = ETH_LINK_DOWN,
123 .link_autoneg = ETH_LINK_SPEED_AUTONEG
127 eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
130 struct tpacket2_hdr *ppd;
131 struct rte_mbuf *mbuf;
133 struct pkt_rx_queue *pkt_q = queue;
135 unsigned long num_rx_bytes = 0;
136 unsigned int framecount, framenum;
138 if (unlikely(nb_pkts == 0))
142 * Reads the given number of packets from the AF_PACKET socket one by
143 * one and copies the packet data into a newly allocated mbuf.
145 framecount = pkt_q->framecount;
146 framenum = pkt_q->framenum;
147 for (i = 0; i < nb_pkts; i++) {
148 /* point at the next incoming frame */
149 ppd = (struct tpacket2_hdr *) pkt_q->rd[framenum].iov_base;
150 if ((ppd->tp_status & TP_STATUS_USER) == 0)
153 /* allocate the next mbuf */
154 mbuf = rte_pktmbuf_alloc(pkt_q->mb_pool);
155 if (unlikely(mbuf == NULL))
158 /* packet will fit in the mbuf, go ahead and receive it */
159 rte_pktmbuf_pkt_len(mbuf) = rte_pktmbuf_data_len(mbuf) = ppd->tp_snaplen;
160 pbuf = (uint8_t *) ppd + ppd->tp_mac;
161 memcpy(rte_pktmbuf_mtod(mbuf, void *), pbuf, rte_pktmbuf_data_len(mbuf));
163 /* release incoming frame and advance ring buffer */
164 ppd->tp_status = TP_STATUS_KERNEL;
165 if (++framenum >= framecount)
167 mbuf->port = pkt_q->in_port;
169 /* account for the receive frame */
172 num_rx_bytes += mbuf->pkt_len;
174 pkt_q->framenum = framenum;
175 pkt_q->rx_pkts += num_rx;
176 pkt_q->rx_bytes += num_rx_bytes;
181 * Callback to handle sending packets through a real NIC.
184 eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
186 struct tpacket2_hdr *ppd;
187 struct rte_mbuf *mbuf;
189 unsigned int framecount, framenum;
191 struct pkt_tx_queue *pkt_q = queue;
193 unsigned long num_tx_bytes = 0;
196 if (unlikely(nb_pkts == 0))
199 memset(&pfd, 0, sizeof(pfd));
200 pfd.fd = pkt_q->sockfd;
201 pfd.events = POLLOUT;
204 framecount = pkt_q->framecount;
205 framenum = pkt_q->framenum;
206 ppd = (struct tpacket2_hdr *) pkt_q->rd[framenum].iov_base;
207 for (i = 0; i < nb_pkts; i++) {
210 /* drop oversized packets */
211 if (rte_pktmbuf_data_len(mbuf) > pkt_q->frame_data_size) {
212 rte_pktmbuf_free(mbuf);
216 /* point at the next incoming frame */
217 if ((ppd->tp_status != TP_STATUS_AVAILABLE) &&
218 (poll(&pfd, 1, -1) < 0))
221 /* copy the tx frame data */
222 pbuf = (uint8_t *) ppd + TPACKET2_HDRLEN -
223 sizeof(struct sockaddr_ll);
224 memcpy(pbuf, rte_pktmbuf_mtod(mbuf, void*), rte_pktmbuf_data_len(mbuf));
225 ppd->tp_len = ppd->tp_snaplen = rte_pktmbuf_data_len(mbuf);
227 /* release incoming frame and advance ring buffer */
228 ppd->tp_status = TP_STATUS_SEND_REQUEST;
229 if (++framenum >= framecount)
231 ppd = (struct tpacket2_hdr *) pkt_q->rd[framenum].iov_base;
234 num_tx_bytes += mbuf->pkt_len;
235 rte_pktmbuf_free(mbuf);
238 /* kick-off transmits */
239 if (sendto(pkt_q->sockfd, NULL, 0, MSG_DONTWAIT, NULL, 0) == -1)
240 num_tx = 0; /* error sending -- no packets transmitted */
242 pkt_q->framenum = framenum;
243 pkt_q->tx_pkts += num_tx;
244 pkt_q->err_pkts += i - num_tx;
245 pkt_q->tx_bytes += num_tx_bytes;
250 eth_dev_start(struct rte_eth_dev *dev)
252 dev->data->dev_link.link_status = ETH_LINK_UP;
257 * This function gets called when the current port gets stopped.
260 eth_dev_stop(struct rte_eth_dev *dev)
264 struct pmd_internals *internals = dev->data->dev_private;
266 for (i = 0; i < internals->nb_queues; i++) {
267 sockfd = internals->rx_queue[i].sockfd;
270 sockfd = internals->tx_queue[i].sockfd;
275 dev->data->dev_link.link_status = ETH_LINK_DOWN;
279 eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
285 eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
287 struct pmd_internals *internals = dev->data->dev_private;
289 dev_info->if_index = internals->if_index;
290 dev_info->max_mac_addrs = 1;
291 dev_info->max_rx_pktlen = (uint32_t)ETH_FRAME_LEN;
292 dev_info->max_rx_queues = (uint16_t)internals->nb_queues;
293 dev_info->max_tx_queues = (uint16_t)internals->nb_queues;
294 dev_info->min_rx_bufsize = 0;
298 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
301 unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
302 unsigned long rx_bytes_total = 0, tx_bytes_total = 0;
303 const struct pmd_internals *internal = dev->data->dev_private;
305 imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ?
306 internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS);
307 for (i = 0; i < imax; i++) {
308 igb_stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts;
309 igb_stats->q_ibytes[i] = internal->rx_queue[i].rx_bytes;
310 rx_total += igb_stats->q_ipackets[i];
311 rx_bytes_total += igb_stats->q_ibytes[i];
314 imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ?
315 internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS);
316 for (i = 0; i < imax; i++) {
317 igb_stats->q_opackets[i] = internal->tx_queue[i].tx_pkts;
318 igb_stats->q_errors[i] = internal->tx_queue[i].err_pkts;
319 igb_stats->q_obytes[i] = internal->tx_queue[i].tx_bytes;
320 tx_total += igb_stats->q_opackets[i];
321 tx_err_total += igb_stats->q_errors[i];
322 tx_bytes_total += igb_stats->q_obytes[i];
325 igb_stats->ipackets = rx_total;
326 igb_stats->ibytes = rx_bytes_total;
327 igb_stats->opackets = tx_total;
328 igb_stats->oerrors = tx_err_total;
329 igb_stats->obytes = tx_bytes_total;
333 eth_stats_reset(struct rte_eth_dev *dev)
336 struct pmd_internals *internal = dev->data->dev_private;
338 for (i = 0; i < internal->nb_queues; i++) {
339 internal->rx_queue[i].rx_pkts = 0;
340 internal->rx_queue[i].rx_bytes = 0;
343 for (i = 0; i < internal->nb_queues; i++) {
344 internal->tx_queue[i].tx_pkts = 0;
345 internal->tx_queue[i].err_pkts = 0;
346 internal->tx_queue[i].tx_bytes = 0;
351 eth_dev_close(struct rte_eth_dev *dev __rte_unused)
356 eth_queue_release(void *q __rte_unused)
361 eth_link_update(struct rte_eth_dev *dev __rte_unused,
362 int wait_to_complete __rte_unused)
368 eth_rx_queue_setup(struct rte_eth_dev *dev,
369 uint16_t rx_queue_id,
370 uint16_t nb_rx_desc __rte_unused,
371 unsigned int socket_id __rte_unused,
372 const struct rte_eth_rxconf *rx_conf __rte_unused,
373 struct rte_mempool *mb_pool)
375 struct pmd_internals *internals = dev->data->dev_private;
376 struct pkt_rx_queue *pkt_q = &internals->rx_queue[rx_queue_id];
377 unsigned int buf_size, data_size;
379 pkt_q->mb_pool = mb_pool;
381 /* Now get the space available for data in the mbuf */
382 buf_size = rte_pktmbuf_data_room_size(pkt_q->mb_pool) -
383 RTE_PKTMBUF_HEADROOM;
384 data_size = internals->req.tp_frame_size;
385 data_size -= TPACKET2_HDRLEN - sizeof(struct sockaddr_ll);
387 if (data_size > buf_size) {
389 "%s: %d bytes will not fit in mbuf (%d bytes)\n",
390 dev->data->name, data_size, buf_size);
394 dev->data->rx_queues[rx_queue_id] = pkt_q;
395 pkt_q->in_port = dev->data->port_id;
401 eth_tx_queue_setup(struct rte_eth_dev *dev,
402 uint16_t tx_queue_id,
403 uint16_t nb_tx_desc __rte_unused,
404 unsigned int socket_id __rte_unused,
405 const struct rte_eth_txconf *tx_conf __rte_unused)
408 struct pmd_internals *internals = dev->data->dev_private;
410 dev->data->tx_queues[tx_queue_id] = &internals->tx_queue[tx_queue_id];
414 static const struct eth_dev_ops ops = {
415 .dev_start = eth_dev_start,
416 .dev_stop = eth_dev_stop,
417 .dev_close = eth_dev_close,
418 .dev_configure = eth_dev_configure,
419 .dev_infos_get = eth_dev_info,
420 .rx_queue_setup = eth_rx_queue_setup,
421 .tx_queue_setup = eth_tx_queue_setup,
422 .rx_queue_release = eth_queue_release,
423 .tx_queue_release = eth_queue_release,
424 .link_update = eth_link_update,
425 .stats_get = eth_stats_get,
426 .stats_reset = eth_stats_reset,
430 * Opens an AF_PACKET socket
433 open_packet_iface(const char *key __rte_unused,
434 const char *value __rte_unused,
437 int *sockfd = extra_args;
439 /* Open an AF_PACKET socket... */
440 *sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
442 RTE_LOG(ERR, PMD, "Could not open AF_PACKET socket\n");
449 static struct rte_vdev_driver pmd_af_packet_drv;
452 rte_pmd_init_internals(const char *name,
454 const unsigned nb_queues,
455 unsigned int blocksize,
456 unsigned int blockcnt,
457 unsigned int framesize,
458 unsigned int framecnt,
459 const unsigned numa_node,
460 struct pmd_internals **internals,
461 struct rte_eth_dev **eth_dev,
462 struct rte_kvargs *kvlist)
464 struct rte_eth_dev_data *data = NULL;
465 struct rte_kvargs_pair *pair = NULL;
469 struct sockaddr_ll sockaddr;
470 struct tpacket_req *req;
471 struct pkt_rx_queue *rx_queue;
472 struct pkt_tx_queue *tx_queue;
473 int rc, tpver, discard;
475 unsigned int i, q, rdsize;
476 int fanout_arg __rte_unused, bypass __rte_unused;
478 for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
479 pair = &kvlist->pairs[k_idx];
480 if (strstr(pair->key, ETH_AF_PACKET_IFACE_ARG) != NULL)
485 "%s: no interface specified for AF_PACKET ethdev\n",
491 "%s: creating AF_PACKET-backed ethdev on numa socket %u\n",
495 * now do all data allocation - for eth_dev structure, dummy pci driver
496 * and internal (private) data
498 data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
502 *internals = rte_zmalloc_socket(name, sizeof(**internals),
504 if (*internals == NULL)
507 for (q = 0; q < nb_queues; q++) {
508 (*internals)->rx_queue[q].map = MAP_FAILED;
509 (*internals)->tx_queue[q].map = MAP_FAILED;
512 req = &((*internals)->req);
514 req->tp_block_size = blocksize;
515 req->tp_block_nr = blockcnt;
516 req->tp_frame_size = framesize;
517 req->tp_frame_nr = framecnt;
519 ifnamelen = strlen(pair->value);
520 if (ifnamelen < sizeof(ifr.ifr_name)) {
521 memcpy(ifr.ifr_name, pair->value, ifnamelen);
522 ifr.ifr_name[ifnamelen] = '\0';
525 "%s: I/F name too long (%s)\n",
529 if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
531 "%s: ioctl failed (SIOCGIFINDEX)\n",
535 (*internals)->if_index = ifr.ifr_ifindex;
537 if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == -1) {
539 "%s: ioctl failed (SIOCGIFHWADDR)\n",
543 memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
545 memset(&sockaddr, 0, sizeof(sockaddr));
546 sockaddr.sll_family = AF_PACKET;
547 sockaddr.sll_protocol = htons(ETH_P_ALL);
548 sockaddr.sll_ifindex = (*internals)->if_index;
550 #if defined(PACKET_FANOUT)
551 fanout_arg = (getpid() ^ (*internals)->if_index) & 0xffff;
552 fanout_arg |= (PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG) << 16;
553 #if defined(PACKET_FANOUT_FLAG_ROLLOVER)
554 fanout_arg |= PACKET_FANOUT_FLAG_ROLLOVER << 16;
558 for (q = 0; q < nb_queues; q++) {
559 /* Open an AF_PACKET socket for this queue... */
560 qsockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
563 "%s: could not open AF_PACKET socket\n",
569 rc = setsockopt(qsockfd, SOL_PACKET, PACKET_VERSION,
570 &tpver, sizeof(tpver));
573 "%s: could not set PACKET_VERSION on AF_PACKET "
574 "socket for %s\n", name, pair->value);
579 rc = setsockopt(qsockfd, SOL_PACKET, PACKET_LOSS,
580 &discard, sizeof(discard));
583 "%s: could not set PACKET_LOSS on "
584 "AF_PACKET socket for %s\n", name, pair->value);
588 #if defined(PACKET_QDISC_BYPASS)
590 rc = setsockopt(qsockfd, SOL_PACKET, PACKET_QDISC_BYPASS,
591 &bypass, sizeof(bypass));
594 "%s: could not set PACKET_QDISC_BYPASS "
595 "on AF_PACKET socket for %s\n", name,
601 rc = setsockopt(qsockfd, SOL_PACKET, PACKET_RX_RING, req, sizeof(*req));
604 "%s: could not set PACKET_RX_RING on AF_PACKET "
605 "socket for %s\n", name, pair->value);
609 rc = setsockopt(qsockfd, SOL_PACKET, PACKET_TX_RING, req, sizeof(*req));
612 "%s: could not set PACKET_TX_RING on AF_PACKET "
613 "socket for %s\n", name, pair->value);
617 rx_queue = &((*internals)->rx_queue[q]);
618 rx_queue->framecount = req->tp_frame_nr;
620 rx_queue->map = mmap(NULL, 2 * req->tp_block_size * req->tp_block_nr,
621 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
623 if (rx_queue->map == MAP_FAILED) {
625 "%s: call to mmap failed on AF_PACKET socket for %s\n",
630 /* rdsize is same for both Tx and Rx */
631 rdsize = req->tp_frame_nr * sizeof(*(rx_queue->rd));
633 rx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node);
634 if (rx_queue->rd == NULL)
636 for (i = 0; i < req->tp_frame_nr; ++i) {
637 rx_queue->rd[i].iov_base = rx_queue->map + (i * framesize);
638 rx_queue->rd[i].iov_len = req->tp_frame_size;
640 rx_queue->sockfd = qsockfd;
642 tx_queue = &((*internals)->tx_queue[q]);
643 tx_queue->framecount = req->tp_frame_nr;
644 tx_queue->frame_data_size = req->tp_frame_size;
645 tx_queue->frame_data_size -= TPACKET2_HDRLEN -
646 sizeof(struct sockaddr_ll);
648 tx_queue->map = rx_queue->map + req->tp_block_size * req->tp_block_nr;
650 tx_queue->rd = rte_zmalloc_socket(name, rdsize, 0, numa_node);
651 if (tx_queue->rd == NULL)
653 for (i = 0; i < req->tp_frame_nr; ++i) {
654 tx_queue->rd[i].iov_base = tx_queue->map + (i * framesize);
655 tx_queue->rd[i].iov_len = req->tp_frame_size;
657 tx_queue->sockfd = qsockfd;
659 rc = bind(qsockfd, (const struct sockaddr*)&sockaddr, sizeof(sockaddr));
662 "%s: could not bind AF_PACKET socket to %s\n",
667 #if defined(PACKET_FANOUT)
668 rc = setsockopt(qsockfd, SOL_PACKET, PACKET_FANOUT,
669 &fanout_arg, sizeof(fanout_arg));
672 "%s: could not set PACKET_FANOUT on AF_PACKET socket "
673 "for %s\n", name, pair->value);
679 /* reserve an ethdev entry */
680 *eth_dev = rte_eth_dev_allocate(name);
681 if (*eth_dev == NULL)
685 * now put it all together
686 * - store queue data in internals,
687 * - store numa_node in eth_dev
688 * - point eth_dev_data to internals
689 * - and point eth_dev structure to new eth_dev_data structure
692 (*internals)->nb_queues = nb_queues;
694 data->dev_private = *internals;
695 data->port_id = (*eth_dev)->data->port_id;
696 data->nb_rx_queues = (uint16_t)nb_queues;
697 data->nb_tx_queues = (uint16_t)nb_queues;
698 data->dev_link = pmd_link;
699 data->mac_addrs = &(*internals)->eth_addr;
701 (*eth_dev)->data->name, strlen((*eth_dev)->data->name));
703 (*eth_dev)->data = data;
704 (*eth_dev)->dev_ops = &ops;
705 (*eth_dev)->driver = NULL;
706 (*eth_dev)->data->dev_flags = RTE_ETH_DEV_DETACHABLE;
707 (*eth_dev)->data->drv_name = pmd_af_packet_drv.driver.name;
708 (*eth_dev)->data->kdrv = RTE_KDRV_NONE;
709 (*eth_dev)->data->numa_node = numa_node;
716 for (q = 0; q < nb_queues; q++) {
717 munmap((*internals)->rx_queue[q].map,
718 2 * req->tp_block_size * req->tp_block_nr);
720 rte_free((*internals)->rx_queue[q].rd);
721 rte_free((*internals)->tx_queue[q].rd);
722 if (((*internals)->rx_queue[q].sockfd != 0) &&
723 ((*internals)->rx_queue[q].sockfd != qsockfd))
724 close((*internals)->rx_queue[q].sockfd);
726 rte_free(*internals);
733 rte_eth_from_packet(const char *name,
735 const unsigned numa_node,
736 struct rte_kvargs *kvlist)
738 struct pmd_internals *internals = NULL;
739 struct rte_eth_dev *eth_dev = NULL;
740 struct rte_kvargs_pair *pair = NULL;
742 unsigned int blockcount;
743 unsigned int blocksize = DFLT_BLOCK_SIZE;
744 unsigned int framesize = DFLT_FRAME_SIZE;
745 unsigned int framecount = DFLT_FRAME_COUNT;
746 unsigned int qpairs = 1;
748 /* do some parameter checking */
753 * Walk arguments for configurable settings
755 for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
756 pair = &kvlist->pairs[k_idx];
757 if (strstr(pair->key, ETH_AF_PACKET_NUM_Q_ARG) != NULL) {
758 qpairs = atoi(pair->value);
760 qpairs > RTE_PMD_AF_PACKET_MAX_RINGS) {
762 "%s: invalid qpairs value\n",
768 if (strstr(pair->key, ETH_AF_PACKET_BLOCKSIZE_ARG) != NULL) {
769 blocksize = atoi(pair->value);
772 "%s: invalid blocksize value\n",
778 if (strstr(pair->key, ETH_AF_PACKET_FRAMESIZE_ARG) != NULL) {
779 framesize = atoi(pair->value);
782 "%s: invalid framesize value\n",
788 if (strstr(pair->key, ETH_AF_PACKET_FRAMECOUNT_ARG) != NULL) {
789 framecount = atoi(pair->value);
792 "%s: invalid framecount value\n",
800 if (framesize > blocksize) {
802 "%s: AF_PACKET MMAP frame size exceeds block size!\n",
807 blockcount = framecount / (blocksize / framesize);
810 "%s: invalid AF_PACKET MMAP parameters\n", name);
814 RTE_LOG(INFO, PMD, "%s: AF_PACKET MMAP parameters:\n", name);
815 RTE_LOG(INFO, PMD, "%s:\tblock size %d\n", name, blocksize);
816 RTE_LOG(INFO, PMD, "%s:\tblock count %d\n", name, blockcount);
817 RTE_LOG(INFO, PMD, "%s:\tframe size %d\n", name, framesize);
818 RTE_LOG(INFO, PMD, "%s:\tframe count %d\n", name, framecount);
820 if (rte_pmd_init_internals(name, *sockfd, qpairs,
821 blocksize, blockcount,
822 framesize, framecount,
823 numa_node, &internals, ð_dev,
827 eth_dev->rx_pkt_burst = eth_af_packet_rx;
828 eth_dev->tx_pkt_burst = eth_af_packet_tx;
834 rte_pmd_af_packet_probe(const char *name, const char *params)
838 struct rte_kvargs *kvlist;
841 RTE_LOG(INFO, PMD, "Initializing pmd_af_packet for %s\n", name);
843 numa_node = rte_socket_id();
845 kvlist = rte_kvargs_parse(params, valid_arguments);
846 if (kvlist == NULL) {
852 * If iface argument is passed we open the NICs and use them for
855 if (rte_kvargs_count(kvlist, ETH_AF_PACKET_IFACE_ARG) == 1) {
857 ret = rte_kvargs_process(kvlist, ETH_AF_PACKET_IFACE_ARG,
858 &open_packet_iface, &sockfd);
863 ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist);
864 close(sockfd); /* no longer needed */
867 rte_kvargs_free(kvlist);
872 rte_pmd_af_packet_remove(const char *name)
874 struct rte_eth_dev *eth_dev = NULL;
875 struct pmd_internals *internals;
878 RTE_LOG(INFO, PMD, "Closing AF_PACKET ethdev on numa socket %u\n",
884 /* find the ethdev entry */
885 eth_dev = rte_eth_dev_allocated(name);
889 internals = eth_dev->data->dev_private;
890 for (q = 0; q < internals->nb_queues; q++) {
891 rte_free(internals->rx_queue[q].rd);
892 rte_free(internals->tx_queue[q].rd);
895 rte_free(eth_dev->data->dev_private);
896 rte_free(eth_dev->data);
898 rte_eth_dev_release_port(eth_dev);
903 static struct rte_vdev_driver pmd_af_packet_drv = {
904 .probe = rte_pmd_af_packet_probe,
905 .remove = rte_pmd_af_packet_remove,
908 RTE_PMD_REGISTER_VDEV(net_af_packet, pmd_af_packet_drv);
909 RTE_PMD_REGISTER_ALIAS(net_af_packet, eth_af_packet);
910 RTE_PMD_REGISTER_PARAM_STRING(net_af_packet,