ethdev: remove detachable device flag
[dpdk.git] / drivers / net / af_packet / rte_eth_af_packet.c
index 77536e8..c6b86a3 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
+#include <rte_ethdev_vdev.h>
 #include <rte_malloc.h>
 #include <rte_kvargs.h>
 #include <rte_vdev.h>
@@ -58,6 +59,7 @@
 #define ETH_AF_PACKET_BLOCKSIZE_ARG    "blocksz"
 #define ETH_AF_PACKET_FRAMESIZE_ARG    "framesz"
 #define ETH_AF_PACKET_FRAMECOUNT_ARG   "framecnt"
+#define ETH_AF_PACKET_QDISC_BYPASS_ARG "qdisc_bypass"
 
 #define DFLT_BLOCK_SIZE                (1 << 12)
 #define DFLT_FRAME_SIZE                (1 << 11)
@@ -74,7 +76,7 @@ struct pkt_rx_queue {
        unsigned int framenum;
 
        struct rte_mempool *mb_pool;
-       uint8_t in_port;
+       uint16_t in_port;
 
        volatile unsigned long rx_pkts;
        volatile unsigned long err_pkts;
@@ -114,6 +116,7 @@ static const char *valid_arguments[] = {
        ETH_AF_PACKET_BLOCKSIZE_ARG,
        ETH_AF_PACKET_FRAMESIZE_ARG,
        ETH_AF_PACKET_FRAMECOUNT_ARG,
+       ETH_AF_PACKET_QDISC_BYPASS_ARG,
        NULL
 };
 
@@ -215,7 +218,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
                mbuf = *bufs++;
 
                /* drop oversized packets */
-               if (rte_pktmbuf_data_len(mbuf) > pkt_q->frame_data_size) {
+               if (mbuf->pkt_len > pkt_q->frame_data_size) {
                        rte_pktmbuf_free(mbuf);
                        continue;
                }
@@ -236,8 +239,17 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
                /* copy the tx frame data */
                pbuf = (uint8_t *) ppd + TPACKET2_HDRLEN -
                        sizeof(struct sockaddr_ll);
-               memcpy(pbuf, rte_pktmbuf_mtod(mbuf, void*), rte_pktmbuf_data_len(mbuf));
-               ppd->tp_len = ppd->tp_snaplen = rte_pktmbuf_data_len(mbuf);
+
+               struct rte_mbuf *tmp_mbuf = mbuf;
+               while (tmp_mbuf) {
+                       uint16_t data_len = rte_pktmbuf_data_len(tmp_mbuf);
+                       memcpy(pbuf, rte_pktmbuf_mtod(tmp_mbuf, void*), data_len);
+                       pbuf += data_len;
+                       tmp_mbuf = tmp_mbuf->next;
+               }
+
+               ppd->tp_len = mbuf->pkt_len;
+               ppd->tp_snaplen = mbuf->pkt_len;
 
                /* release incoming frame and advance ring buffer */
                ppd->tp_status = TP_STATUS_SEND_REQUEST;
@@ -251,8 +263,11 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
        }
 
        /* kick-off transmits */
-       if (sendto(pkt_q->sockfd, NULL, 0, MSG_DONTWAIT, NULL, 0) == -1)
-               num_tx = 0; /* error sending -- no packets transmitted */
+       if (sendto(pkt_q->sockfd, NULL, 0, MSG_DONTWAIT, NULL, 0) == -1) {
+               /* error sending -- no packets transmitted */
+               num_tx = 0;
+               num_tx_bytes = 0;
+       }
 
        pkt_q->framenum = framenum;
        pkt_q->tx_pkts += num_tx;
@@ -316,7 +331,7 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->min_rx_bufsize = 0;
 }
 
-static void
+static int
 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 {
        unsigned i, imax;
@@ -349,6 +364,7 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
        igb_stats->opackets = tx_total;
        igb_stats->oerrors = tx_err_total;
        igb_stats->obytes = tx_bytes_total;
+       return 0;
 }
 
 static void
@@ -409,7 +425,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
        if (data_size > buf_size) {
                RTE_LOG(ERR, PMD,
                        "%s: %d bytes will not fit in mbuf (%d bytes)\n",
-                       dev->data->name, data_size, buf_size);
+                       dev->device->name, data_size, buf_size);
                return -ENOMEM;
        }
 
@@ -451,7 +467,7 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        if (s < 0)
                return -EINVAL;
 
-       strncpy(ifr.ifr_name, internals->if_name, IFNAMSIZ);
+       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", internals->if_name);
        ret = ioctl(s, SIOCSIFMTU, &ifr);
        close(s);
 
@@ -471,7 +487,7 @@ eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
        if (s < 0)
                return;
 
-       strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+       snprintf(ifr.ifr_name, IFNAMSIZ, "%s", if_name);
        if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
                goto out;
        ifr.ifr_flags &= mask;
@@ -539,18 +555,20 @@ open_packet_iface(const char *key __rte_unused,
 static struct rte_vdev_driver pmd_af_packet_drv;
 
 static int
-rte_pmd_init_internals(const char *name,
+rte_pmd_init_internals(struct rte_vdev_device *dev,
                        const int sockfd,
                        const unsigned nb_queues,
                        unsigned int blocksize,
                        unsigned int blockcnt,
                        unsigned int framesize,
                        unsigned int framecnt,
-                       const unsigned numa_node,
+                      unsigned int qdisc_bypass,
                        struct pmd_internals **internals,
                        struct rte_eth_dev **eth_dev,
                        struct rte_kvargs *kvlist)
 {
+       const char *name = rte_vdev_device_name(dev);
+       const unsigned int numa_node = dev->device.numa_node;
        struct rte_eth_dev_data *data = NULL;
        struct rte_kvargs_pair *pair = NULL;
        struct ifreq ifr;
@@ -563,7 +581,9 @@ rte_pmd_init_internals(const char *name,
        int rc, tpver, discard;
        int qsockfd = -1;
        unsigned int i, q, rdsize;
-       int fanout_arg __rte_unused, bypass __rte_unused;
+#if defined(PACKET_FANOUT)
+       int fanout_arg;
+#endif
 
        for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
                pair = &kvlist->pairs[k_idx];
@@ -623,6 +643,8 @@ rte_pmd_init_internals(const char *name,
                goto error_early;
        }
        (*internals)->if_name = strdup(pair->value);
+       if ((*internals)->if_name == NULL)
+               goto error_early;
        (*internals)->if_index = ifr.ifr_ifindex;
 
        if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == -1) {
@@ -677,9 +699,8 @@ rte_pmd_init_internals(const char *name,
                }
 
 #if defined(PACKET_QDISC_BYPASS)
-               bypass = 1;
                rc = setsockopt(qsockfd, SOL_PACKET, PACKET_QDISC_BYPASS,
-                               &bypass, sizeof(bypass));
+                               &qdisc_bypass, sizeof(qdisc_bypass));
                if (rc == -1) {
                        RTE_LOG(ERR, PMD,
                                "%s: could not set PACKET_QDISC_BYPASS "
@@ -687,6 +708,8 @@ rte_pmd_init_internals(const char *name,
                                pair->value);
                        goto error;
                }
+#else
+               RTE_SET_USED(qdisc_bypass);
 #endif
 
                rc = setsockopt(qsockfd, SOL_PACKET, PACKET_RX_RING, req, sizeof(*req));
@@ -768,7 +791,7 @@ rte_pmd_init_internals(const char *name,
        }
 
        /* reserve an ethdev entry */
-       *eth_dev = rte_eth_dev_allocate(name);
+       *eth_dev = rte_eth_vdev_allocate(dev, 0);
        if (*eth_dev == NULL)
                goto error;
 
@@ -782,22 +805,15 @@ rte_pmd_init_internals(const char *name,
 
        (*internals)->nb_queues = nb_queues;
 
+       rte_memcpy(data, (*eth_dev)->data, sizeof(*data));
        data->dev_private = *internals;
-       data->port_id = (*eth_dev)->data->port_id;
        data->nb_rx_queues = (uint16_t)nb_queues;
        data->nb_tx_queues = (uint16_t)nb_queues;
        data->dev_link = pmd_link;
        data->mac_addrs = &(*internals)->eth_addr;
-       strncpy(data->name,
-               (*eth_dev)->data->name, strlen((*eth_dev)->data->name));
 
        (*eth_dev)->data = data;
        (*eth_dev)->dev_ops = &ops;
-       (*eth_dev)->driver = NULL;
-       (*eth_dev)->data->dev_flags = RTE_ETH_DEV_DETACHABLE;
-       (*eth_dev)->data->drv_name = pmd_af_packet_drv.driver.name;
-       (*eth_dev)->data->kdrv = RTE_KDRV_NONE;
-       (*eth_dev)->data->numa_node = numa_node;
 
        return 0;
 
@@ -822,11 +838,11 @@ error_early:
 }
 
 static int
-rte_eth_from_packet(const char *name,
+rte_eth_from_packet(struct rte_vdev_device *dev,
                     int const *sockfd,
-                    const unsigned numa_node,
                     struct rte_kvargs *kvlist)
 {
+       const char *name = rte_vdev_device_name(dev);
        struct pmd_internals *internals = NULL;
        struct rte_eth_dev *eth_dev = NULL;
        struct rte_kvargs_pair *pair = NULL;
@@ -836,6 +852,7 @@ rte_eth_from_packet(const char *name,
        unsigned int framesize = DFLT_FRAME_SIZE;
        unsigned int framecount = DFLT_FRAME_COUNT;
        unsigned int qpairs = 1;
+       unsigned int qdisc_bypass = 1;
 
        /* do some parameter checking */
        if (*sockfd < 0)
@@ -887,6 +904,16 @@ rte_eth_from_packet(const char *name,
                        }
                        continue;
                }
+               if (strstr(pair->key, ETH_AF_PACKET_QDISC_BYPASS_ARG) != NULL) {
+                       qdisc_bypass = atoi(pair->value);
+                       if (qdisc_bypass > 1) {
+                               RTE_LOG(ERR, PMD,
+                                       "%s: invalid bypass value\n",
+                                       name);
+                               return -1;
+                       }
+                       continue;
+               }
        }
 
        if (framesize > blocksize) {
@@ -909,11 +936,12 @@ rte_eth_from_packet(const char *name,
        RTE_LOG(INFO, PMD, "%s:\tframe size %d\n", name, framesize);
        RTE_LOG(INFO, PMD, "%s:\tframe count %d\n", name, framecount);
 
-       if (rte_pmd_init_internals(name, *sockfd, qpairs,
-                                  blocksize, blockcount,
-                                  framesize, framecount,
-                                  numa_node, &internals, &eth_dev,
-                                  kvlist) < 0)
+       if (rte_pmd_init_internals(dev, *sockfd, qpairs,
+                                  blocksize, blockcount,
+                                  framesize, framecount,
+                                  qdisc_bypass,
+                                  &internals, &eth_dev,
+                                  kvlist) < 0)
                return -1;
 
        eth_dev->rx_pkt_burst = eth_af_packet_rx;
@@ -925,15 +953,12 @@ rte_eth_from_packet(const char *name,
 static int
 rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
 {
-       const char *name = rte_vdev_device_name(dev);
-       unsigned numa_node;
        int ret = 0;
        struct rte_kvargs *kvlist;
        int sockfd = -1;
 
-       RTE_LOG(INFO, PMD, "Initializing pmd_af_packet for %s\n", name);
-
-       numa_node = rte_socket_id();
+       RTE_LOG(INFO, PMD, "Initializing pmd_af_packet for %s\n",
+               rte_vdev_device_name(dev));
 
        kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
        if (kvlist == NULL) {
@@ -953,7 +978,10 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
                        goto exit;
        }
 
-       ret = rte_eth_from_packet(name, &sockfd, numa_node, kvlist);
+       if (dev->device.numa_node == SOCKET_ID_ANY)
+               dev->device.numa_node = rte_socket_id();
+
+       ret = rte_eth_from_packet(dev, &sockfd, kvlist);
        close(sockfd); /* no longer needed */
 
 exit:
@@ -1006,4 +1034,5 @@ RTE_PMD_REGISTER_PARAM_STRING(net_af_packet,
        "qpairs=<int> "
        "blocksz=<int> "
        "framesz=<int> "
-       "framecnt=<int>");
+       "framecnt=<int> "
+       "qdisc_bypass=<0|1>");